From: kilian (dks-laptop) Date: Sat, 2 Nov 2019 07:27:54 +0000 (+0100) Subject: v20191031 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=c701915302993d7ae7e4cf463366e481e56f43f7;p=hourtrax.git v20191031 --- diff --git a/CGI/api/db.cgi b/CGI/api/db.cgi index a69e00b..3a6a3e9 100755 --- a/CGI/api/db.cgi +++ b/CGI/api/db.cgi @@ -34,7 +34,8 @@ if ($sitecfg->{dbtype} eq "SQLite"){ $dbredirect->{dsn} = "DBI:SQLite:dbname=".$sitecfg->{datapath}.'/'.$p->{db}.'.sqlite'; } } -$html->{conn} = $dbredirect; +#if () +#$html->{conn} = $dbredirect; # if ($sess == undef){ # $html->{error} = "No Authorisation"; # print JSON::PP::encode_json($html); diff --git a/CGI/api/lib/dksconfig.pm b/CGI/api/lib/dksconfig.pm index fba0eb5..e35669d 100755 --- a/CGI/api/lib/dksconfig.pm +++ b/CGI/api/lib/dksconfig.pm @@ -7,14 +7,12 @@ use strict; use File::Basename; use Exporter 'import'; our @EXPORT_OK = qw($sitecfg); -my $cfgpath='dks'; +my $cfgpath=$ENV{HOME}.'/.hourtrax'; if ($^O eq "MSWin32"){ - $cfgpath = $ENV{APPDATA}.'/dks'; + $cfgpath = $ENV{APPDATA}.'/hourtrax'; } elsif ($^O eq "darwin"){ - $cfgpath = $ENV{HOME}.'/.dks'; -} else { - $cfgpath = $ENV{HOME}.'/.dks'; -} + $cfgpath = $ENV{HOME}.'/Library/Application Support/hourtrax'; +} $cfgpath =~ s/\\/\//g; our $sitecfg ={ #cookiename => undef, diff --git a/CGI/api/service.cgi b/CGI/api/service.cgi index 7e2156f..1e019e6 100644 --- a/CGI/api/service.cgi +++ b/CGI/api/service.cgi @@ -12,6 +12,7 @@ use File::Basename; use JSON::PP; use dksconfig qw/$sitecfg/; use dksdb; +use Digest::SHA::PurePerl qw(sha256_hex); # use session; #use sendemail; @@ -143,7 +144,7 @@ sub getWebLogin(){ my $apppath = &getappconfigpath(); my $loginname= ""; - print "read:". $apppath.'/'.&getAppName().'.passwd'."\n"; + #print "read:". $apppath.'/'.&getAppName().'.passwd'."\n"; if (-e $apppath.'/'.&getAppName().'.passwd'){ open(AUTH,$apppath.'/'.&getAppName().'.passwd'); while (my $l = ){ diff --git a/CGI/tmpl/app/timeclock/index.js b/CGI/tmpl/app/timeclock/index.js index 70fc74a..1f9310f 100644 --- a/CGI/tmpl/app/timeclock/index.js +++ b/CGI/tmpl/app/timeclock/index.js @@ -50,7 +50,10 @@ function displaypanel(){ stopCheckIdle(); } console.log("Current Panel:" + currentpanel); - document.getElementById("pnl_" + currentpanel).style.display = 'block'; + if (currentpanel){ + document.getElementById("pnl_" + currentpanel).style.display = 'block'; + } + return false; } @@ -184,10 +187,10 @@ function loadtrackdata(data){ var cdate = new Date().toISOString().substring(0,10); document.getElementById("btntrackin").disabled = true; document.getElementById("btntrackout").disabled = true; - console.log(cdate + "<=>" + data[0].cmpdaydate); - if (data && data[0]){ + //console.log(cdate + "<=>" + data[0].cmpdaydate); + if (data && data[0] && data.length > 0){ lasttrack=data[0]; - if (data[0].cmpdaydate == cdate){ + if (data[0].cmpdaydate && (data[0].cmpdaydate == cdate)){ console.log("IN:" + data[0].stamp_in); console.log("out:" + data[0].stamp_out); if ((data[0].stamp_in != null) && (data[0].stamp_out != null)){ @@ -199,7 +202,7 @@ function loadtrackdata(data){ document.getElementById("btntrackin").disabled = false; } // - document.getElementById("lasttrack").innerHTML = "Dernier Pointage: " + ((data[0].daydate)?data[0].daydate:"") + " "+ ((data[0].stamp_in)?" Entrée:" + data[0].stamp_in:"") + " Sortie: " +((data[0].stamp_out)? + data[0].stamp_out:"N/A") + ""; + document.getElementById("lasttrack").innerHTML = "Dernier Pointage:
" + ((data[0].daydate)?data[0].daydate:"") + " "+ ((data[0].stamp_in)?" Entrée:" + data[0].stamp_in:"N/A") + " Sortie: " +((data[0].stamp_out)?data[0].stamp_out:"N/A") + ""; } else { lasttrack = null; document.getElementById("btntrackin").disabled = false; @@ -255,9 +258,9 @@ function setTrack(direction){ var sql = ""; //intervaltime = 60; if (direction == 'in'){ - sql = "INSERT INTO hours (id_staff, stamp_in,daydate ) VALUES ("+currentuser.id+",CURRENT_TIMESTAMP,CURRENT_DATE);"; + sql = "INSERT INTO hours (id_staff, stamp_in) VALUES ("+currentuser.id+",CURRENT_TIMESTAMP);"; } else if (direction == 'out'){ - sql = "UPDATE hours SET stamp_out=CURRENT_TIMESTAMP where id_staff='"+ currentuser.userid+"' and id='"+lasttrack.id+"';"; + sql = "UPDATE hours SET stamp_out=CURRENT_TIMESTAMP where id_staff='"+ currentuser.id+"' and id='"+lasttrack.id+"';"; } //console.log(sql); req.reqdata("POST","db.cgi",{"sql":sql},showstatus); diff --git a/CGI/tmpl/app/timeclock/login.js b/CGI/tmpl/app/timeclock/login.js deleted file mode 100644 index 2687bab..0000000 --- a/CGI/tmpl/app/timeclock/login.js +++ /dev/null @@ -1,154 +0,0 @@ -var login = { - userid: null, - pinfield: null, - gotoLogin: function (btn){ - document.getElementById("reload").style.visibility = 'visible'; - document.getElementById("mnuviews").style.visibility = 'hidden'; - login.pinfield = 'pincode'; - console.log(typeof(btn)); - console.log(btn); - app.intervaltime = 60; - - if (typeof(btn) == "object"){ - if (btn){ - console.log(btn); - document.getElementById("pinmessage").innerHTML = ''; - document.getElementById('pincode').value = ''; - document.getElementById("usergreeting1").innerHTML ="Bonjour " + btn.dataset.prename + ", entrez votre code pin:"; - login.userid= btn.dataset.id; - } else { - login.userid= btn.dataset.id; - document.getElementById("usergreeting1").innerHTML="Bonjour " + btn.getAttribute('data-prename') + ", Entrez votre code pin:"; - document.getElementById("pinmessage").innerHTML = ''; - app.startCheckIdle(); - } - - } else if ((typeof(btn) == "string") && (btn == 'notpasswd')) { - document.getElementById("usergreeting1").innerHTML ="Bonjour " + document.getElementById("btn_user_" + login.userid).dataset.prename + ", entrez votre code pin:"; - - } - app.showscreen('scruserpin'); - }, - gotoNewLogin: function (btn){ - document.getElementById("reload").style.visibility = 'visible'; - document.getElementById("mnuviews").style.visibility = 'hidden'; - console.log("New Login!"); - console.log(btn); - app.intervaltime = 60; - if (btn != null){ - login.userid= btn.getAttribute('data-id'); - document.getElementById("usergreeting2").innerHTML="Bonjour, " + btn.getAttribute('data-prename') + "! Entrez votre nouveau code pin:"; - app.startCheckIdle(); - } - - login.pinfield = "newpincode1"; - document.getElementById("newpincode1").value = ""; - document.getElementById("newpincode2").value = ""; - document.getElementById("pinmessage2").innerHTML = ''; - app.showscreen('scrnewuserpin'); - - }, - gotoUsers: function(){ - var sqlq = "select id,prename,surname,case when pin is null then 'nopin' else null end as haspin, case when blocked is not null then 'blocked' else null end as isblocked from staff st left join (select id_staff,max(startdate) as startdate from contract where startdate <= CURRENT_DATE group by id_staff) co on (st.id=co.id_staff);"; - req.reqdata("POST","db.cgi",{"sql":sqlq},login.loadUsers); - - }, - setPin:function (key){ - app.intervaltime = 60; - if (key == 'COR'){ - document.getElementById('pincode').value = ''; - document.getElementById('newpincode1').value = ''; - document.getElementById('newpincode2').value = ''; - if (login.pinfield == "newpincode2"){ - login.pinfield = "newpincode1"; - } - document.getElementById("pinmessage").innerHTML = ''; - document.getElementById("pinmessage2").innerHTML = ''; - } else if (key == 'OK'){ - if (login.pinfield == 'pincode'){ - app.showscreen('scrloader'); - //var xa = {"type":"querysorted","sql":"select id from staff where id='"+login.userid+"' and pin='"+document.getElementById("pincode").value+"';"}; - req.reqdata("POST","db.cgi",{"sql":"select id from staff where id='"+login.userid+"' and pin='"+document.getElementById("pincode").value+"';"},login.getAccess); - - } else if (login.pinfield == 'newpincode1'){ - login.pinfield = 'newpincode2'; - } else if (login.pinfield == 'newpincode2'){ - var pin1 = document.getElementById("newpincode1").value; - var pin2 = document.getElementById("newpincode2").value; - if ((pin1.length < 4) || (pin2.length < 4)){ - document.getElementById("pinmessage2").innerHTML = 'minimum 4 nombre requis!'; - } - else if (pin1 != pin2){ - document.getElementById("pinmessage2").innerHTML = 'les codes pin sont pas identiques!'; - } else { - app.showscreen('scrloader'); - //var xa = {"type":"exec",; - req.reqdata("POST","db.cgi",{"db":"hourtrax","type":"exec","sql":"UPDATE staff SET pin='"+ pin1 +"' WHERE id='"+login.userid+"';"},login.gotoLogin); - - } - } - - } else { - //console.log("Add number " + key); - var cobj = document.getElementById(login.pinfield); - var cpin = cobj.value; - - cobj.value = cpin + key; - } - }, - getAccess: function(data){ - app.intervaltime = 60; - console.log(data); - console.log('getAccess'); - if ((data) && (data[0])){ - - req.reqdata("POST","db.cgi",{"sql":"update staff set loginattemps=null where id='"+login.userid+"';"},null) - - // console.log("Access OK!") - // if (ret){ - var xq = "select last_id, case when current_stamp_in is not null then strftime('%d.%m.%Y
%H:%M',current_stamp_in) else null end as current_stamp_in, case when current_stamp_out is not null then strftime('%d.%m.%Y
%H:%M',current_stamp_out) else null end as current_stamp_out,cast((daytrack / 3600.0) as integer) || ':' || case when cast(((daytrack % 3600.0) / 60.0) as integer) < 10 then '0' else '' end || cast(((daytrack % 3600.0) / 60.0) as integer) as monthtrack from (select max(id) as last_id, case when date(max(stamp_in)) = CURRENT_DATE then max(stamp_in) else null end as current_stamp_in,case when date(max(stamp_out)) = CURRENT_DATE then max(stamp_out) else null end as current_stamp_out,sum(case when stamp_out is not null then cast(strftime('%s',stamp_out) as integer) - cast(strftime('%s',stamp_in) as integer) else 0 end) as daytrack from hours where id_staff='"+ login.userid+"' and stamp_in between date('now','start of month') and date('now','start of month','+1 month','-1 day'));"; - req.reqdata("POST","db.cgi",{"sql":xq},track.loadtrackscreen); - - // } - } else { - //var xa = {"type":"exec","sql":"update staff set loginattemps=(select case when max(loginattemps) is null then 1 else loginattemps+1 end as newattemps from staff where id='"+login.userid+"') where id='"+login.userid+'";'}; - req.reqdata("POST","db.cgi",{"sql":"update staff set loginattemps=(select case when max(loginattemps) is null then 1 else loginattemps+1 end as newattemps from staff where id='"+login.userid+"') where id='"+login.userid+'";'},null); - - document.getElementById("pinmessage").innerHTML = 'code pin pas correcte!'; - login.gotoLogin('notpassed'); - } - - //console.log(data); -// if(login.curpincode == '1234'){ -// -// } else { -// login.curpincode = ''; -// login.pinenc = ''; -// document.getElementById("pincode").innerHTML = login.pinenc; -// document.getElementById("pinmessage").innerHTML = 'Code pas correcte'; -// } - }, - loadUsers: function(data){ - document.getElementById("reload").style.visibility = 'hidden'; - document.getElementById("mnuviews").style.visibility = 'hidden'; - var ulist = document.getElementById("scruserlist"); - ulist.innerHTML = ''; - console.log('loadUsers'); - console.log( data); - if (data != null){ - var btns = ''; - for (var i in data){ - console.log(i); - var disabled = ";" - if (data[i].isblocked != null){ - diabled='disabled="1"'; - } - btns += ''; - } - ulist.innerHTML = btns; - } - app.stopCheckIdle(); - app.showscreen('scruserlist'); - } -} - diff --git a/CGI/tmpl/app/timeclock/oldindex.js b/CGI/tmpl/app/timeclock/oldindex.js deleted file mode 100644 index c0b6876..0000000 --- a/CGI/tmpl/app/timeclock/oldindex.js +++ /dev/null @@ -1,34 +0,0 @@ -var app={ - interval: null, - intervaltime: 60, - currentscreen: 'scrloader', - showscreen: function screen(screenid){ - //console.log("old screen:" + app.currentscreen); - document.getElementById(app.currentscreen).style.display = 'none'; - document.getElementById(screenid).style.display = 'block'; - app.currentscreen = screenid; - //console.log("new screen:" + app.currentscreen); - }, - checkIdle: function(){ - if (app.intervaltime < 0){ - location.href = "clock.html"; - } else { - app.intervaltime = app.intervaltime - 1; - } - }, - startCheckIdle: function(){ - window.setInterval(app.checkIdle(),1000); - - }, - stopCheckIdle: function(){ - window.clearInterval(app.interval); - }, - database: 'hourtrax' - -} - -window.onload = function() { - //console.log('window - onload'); - login.gotoUsers(); -}; - diff --git a/CGI/tmpl/app/timeclock/oldindex.tt b/CGI/tmpl/app/timeclock/oldindex.tt deleted file mode 100644 index 4332da5..0000000 --- a/CGI/tmpl/app/timeclock/oldindex.tt +++ /dev/null @@ -1,96 +0,0 @@ -[% USE date %] -[% vstamp=date.format(date.now, '%d%m%Y%H%M%S') %] - - - - -DKS Hourtrax - - - - - - - - - -
-

HourTrax  

-   -
-   -   -
- -
-
- -
-
-
Bonjour Prename,
-
-
-
- - - - - - - - - - - - -
-
-
-
Bonjour Prename,
-
-
-
- - - - - - - - - - - - -
-
-
-
Prénom Nom
-
Total heures mois courrant: 00:00 h
-
- -
-
-
- - - -
-
- -
- -
- - - - - - - - - - - \ No newline at end of file diff --git a/CGI/tmpl/app/timeclock/track.js b/CGI/tmpl/app/timeclock/track.js deleted file mode 100644 index 3a21f44..0000000 --- a/CGI/tmpl/app/timeclock/track.js +++ /dev/null @@ -1,58 +0,0 @@ -var track = { - trackid: null, - setTrack: function(type){ - app.showscreen('scrloader'); - console.log(type); - var tracksql = ""; - if (type == 'in'){ - tracksql = "insert into hours (id_staff,stamp_in) VALUES ('"+ login.userid+"',CURRENT_TIMESTAMP);"; - } else if (type == 'out'){ - tracksql = "update hours set stamp_out=CURRENT_TIMESTAMP where id_staff='"+ login.userid+"' and id='"+track.trackid+"';"; - } - //var xt = {"type":"exec","sql":tracksql}; - console.log("TRACK SQL: " + tracksql); - req.reqdata("POST","db.cgi",{"sql":tracksql},track.loadsuccessscreen); - }, - loadtrackscreen: function(data){ - - console.log('loadtrackscreen'); - document.getElementById("mnuviews").style.visibility = 'visible'; - console.log(data); - if (data) { - var btn=document.getElementById("btn_user_" + login.userid); - document.getElementById("usergreeting3").innerHTML = btn.getAttribute("data-prename") + " " + btn.getAttribute("data-surname"); - document.getElementById("monthhours").innerHTML = data[0].monthtrack + "h"; - document.getElementById("btntrackin").setAttribute("disabled",false); - document.getElementById("btntrackout").setAttribute("disabled",false); - document.getElementById("lasttrackin").innerHTML = ' 
 '; - document.getElementById("lasttrackout").innerHTML = ' 
 '; - track.trackid = data[0].last_id; - if (data[0].current_stamp_in != null){ - document.getElementById("lasttrackin").innerHTML = data[0].current_stamp_in; - } - if (data[0].current_stamp_out != null){ - document.getElementById("lasttrackout").innerHTML = data[0].current_stamp_out; - } - if ((data[0].current_stamp_in == null) && (data[0].current_stamp_out == null)){ - document.getElementById("btntrackin").removeAttribute("disabled"); - } else if ((data[0].current_stamp_in != null) && (data[0].current_stamp_out == null)){ - document.getElementById("btntrackout").removeAttribute("disabled"); - } else if ((data[0].current_stamp_in != null) && (data[0].current_stamp_out != null)) { - if (data[0].current_stamp_in > data[0].current_stamp_out){ - document.getElementById("btntrackout").removeAttribute("disabled"); - } else { - document.getElementById("btntrackin").removeAttribute("disabled"); - } - } - } - //document.getElementById("usergreeting3").value = "" - app.showscreen('scrtimetracker'); - }, - loadsuccessscreen: function(data){ - console.log(data); - document.getElementById("statusmsg").innerHTML = "L'heure est enregistré"; - app.showscreen('scrstatus'); - track.trackid = null; - setTimeout("parent.admin.loadapp('timeclock');",3000); - } -} \ No newline at end of file diff --git a/app/main.js b/app/main.js index f347ba9..6e7b96f 100644 --- a/app/main.js +++ b/app/main.js @@ -25,8 +25,8 @@ function createWindow () { console.log("new windows"); win = new BrowserWindow({show: true, width: 800, height: 470,frame: false, WebPreferences: {sandbox: true}}) win.setMenu(null) - //win.maximize() - //win.setFullScreen(true) + win.maximize() + win.setFullScreen(true) // child(executablePath, parameters, function(err, data) { // if(err){ // console.error('stderr',err); @@ -49,9 +49,9 @@ function createWindow () { // and load the index.html of the app. win.loadURL(myurl) - console.log("Test load URL") + //console.log("Test load URL") // Open the DevTools. - win.webContents.openDevTools({ mode: 'detach' }); + //win.webContents.openDevTools({ mode: 'detach' }); // Emitted when the window is closed. win.on('closed', () => { diff --git a/data/hourtrax.sqlite b/data/hourtrax.sqlite index 1c6e151..9d88355 100644 Binary files a/data/hourtrax.sqlite and b/data/hourtrax.sqlite differ diff --git a/hourtrax.pl b/hourtrax.pl index 465bd6e..5303bda 100644 --- a/hourtrax.pl +++ b/hourtrax.pl @@ -15,6 +15,7 @@ use Plack::Middleware::Auth::Basic; use Plack::Middleware::DirIndex; use Plack::Request; use Plack::Runner; +use Digest::SHA::PurePerl qw(sha256_hex); #use Module::Service; #use Module::Test; # use Module::SQLite; @@ -23,24 +24,29 @@ use Plack::Runner; print $^O."\n"; print $RealBin."\n"; -my $datadir = $RealBin.'/data'; +my $datadir=$ENV{HOME}.'/.hourtrax'; +if ($^O eq "MSWin32"){ + $datadir = $ENV{APPDATA}.'/hourtrax'; +} elsif ($^O eq "darwin"){ + $datadir = $ENV{HOME}.'/Library/Application Support/hourtrax'; +} #my $webdir = dirname($RealBin).'/web'; print "Datadir:".$datadir."\n"; my @match = grep { /par-.*inc$/} @INC; -# if ($^O ne "MSWin32"){ -# use POSIX qw(setsid); -# open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; -# open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; -# open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!"; +if ($^O ne "MSWin32"){ + use POSIX qw(setsid); + #open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + # open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; + # open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!"; -# die "cannot start process $!" unless defined (my $child = fork); -# exit 0 if $child; -# setsid() or die "cannot start new session $!"; -# chdir('/'); -# umask(0); -# system("echo ".$$." > /home/dks/data/hourtrax.pid"); -# } + die "cannot start process $!" unless defined (my $child = fork); + exit 0 if $child; + setsid() or die "cannot start new session $!"; + chdir('/'); + umask(0); + system("echo ".$$." > ".$datadir."/hourtrax.pid"); +} my $basedir = dirname($0); if (scalar(@match) > 0){ @@ -48,27 +54,20 @@ if (scalar(@match) > 0){ } my $cfgpath = ""; -#print "BASEDIR:".$basedir."\n"; - - -# sub version { -# require Twiggy; -# print "Twiggy $Twiggy::VERSION\n"; -# } -my $name = basename($0); -$name =~ s/srv\.pl$//; -$name =~ s/srv\.exe$//; -$name = lc($name); +# my $name = basename($0); +# $name =~ s/srv\.pl$//; +# $name =~ s/srv\.exe$//; +# $name = lc($name); sub authen_cb { my($username, $password, $env) = @_; my $auth = 0; #print "Check AUTH\n"; - if (-e $datadir.'/'.$name.'.passwd'){ - open(AUTH,$datadir.'/'.$name.'.passwd'); + if (-e $datadir.'/auth.passwd'){ + open(AUTH,$datadir.'/auth.passwd'); while (my $l = ){ chomp($l); if ($l eq $username.'='.$password){ @@ -83,22 +82,26 @@ sub authen_cb { my $allapp = builder { - enable_if { $_[0]->{REMOTE_ADDR} ne 'localhost' && $_[0]->{REMOTE_ADDR} ne '127.0.0.1' } "Auth::Basic", authenticator => \&authen_cb; + #enable_if { $_[0]->{REMOTE_ADDR} ne 'localhost' && $_[0]->{REMOTE_ADDR} ne '127.0.0.1' } "Auth::Basic", authenticator => \&authen_cb; enable "Plack::Middleware::DirIndex", dir_index => 'index.html'; - mount "/" => Plack::App::WrapCGI->new(script => dirname($0)."/CGI/index.cgi")->to_app; + mount "/" => Plack::App::WrapCGI->new(script => $RealBin."/CGI/index.cgi")->to_app; - opendir(API,dirname($0)."/CGI/api"); + opendir(API,$RealBin."/CGI/api"); while (my $s = readdir(API)){ + chomp($s); + print $s."\n"; if ($s =~ /\.cgi$/){ - mount "/api/".$s => Plack::App::WrapCGI->new(script => dirname($0)."/CGI/api/".$s)->to_app; + print "Start /api/$s\n"; + mount "/api/".$s => Plack::App::WrapCGI->new(script => $RealBin."/CGI/api/".$s)->to_app; } } closedir(API); - mount "/htdocs" => Plack::App::File->new(root => dirname($0)."/htdocs")->to_app; + mount "/htdocs" => Plack::App::File->new(root => $RealBin."/htdocs")->to_app; }; -my @args = ("-p","6060","--error-log","error.log","--access-log","access.log"); +my @args = ("-p","6060"); +#,"--error-log",$datadir."/error.log","--access-log",$datadir."/access.log"); my $runner = Plack::Runner->new(server => 'Starlight', env => 'deployment', ipv6 => '1' );#env => development, test $runner->parse_options(@args); $runner->run($allapp);