Fix for rare issue with Automated Reports

git-svn-id: svn://192.168.202.10@3819 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2024-04-02 02:38:44 +00:00
parent 58bc293076
commit 97a3ccab17
12 changed files with 2199 additions and 11 deletions
+23 -3
View File
@@ -15,7 +15,7 @@
# - Auto reset lists at defined times
# - Auto restarts Asterisk process if enabled in servers settings
#
# Copyright (C) 2023 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2024 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGES
# 61011-1348 - First build
@@ -170,9 +170,10 @@
# 230925-1454 - Added -recmon settings
# 231136-2158 - Added hopper_hold_inserts HCI lead reservations clearing for old reservations
# 231129-0849 - Added reset of vicidial_phone_number_call_daily_counts table
# 240401-1810 - Added purging of vicidial_pending_ar records older than 7 days
#
$build = '231129-0849';
$build = '240401-1810';
$DB=0; # Debug flag
$teodDB=0; # flag to log Timeclock End of Day processes to log file
@@ -2202,6 +2203,24 @@ if ($timeclock_end_of_day_NOW > 0)
##### END vicidial_khomp_log end of day process removing records older than 7 days #####
##### BEGIN vicidial_pending_ar end of day process removing records older than 7 days #####
$stmtA = "DELETE from vicidial_pending_ar where start_datetime < \"$SDSQLdate\";";
if($DBX){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
if($DB){print STDERR "\n|$affected_rows vicidial_pending_ar records older than 7 days purged|\n";}
if ($teodDB) {$event_string = "vicidial_pending_ar records older than 7 days purged: |$stmtA|$affected_rows|"; &teod_logger;}
$stmtA = "optimize table vicidial_pending_ar;";
if($DBX){print STDERR "\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@aryA = $sthA->fetchrow_array;
if ($DB) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
$sthA->finish();
##### END vicidial_pending_ar end of day process removing records older than 7 days #####
##### BEGIN vicidial_two_factor_auth end of day process removing expired and older records #####
$stmtA = "DELETE from vicidial_two_factor_auth where (auth_exp_date < NOW()) or ( (auth_code_exp_date < NOW()) and (auth_stage != '1') );";
if($DBX){print STDERR "\n|$stmtA|\n";}
@@ -5962,8 +5981,9 @@ if ($SSenable_auto_reports > 0)
$r++;
}
if ($DB) {print "Automated Reports DONE: $r\n";}
if ($DB) {print "Automated Reports launched: $r\n";}
}
if ($DB) {print "Automated Reports DONE\n";}
}
################################################################################
##### END automated reports
@@ -228,6 +228,7 @@ while (@group=$campaign_rslt->fetchrow_array)
$inventory_ptnstr="|";
while (@row=$rslt->fetchrow_array)
{
$row[0] =~ s/[^-_0-9\p{L}]//ugi;
$dial_statuses.="$row[0] ";
$inventory_statuses.="'$row[0]',";
$inventory_ptnstr.="$row[0]|";
@@ -383,6 +384,7 @@ sub GetListCount
$new_count=0; $total_calls=0;
while (@ct_row=$ct_rslt->fetchrow_array)
{
$ct_row[0] =~ s/[^-_0-9\p{L}]//ugi;
$list_start_inv+=$ct_row[2];
$total_calls+=($ct_row[1]*$ct_row[2]);
if ($inventory_ptnstr=~/\|$ct_row[0]\|/ && $ct_row[1]=="0") {$new_count+=$ct_row[2];}
+10 -1
View File
@@ -9,7 +9,7 @@
#
# /usr/share/astguiclient/AST_email_web_report.pl --email-list=test@gmail.com --email-sender=test@test.com
#
# Copyright (C) 2020 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2024 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGES
# 90225-1247 - First version
@@ -22,6 +22,7 @@
# 170719-1242 - Added more debug and '8days' date option
# 170825-1114 - Added report filename_override option
# 200601-0941 - Added support to launch an SFTP process using settings containers, added settings container CLI option for Email/FTP settings
# 240401-1341 - Added vicidial_pending_ar table entries
#
$txt = '.txt';
@@ -521,6 +522,8 @@ if (length($report_id) > 1)
$email_subject =~ s/--A--date--B--|--A--today--B--/$year-$mon-$mday/gi;
$email_subject =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi;
$email_subject =~ s/--A--datetime--B--/$year-$mon-$mday $hour:$min:$sec/gi;
@php_script_url = $location =~ /([\w-]+\.php)/g;
$php_script = $php_script_url[0];
$location =~ s/\&/\\&/gi;
$location =~ s/--A--today--B--/$year-$mon-$mday/gi;
$location =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi;
@@ -543,6 +546,7 @@ if (length($report_id) > 1)
$filename_override =~ s/--A--30days--B--/$Hyear-$Hmon-$Hmday/gi;
$filename_override =~ s/--A--filedatetime--B--/$filedatetime/gi;
if ($DB) {print "FINAL LOCATION: |$location|\n";}
if ($DB) {print "REPORT SCRIPT: |$php_script|\n";}
if ($DB) {print "FILENAME OVERRIDE: |$filename_override|\n";}
}
else
@@ -669,6 +673,11 @@ else
}
### GRAB THE REPORT
$stmtB="INSERT INTO vicidial_pending_ar SET start_datetime='$timestamp', user='$http_user', report_id='$report_id', php_script='$php_script', status='TRIGGERED', notes='';";
$Iaffected_rows = $dbhA->do($stmtB);
if ($DB) {print "Pending AR entry inserted: $Iaffected_rows|$stmtB\n";}
if (!$Q) {print "Running Report $ship_date\n$location\n";}
`/usr/bin/wget --auth-no-challenge --http-user=$http_user --http-password=$http_pass --output-document=/tmp/X$HTMLfile --output-file=/tmp/Y$HTMLfileLOG $location `;
@@ -20,11 +20,12 @@
#
# MAKE SURE YOU TEST THAT THIS IS WORKING MANUALLY!!!
#
# Copyright (C) 2022 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2024 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGES
# 200601-1047 - First version, based upon AST_email_web_report.pl
# 221002-1603 - Added comments for optional additional FTPSSL variable: "OverridePASV"
# 240401-1343 - Added vicidial_pending_ar table entries
#
$txt = '.txt';
@@ -550,6 +551,8 @@ if (length($report_id) > 1)
$email_subject =~ s/--A--date--B--|--A--today--B--/$year-$mon-$mday/gi;
$email_subject =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi;
$email_subject =~ s/--A--datetime--B--/$year-$mon-$mday $hour:$min:$sec/gi;
@php_script_url = $location =~ /([\w-]+\.php)/g;
$php_script = $php_script_url[0];
$location =~ s/\&/\\&/gi;
$location =~ s/--A--today--B--/$year-$mon-$mday/gi;
$location =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi;
@@ -572,6 +575,7 @@ if (length($report_id) > 1)
$filename_override =~ s/--A--30days--B--/$Hyear-$Hmon-$Hmday/gi;
$filename_override =~ s/--A--filedatetime--B--/$filedatetime/gi;
if ($DB) {print "FINAL LOCATION: |$location|\n";}
if ($DB) {print "REPORT SCRIPT: |$php_script|\n";}
if ($DB) {print "FILENAME OVERRIDE: |$filename_override|\n";}
}
else
@@ -656,6 +660,11 @@ else
}
### GRAB THE REPORT
$stmtB="INSERT INTO vicidial_pending_ar SET start_datetime='$timestamp', user='$http_user', report_id='$report_id', php_script='$php_script', status='TRIGGERED', notes='';";
$Iaffected_rows = $dbhA->do($stmtB);
if ($DB) {print "Pending AR entry inserted: $Iaffected_rows|$stmtB\n";}
if (!$Q) {print "Running Report $ship_date\n$location\n";}
`/usr/bin/wget --auth-no-challenge --http-user=$http_user --http-password=$http_pass --output-document=/tmp/X$HTMLfile --output-file=/tmp/Y$HTMLfileLOG $location `;
+10 -1
View File
@@ -17,10 +17,11 @@
#
# MAKE SURE YOU TEST THAT THIS IS WORKING MANUALLY!!!
#
# Copyright (C) 2020 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2024 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGES
# 200601-1047 - First version, based upon AST_email_web_report.pl
# 240401-1342 - Added vicidial_pending_ar table entries
#
$txt = '.txt';
@@ -532,6 +533,8 @@ if (length($report_id) > 1)
$email_subject =~ s/--A--date--B--|--A--today--B--/$year-$mon-$mday/gi;
$email_subject =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi;
$email_subject =~ s/--A--datetime--B--/$year-$mon-$mday $hour:$min:$sec/gi;
@php_script_url = $location =~ /([\w-]+\.php)/g;
$php_script = $php_script_url[0];
$location =~ s/\&/\\&/gi;
$location =~ s/--A--today--B--/$year-$mon-$mday/gi;
$location =~ s/--A--yesterday--B--/$Tyear-$Tmon-$Tmday/gi;
@@ -554,6 +557,7 @@ if (length($report_id) > 1)
$filename_override =~ s/--A--30days--B--/$Hyear-$Hmon-$Hmday/gi;
$filename_override =~ s/--A--filedatetime--B--/$filedatetime/gi;
if ($DB) {print "FINAL LOCATION: |$location|\n";}
if ($DB) {print "REPORT SCRIPT: |$php_script|\n";}
if ($DB) {print "FILENAME OVERRIDE: |$filename_override|\n";}
}
else
@@ -638,6 +642,11 @@ else
}
### GRAB THE REPORT
$stmtB="INSERT INTO vicidial_pending_ar SET start_datetime='$timestamp', user='$http_user', report_id='$report_id', php_script='$php_script', status='TRIGGERED', notes='';";
$Iaffected_rows = $dbhA->do($stmtB);
if ($DB) {print "Pending AR entry inserted: $Iaffected_rows|$stmtB\n";}
if (!$Q) {print "Running Report $ship_date\n$location\n";}
`/usr/bin/wget --auth-no-challenge --http-user=$http_user --http-password=$http_pass --output-document=/tmp/X$HTMLfile --output-file=/tmp/Y$HTMLfileLOG $location `;
+22 -1
View File
@@ -298,7 +298,7 @@ if ($sthArows > 0)
$sthA->finish();
### Grab system_settings values from the database
$stmtA = "SELECT sip_event_logging FROM system_settings limit 1;";
$stmtA = "SELECT sip_event_logging,enable_auto_reports FROM system_settings limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -306,6 +306,7 @@ if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$SSsip_event_logging = $aryA[0];
$SSenable_auto_reports = $aryA[1];
}
$sthA->finish();
@@ -637,6 +638,26 @@ if (!$T)
}
if (!$Q) {print " - OPTIMIZE vicidial_3way_press_multi \n";}
if ($SSenable_auto_reports > 0)
{
$stmtA = "UPDATE vicidial_pending_ar SET status='ERROR' where status='TRIGGERED' and start_datetime < '$SQLdate_NEG_tenminute';";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T) { $affected_rows = $dbhA->do($stmtA);}
if (!$Q) {print " - vicidial_pending_ar flush: $affected_rows rows\n";}
$stmtA = "OPTIMIZE table vicidial_pending_ar;";
if($DB){print STDERR "\n|$stmtA|\n";}
if (!$T)
{
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@aryA = $sthA->fetchrow_array;
if (!$Q) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
$sthA->finish();
}
if (!$Q) {print " - OPTIMIZE vicidial_pending_ar \n";}
}
$stmtA = "DELETE from server_live_stats where update_time < '$DQLdate_NEG_twelvehour';";
if($DB){print STDERR "\n|$stmtA|\n";}
Binary file not shown.
+2
View File
@@ -83,3 +83,5 @@ SRDROP - SHARED outbound campaign drop to in-group, not included in most DROP st
HUCXXX - Enhanced Disconnect Logging level 3 failed calls, where 'XXX' is the disconnect code. For example: "HUC18" for Cause 18 (SIP 408 Request timeout)
ADAIR - Dead Air Auto, for AMD NOAUDIODATA calls
ACFLTR - Inbound call areacode filter check
LTMGAD - Campaign HotKey option, will transfer customer to voicemail message and disposition the call
XAMMAD - Campaign HotKey option, will transfer customer to voicemail message and disposition the call
@@ -5233,6 +5233,32 @@ mb_available BIGINT(14) default '0',
unique index livepartitions (server_ip, partition_path)
) ENGINE=MyISAM;
CREATE TABLE inbound_disabled_entries (
interval_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
start_datetime DATETIME,
end_datetime datetime,
location VARCHAR(50),
message VARCHAR(100),
message_type ENUM('MEETING','CLOSED','WEATHER','CUSTOM'),
status ENUM('ACTIVE','LIVE','COMPLETED','CANCELLED') DEFAULT 'ACTIVE',
user VARCHAR(20),
modify_date TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
modified_by VARCHAR(20),
holiday_id VARCHAR(30),
KEY inbound_disabled_entries_key (start_datetime,end_datetime,location)
) ENGINE=MyISAM;
CREATE TABLE vicidial_pending_ar (
ar_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
report_id VARCHAR(30) default '',
start_datetime DATETIME,
php_script VARCHAR(50) default '',
user VARCHAR(20),
status ENUM('TRIGGERED','AUTHORIZED','COMPLETED','ERROR') DEFAULT 'TRIGGERED',
notes TEXT,
KEY pending_ar_key (user,start_datetime)
) ENGINE=MyISAM;
ALTER TABLE vicidial_email_list MODIFY message text character set utf8;
@@ -5632,4 +5658,4 @@ INSERT INTO `wallboard_reports` VALUES ('AGENTS_AND_QUEUES','Agents and Queues',
UPDATE system_settings set vdc_agent_api_active='1';
UPDATE system_settings SET db_schema_version='1710',db_schema_update_date=NOW(),reload_timestamp=NOW();
UPDATE system_settings SET db_schema_version='1711',db_schema_update_date=NOW(),reload_timestamp=NOW();
File diff suppressed because it is too large Load Diff
+28
View File
@@ -2669,3 +2669,31 @@ UPDATE system_settings SET db_schema_version='1709',db_schema_update_date=NOW()
ALTER TABLE vicidial_call_time_holidays ADD holiday_method VARCHAR(40) default 'REPLACE';
UPDATE system_settings SET db_schema_version='1710',db_schema_update_date=NOW() where db_schema_version < 1710;
CREATE TABLE inbound_disabled_entries (
interval_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
start_datetime DATETIME,
end_datetime datetime,
location VARCHAR(50),
message VARCHAR(100),
message_type ENUM('MEETING','CLOSED','WEATHER','CUSTOM'),
status ENUM('ACTIVE','LIVE','COMPLETED','CANCELLED') DEFAULT 'ACTIVE',
user VARCHAR(20),
modify_date TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
modified_by VARCHAR(20),
holiday_id VARCHAR(30),
KEY inbound_disabled_entries_key (start_datetime,end_datetime,location)
) ENGINE=MyISAM;
CREATE TABLE vicidial_pending_ar (
ar_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
report_id VARCHAR(30) default '',
start_datetime DATETIME,
php_script VARCHAR(50) default '',
user VARCHAR(20),
status ENUM('TRIGGERED','AUTHORIZED','COMPLETED','ERROR') DEFAULT 'TRIGGERED',
notes TEXT,
KEY pending_ar_key (user,start_datetime)
) ENGINE=MyISAM;
UPDATE system_settings SET db_schema_version='1711',db_schema_update_date=NOW() where db_schema_version < 1711;
+24 -2
View File
@@ -4,7 +4,7 @@
#
# functions for administrative scripts and reports
#
# Copyright (C) 2023 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2024 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
#
# CHANGES:
@@ -41,6 +41,7 @@
# 210615-0952 - Default security fix, CVE-2021-28854
# 220921-1209 - Added more failed login logging in user_authorization function
# 231119-1445 - Added user_authorization for HCI page users
# 240401-1459 - Added check for vicidial_pending_ar entries in user_authorization
#
##### BEGIN validate user login credentials, check for failed lock out #####
@@ -51,7 +52,7 @@ function user_authorization($user,$pass,$user_option,$user_update,$api_call)
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,webroot_writable,pass_hash_enabled,pass_key,pass_cost,allow_ip_lists,system_ip_blacklist,two_factor_auth_hours,two_factor_container FROM system_settings;";
$stmt = "SELECT use_non_latin,webroot_writable,pass_hash_enabled,pass_key,pass_cost,allow_ip_lists,system_ip_blacklist,two_factor_auth_hours,two_factor_container,enable_auto_reports FROM system_settings;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysqli_num_rows($rslt);
@@ -67,6 +68,7 @@ function user_authorization($user,$pass,$user_option,$user_update,$api_call)
$SSsystem_ip_blacklist = $row[6];
$SStwo_factor_auth_hours = $row[7];
$SStwo_factor_container = $row[8];
$SSenable_auto_reports = $row[9];
}
##### END SETTINGS LOOKUP #####
###########################################
@@ -260,6 +262,26 @@ function user_authorization($user,$pass,$user_option,$user_update,$api_call)
if ($VALID_2FA < 1)
{
$auth_key='2FA';
if ( ($user_option == 'REPORTS') and ($SSenable_auto_reports > 0) )
{
# If this is a REPORT, check for a triggered automated report, and if so, allow it to proceed
$stmt="SELECT count(*) from vicidial_pending_ar where user='$user' and status='TRIGGERED' and start_datetime > date_add(now(), interval 5 minute);";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$auth_check_to_print = mysqli_num_rows($rslt);
if ($auth_check_to_print > 0)
{
$row=mysqli_fetch_row($rslt);
if ($row[0] > 0);
{
$stmt="UPDATE vicidial_pending_ar SET status='AUTHORIZED',notes='$NOW_TIME $ip' WHERE user='$user' and status='TRIGGERED' and start_datetime > date_add(now(), interval 5 minute) order by start_datetime limit 1;";
$rslt=mysql_to_mysqli($stmt, $link);
$auth_key='GOOD';
}
}
}
}
}
}