LICENSE: AGPLv2
#
# CHANGELOG
# 80523-0134 - First Build
# 80524-0225 - Changed event_date to DATETIME, added timestamp field and tcid_link field
# 80525-2351 - Added an audit log that is not to be editable
# 80602-0641 - Fixed status update bug
# 90508-0727 - Changed to PHP long tags
# 100621-1023 - Added admin_web_directory variable
# 130328-0021 - Converted ereg to preg functions
# 130603-2211 - Added login lockout for 15 minutes after 10 failed logins, and other security fixes
# 130705-2010 - Added optional encrypted passwords compatibility
# 130802-1031 - Changed to PHP mysqli functions
# 131208-2155 - Added user log TIMEOUTLOGOUT event status
#
$version = '2.8-10';
$build = '131208-2155';
$StarTtimE = date("U");
$NOW_TIME = date("Y-m-d H:i:s");
$last_action_date = $NOW_TIME;
$US='_';
$CL=':';
$AT='@';
$DS='-';
$date = date("r");
$ip = getenv("REMOTE_ADDR");
$browser = getenv("HTTP_USER_AGENT");
$script_name = getenv("SCRIPT_NAME");
$server_name = getenv("SERVER_NAME");
$server_port = getenv("SERVER_PORT");
if (preg_match("/443/i",$server_port)) {$HTTPprotocol = 'https://';}
else {$HTTPprotocol = 'http://';}
if (($server_port == '80') or ($server_port == '443') ) {$server_port='';}
else {$server_port = "$CL$server_port";}
$agcPAGE = "$HTTPprotocol$server_name$server_port$script_name";
$agcDIR = preg_replace('/timeclock\.php/i','',$agcPAGE);
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["phone_login"])) {$phone_login=$_GET["phone_login"];}
elseif (isset($_POST["phone_login"])) {$phone_login=$_POST["phone_login"];}
if (isset($_GET["phone_pass"])) {$phone_pass=$_GET["phone_pass"];}
elseif (isset($_POST["phone_pass"])) {$phone_pass=$_POST["phone_pass"];}
if (isset($_GET["VD_login"])) {$VD_login=$_GET["VD_login"];}
elseif (isset($_POST["VD_login"])) {$VD_login=$_POST["VD_login"];}
if (isset($_GET["VD_pass"])) {$VD_pass=$_GET["VD_pass"];}
elseif (isset($_POST["VD_pass"])) {$VD_pass=$_POST["VD_pass"];}
if (isset($_GET["VD_campaign"])) {$VD_campaign=$_GET["VD_campaign"];}
elseif (isset($_POST["VD_campaign"])) {$VD_campaign=$_POST["VD_campaign"];}
if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
if (isset($_GET["commit"])) {$commit=$_GET["commit"];}
elseif (isset($_POST["commit"])) {$commit=$_POST["commit"];}
if (isset($_GET["referrer"])) {$referrer=$_GET["referrer"];}
elseif (isset($_POST["referrer"])) {$referrer=$_POST["referrer"];}
if (isset($_GET["user"])) {$user=$_GET["user"];}
elseif (isset($_POST["user"])) {$user=$_POST["user"];}
if (isset($_GET["pass"])) {$pass=$_GET["pass"];}
elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];}
if (!isset($phone_login))
{
if (isset($_GET["pl"])) {$phone_login=$_GET["pl"];}
elseif (isset($_POST["pl"])) {$phone_login=$_POST["pl"];}
}
if (!isset($phone_pass))
{
if (isset($_GET["pp"])) {$phone_pass=$_GET["pp"];}
elseif (isset($_POST["pp"])) {$phone_pass=$_POST["pp"];}
}
### security strip all non-alphanumeric characters out of the variables ###
$DB=preg_replace("/[^0-9a-z]/","",$DB);
$phone_login=preg_replace("/[^\,0-9a-zA-Z]/","",$phone_login);
$phone_pass=preg_replace("/[^0-9a-zA-Z]/","",$phone_pass);
$VD_login=preg_replace("/[^0-9a-zA-Z]/","",$VD_login);
$VD_pass=preg_replace("/[^0-9a-zA-Z]/","",$VD_pass);
$VD_campaign=preg_replace("/[^0-9a-zA-Z_]/","",$VD_campaign);
$user=preg_replace("/[^0-9a-zA-Z]/","",$user);
$pass=preg_replace("/[^0-9a-zA-Z]/","",$pass);
$stage=preg_replace("/[^0-9a-zA-Z]/","",$stage);
$commit=preg_replace("/[^0-9a-zA-Z]/","",$commit);
$referrer=preg_replace("/[^0-9a-zA-Z]/","",$referrer);
require_once("dbconnect_mysqli.php");
require_once("functions.php");
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,admin_home_url,admin_web_directory FROM system_settings;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysqli_num_rows($rslt);
$i=0;
while ($i < $qm_conf_ct)
{
$row=mysqli_fetch_row($rslt);
$non_latin = $row[0];
$welcomeURL = $row[1];
$admin_web_directory = $row[2];
$i++;
}
##### END SETTINGS LOOKUP #####
###########################################
header ("Content-type: text/html; charset=utf-8");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
if ( ($stage == 'login') or ($stage == 'logout') )
{
### see if user/pass exist for this user in vicidial_users table
$valid_user=0;
$auth_message = user_authorization($user,$pass,'',1,0,0);
if ($auth_message == 'GOOD')
{$valid_user=1;}
print "\n";
if ($valid_user < 1)
{
### NOT A VALID USER/PASS
$VDdisplayMESSAGE = "O usuário e a senha que você digitou não estão ativos no sistema
Por favor, tente novamente:";
echo"
\n";
echo"Agent Relogio ponto\n";
echo"\n";
echo"\n";
echo "\n";
echo "\n\n";
echo "\n\n";
echo "\n\n";
exit;
}
else
{
### VALID USER/PASS, CONTINUE
### get name and group for this user
$stmt="SELECT full_name,user_group from vicidial_users where user='$user' and active='Y';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$full_name = $row[0];
$user_group = $row[1];
print "\n";
### get vicidial_timeclock_status record count for this user
$stmt="SELECT count(*) from vicidial_timeclock_status where user='$user';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$vts_count = $row[0];
$last_action_sec=99;
if ($vts_count > 0)
{
### vicidial_timeclock_status record found, grab status and date of last activity
$stmt="SELECT status,event_epoch from vicidial_timeclock_status where user='$user';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$status = $row[0];
$event_epoch = $row[1];
$last_action_date = date("Y-m-d H:i:s", $event_epoch);
$last_action_sec = ($StarTtimE - $event_epoch);
if ($last_action_sec > 0)
{
$totTIME_H = ($last_action_sec / 3600);
$totTIME_H_int = round($totTIME_H, 2);
$totTIME_H_int = intval("$totTIME_H");
$totTIME_M = ($totTIME_H - $totTIME_H_int);
$totTIME_M = ($totTIME_M * 60);
$totTIME_M_int = round($totTIME_M, 2);
$totTIME_M_int = intval("$totTIME_M");
$totTIME_S = ($totTIME_M - $totTIME_M_int);
$totTIME_S = ($totTIME_S * 60);
$totTIME_S = round($totTIME_S, 0);
if (strlen($totTIME_H_int) < 1) {$totTIME_H_int = "0";}
if ($totTIME_M_int < 10) {$totTIME_M_int = "0$totTIME_M_int";}
if ($totTIME_S < 10) {$totTIME_S = "0$totTIME_S";}
$totTIME_HMS = "$totTIME_H_int:$totTIME_M_int:$totTIME_S";
}
else
{
$totTIME_HMS='0:00:00';
}
print "\n";
}
else
{
### No vicidial_timeclock_status record found, insert one
$stmt="INSERT INTO vicidial_timeclock_status set status='START', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$status='START';
$totTIME_HMS='0:00:00';
$affected_rows = mysqli_affected_rows($link);
print "\n";
}
if ( ($last_action_sec < 30) and ($status != 'START') )
{
### You cannot log in or out within 30 segundos of your last login/logout
$VDdisplayMESSAGE = "Você não pode entrar ou sair dentro de 30 segundos do seu último login ou logout";
echo"\n";
echo"Agent Relogio ponto\n";
echo"\n";
echo"\n";
echo "\n";
echo "\n\n";
echo "\n\n";
echo "\n\n";
exit;
}
if ($commit == 'YES')
{
if ( ( ($status=='AUTOLOGOUT') or ($status=='START') or ($status=='LOGOUT') or ($status=='TIMEOUTLOGOUT') ) and ($stage=='login') )
{
$VDdisplayMESSAGE = "Você tem agora registrados em";
$LOGtimeMESSAGE = "Você logou em $NOW_TIME";
### Add a record to the timeclock log
$stmt="INSERT INTO vicidial_timeclock_log set event='LOGIN', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', event_date='$NOW_TIME';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$timeclock_id = mysqli_insert_id($link);
print "\n";
### Update the user's timeclock status record
$stmt="UPDATE vicidial_timeclock_status set status='LOGIN', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip' where user='$user';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
print "\n";
### Add a record to the timeclock audit log
$stmt="INSERT INTO vicidial_timeclock_audit_log set timeclock_id='$timeclock_id', event='LOGIN', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', event_date='$NOW_TIME';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
print "\n";
}
if ( ($status=='LOGIN') and ($stage=='logout') )
{
$VDdisplayMESSAGE = "Você efetuou logout";
$LOGtimeMESSAGE = "Você saiu em$NOW_TIME
Quantidade de tempo que ficou logado:$totTIME_HMS";
### Add a record to the timeclock log
$stmt="INSERT INTO vicidial_timeclock_log set event='LOGOUT', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', login_sec='$last_action_sec', event_date='$NOW_TIME';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$timeclock_id = mysqli_insert_id($link);
print "\n";
### Update last login record in the timeclock log
$stmt="UPDATE vicidial_timeclock_log set login_sec='$last_action_sec',tcid_link='$timeclock_id' where event='LOGIN' and user='$user' order by timeclock_id desc limit 1;";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
print "\n";
### Update the user's timeclock status record
$stmt="UPDATE vicidial_timeclock_status set status='LOGOUT', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip' where user='$user';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
print "\n";
### Add a record to the timeclock audit log
$stmt="INSERT INTO vicidial_timeclock_audit_log set timeclock_id='$timeclock_id', event='LOGOUT', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', login_sec='$last_action_sec', event_date='$NOW_TIME';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
print "\n";
### Update last login record in the timeclock audit log
$stmt="UPDATE vicidial_timeclock_audit_log set login_sec='$last_action_sec',tcid_link='$timeclock_id' where event='LOGIN' and user='$user' order by timeclock_id desc limit 1;";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
print "\n";
}
if ( ( ( ($status=='AUTOLOGOUT') or ($status=='START') or ($status=='LOGOUT') or ($status=='TIMEOUTLOGOUT') ) and ($stage=='logout') ) or ( ($status=='LOGIN') and ($stage=='login') ) )
{echo "ERRO: relogio ponto já registrado:$status|$stage"; exit;}
if ($referrer=='agent')
{$BACKlink = "VOLTAR para tela de login do Agente";}
if ($referrer=='admin')
{$BACKlink = "VOLTAR para Administração";}
if ($referrer=='welcome')
{$BACKlink = "VOLTAR para Tela Inicial";}
echo"\n";
echo"Agent Relogio ponto\n";
echo"\n";
echo"\n";
echo "\n";
echo "
$VDdisplayMESSAGE
";
echo "";
echo " | ";
echo " Relogio ponto | ";
echo "
\n";
echo "| |
\n";
echo " $LOGtimeMESSAGE |
\n";
echo " $BACKlink |
\n";
echo " VERSÃO: $version CONFIGURAÇÃO: $build |
\n";
echo "
\n";
echo "\n\n";
echo "\n\n";
exit;
}
if ( ($status=='AUTOLOGOUT') or ($status=='START') or ($status=='LOGOUT') or ($status=='TIMEOUTLOGOUT') )
{
$VDdisplayMESSAGE = "Tempo desde o último login:$totTIME_HMS";
$log_action = 'login';
$button_name = 'LOGIN';
$LOGtimeMESSAGE = "Você saiu pela última vez em:$last_action_date
Clique LOGIN abaixo para entrar";
}
if ($status=='LOGIN')
{
$VDdisplayMESSAGE = "Tempo total desde que entrou no sistema:$totTIME_HMS";
$log_action = 'logout';
$button_name = 'LOGOUT';
$LOGtimeMESSAGE = "Você entrou em: $last_action_date
Tempo total desde que entrou no sistema:$totTIME_HMS
Clique LOGOUT abaixo para sair";
}
echo"\n";
echo"Agent Relogio ponto\n";
echo"\n";
echo"\n";
echo "\n";
echo "\n\n";
echo "\n\n";
echo "\n\n";
exit;
}
}
else
{
echo"\n";
echo"Agent Relogio ponto\n";
echo"\n";
echo"\n";
echo "\n";
echo "\n\n";
echo "\n\n";
echo "\n\n";
}
exit;
?>