Added reset_password option to update_user Non-Agent API function

Added new reset_agent_pass_email.php script

git-svn-id: svn://192.168.202.10@3675 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2023-01-23 05:07:40 +00:00
parent a1a8f0f9f2
commit 01caaebec6
4 changed files with 616 additions and 6 deletions
+8 -1
View File
@@ -1,4 +1,4 @@
NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2022-11-09
NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2023-01-23
This document describes the functions of an API(Application Programming
Interface) for all functions NOT directly relating to the VICIDIAL Agent screen.
@@ -205,6 +205,7 @@ Changes:
220902-0823 - Added dial_status_add/dial_status_remove options to update_campaign function
220920-0814 - Added more "XDAY" options to add_lead duplicate checks
221108-1849 - Added include_ip option for agent_status function
230122-1821 - Added reset_password option to update_user function
API Functions use the 'function' variable
@@ -1454,6 +1455,8 @@ camp_rg_only - 0 or 1, this will set only one campaign rank/grade for this user
campaign_id - only required for use with camp_rg_only
ingrp_rg_only - 0 or 1, this will set only one inbound group rank/grade for this user, requires group_id to be set
group_id - only required for use with ingrp_rg_only
reset_password - 0 or 8+ digits, this will reset the user's password to a random password of this length and email the new password to the user
NOTE: the 'email' field is required if the user's current email is not a valid email address
Example URL strings for API calls:
http://server/vicidial/non_agent_api.php?source=test&function=update_user&user=6666&pass=1234&agent_user=2424&agent_pass=9876
@@ -1461,6 +1464,7 @@ http://server/vicidial/non_agent_api.php?source=test&function=update_user&user=6
http://server/vicidial/non_agent_api.php?source=test&function=update_user&user=6666&pass=1234&agent_user=2424&agent_full_name=Testing&hotkeys_active=1&active=Y
http://server/vicidial/non_agent_api.php?source=test&function=update_user&user=6666&pass=1234&agent_user=2424&campaign_rank=3&campaign_grade=4
http://server/vicidial/non_agent_api.php?source=test&function=update_user&user=6666&pass=1234&agent_user=2424&ingroup_rank=3&ingroup_grade=4&ingrp_rg_only=1&group_id=TEST_IN
http://server/vicidial/non_agent_api.php?source=test&function=update_user&user=6666&pass=1234&agent_user=2424&reset_password=12&email=info@vicidial.com
Example responses:
ERROR: update_user USER DOES NOT HAVE PERMISSION TO UPDATE USERS - 6666|0
@@ -1490,6 +1494,9 @@ ERROR: update_user YOU MUST USE A VALID IN-GROUP GRADE, THIS IS AN OPTIONAL FIEL
ERROR: update_user NO UPDATES DEFINED - 6666|0
NOTICE: update_user USER CAMPAIGN RANKS/GRADES HAVE BEEN UPDATED - 6666|9|10|TESTCAMP|1
NOTICE: update_user USER IN-GROUP RANKS/GRADES HAVE BEEN UPDATED - 6666|9|10|TEST_IN|1
NOTICE: update_user USER PASSWORD RESET FAILED: NO VALID EMAIL PROVIDED - 6666|email@doman
NOTICE: update_user USER PASSWORD RESET FAILED: EMAIL FAILURE - 6666|info@vicidial.com|email-error
NOTICE: update_user update_user USER PASSWORD HAS BEEN RESET - 6666|info@vicidial.com
SUCCESS: update_user USER HAS BEEN UPDATED - 6666|7878
SUCCESS: update_user USER HAS BEEN DELETED - 6666|7878
+1 -1
View File
@@ -49146,7 +49146,7 @@ if ($ADD==99999701)
$stmt = "INSERT INTO vicidial_agent_function_log set agent_log_id='0',user='$user',function='2FA_send',event_time=NOW(),campaign_id='-ADMIN-',user_group='$LOGuser_group',lead_id='0',uniqueid='ERROR',caller_code='$ip',stage='$stage',comments='EMAIL: $LOGemail';";
$error_msg = error_get_last()['message'];
echo "error_msg";
echo "$error_msg";
}
### LOG INSERTION Admin Log Table ###
+87 -4
View File
@@ -199,10 +199,11 @@
# 220920-0814 - Added more "XDAY" options to add_lead duplicate checks
# 221108-1849 - Added include_ip option for agent_status function
# 230118-0833 - Added ingroup_list and callmenu_list functions
# 230122-1821 - Added reset_password option to update_user function
#
$version = '2.14-176';
$build = '230118-0833';
$version = '2.14-177';
$build = '230122-1821';
$php_script='non_agent_api.php';
$api_url_log = 0;
@@ -358,8 +359,6 @@ if (isset($_GET["hotkeys_active"])) {$hotkeys_active=$_GET["hotkeys_active"];
elseif (isset($_POST["hotkeys_active"])) {$hotkeys_active=$_POST["hotkeys_active"];}
if (isset($_GET["voicemail_id"])) {$voicemail_id=$_GET["voicemail_id"];}
elseif (isset($_POST["voicemail_id"])) {$voicemail_id=$_POST["voicemail_id"];}
if (isset($_GET["email"])) {$email=$_GET["email"];}
elseif (isset($_POST["email"])) {$email=$_POST["email"];}
if (isset($_GET["custom_one"])) {$custom_one=$_GET["custom_one"];}
elseif (isset($_POST["custom_one"])) {$custom_one=$_POST["custom_one"];}
if (isset($_GET["custom_two"])) {$custom_two=$_GET["custom_two"];}
@@ -710,6 +709,8 @@ if (isset($_GET["dial_status_remove"])) {$dial_status_remove=$_GET["dial_stat
elseif (isset($_POST["dial_status_remove"])) {$dial_status_remove=$_POST["dial_status_remove"];}
if (isset($_GET["include_ip"])) {$include_ip=$_GET["include_ip"];}
elseif (isset($_POST["include_ip"])) {$include_ip=$_POST["include_ip"];}
if (isset($_GET["reset_password"])) {$reset_password=$_GET["reset_password"];}
elseif (isset($_POST["reset_password"])) {$reset_password=$_POST["reset_password"];}
$DB=preg_replace('/[^0-9]/','',$DB);
@@ -864,6 +865,7 @@ $preset_number = preg_replace('/[^\*\#\.\_0-9a-zA-Z]/','',$preset_number);
$preset_dtmf = preg_replace('/[^- \,\*\#0-9a-zA-Z]/','',$preset_dtmf);
$action = preg_replace('/[^0-9a-zA-Z]/','',$action);
$include_ip = preg_replace('/[^0-9a-zA-Z]/','',$include_ip);
$reset_password = preg_replace('/[^0-9]/','',$reset_password);
if ($non_latin < 1)
{
@@ -4334,6 +4336,87 @@ if ($function == 'update_user')
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
}
if ( (strlen($reset_password) > 0) and ($reset_password > 7) )
{
### BEGIN reset_password section ###
if (strlen($email) < 5)
{
$stmt="SELECT email from vicidial_users where user='$agent_user';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$email = $row[0];
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$result = 'NOTICE';
$result_reason = "update_user USER PASSWORD RESET FAILED: NO VALID EMAIL PROVIDED";
$data = "$agent_user|$email";
echo "$result: $result_reason - $user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
}
else
{
$temp_pass = '';
$possible = "0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
$i = 0;
while ($i < $reset_password)
{
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
$temp_pass .= $char;
$i++;
}
$email_message = "Here is your new temporary password: $temp_pass";
$email_subject = "User Account Reset";
$success = mail($email, $email_subject, $email_message);
if ($success)
{
$pass_hash='';
$pass_hashSQL='';
if ($SSpass_hash_enabled > 0)
{
if (strlen($temp_pass) > 1)
{
$temp_pass = preg_replace("/\'|\"|\\\\|;| /","",$temp_pass);
$pass_hash = exec("../agc/bp.pl --pass=$temp_pass");
$pass_hash = preg_replace("/PHASH: |\n|\r|\t| /",'',$pass_hash);
$pass_hashSQL = ",pass_hash='$pass_hash'";
}
$temp_pass='';
}
$stmt="UPDATE vicidial_users SET force_change_password='Y',pass='$temp_pass' $pass_hashSQL WHERE user='$agent_user';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "|$stmt|\n";}
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = preg_replace('/;/', '', $SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$user', ip_address='$ip', event_section='USERS', event_type='MODIFY', record_id='$agent_user', event_code='ADMIN API RESET PASS', event_sql=\"$SQL_log\", event_notes='user: $agent_user';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$result = 'NOTICE';
$result_reason = "update_user USER PASSWORD HAS BEEN RESET";
$data = "$agent_user|$email";
echo "$result: $result_reason - $user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
}
else
{
$error_msg = error_get_last()['message'];
$result = 'NOTICE';
$result_reason = "update_user USER PASSWORD RESET FAILED: EMAIL FAILURE";
$data = "$agent_user|$email|$error_msg";
echo "$result: $result_reason - $user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
}
}
### END reset_password section ###
}
$updateSQL = "$passSQL$pass_hashSQL$full_nameSQL$user_levelSQL$user_groupSQL$phone_loginSQL$phone_passSQL$hotkeys_activeSQL$voicemail_idSQL$emailSQL$custom_oneSQL$custom_twoSQL$custom_threeSQL$custom_fourSQL$custom_fiveSQL$activeSQL$wrapup_seconds_overrideSQL";
if (strlen($updateSQL)< 3)
@@ -0,0 +1,520 @@
<?php
# reset_agent_pass_email.php
#
# Copyright (C) 2023 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# NOTE: It is required that you add a Settings Container with the ID of 'AGENT_RESET_OPTIONS' for this utility to work
#
# Contents of the Settings Container:
# RESET_USER_GROUPS=>105500,553101,553102,155110
# RESET_PASSWORD=>321reset
#
# CHANGES
# 230122-2244 - First build based on reset_agent_pass.php
#
$startMS = microtime();
$report_name='Reset Agent Pass';
require("dbconnect_mysqli.php");
require("functions.php");
$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
$PHP_SELF=$_SERVER['PHP_SELF'];
$PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF);
$ip = getenv("REMOTE_ADDR");
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["group"])) {$group=$_GET["group"];}
elseif (isset($_POST["group"])) {$group=$_POST["group"];}
if (isset($_GET["reset_agent"])) {$reset_agent=$_GET["reset_agent"];}
elseif (isset($_POST["reset_agent"])) {$reset_agent=$_POST["reset_agent"];}
if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];}
elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];}
if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];}
elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];}
if (isset($_GET["submit"])) {$submit=$_GET["submit"];}
elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];}
if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
if (isset($_GET["email"])) {$email=$_GET["email"];}
elseif (isset($_POST["email"])) {$email=$_POST["email"];}
$DB=preg_replace("/[^0-9a-zA-Z]/","",$DB);
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,webroot_writable,outbound_autodial_active,user_territories_active,enable_languages,language_method,pass_hash_enabled,allow_web_debug FROM system_settings;";
$rslt=mysql_to_mysqli($stmt, $link);
#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];
$webroot_writable = $row[1];
$SSoutbound_autodial_active = $row[2];
$user_territories_active = $row[3];
$SSenable_languages = $row[4];
$SSlanguage_method = $row[5];
$SSpass_hash_enabled = $row[6];
$SSallow_web_debug = $row[7];
}
if ($SSallow_web_debug < 1) {$DB=0;}
##### END SETTINGS LOOKUP #####
###########################################
$list_id = preg_replace('/[^0-9]/', '', $list_id);
$group = preg_replace('/[^-_0-9a-zA-Z]/', '', $group);
$submit = preg_replace('/[^-_0-9a-zA-Z]/', '', $submit);
$SUBMIT = preg_replace('/[^-_0-9a-zA-Z]/', '', $SUBMIT);
$stage = preg_replace('/[^-_0-9a-zA-Z]/', '', $stage);
$server_ip = preg_replace('/[^-\.\:\_0-9a-zA-Z]/', '', $server_ip);
if ($non_latin < 1)
{
$PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER);
$PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW);
$reset_agent = preg_replace('/[^-_0-9a-zA-Z]/', '', $reset_agent);
$email = preg_replace('/[^- \'\+\.\:\/\@\%\_0-9a-zA-Z]/','',$email);
}
else
{
$PHP_AUTH_USER = preg_replace('/[^-_0-9\p{L}]/u', '', $PHP_AUTH_USER);
$PHP_AUTH_PW = preg_replace('/[^-_0-9\p{L}]/u', '', $PHP_AUTH_PW);
$reset_agent = preg_replace('/[^-_0-9\p{L}]/u',"",$reset_agent);
$email = preg_replace('/[^- \'\+\.\:\/\@\%\_0-9\p{L}]/u','',$email);
}
$stmt="SELECT selected_language from vicidial_users where user='$PHP_AUTH_USER';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$sl_ct = mysqli_num_rows($rslt);
if ($sl_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$VUselected_language = $row[0];
}
$auth=0;
$reports_auth=0;
$admin_auth=0;
$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0);
if ($auth_message == 'GOOD')
{$auth=1;}
if ($auth > 0)
{
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level >= 7 and view_reports='1';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$admin_auth=$row[0];
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level >= 7 and modify_users='1';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$reports_auth=$row[0];
if ($reports_auth < 1)
{
$VDdisplayMESSAGE = _QXZ("You are not allowed to reset agent passwords");
Header ("Content-type: text/html; charset=utf-8");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n";
exit;
}
if ( ($reports_auth > 0) and ($admin_auth < 1) )
{
$ADD=999999;
$reports_only_user=1;
}
}
else
{
$VDdisplayMESSAGE = _QXZ("Login incorrect, please try again");
if ($auth_message == 'LOCK')
{
$VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes");
Header ("Content-type: text/html; charset=utf-8");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n";
exit;
}
if ($auth_message == 'IPBLOCK')
{
$VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip";
Header ("Content-type: text/html; charset=utf-8");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n";
exit;
}
Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\"");
Header("HTTP/1.0 401 Unauthorized");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n";
exit;
}
$stmt="SELECT modify_users,user_group,user_level from vicidial_users where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGmodify_users = $row[0];
$LOGuser_group = $row[1];
$LOGuser_level = $row[2];
if ($LOGmodify_users < 1)
{
Header ("Content-type: text/html; charset=utf-8");
echo _QXZ("You do not have permissions to modify users").": |$PHP_AUTH_USER|\n";
exit;
}
$stmt="SELECT reports_header_override,admin_home_url from vicidial_user_groups where user_group='$LOGuser_group';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGreports_header_override = $row[0];
$LOGadmin_home_url = $row[1];
if (strlen($LOGadmin_home_url) > 5) {$SSadmin_home_url = $LOGadmin_home_url;}
##### BEGIN log visit to the vicidial_report_log table #####
$LOGip = getenv("REMOTE_ADDR");
$LOGbrowser = getenv("HTTP_USER_AGENT");
$LOGscript_name = getenv("SCRIPT_NAME");
$LOGserver_name = getenv("SERVER_NAME");
$LOGserver_port = getenv("SERVER_PORT");
$LOGrequest_uri = getenv("REQUEST_URI");
$LOGhttp_referer = getenv("HTTP_REFERER");
$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser);
$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri);
$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer);
if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';}
else {$HTTPprotocol = 'http://';}
if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';}
else {$LOGserver_port = ":$LOGserver_port";}
$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri";
$LOGhostname = php_uname('n');
if (strlen($LOGhostname)<1) {$LOGhostname='X';}
if (strlen($LOGserver_name)<1) {$LOGserver_name='X';}
$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$webserver_id_ct = mysqli_num_rows($rslt);
if ($webserver_id_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$webserver_id = $row[0];
}
else
{
##### insert webserver entry
$stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$webserver_id = mysqli_insert_id($link);
}
$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name', url='$LOGfull_url', webserver='$webserver_id';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$report_log_id = mysqli_insert_id($link);
##### END log visit to the vicidial_report_log table #####
if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) )
{
mysqli_close($link);
$use_slave_server=1;
$db_source = 'S';
require("dbconnect_mysqli.php");
$MAIN.="<!-- Using slave server $slave_db_server $db_source -->\n";
}
if ($db_source == 'S')
{
mysqli_close($link);
$use_slave_server=0;
$db_source = 'M';
require("dbconnect_mysqli.php");
}
$NOW_DATE = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$FILEDATE = date("YmdHis");
$STARTtime = date("U");
?>
<HTML>
<HEAD>
<STYLE type="text/css">
<!--
.green {color: white; background-color: green}
.red {color: white; background-color: red}
.blue {color: white; background-color: blue}
.purple {color: white; background-color: purple}
-->
</STYLE>
<?php
echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n";
echo "<TITLE>"._QXZ("Reset Agent Password")."</TITLE></HEAD><BODY BGCOLOR=WHITE marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>\n";
$short_header=1;
require("admin_header.php");
$stmt = "SELECT count(*) FROM vicidial_settings_containers where container_id='AGENT_RESET_OPTIONS';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$sc_ct = mysqli_num_rows($rslt);
if ($sc_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$SC_count = $row[0];
}
if ($SC_count > 0)
{
$stmt = "SELECT container_entry FROM vicidial_settings_containers where container_id='AGENT_RESET_OPTIONS';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$sc_ct = mysqli_num_rows($rslt);
if ($sc_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$container_entry = $row[0];
$container_ARY = explode("\n",$container_entry);
$p=0;
$reset_user_groups='';
$reset_password='';
$container_ct = count($container_ARY);
while ($p <= $container_ct)
{
$line = $container_ARY[$p];
$line = preg_replace("/\n|\r|\t|\#.*|;.*/",'',$line);
if (preg_match("/^RESET_USER_GROUPS/",$line))
{$reset_user_groups = $line; $reset_user_groups = trim(preg_replace("/.*=>/",'',$reset_user_groups));}
# if (preg_match("/^RESET_PASSWORD/",$line))
# {$reset_password = $line; $reset_password = trim(preg_replace("/.*=>/",'',$reset_password));}
$p++;
}
}
else
{
echo _QXZ("ERROR: Missing settings")."\n";
exit;
}
}
else
{
echo _QXZ("ERROR: Missing settings")."\n";
exit;
}
#if (strlen($reset_password) < 1)
# {
# echo "ERROR: Missing Setting- RESET_PASSSWORD: $reset_password \n";
# exit;
# }
if (strlen($reset_user_groups) < 1)
{
echo "ERROR: Missing Setting- RESET_USER_GROUPS: $reset_user_groups \n";
exit;
}
if ($DB) {echo "DEBUG: |$reset_password|$reset_user_groups|\n";}
if ($reset_user_groups == '---ALL---')
{$user_groupSQL='';}
else
{
$reset_user_groups = preg_replace("/,/","','",$reset_user_groups);
$user_groupSQL = " and user_group IN('$reset_user_groups')";
}
if (strlen($reset_agent) < 1)
{
$owner_menu="<option value=\"\">--- "._QXZ("SELECT AGENT HERE")." ---</option>\n";
$list_idSQL='';
$owners_to_print=0;
if (strlen($list_id) > 1) {$list_idSQL = "and list_id='$list_id'";}
$stmt="SELECT user from vicidial_users where user_level < $LOGuser_level $user_groupSQL order by user;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
if ($rslt) {$owners_to_print = mysqli_num_rows($rslt);}
$i=0;
while ($i < $owners_to_print)
{
$row=mysqli_fetch_row($rslt);
$owners[$i] = $row[0];
$i++;
}
$i=0;
while ($i < $owners_to_print)
{
$users_to_print=0;
$stmt="SELECT user,full_name from vicidial_users where user='$owners[$i]';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
if ($rslt) {$users_to_print = mysqli_num_rows($rslt);}
if ($users_to_print > 0)
{
$row=mysqli_fetch_row($rslt);
$owners_name[$i] = $row[1];
}
$owner_menu .= "<option value=\"$owners[$i]\">$owners[$i] - $owners_name[$i]</option>\n";
$i++;
}
echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
echo "<FORM ACTION=\"$PHP_SELF\" METHOD=GET>\n";
echo _QXZ("Reset Agent").": <SELECT SIZE=1 NAME=reset_agent>\n";
echo "$owner_menu";
echo "</SELECT>\n";
echo " &nbsp; &nbsp; \n";
echo "<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE='"._QXZ("SUBMIT")."'>\n";
echo "</FORM>\n\n";
echo "<PRE><FONT SIZE=2>\n\n";
echo "\n\n";
echo _QXZ("PLEASE SELECT AN AGENT AND CLICK SUBMIT")."\n";
}
else
{
$email_good=0;
$stmt="SELECT email,full_name from vicidial_users where user='$reset_agent';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$DBemail = $row[0];
$DBfull_name = $row[1];
if (strlen($email) < 5)
{
$email = $DBemail;
}
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
$email_good++;
}
if ( ($stage == 'finish') and ($email_good > 0) )
{
# $new_pass1 = $reset_password;
echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
echo _QXZ("RESET AGENT").": $reset_agent \n";
$LOGaffected_rows=0;
$UPDATEaffected_rows=0;
$temp_pass = '';
$possible = "0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
$i = 0;
while ($i < 12)
{
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
$temp_pass .= $char;
$i++;
}
$email_message = "Dear $DBfull_name,\n\nYour password has been successfully reset. Please use the following temporary password when logging into the Vox application next time.\nTemporary Password: $temp_pass\n\nAfter entry of your temporary password, you will be required to enter a new password of your choosing that must adhere to password requirements.\n\nPlease let your supervisor know if you encounter any issues or have any questions.\n\nThank you.";
$email_subject = "User Account Reset";
$success = mail($email, $email_subject, $email_message);
if ($success)
{
$pass_hash='';
$pass_hashSQL='';
if ($SSpass_hash_enabled > 0)
{
if (strlen($temp_pass) > 1)
{
$temp_pass = preg_replace("/\'|\"|\\\\|;| /","",$temp_pass);
$pass_hash = exec("../agc/bp.pl --pass=$temp_pass");
$pass_hash = preg_replace("/PHASH: |\n|\r|\t| /",'',$pass_hash);
$pass_hashSQL = ",pass_hash='$pass_hash'";
}
$temp_pass='';
}
$stmt="UPDATE vicidial_users SET force_change_password='Y',email='$email',pass='$temp_pass' $pass_hashSQL where user='$reset_agent';";
$rslt=mysql_to_mysqli($stmt, $link);
$tempUPDATEaffected_rows = mysqli_affected_rows($link);
if ($DB) {echo "$tempUPDATEaffected_rows|$stmt|\n";}
if ($tempUPDATEaffected_rows > 0)
{
$UPDATEaffected_rows = ($UPDATEaffected_rows + $tempUPDATEaffected_rows);
}
if ($UPDATEaffected_rows > 0)
{
### LOG INSERTION Admin Log Table ###
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='USERS', event_type='MODIFY', record_id='$reset_agent', event_code='ADMIN RESET AGENT PASS', event_sql=\"\", event_notes='reset agent: $reset_agent users updated: $UPDATEaffected_rows email: $email';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
}
echo _QXZ("Process complete, records updated").": $UPDATEaffected_rows <br>\n";
echo "<a href=\"$PHP_SELF\">"._QXZ("Click here to go back to the reset agent pass screen")."</a> <br>\n";
}
else
{
$error_msg = error_get_last()['message'];
echo _QXZ("ERROR: email did not send").": $email|$error_msg <br>\n";
}
}
else
{
echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
echo "<FORM ACTION=\"$PHP_SELF\" METHOD=GET>\n";
echo "<input type=hidden name=reset_agent value=\"$reset_agent\">\n";
echo "<input type=hidden name=stage value=\"finish\">\n";
echo "Agent Email: <input type=text size=100 name=email value=\"$email\">\n";
echo " &nbsp; &nbsp; \n";
echo "<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE='"._QXZ("SUBMIT")."'>\n";
echo "</FORM>\n\n";
}
}
$endMS = microtime();
$startMSary = explode(" ",$startMS);
$endMSary = explode(" ",$endMS);
$runS = ($endMSary[0] - $startMSary[0]);
$runM = ($endMSary[1] - $startMSary[1]);
$TOTALrun = ($runS + $runM);
$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
?>
</PRE>
</TD></TR></TABLE>
</BODY></HTML>