LICENSE: AGPLv2
#
# CHANGELOG
# 110511-1336 - First Build
# 110526-1757 - Added webphone_auto_answer option
# 120223-2124 - Removed logging of good login passwords if webroot writable is enabled
# 130123-1923 - Added ability to use user-login-first options.php option
# 130328-0005 - Converted ereg to preg functions
# 130603-2212 - Added login lockout for 15 minutes after 10 failed logins, and other security fixes
# 130718-0946 - Fixed login bug
# 130802-1139 - Changed to PHP mysqli functions
# 140810-2113 - Changed to use QXZ function for echoing text
# 141118-1238 - Formatting changes for QXZ output
# 141216-2127 - Added language settings lookups and user/pass variable standardization
# 170409-1600 - Added IP List validation code
# 170511-1107 - Added code for WebRTC phones
# 181003-1736 - Added external_web_socket_url option
# 200123-1639 - Added Webphone options
# 210615-1028 - Default security fixes, CVE-2021-28854
# 210616-2043 - Added optional CORS support, see options.php for details
# 220220-0936 - Added allow_web_debug system setting
# 221021-1026 - Added webphone_settings phones option
#
$version = '2.14-19p';
$build = '221021-1026';
$php_script = 'phone_only.php';
$mel=1; # Mysql Error Log enabled = 1
$mysql_log_count=74;
$one_mysql_log=0;
require_once("dbconnect_mysqli.php");
require_once("functions.php");
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["relogin"])) {$relogin=$_GET["relogin"];}
elseif (isset($_POST["relogin"])) {$relogin=$_POST["relogin"];}
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"];}
}
if (!isset($flag_channels))
{
$flag_channels=0;
$flag_string='';
}
### 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("/\'|\"|\\\\|;| /","",$VD_login);
$VD_pass=preg_replace("/\'|\"|\\\\|;| /","",$VD_pass);
$relogin=preg_replace("/[^-_0-9a-zA-Z]/","",$relogin);
$forever_stop=0;
if ($force_logout)
{
echo _QXZ("You have now logged out. Thank you")."\n";
exit;
}
$isdst = date("I");
$StarTtimE = date("U");
$NOW_TIME = date("Y-m-d H:i:s");
$tsNOW_TIME = date("YmdHis");
$FILE_TIME = date("Ymd-His");
$loginDATE = date("Ymd");
$CIDdate = date("ymdHis");
$month_old = mktime(11, 0, 0, date("m"), date("d")-2, date("Y"));
$past_month_date = date("Y-m-d H:i:s",$month_old);
$minutes_old = mktime(date("H"), date("i")-2, date("s"), date("m"), date("d"), date("Y"));
$past_minutes_date = date("Y-m-d H:i:s",$minutes_old);
$webphone_width = 460;
$webphone_height = 500;
$random = (rand(1000000, 9999999) + 10000000);
#############################################
##### START SYSTEM_SETTINGS AND USER LANGUAGE LOOKUP #####
$stmt = "SELECT use_non_latin,vdc_header_date_format,vdc_customer_date_format,vdc_header_phone_format,webroot_writable,timeclock_end_of_day,vtiger_url,enable_vtiger_integration,outbound_autodial_active,enable_second_webform,user_territories_active,static_agent_url,custom_fields_enabled,enable_languages,language_method,allow_web_debug FROM system_settings;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'09001',$VD_login,$server_ip,$session_name,$one_mysql_log);}
#if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysqli_num_rows($rslt);
if ($qm_conf_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$non_latin = $row[0];
$vdc_header_date_format = $row[1];
$vdc_customer_date_format = $row[2];
$vdc_header_phone_format = $row[3];
$WeBRooTWritablE = $row[4];
$timeclock_end_of_day = $row[5];
$vtiger_url = $row[6];
$enable_vtiger_integration = $row[7];
$outbound_autodial_active = $row[8];
$enable_second_webform = $row[9];
$user_territories_active = $row[10];
$static_agent_url = $row[11];
$custom_fields_enabled = $row[12];
$SSenable_languages = $row[13];
$SSlanguage_method = $row[14];
$SSallow_web_debug = $row[15];
}
if ($SSallow_web_debug < 1) {$DB=0;}
$VUselected_language = '';
$stmt="SELECT selected_language from vicidial_users where user='$VD_login';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'09074',$VD_login,$server_ip,$session_name,$one_mysql_log);}
$sl_ct = mysqli_num_rows($rslt);
if ($sl_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$VUselected_language = $row[0];
}
##### END SETTINGS LOOKUP #####
###########################################
if ($non_latin < 1)
{
$VD_login=preg_replace("/[^-_0-9a-zA-Z]/","",$VD_login);
$VD_pass=preg_replace("/[^-_0-9a-zA-Z]/","",$VD_pass);
}
else
{
$VD_login = preg_replace('/[^-_0-9\p{L}]/u','',$VD_login);
$VD_pass = preg_replace('/[^-_0-9\p{L}]/u','',$VD_pass);
}
##### DEFINABLE SETTINGS AND OPTIONS
###########################################
# set defaults for hard-coded variables
$user_login_first = '0'; # set to 1 to have the vicidial_user login before the phone login
$clientDST = '1'; # set to 1 to check for DST on server for agent time
$PhonESComPIP = '1'; # set to 1 to log computer IP to phone if blank, set to 2 to force log each login
$hide_timeclock_link = '0'; # set to 1 to hide the timeclock link on the agent login screen
$stretch_dimensions = '1'; # sets the vicidial screen to the size of the browser window
$BROWSER_HEIGHT = 500; # set to the minimum browser height, default=500
$BROWSER_WIDTH = 770; # set to the minimum browser width, default=770
$webphone_width = 460; # set the webphone frame width
$webphone_height = 500; # set the webphone frame height
$webphone_pad = 0; # set the table cellpadding for the webphone
$webphone_location = 'right'; # set the location on the agent screen 'right' or 'bar'
$MAIN_COLOR = '#CCCCCC'; # old default is E0C2D6
$SCRIPT_COLOR = '#E6E6E6'; # old default is FFE7D0
$FORM_COLOR = '#EFEFEF';
$SIDEBAR_COLOR = '#F6F6F6';
# if options file exists, use the override values for the above variables
# see the options-example.php file for more information
if (file_exists('options.php'))
{
require('options.php');
}
$US='_';
$CL=':';
$AT='@';
$DS='-';
$date = date("r");
$ip = getenv("REMOTE_ADDR");
$browser = getenv("HTTP_USER_AGENT");
$browser=preg_replace("/\'|\"|\\\\/","",$browser);
$script_name = getenv("SCRIPT_NAME");
$server_name = getenv("SERVER_NAME");
$server_port = getenv("SERVER_PORT");
$PHP_SELF=$_SERVER['PHP_SELF'];
$PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF);
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";}
$FQDN = "$server_name$server_port";
$agcPAGE = "$HTTPprotocol$server_name$server_port$script_name";
$agcDIR = preg_replace('/phone_only\.php/i','',$agcPAGE);
if (strlen($static_agent_url) > 5)
{$agcPAGE = $static_agent_url;}
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
echo '
';
echo "\n";
echo "\n";
$stmt="SELECT user_group from vicidial_users where user='$VD_login';";
if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);}
$rslt=mysql_to_mysqli($stmt, $link);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'09002',$VD_login,$server_ip,$session_name,$one_mysql_log);}
$row=mysqli_fetch_row($rslt);
$VU_user_group=$row[0];
if ($relogin == 'YES')
{
echo ""._QXZ("Phone web client: Login")."\n";
echo "\n";
echo "\n";
if ($hide_timeclock_link < 1)
{echo " "._QXZ("Timeclock")."
\n";}
echo "\n";
echo "\n\n";
echo "\n\n";
echo "\n\n";
exit;
}
if ($user_login_first == 1)
{
if ( (strlen($VD_login)<1) or (strlen($VD_pass)<1) )
{
echo ""._QXZ("Phone web client: Login")."\n";
echo "\n";
echo "\n";
if ($hide_timeclock_link < 1)
{echo " "._QXZ("Timeclock")."
\n";}
echo "\n";
echo "\n\n";
echo "\n\n";
echo "