From 6bf7fd6116bf05f6264def26a650c785d8578743 Mon Sep 17 00:00:00 2001 From: mattf Date: Mon, 7 Aug 2006 14:21:53 +0000 Subject: [PATCH] changed VICIDIAL_IN_new_leads_file.pl to DBI Deleted old Net-MySQL directory, depricated git-svn-id: svn://192.168.202.10@116 3d104415-ff17-0410-8863-d5cf3c621b8a --- .../ADMIN_adjust_GMTnow_on_leads.pl | 688 ---------- .../Net-MySQL_bin-agi/AST_DB_optimize.pl | 153 --- .../trunk/Net-MySQL_bin-agi/AST_VDhopper.pl | 1192 ----------------- .../AST_cleanup_agent_log.pl | 236 ---- .../Net-MySQL_bin-agi/AST_conf_update.pl | 220 --- .../Net-MySQL_bin-agi/AST_flush_DBqueue.pl | 189 --- .../AST_manager_kill_hung_congested.pl | 335 ----- .../Net-MySQL_bin-agi/AST_manager_listen.pl | 594 -------- .../Net-MySQL_bin-agi/AST_manager_send.pl | 384 ------ .../Net-MySQL_bin-agi/AST_reset_mysql_vars.pl | 72 - .../AST_send_action_child.pl | 258 ---- .../trunk/Net-MySQL_bin-agi/AST_vm_update.pl | 202 --- .../trunk/bin/VICIDIAL_IN_new_leads_file.pl | 132 +- 13 files changed, 69 insertions(+), 4586 deletions(-) delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/ADMIN_adjust_GMTnow_on_leads.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_DB_optimize.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_VDhopper.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_cleanup_agent_log.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_conf_update.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_flush_DBqueue.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_kill_hung_congested.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_listen.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_send.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_reset_mysql_vars.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_send_action_child.pl delete mode 100644 agc_2-X/trunk/Net-MySQL_bin-agi/AST_vm_update.pl diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/ADMIN_adjust_GMTnow_on_leads.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/ADMIN_adjust_GMTnow_on_leads.pl deleted file mode 100644 index ab4ed81d..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/ADMIN_adjust_GMTnow_on_leads.pl +++ /dev/null @@ -1,688 +0,0 @@ -#!/usr/bin/perl - -# ADMIN_adjust_GMTnow_on_leads.pl -# -# program goes throught the vicidial_list table and adjusts the gmt_offset_now -# field to change it to today's offset if needed because of Daylight Saving Time -# -# run every time you load leads into the vicidial_list table -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# -# 50810-1540 - Added database server variable definitions lookup -# 60615-1717 - Added definition GMT lookup from database not flat text file -# - -$MT[0]=''; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-q] = quiet\n [-t] = test\n [--debug] = debugging messages\n\n"; - } - else - { - if ($args =~ /-q/i) - { - $q=1; $Q=1; - } - if ($args =~ /--debug/i) - { - $DB=1; - print "\n-----DEBUGGING -----\n\n"; - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } - if ($args =~ /-t|--test/i) - { - $T=1; $TEST=1; - print "\n-----TESTING -----\n\n"; - } - } -} -else -{ -print "no command line options set\n"; -} - -if ($DB) {print "STARTING TIME ZONE DAYLIGHT SAVING TIME CALCULATION SCRIPT\n\n\n\n";} - -### end parsing run-time options ### - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -$secX = time(); -# $secX = '1079989363'; # epoch for March 22, 2993 -# $secX = '1097989363'; # epoch for October 17, 2004 - - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secX); - $mon++; - $year = ($year + 1900); - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} - $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); - -use Net::MySQL; - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - ### Grab Server values from the database - $stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrUSERNAMElisten,ASTmgrUSERNAMEsend,max_vicidial_trunks,answer_transfer_agent,local_gmt,ext_context FROM servers where server_ip = '$server_ip';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBtelnet_host = "$record->[0]"; - $DBtelnet_port = "$record->[1]"; - $DBASTmgrUSERNAME = "$record->[2]"; - $DBASTmgrSECRET = "$record->[3]"; - $DBASTmgrUSERNAMEupdate = "$record->[4]"; - $DBASTmgrUSERNAMElisten = "$record->[5]"; - $DBASTmgrUSERNAMEsend = "$record->[6]"; - $DBmax_vicidial_trunks = "$record->[7]"; - $DBanswer_transfer_agent= "$record->[8]"; - $DBSERVER_GMT = "$record->[9]"; - $DBext_context = "$record->[10]"; - if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} - if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} - if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} - if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} - if ($DBASTmgrUSERNAMEupdate) {$ASTmgrUSERNAMEupdate = $DBASTmgrUSERNAMEupdate;} - if ($DBASTmgrUSERNAMElisten) {$ASTmgrUSERNAMElisten = $DBASTmgrUSERNAMElisten;} - if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} - if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} - if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} - if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} - if ($DBext_context) {$ext_context = $DBext_context;} - } - } - - $LOCAL_GMT_OFF = $SERVER_GMT; - $LOCAL_GMT_OFF_STD = $SERVER_GMT; - -if ($isdst) {$LOCAL_GMT_OFF++;} -if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";} - - - $stmtA = "select distinct phone_code from vicidial_list;"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countY=0; - @phone_codes=@MT; - $phone_codes_list='|'; - while ($recordA = $iterA->each) - { - $phone_codes[$rec_countY] = $recordA->[0]; - $phone_codes_ORIG[$rec_countY] = $recordA->[0]; - $phone_codes[$rec_countY] =~ s/011|0011| |\t|\r|\n//gi; - - # if ( ($phone_codes_list !~ /\|$phone_codes[$rec_countY]\|/) && (length($phone_codes[$rec_countY]) > 0) ) - # { - # $phone_codes_list .= "$phone_codes[$rec_countY]|"; - # } - - if ($DBX) {print "|",$recordA->[0],"|","\n";} - $rec_countY++; - } - } - - if ($DB) {print " - Unique Country dial codes found: $rec_countY\n";} - - - $stmtA = "select * from vicidial_phone_codes;"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countZ=0; - @codefile=@MT; - while ($recordA = $iterA->each) - { - $codefile[$rec_countZ] = "$recordA->[0]\t$recordA->[1]\t$recordA->[2]\t$recordA->[3]\t$recordA->[4]\t$recordA->[5]\t$recordA->[6]\t$recordA->[7]\n"; - $rec_countZ++; - } - } - - if ($DB) {print " - GMT phone codes records: $rec_countZ\n";} - -# open(codefile, "/home/cron/phone_codes_GMT.txt") || die "can't open /home/cron/phone_codes_GMT.txt: $!\n"; -# @codefile = ; -# close(codefile); - -$ep=0; $ei=0; $ee=0; -$d=0; -foreach (@phone_codes) - { - $match_code = $phone_codes[$d]; - $match_code_ORIG = $phone_codes_ORIG[$d]; - - if ($DB) {print "\nRUNNING LOOP FOR COUNTRY CODE: $match_code\n";} - - $e=0; - foreach (@codefile) - { - chomp($codefile[$e]); - if ($codefile[$e] =~ /^$match_code\t/) - { - @m = split(/\t/, $codefile[$e]); - $area_code = $m[2]; - $area_state = $m[3]; - $area_GMT = $m[4]; $area_GMT =~ s/\+//gi; $area_GMT = ($area_GMT + 0); - $area_GMT_method = $m[6]; - if ($area_code =~ /S/) # look for state override flag in areacode field - { - $area_code =~ s/\D//gi; - $AC_match = " and phone_number LIKE \"$area_code%\" and state='$area_state'"; - if ($DB) {print " AREA CODE STATE OVERRIDE: $codefile[$e]\n";} - } - else - { - if ($area_code =~ /\*/) {$AC_match = '';} - else {$AC_match = " and phone_number LIKE \"$area_code%\"";} - } - if ($DBX) {print "PROCESSING THIS LINE: $codefile[$e]\n";} - $stmtA = "select count(*) from vicidial_list where phone_code='$match_code_ORIG' $AC_match;"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $rec_countZ=0; - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - $rec_countZ = $recordA->[0]; - } - } - if (!$rec_countZ) - { - if ($DB) {print " IGNORING: $codefile[$e]\n";} - $ei++; - } - else - { - $AC_GMT_diff = ($area_GMT - $LOCAL_GMT_OFF_STD); - $AC_localtime = ($secX + (3600 * $AC_GMT_diff)); - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($AC_localtime); - $year = ($year + 1900); - $mon++; - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} - $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); - - $AC_processed=0; - if ( (!$AC_processed) && ($area_GMT_method =~ /FSA-LSO/) ) - { - if ($DBX) {print " First Sunday April to Last Sunday October\n";} - &USA_dstcalc; - if ($DBX) {print " DST: $USA_DST\n";} - if ($USA_DST) {$area_GMT++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($area_GMT_method =~ /LSM-LSO/) ) - { - if ($DBX) {print " Last Sunday March to Last Sunday October\n";} - &GBR_dstcalc; - if ($DBX) {print " DST: $GBR_DST\n";} - if ($GBR_DST) {$area_GMT++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($area_GMT_method =~ /LSO-LSM/) ) - { - if ($DBX) {print " Last Sunday October to Last Sunday March\n";} - &AUS_dstcalc; - if ($DBX) {print " DST: $AUS_DST\n";} - if ($AUS_DST) {$area_GMT++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($area_GMT_method =~ /FSO-LSM/) ) - { - if ($DBX) {print " First Sunday October to Last Sunday March\n";} - &AUST_dstcalc; - if ($DBX) {print " DST: $AUST_DST\n";} - if ($AUST_DST) {$area_GMT++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($area_GMT_method =~ /FSO-TSM/) ) - { - if ($DBX) {print " First Sunday October to Third Sunday March\n";} - &NZL_dstcalc; - if ($DBX) {print " DST: $NZL_DST\n";} - if ($NZL_DST) {$area_GMT++;} - $AC_processed++; - } - if (!$AC_processed) - { - if ($DBX) {print " No DST Method Found\n";} - if ($DBX) {print " DST: 0\n";} - $AC_processed++; - } - - - if ($AC_processed) - { - $stmtA = "select count(*) from vicidial_list where phone_code='$match_code_ORIG' $AC_match and gmt_offset_now != '$area_GMT';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $rec_countW=0; - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - $rec_countW = $recordA->[0]; - } - } - if (!$rec_countW) - { - if ($DB) {print " ALL GMT ALREADY CORRECT FOR : $match_code_ORIG $area_code $area_GMT\n";} - $ei++; - } - else - { - $stmtA = "update vicidial_list set gmt_offset_now='$area_GMT' where phone_code='$match_code_ORIG' $AC_match and gmt_offset_now != '$area_GMT';"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - $Prec_countW = sprintf("%8s", $rec_countW); - if ($DB) {print " $Prec_countW records in $match_code_ORIG $area_code updated to $area_GMT\n";} - $ee++; - # sleep(1); - } - } - } - - $ep++; - } - else - { - if ($DBX) {print " IGNORING: $codefile[$e]\n";} - $ei++; - } - $e++; - } - - $d++; - } - - - - $dbhA->close; - -if($DB){print "\nDONE\n";} - -exit; - - - - -sub USA_dstcalc { -#********************************************************************** -# FSA-LSO -# This is returns 1 if Daylight Savings Time is in effect and 0 if -# Standard time is in effect. -# Based on first Sunday in April and last Sunday in October at 2 am. -# INPUTS: -# mm INTEGER Month. -# dd INTEGER Day of the month. -# ns INTEGER Seconds into the day. -# dow INTEGER Day of week (0=Sunday, to 6=Saturday) -# OPTIONAL INPUT: -# timezone INTEGER hour difference UTC - local standard time -# (DEFAULT is blank) -# make calculations based on UTC time, -# which means shift at 10:00 UTC in April -# and 9:00 UTC in October -# OUTPUT: -# INTEGER 1 = DST, 0 = not DST -#********************************************************************** - - $USA_DST=0; - $mm = $mon; - $dd = $mday; - $ns = $dsec; - $dow= $wday; - - if ($mm < 4 || $mm > 10) { - $USA_DST=0; return 0; - } elsif ($mm >= 5 && $mm <= 9) { - $USA_DST=1; return 1; - } elsif ($mm == 4) { - if ($dd > 7) { - $USA_DST=1; return 1; - } elsif ($dd >= ($dow+1)) { - if ($timezone) { - if ($dow == 0 && $ns < (7200+$timezone*3600)) { - $USA_DST=0; return 0; - } else { - $USA_DST=1; return 1; - } - } else { - if ($dow == 0 && $ns < 7200) { - $USA_DST=0; return 0; - } else { - $USA_DST=1; return 1; - } - } - } else { - $USA_DST=0; return 0; - } - } elsif ($mm == 10) { - if ($dd < 25) { - $USA_DST=1; return 1; - } elsif ($dd < ($dow+25)) { - $USA_DST=1; return 1; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (7200+($timezone-1)*3600)) { - $USA_DST=1; return 1; - } else { - $USA_DST=0; return 0; - } - } else { # local time calculations - if ($ns < 7200) { - $USA_DST=1; return 1; - } else { - $USA_DST=0; return 0; - } - } - } else { - $USA_DST=0; return 0; - } - } # end of month checks -} # end of subroutine dstcalc - - - - -sub GBR_dstcalc { -#********************************************************************** -# This is returns 1 if Daylight Savings Time is in effect and 0 if -# Standard time is in effect. -# Based on last Sunday in March and last Sunday in October at 1 am. -#********************************************************************** - - $GBR_DST=0; - $mm = $mon; - $dd = $mday; - $ns = $dsec; - $dow= $wday; - - if ($mm < 3 || $mm > 10) { - $GBR_DST=0; return 0; - } elsif ($mm >= 4 && $mm <= 9) { - $GBR_DST=1; return 1; - } elsif ($mm == 3) { - if ($dd < 25) { - $GBR_DST=0; return 0; - } elsif ($dd < ($dow+25)) { - $GBR_DST=0; return 0; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (3600+($timezone-1)*3600)) { - $GBR_DST=0; return 0; - } else { - $GBR_DST=1; return 1; - } - } else { # local time calculations - if ($ns < 3600) { - $GBR_DST=0; return 0; - } else { - $GBR_DST=1; return 1; - } - } - } else { - $GBR_DST=1; return 1; - } - } elsif ($mm == 10) { - if ($dd < 25) { - $GBR_DST=1; return 1; - } elsif ($dd < ($dow+25)) { - $GBR_DST=1; return 1; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (3600+($timezone-1)*3600)) { - $GBR_DST=1; return 1; - } else { - $GBR_DST=0; return 0; - } - } else { # local time calculations - if ($ns < 3600) { - $GBR_DST=1; return 1; - } else { - $GBR_DST=0; return 0; - } - } - } else { - $GBR_DST=0; return 0; - } - } # end of month checks -} # end of subroutine dstcalc - - - - -sub AUS_dstcalc { -#********************************************************************** -# This is returns 1 if Daylight Savings Time is in effect and 0 if -# Standard time is in effect. -# Based on last Sunday in October and last Sunday in March at 1 am. -#********************************************************************** - - $AUS_DST=0; - $mm = $mon; - $dd = $mday; - $ns = $dsec; - $dow= $wday; - - if ($mm < 3 || $mm > 10) { - $AUS_DST=1; return 1; - } elsif ($mm >= 4 && $mm <= 9) { - $AUS_DST=0; return 0; - } elsif ($mm == 3) { - if ($dd < 25) { - $AUS_DST=1; return 1; - } elsif ($dd < ($dow+25)) { - $AUS_DST=1; return 1; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (3600+($timezone-1)*3600)) { - $AUS_DST=1; return 1; - } else { - $AUS_DST=0; return 0; - } - } else { # local time calculations - if ($ns < 3600) { - $AUS_DST=1; return 1; - } else { - $AUS_DST=0; return 0; - } - } - } else { - $AUS_DST=0; return 0; - } - } elsif ($mm == 10) { - if ($dd < 25) { - $AUS_DST=0; return 0; - } elsif ($dd < ($dow+25)) { - $AUS_DST=0; return 0; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (3600+($timezone-1)*3600)) { - $AUS_DST=0; return 0; - } else { - $AUS_DST=1; return 1; - } - } else { # local time calculations - if ($ns < 3600) { - $AUS_DST=0; return 0; - } else { - $AUS_DST=1; return 1; - } - } - } else { - $AUS_DST=1; return 1; - } - } # end of month checks -} # end of subroutine dstcalc - - - - - -sub AUST_dstcalc { -#********************************************************************** -# TASMANIA ONLY -# This is returns 1 if Daylight Savings Time is in effect and 0 if -# Standard time is in effect. -# Based on first Sunday in October and last Sunday in March at 1 am. -#********************************************************************** - - $AUST_DST=0; - $mm = $mon; - $dd = $mday; - $ns = $dsec; - $dow= $wday; - - if ($mm < 3 || $mm > 10) { - $AUST_DST=1; return 1; - } elsif ($mm >= 4 && $mm <= 9) { - $AUST_DST=0; return 0; - } elsif ($mm == 3) { - if ($dd < 25) { - $AUST_DST=1; return 1; - } elsif ($dd < ($dow+25)) { - $AUST_DST=1; return 1; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (3600+($timezone-1)*3600)) { - $AUST_DST=1; return 1; - } else { - $AUST_DST=0; return 0; - } - } else { # local time calculations - if ($ns < 3600) { - $AUST_DST=1; return 1; - } else { - $AUST_DST=0; return 0; - } - } - } else { - $AUST_DST=0; return 0; - } - } elsif ($mm == 10) { - if ($dd > 7) { - $AUST_DST=1; return 1; - } elsif ($dd >= ($dow+1)) { - if ($timezone) { - if ($dow == 0 && $ns < (7200+$timezone*3600)) { - $AUST_DST=0; return 0; - } else { - $AUST_DST=1; return 1; - } - } else { - if ($dow == 0 && $ns < 3600) { - $AUST_DST=0; return 0; - } else { - $AUST_DST=1; return 1; - } - } - } else { - $AUST_DST=0; return 0; - } - } # end of month checks -} # end of subroutine dstcalc - - - - - -sub NZL_dstcalc { -#********************************************************************** -# This is returns 1 if Daylight Savings Time is in effect and 0 if -# Standard time is in effect. -# Based on first Sunday in October and third Sunday in March at 1 am. -#********************************************************************** - - $NZL_DST=0; - $mm = $mon; - $dd = $mday; - $ns = $dsec; - $dow= $wday; - - if ($mm < 3 || $mm > 10) { - $NZL_DST=1; return 1; - } elsif ($mm >= 4 && $mm <= 9) { - $NZL_DST=0; return 0; - } elsif ($mm == 3) { - if ($dd < 14) { - $NZL_DST=1; return 1; - } elsif ($dd < ($dow+14)) { - $NZL_DST=1; return 1; - } elsif ($dow == 0) { - if ($timezone) { # UTC calculations - if ($ns < (3600+($timezone-1)*3600)) { - $NZL_DST=1; return 1; - } else { - $NZL_DST=0; return 0; - } - } else { # local time calculations - if ($ns < 3600) { - $NZL_DST=1; return 1; - } else { - $NZL_DST=0; return 0; - } - } - } else { - $NZL_DST=0; return 0; - } - } elsif ($mm == 10) { - if ($dd > 7) { - $NZL_DST=1; return 1; - } elsif ($dd >= ($dow+1)) { - if ($timezone) { - if ($dow == 0 && $ns < (7200+$timezone*3600)) { - $NZL_DST=0; return 0; - } else { - $NZL_DST=1; return 1; - } - } else { - if ($dow == 0 && $ns < 3600) { - $NZL_DST=0; return 0; - } else { - $NZL_DST=1; return 1; - } - } - } else { - $NZL_DST=0; return 0; - } - } # end of month checks -} # end of subroutine dstcalc diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_DB_optimize.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_DB_optimize.pl deleted file mode 100644 index 2c1aabf2..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_DB_optimize.pl +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/perl -# -# AST_DB_optimize.pl version 0.1 -# -# DESCRIPTION: -# optimizes the tables used in the asterisk MySQL database -# -# It is recommended that you run this program on the local Asterisk machine -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -use Net::MySQL; - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - - - $stmtA = "optimize table call_log;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table park_log;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_log;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_closer_log;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_xfer_log;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_list;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_manager;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_auto_calls;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - $stmtA = "optimize table vicidial_live_agents;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - if ($DB) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - - - $dbhA->close; - - -exit; - - - - - - diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_VDhopper.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_VDhopper.pl deleted file mode 100644 index ab55395c..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_VDhopper.pl +++ /dev/null @@ -1,1192 +0,0 @@ -#!/usr/bin/perl -# -# AST_VDhopper.pl version 0.9 -# -# DESCRIPTION: -# uses Net::MySQL to update the VICIDIAL leads hopper for the new streamlined -# approach of allocating leads to client machines. -# -# SUMMARY: -# This program was designed for people using the Asterisk PBX with VICIDIAL -# -# For the client to use VICIDIAL, this program must be in the cron running -# every minute -# -# For this program to work you need to have the "asterisk" MySQL database -# created and create the tables listed in the CONF_MySQL.txt file, also make sure -# that the machine running this program has read/write/update/delete access -# to that database -# -# It is recommended that you run this program on the local Asterisk machine -# -# If this script is run ever minute and you are getting close to no leads after -# a minute, you may want to play with the variables below to streamline for -# your usage -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# 50810-1613 - Added database server variable definitions lookup -# 60215-1106 - Added Scheduled Callback release functionality -# 60228-1623 - Change Callback activation to set the called_since_last_reset=N -# 60228-1735 - Added hopper gmt validation to remove gmt outside of time range -# 60320-0932 - Added inactive lead list hopper deletion (Thanks Vic Jolin) -# 60322-1030 - Added super debug output -# 60418-0947 - Added lead filter per campaign -# 60509-1416 - Rewrite of local_call_time functions -# 60511-1150 - Added inserts into vicidial_campaign_stats table -# 60609-1451 - Added ability to filter by DNC list vicidial_dnc -# 60614-1159 - Added campaign lead recycling ability -# - -# constants -$DB=0; # Debug flag, set to 0 for no debug messages, On an active system this will generate lots of lines of output per minute -$US='__'; -$MT[0]=''; -#$vicidial_hopper='TEST_vicidial_hopper'; # for testing -$vicidial_hopper='vicidial_hopper'; - -# options -$insert_auto_CB_to_hopper = 1; # set to 1 to automatically insert ANYONE callbacks into the hopper - - -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year = ($year + 1900); -$mon++; -if ($mon < 10) {$mon = "0$mon";} -if ($mday < 10) {$mday = "0$mday";} -if ($hour < 10) {$Fhour = "0$hour";} -if ($min < 10) {$min = "0$min";} -if ($sec < 10) {$sec = "0$sec";} -$now_date = "$year-$mon-$mday $hour:$min:$sec"; -$VDL_date = "$year-$mon-$mday 00:00:01"; - -if (!$VDHLOGfile) {$VDHLOGfile = "/home/cron/hopper.$year-$mon-$mday";} - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options(must stay in this order):\n [--debug] = debug\n [--debugX] = super debug\n [--dbgmt] = show GMT offset of records as they are inserted into hopper\n [-t] = test\n [--level=XXX] = force a hopper_level of XXX\n [--campaign=XXX] = run for campaign XXX only\n\n"; - } - else - { - if ($args =~ /--campaign=/i) - { - # print "\n|$ARGS|\n\n"; - @data_in = split(/--campaign=/,$args); - $CLIcampaign = $data_in[1]; - } - else - {$CLIcampaign = '';} - if ($args =~ /--level=/i) - { - @data_in = split(/--level=/,$args); - $CLIlevel = $data_in[1]; - $CLIlevel =~ s/ .*$//gi; - $CLIlevel =~ s/\D//gi; - print "\n-----HOPPER LEVEL OVERRIDE: $CLIlevel -----\n\n"; - } - else - {$CLIlevel = '';} - if ($args =~ /--debug/i) - { - $DB=1; - print "\n----- DEBUG -----\n\n"; - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER DEBUG -----\n\n"; - } - if ($args =~ /--dbgmt/i) - { - $DB_show_offset=1; - print "\n-----DEBUG GMT -----\n\n"; - } - if ($args =~ /-t/i) - { - $T=1; $TEST=1; - print "\n-----TESTING -----\n\n"; - } - if ($args =~ /--wipe-hopper-clean/i) - { - $wipe_hopper_clean=1; - } - } -} -else -{ -print "no command line options set\n"; -} - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -sleep(1); ### sleep for 5 seconds to stagger cron script load - -#use lib './lib', '../lib'; -use Net::MySQL; - - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - -### Grab Server values from the database -$stmtA = "SELECT local_gmt FROM servers where server_ip = '$server_ip';"; -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBSERVER_GMT = "$record->[0]"; - if (length($DBSERVER_GMT)>0) {$SERVER_GMT = $DBSERVER_GMT;} - } - } - - -$secX = time(); - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secX); - $LOCAL_GMT_OFF = $SERVER_GMT; - $LOCAL_GMT_OFF_STD = $SERVER_GMT; - if ($isdst) {$LOCAL_GMT_OFF++;} - - -$GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now); - $mon++; - $year = ($year + 1900); - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} - - - if ($DB) {print "TIME DEBUG: $LOCAL_GMT_OFF_STD|$LOCAL_GMT_OFF|$isdst| GMT: $hour:$min\n";} - -if ($wipe_hopper_clean) - { - $stmtA = "DELETE from $vicidial_hopper;"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print "Hopper Wiped Clean: $affected_rows\n";} - $event_string = "|HOPPER WIPE CLEAN|"; - &event_logger; - - exit; - } - -### Delete leads from inactive lists if there are any -$stmtA = "SELECT * FROM vicidial_lists where active='N';"; -if ($DB) {print $stmtA;} -$inactive_lists=''; -$inactive_lists_count=0; -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $inactive_list = $record->[0]; - $inactive_lists .= "'$inactive_list',"; - $inactive_lists_count++; - } - } -if ($DB) {print "Inactive Lists: $inactive_lists_count\n";} - -if ($inactive_lists_count > 0) - { - chop($inactive_lists); - $stmtA = "DELETE from $vicidial_hopper where list_id IN($inactive_lists);"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print "Inactive List Leads Deleted: $affected_rows |$stmtA|\n";} - $event_string = "|INACTIVE LIST DEL|$affected_rows|"; - &event_logger; - } - - -### BEGIN Change CBHOLD status leads to CALLBK if their vicidial_callbacks time has passed -$stmtA = "SELECT count(*) FROM vicidial_callbacks where callback_time <= '$now_date' and status='ACTIVE';"; -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $CBHOLD_count = "$record->[0]"; - } - } - - if ($DB) {print "CALLBACK HOLD: $CBHOLD_count|$stmtA|\n";} - -if ($CBHOLD_count > 0) - { - $update_leads=''; - $stmtA = "SELECT vicidial_callbacks.lead_id,recipient,campaign_id,vicidial_callbacks.list_id,gmt_offset_now FROM vicidial_callbacks,vicidial_list where callback_time <= '$now_date' and vicidial_callbacks.status='ACTIVE' and vicidial_callbacks.lead_id=vicidial_list.lead_id;"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $cbc=0; - $cba=0; - while ( $record = $iter->each) - { - $lead_ids[$cbc] = $record->[0]; - $recipient = $record->[1]; - $update_leads .= "'$lead_ids[$cbc]',"; - if ($recipient == 'ANYONE') - { - $CA_lead_id[$cba] = $record->[0]; - $CA_campaign_id[$cba] = $record->[2]; - $CA_list_id[$cba] = $record->[3]; - $CA_gmt_offset_now[$cba] = $record->[4]; - $cba++; - } - $cbc++; - } - } - if ($cbc > 0) - { - chop($update_leads); - - $stmtA = "UPDATE vicidial_list set status='CALLBK', called_since_last_reset='N' where lead_id IN($update_leads);"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print "Scheduled Callbacks Activated: $affected_rows\n";} - $event_string = "|CALLBACKS LISTACT|$affected_rows|"; - &event_logger; - - $stmtA = "UPDATE vicidial_callbacks set status='LIVE' where lead_id IN($update_leads);"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print "Scheduled Callbacks Activated: $affected_rows\n";} - $event_string = "|CALLBACKS CB ACT |$affected_rows|"; - &event_logger; - - } - ### INSERT ANYONE CALLBACKS INTO HOPPER DIRECTLY ### - if ( ($cba > 0) && ($insert_auto_CB_to_hopper) ) - { - if ($DB) {print "ANYONE Scheduled Callbacks Inserted into hopper: $cba\n";} - $event_string = "|ANYONE CB HOPPER |$cba|"; - &event_logger; - $CAu=0; - foreach(@CA_lead_id) - { - $stmtA = "INSERT INTO $vicidial_hopper SET lead_id='$CA_lead_id[$CAu]',campaign_id='$CA_campaign_id[$CAu]',list_id='$CA_list_id[$CAu]',gmt_offset_now='$CA_gmt_offset_now[$CAu]';"; - $dbhA->query("$stmtA"); - $CAu++; - } - } - } -### END Change CBHOLD status leads to CALLBK if their vicidial_callbacks time has passed - - - -@campaign_id=@MT; - -if ($CLIcampaign) - { - $stmtA = "SELECT * from vicidial_campaigns where campaign_id='$CLIcampaign'"; - } -else - { - $stmtA = "SELECT * from vicidial_campaigns where active='Y'"; - } - -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $campaign_id[$rec_count] = "$record->[0]"; - $dial_status_a[$rec_count] = "$record->[3]"; - $dial_status_b[$rec_count] = "$record->[4]"; - $dial_status_c[$rec_count] = "$record->[5]"; - $dial_status_d[$rec_count] = "$record->[6]"; - $dial_status_e[$rec_count] = "$record->[7]"; - $lead_order[$rec_count] = "$record->[8]"; - if (!$CLIlevel) - {$hopper_level[$rec_count] = "$record->[13]";} - else - {$hopper_level[$rec_count] = "$CLIlevel";} - $local_call_time[$rec_count] = "$record->[16]"; - $lead_filter_id[$rec_count] = "$record->[35]"; - $use_internal_dnc[$rec_count] = "$record->[43]"; - $rec_count++; - } - } - -$i=0; -foreach(@campaign_id) - { - ### close out MySQL connection and re-connect to start new connection ### -# $dbhA->close(); -# my $dbhA = ''; - - ### Make sure this file is in a libs path or put the absolute path to it -# require("/home/cron/AST_SERVER_conf.pl"); # local configuration file -# if (!$DB_port) {$DB_port='3306';} -# use Net::MySQL; - -# my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") -# or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - $VCSdialable_leads=0; - $VCScalls_today=0; - $VCSdrops_today=0; - $VCSdrops_today_pct=0; - $vicidial_log = 'vicidial_log'; - - $stmtA = "SELECT dialable_leads from vicidial_campaign_stats where campaign_id='$campaign_id[$i]';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $VCSdialable_leads = "$record->[0]"; - } - } - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $VCScalls_today = "$record->[0]"; - } - } - if ($VCScalls_today > 0) - { - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN('DROP','XDROP');"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $VCSdrops_today = "$record->[0]"; - if ($VCSdrops_today > 0) - { - $VCSdrops_today_pct = ( ($VCSdrops_today / $VCScalls_today) * 100 ); - $VCSdrops_today_pct = sprintf("%.2f", $VCSdrops_today_pct); - } - } - } - } - - $stmtA = "UPDATE vicidial_campaign_stats SET calls_today='$VCScalls_today',drops_today='$VCSdrops_today',drops_today_pct='$VCSdrops_today_pct' where campaign_id='$campaign_id[$i]';"; - $dbhA->query("$stmtA"); - - ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### - $g=0; - $p='13'; - $GMT_gmt[0] = ''; - $GMT_hour[0] = ''; - $GMT_day[0] = ''; - if ($DBX) {print "\n |GMT-DAY-HOUR| ";} - while ($p > -13) - { - $pzone = ($GMT_now + ($p * 3600)); - ($psec,$pmin,$phour,$pmday,$pmon,$pyear,$pday,$pyday,$pisdst) = localtime($pzone); - $phour=($phour * 100); - $tz = sprintf("%.2f", $p); - $GMT_gmt[$g] = "$tz"; - $GMT_day[$g] = "$pday"; - $GMT_hour[$g] = ($phour + $pmin); - $p = ($p - 0.25); - if ($DBX) {print "|$GMT_gmt[$g]-$GMT_day[$g]-$GMT_hour[$g]|";} - $g++; - } - if ($DBX) {print "\n";} - - $stmtA = "SELECT * FROM vicidial_call_times where call_time_id='$local_call_time[$i]';"; - if ($DBX) {print " |$stmtA|\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $Gct_default_start = "$record->[3]"; - $Gct_default_stop = "$record->[4]"; - $Gct_sunday_start = "$record->[5]"; - $Gct_sunday_stop = "$record->[6]"; - $Gct_monday_start = "$record->[7]"; - $Gct_monday_stop = "$record->[8]"; - $Gct_tuesday_start = "$record->[9]"; - $Gct_tuesday_stop = "$record->[10]"; - $Gct_wednesday_start = "$record->[11]"; - $Gct_wednesday_stop = "$record->[12]"; - $Gct_thursday_start = "$record->[13]"; - $Gct_thursday_stop = "$record->[14]"; - $Gct_friday_start = "$record->[15]"; - $Gct_friday_stop = "$record->[16]"; - $Gct_saturday_start = "$record->[17]"; - $Gct_saturday_stop = "$record->[18]"; - $Gct_state_call_times = "$record->[19]"; - } - } - - $ct_states = ''; - $ct_state_gmt_SQL = ''; - $del_state_gmt_SQL = ''; - $ct_srs=0; - $b=0; - if (length($Gct_state_call_times)>2) - { - @state_rules = split(/\|/,$Gct_state_call_times); - $ct_srs = ($#state_rules - 2); - } - while($ct_srs >= $b) - { - if (length($state_rules[$b])>1) - { - $stmtA = "SELECT * from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; - if ($DBX) {print " |$stmtA|\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $Gstate_call_time_id = "$record->[0]"; - $Gstate_call_time_state = "$record->[1]"; - $Gsct_default_start = "$record->[4]"; - $Gsct_default_stop = "$record->[5]"; - $Gsct_sunday_start = "$record->[6]"; - $Gsct_sunday_stop = "$record->[7]"; - $Gsct_monday_start = "$record->[8]"; - $Gsct_monday_stop = "$record->[9]"; - $Gsct_tuesday_start = "$record->[10]"; - $Gsct_tuesday_stop = "$record->[11]"; - $Gsct_wednesday_start = "$record->[12]"; - $Gsct_wednesday_stop = "$record->[13]"; - $Gsct_thursday_start = "$record->[14]"; - $Gsct_thursday_stop = "$record->[15]"; - $Gsct_friday_start = "$record->[16]"; - $Gsct_friday_stop = "$record->[17]"; - $Gsct_saturday_start = "$record->[18]"; - $Gsct_saturday_stop = "$record->[19]"; - $ct_states .="'$Gstate_call_time_state',"; - } - } - - $r=0; - $state_gmt=''; - $del_state_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - else - {$del_state_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - $state_gmt = "$state_gmt'99'"; - $del_state_gmt = "$del_state_gmt'99'"; - $ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; - $del_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($del_state_gmt)) "; - } - - $b++; - } - if (length($ct_states)>2) - { - $ct_states =~ s/,$//gi; - $ct_statesSQL = "and state NOT IN($ct_states)"; - } - else - { - $ct_statesSQL = ""; - } - - $r=0; - $default_gmt=''; - $del_default_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gct_monday_start==0) and ($Gct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gct_friday_start==0) and ($Gct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - else - {$del_default_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - - $default_gmt = "$default_gmt'99'"; - $del_default_gmt = "$del_default_gmt'99'"; - $all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL"; - $del_gmtSQL = "(gmt_offset_now IN($del_default_gmt) $ct_statesSQL) $del_state_gmt_SQL"; - - ##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ### - - ##### BEGIN lead recycling parsing and prep ### - - $stmtA = "SELECT * from vicidial_lead_recycle where campaign_id='$campaign_id[$i]' and active='Y';"; - $dbhA->query("$stmtA"); - $rec_ct=0; - if ($dbhA->has_selected_record) - { - @recycle_status=@MT; - @recycle_delay=@MT; - @recycle_maximum=@MT; - @RSQLdate=@MT; - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $recycle_status[$rec_ct] = $record->[2]; - $recycle_delay[$rec_ct] = $record->[3]; - $recycle_maximum[$rec_ct] = $record->[4]; - $rec_ct++; - } - } - - if ($rec_ct > 0) - { - $rc=0; - $recycle_SQL = "( "; - while($rc < $rec_ct) - { - $secX = time(); - $Rtarget = ($secX - $recycle_delay[$rc]); - ($Rsec,$Rmin,$Rhour,$Rmday,$Rmon,$Ryear,$Rwday,$Ryday,$Risdst) = localtime($Rtarget); - $Ryear = ($Ryear + 1900); - $Rmon++; - if ($Rmon < 10) {$Rmon = "0$Rmon";} - if ($Rmday < 10) {$Rmday = "0$Rmday";} - if ($Rhour < 10) {$Rhour = "0$Rhour";} - if ($Rmin < 10) {$Rmin = "0$Rmin";} - if ($Rsec < 10) {$Rsec = "0$Rsec";} - $RSQLdate[$rc] = "$Ryear-$Rmon-$Rmday $Rhour:$Rmin:$Rsec"; - $Y=1; - $recycle_Y = "'Y'"; - while ($Y < $recycle_maximum[$rc]) - { - $recycle_Y .= ",'Y$Y'"; - $Y++; - } - - if ($rc > 0) {$recycle_SQL .= " or ";} - - $recycle_SQL .= "( (called_since_last_reset IN($recycle_Y)) and (status='$recycle_status[$rc]') and (modify_date < \"$RSQLdate[$rc]\") )"; - - if ($DBX) {print "RECYCLE: |$campaign_id[$i]|$recycle_status[$rc]|$recycle_delay[$rc]|$recycle_maximum[$rc]|$RSQLdate[$rc]|\n";} - $rc++; - } - - $recycle_SQL .= " )"; - - if ($DBX) {print "RECYCLE SQL: |$recycle_SQL|\n";} - } - ##### END lead recycling parsing and prep ### - - if ($DB) {print "Starting hopper run for $campaign_id[$i] campaign- GMT: $local_call_time[$i] HOPPER: $hopper_level[$i] \n";} - - ### Delete the DONE leads if there are any - $stmtA = "DELETE from $vicidial_hopper where campaign_id='$campaign_id[$i]' and status IN('DONE');"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print " hopper DONE cleared: $affected_rows\n";} - if ($DBX) {print " |$stmtA|\n";} - - ### Delete the leads that are out of GMT time range if there are any - $stmtA = "DELETE from $vicidial_hopper where campaign_id='$campaign_id[$i]' and ($del_gmtSQL);"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print " hopper GMT BAD cleared: $affected_rows\n";} - if ($DBX) {print " |$stmtA|\n";} - - ### Find out how many leads are in the hopper from a specific campaign - $hopper_ready_count=0; - $stmtA = "SELECT count(*) from $vicidial_hopper where campaign_id='$campaign_id[$i]' and status='READY';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_countA=0; - while ( $record = $iter->each) - { - $hopper_ready_count = $record->[0]; - if ($DB) {print " hopper READY count: $hopper_ready_count\n";} - if ($DBX) {print " |$stmtA|\n";} - $rec_countA++; - } - } - $event_string = "|$campaign_id[$i]|$hopper_level[$i]|$hopper_ready_count|$local_call_time[$i]||"; - &event_logger; - - ##### IF hopper level is below set minimum, then try to add more leads ##### - if ($hopper_ready_count < $hopper_level[$i]) - { - if ($DB) {print " hopper too low ($hopper_ready_count|$hopper_level[$i]) starting hopper dump\n";} - - ### Get list of the lists in the campaign ### - $stmtA = "SELECT list_id FROM vicidial_lists where campaign_id='$campaign_id[$i]' and active='Y';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_countLISTS=0; - $camp_lists = ''; - while ( $record = $iter->each) - { - $camp_lists .= "'$record->[0]',"; - $rec_countLISTS++; - } - chop($camp_lists); - } - if ($DB) {print " campaign lists count: $rec_countLISTS | $camp_lists\n";} - if ($DBX) {print " |$stmtA|\n";} - - if ( ($lead_filter_id[$i] !~ /NONE/) && (length($lead_filter_id[$i])>0) ) - { - ### Get SQL of lead filter for the campaign ### - $stmtA = "SELECT lead_filter_sql FROM vicidial_lead_filters where lead_filter_id='$lead_filter_id[$i]';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $lead_filter_sql[$i] = "$record->[0]"; - } - } - $lead_filter_sql[$i] =~ s/^and|and$|^or|or$|^ and|and $|^ or|or $//gi; - $lead_filter_sql[$i] = "and $lead_filter_sql[$i]"; - if ($DB) {print " campaign lists count: $rec_countLISTS | $camp_lists\n";} - if ($DB) {print " lead filter $lead_filter_id[$i] defined for $campaign_id[$i]\n";} - if ($DBX) {print " |$lead_filter_sql[$i]|\n";} - } - else - { - $lead_filter_sql[$i] = ''; - if ($DB) {print " no lead filter defined for campaign: $campaign_id[$i]\n";} - if ($DBX) {print " |$lead_filter_id[$i]|\n";} - } - - $stmtA = "SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN('$dial_status_a[$i]','$dial_status_b[$i]','$dial_status_c[$i]','$dial_status_d[$i]','$dial_status_e[$i]') and list_id IN($camp_lists) and ($all_gmtSQL) $lead_filter_sql[$i];"; - if ($DBX) {print " |$stmtA|\n";} - $dbhA->query("$stmtA"); - $campaign_leads_to_call=0; - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $campaign_leads_to_call = "$record->[0]"; - if ($DB) {print " leads to call count: $campaign_leads_to_call\n";} - if ($DBX) {print " |$stmtA|\n";} - } - } - if ($lead_order[$i] =~ /DOWN COUNT 2nd NEW|DOWN COUNT 3rd NEW|DOWN COUNT 4th NEW/) - { - $stmtA = "SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists) and ($all_gmtSQL) $lead_filter_sql[$i];"; - $dbhA->query("$stmtA"); - $NEW_campaign_leads_to_call=0; - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $NEW_campaign_leads_to_call = "$record->[0]"; - if ($DB) {print " NEW leads to call count: $NEW_campaign_leads_to_call\n";} - if ($DBX) {print " |$stmtA|\n";} - } - } - } - - ##### IF no NEW leads to be called, error out of this campaign ##### - if ( ($lead_order[$i] =~ /DOWN COUNT 2nd NEW|DOWN COUNT 3rd NEW|DOWN COUNT 4th NEW/) && ($NEW_campaign_leads_to_call > 0) ) {$GOOD=1;} - else - { - if ($DB) {print " ERROR CANNOT ADD ANY NEW LEADS TO HOPPER\n";} - } - - ##### IF no leads to be called, error out of this campaign ##### - if ($campaign_leads_to_call < 1) - { - if ($DB) {print " ERROR CANNOT ADD ANY LEADS TO HOPPER\n";} - if ($VCSdialable_leads > 0) - { - $stmtA = "UPDATE vicidial_campaign_stats SET dialable_leads='0' where campaign_id='$campaign_id[$i]';"; - $dbhA->query("$stmtA"); - } - } - else - { - if ($VCSdialable_leads != $campaign_leads_to_call) - { - $stmtA = "UPDATE vicidial_campaign_stats SET dialable_leads='$campaign_leads_to_call' where campaign_id='$campaign_id[$i]';"; - $dbhA->query("$stmtA"); - } - if ($DB) {print " Getting Leads to add to hopper\n";} - ### grab leads already in hopper so we don't duplicate - $stmtA = "SELECT lead_id FROM $vicidial_hopper where campaign_id='$campaign_id[$i]';"; - if ($DBX) {print " |$stmtA|\n";} - $dbhA->query("$stmtA"); - $rec_countLISTS=0; - $lead_id_lists = ''; - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $lead_id_lists .= "'$record->[0]',"; - $rec_countLISTS++; - } - $lead_id_lists .= "'0'"; - } - - $order_stmt=''; - $NEW_count = 0; - $NEW_level = 0; - $OTHER_level = $hopper_level[$i]; - if ($lead_order[$i] eq "DOWN") {$order_stmt = 'order by lead_id asc';} - if ($lead_order[$i] eq "UP") {$order_stmt = 'order by lead_id desc';} - if ($lead_order[$i] eq "UP LAST NAME") {$order_stmt = 'order by last_name desc, lead_id asc';} - if ($lead_order[$i] eq "DOWN LAST NAME") {$order_stmt = 'order by last_name, lead_id asc';} - if ($lead_order[$i] eq "UP PHONE") {$order_stmt = 'order by phone_number desc, lead_id asc';} - if ($lead_order[$i] eq "DOWN PHONE") {$order_stmt = 'order by phone_number, lead_id asc';} - if ($lead_order[$i] eq "UP COUNT") {$order_stmt = 'order by called_count desc, lead_id asc';} - if ($lead_order[$i] eq "DOWN COUNT") {$order_stmt = 'order by called_count, lead_id asc';} - if ($lead_order[$i] eq "DOWN COUNT 2nd NEW") {$NEW_count = 2;} - if ($lead_order[$i] eq "DOWN COUNT 3rd NEW") {$NEW_count = 3;} - if ($lead_order[$i] eq "DOWN COUNT 4th NEW") {$NEW_count = 4;} - - ### BEGIN recycle grab leads ### - if ($rec_ct > 0) - { - if ($DB) {print " looking for RECYCLE leads, maximum of 100\n";} - - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where $recycle_SQL and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and ($all_gmtSQL) $lead_filter_sql[$i] limit 100;"; - if ($DBX) {print " |$stmtA|\n";} - $REC_rec_countLEADS=0; - @REC_leads_to_hopper=@MT; - @REC_lists_to_hopper=@MT; - @REC_phone_to_hopper=@MT; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $REC_leads_to_hopper[$REC_rec_countLEADS] = "$record->[0]"; - $REC_lists_to_hopper[$REC_rec_countLEADS] = "$record->[1]"; - $REC_gmt_to_hopper[$REC_rec_countLEADS] = "$record->[2]"; - $REC_phone_to_hopper[$REC_rec_countLEADS] = "$record->[3]"; - $REC_state_to_hopper[$REC_rec_countLEADS] = "$record->[4]"; - if ($DB_show_offset) {print "LEAD_ADD: $record->[2] $record->[3] $record->[4]\n";} - $REC_rec_countLEADS++; - } - } - if ($DB) {print " RECYCLE leads to call count: $REC_rec_countLEADS\n";} - if ($DBX) {print " |$stmtA|\n";} - } - ### END recycle grab leads ### - - if ($NEW_count > 0) - { - $NEW_level = int($hopper_level[$i] / $NEW_count); - $OTHER_level = ($hopper_level[$i] - $NEW_level); - $order_stmt = 'order by called_count, lead_id asc'; - if ($DB) {print " looking for $NEW_level NEW leads mixed in with $OTHER_level other leads\n";} - - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and ($all_gmtSQL) $lead_filter_sql[$i] $order_stmt limit $NEW_level;"; - if ($DBX) {print " |$stmtA|\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $NEW_rec_countLEADS=0; - @NEW_leads_to_hopper=@MT; - @NEW_lists_to_hopper=@MT; - @NEW_phone_to_hopper=@MT; - while ( $record = $iter->each) - { - $NEW_leads_to_hopper[$NEW_rec_countLEADS] = "$record->[0]"; - $NEW_lists_to_hopper[$NEW_rec_countLEADS] = "$record->[1]"; - $NEW_gmt_to_hopper[$NEW_rec_countLEADS] = "$record->[2]"; - $NEW_phone_to_hopper[$NEW_rec_countLEADS] = "$record->[3]"; - $NEW_state_to_hopper[$NEW_rec_countLEADS] = "$record->[4]"; - if ($DB_show_offset) {print "LEAD_ADD: $record->[2] $record->[3] $record->[4]\n";} - $NEW_rec_countLEADS++; - } - } - - } - - if ($DB) {print " lead call order: $order_stmt\n";} - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where called_since_last_reset='N' and status IN('$dial_status_a[$i]','$dial_status_b[$i]','$dial_status_c[$i]','$dial_status_d[$i]','$dial_status_e[$i]') and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and ($all_gmtSQL) $lead_filter_sql[$i] $order_stmt limit $OTHER_level;"; - if ($DBX) {print " |$stmtA|\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_countLEADS=0; $NEW_dec=99; $NEW_in=0; - @leads_to_hopper=@MT; - @lists_to_hopper=@MT; - @gmt_to_hopper=@MT; - @state_to_hopper=@MT; - @phone_to_hopper=@MT; - while ( $record = $iter->each) - { - if ( ($NEW_count > 0) && ($NEW_rec_countLEADS > $NEW_in) ) - { - if ($DB_show_offset) {print "NEW_COUNT: $NEW_count|$NEW_dec|$NEW_in|$NEW_rec_countLEADS\n";} - if ($NEW_count > $NEW_dec) - { - $NEW_dec++; - } - else - { - $leads_to_hopper[$rec_countLEADS] = "$NEW_leads_to_hopper[$NEW_in]"; - $lists_to_hopper[$rec_countLEADS] = "$NEW_lists_to_hopper[$NEW_in]"; - $gmt_to_hopper[$rec_countLEADS] = "$NEW_gmt_to_hopper[$NEW_in]"; - $state_to_hopper[$rec_countLEADS] = "$NEW_state_to_hopper[$NEW_in]"; - $phone_to_hopper[$rec_countLEADS] = "$NEW_phone_to_hopper[$NEW_in]"; - if ($DB_show_offset) {print "LEAD_ADD: $NEW_leads_to_hopper[$NEW_in] $NEW_phone_to_hopper[$NEW_in]\n";} - $rec_countLEADS++; - $NEW_in++; - $NEW_dec=2; - } - } - if ($REC_rec_countLEADS > $REC_insert_count) - { - $leads_to_hopper[$rec_countLEADS] = "$REC_leads_to_hopper[$REC_insert_count]"; - $lists_to_hopper[$rec_countLEADS] = "$REC_lists_to_hopper[$REC_insert_count]"; - $gmt_to_hopper[$rec_countLEADS] = "$REC_gmt_to_hopper[$REC_insert_count]"; - $state_to_hopper[$rec_countLEADS] = "$REC_state_to_hopper[$REC_insert_count]"; - $phone_to_hopper[$rec_countLEADS] = "$REC_phone_to_hopper[$REC_insert_count]"; - $rec_countLEADS++; - $REC_insert_count++; - } - $leads_to_hopper[$rec_countLEADS] = "$record->[0]"; - $lists_to_hopper[$rec_countLEADS] = "$record->[1]"; - $gmt_to_hopper[$rec_countLEADS] = "$record->[2]"; - $state_to_hopper[$rec_countLEADS] = "$record->[4]"; - $phone_to_hopper[$rec_countLEADS] = "$record->[3]"; - if ($DB_show_offset) {print "LEAD_ADD: $record->[2] $record->[3] $record->[4]\n";} - $rec_countLEADS++; - } - } - - if ($DB) {print " Adding to hopper: $rec_countLEADS\n";} - $event_string = "|$campaign_id[$i]|Added to hopper $rec_countLEADS|"; - &event_logger; - - $h=0; - foreach(@leads_to_hopper) - { - if ($leads_to_hopper[$h] != '0') - { - $DNClead=0; - if ($use_internal_dnc[$i] =~ /Y/) - { - if ($DB) {print " Doinbg DNC Check: $phone_to_hopper[$h]\n";} - $stmtA = "SELECT count(*) from vicidial_dnc where phone_number='$phone_to_hopper[$h]';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $DNClead = "$record->[0]"; - } - } - if ($DNClead != '0') - { - $stmtA = "UPDATE vicidial_list SET status='DNCL' where lead_id='$leads_to_hopper[$h]';"; - $dbhA->query("$stmtA"); - if ($DB) {print "Flagging DNC lead: $leads_to_hopper[$h] $phone_to_hopper[$h]\n";} - } - } - if ($DNClead == '0') - { - $stmtA = "INSERT INTO $vicidial_hopper (lead_id,campaign_id,status,user,list_id,gmt_offset_now,state) values('$leads_to_hopper[$h]','$campaign_id[$i]','READY','','$lists_to_hopper[$h]','$gmt_to_hopper[$h]','$state_to_hopper[$h]');"; - $dbhA->query("$stmtA"); - } - } - $h++; - } - if ($DB) {print " DONE with this campaign\n";} - - } - } - - - $i++; - } - - -$dbhA->close; - -if($DB){print "DONE... Exiting... Goodbye... See you later... Really, I mean it :)\n";} - -exit; - - - -sub event_logger { - ### open the log file for writing ### - open(Lout, ">>$VDHLOGfile") - || die "Can't open $VDHLOGfile: $!\n"; - - print Lout "$now_date|$event_string|\n"; - - close(Lout); - -$event_string=''; -} - - diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_cleanup_agent_log.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_cleanup_agent_log.pl deleted file mode 100644 index 7f405a09..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_cleanup_agent_log.pl +++ /dev/null @@ -1,236 +0,0 @@ -#!/usr/bin/perl -# -# AST_cleanup_agent_log.pl version 0.1 -# -# DESCRIPTION: -# to be run frequently to clean up the vicidial_agent_log to fix erroneous time -# calculations due to out-of-order vicidial_agent_log updates. This happens 0.5% -# of the time in our test setups, but that leads to inaccurate time logs so we -# wrote this script to fix the miscalculations -# -# This program only needs to be run by one server -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# - - -# constants -$COUNTER_OUTPUT=1; # set to 1 to display the counter as the script runs -$US='__'; -$MT[0]=''; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n[-debugX] = Extra-verbose debug messages\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - print "\n----- DEBUGGING -----\n\n"; - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } - if ($args =~ /-t/i) - { - $TEST=1; - $T=1; - print "\n----- TEST RUN, NO UPDATES -----\n\n"; - } - } -} -else -{ -# print "no command line options set\n"; -} -### end parsing run-time options ### - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -use Net::MySQL; - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - - if ($DB) {print " - cleaning up pause time\n";} - ### Grab any pause time record greater than 50000 - $stmtA = "SELECT agent_log_id,pause_epoch,wait_epoch from vicidial_agent_log where pause_sec>50000;"; - if ($DBX) {print "$stmtA\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $i=0; - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBout = ''; - $agent_log_id[$i] = "$record->[0]"; - $pause_epoch[$i] = "$record->[1]"; - $wait_epoch[$i] = "$record->[2]"; - $pause_sec[$i] = int($wait_epoch[$i] - $pause_epoch[$i]); - if ( ($pause_sec[$i] < 0) || ($pause_sec[$i] > 50000) ) - { - $DBout = "Override output: $pause_sec[$i]"; - $pause_sec[$i] = 0; - } - if ($DBX) {print "$i - $agent_log_id[$i] |$wait_epoch[$i]|$pause_epoch[$i]|$pause_sec[$i]|$DBout|\n";} - $i++; - } - } - $h=0; - while ($h < $i) - { - $stmtA = "UPDATE vicidial_agent_log set pause_sec='$pause_sec[$h]' where agent_log_id='$agent_log_id[$h]';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - if (!$TEST) {$dbhA->query($stmtA); }# or die "Couldn't execute query: |$stmtA|\n"; - $h++; - } - if ($DB) {print STDERR " Pause times fixed: $h\n";} - - - - - - @agent_log_id=@MT; - @wait_epoch=@MT; - - if ($DBX) {print "\n\n";} - if ($DB) {print " - cleaning up wait time\n";} - ### Grab any pause time record greater than 50000 - $stmtA = "SELECT agent_log_id,wait_epoch,talk_epoch from vicidial_agent_log where wait_sec>50000;"; - if ($DBX) {print "$stmtA\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $i=0; - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBout = ''; - $agent_log_id[$i] = "$record->[0]"; - $wait_epoch[$i] = "$record->[1]"; - $talk_epoch[$i] = "$record->[2]"; - $wait_sec[$i] = int($talk_epoch[$i] - $wait_epoch[$i]); - if ( ($wait_sec[$i] < 0) || ($wait_sec[$i] > 50000) ) - { - $DBout = "Override output: $wait_sec[$i]"; - $wait_sec[$i] = 0; - } - if ($DBX) {print "$i - $agent_log_id[$i] |$talk_epoch[$i]|$wait_epoch[$i]|$wait_sec[$i]|$DBout|\n";} - $i++; - } - } - $h=0; - while ($h < $i) - { - $stmtA = "UPDATE vicidial_agent_log set wait_sec='$wait_sec[$h]' where agent_log_id='$agent_log_id[$h]';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - if (!$TEST) {$dbhA->query($stmtA); }# or die "Couldn't execute query: |$stmtA|\n"; - $h++; - } - if ($DB) {print STDERR " Wait times fixed: $h\n";} - - - - - - @agent_log_id=@MT; - @talk_epoch=@MT; - - if ($DBX) {print "\n\n";} - if ($DB) {print " - cleaning up talk time\n";} - ### Grab any pause time record greater than 50000 - $stmtA = "SELECT agent_log_id,talk_epoch,dispo_epoch from vicidial_agent_log where talk_sec>50000;"; - if ($DBX) {print "$stmtA\n";} - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $i=0; - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBout = ''; - $agent_log_id[$i] = "$record->[0]"; - $talk_epoch[$i] = "$record->[1]"; - $dispo_epoch[$i] = "$record->[2]"; - $talk_sec[$i] = int($dispo_epoch[$i] - $talk_epoch[$i]); - if ( ($talk_sec[$i] < 0) || ($talk_sec[$i] > 50000) ) - { - $DBout = "Override output: $talk_sec[$i]"; - $talk_sec[$i] = 0; - } - if ($DBX) {print "$i - $agent_log_id[$i] |$dispo_epoch[$i]|$talk_epoch[$i]|$talk_sec[$i]|$DBout|\n";} - $i++; - } - } - $h=0; - while ($h < $i) - { - $stmtA = "UPDATE vicidial_agent_log set talk_sec='$talk_sec[$h]' where agent_log_id='$agent_log_id[$h]';"; - if($DBX){print STDERR "|$stmtA|\n";} - if (!$TEST) {$dbhA->query($stmtA); }# or die "Couldn't execute query: |$stmtA|\n"; - $h++; - } - if ($DB) {print STDERR " Talk times fixed: $h\n";} - - - - - - @agent_log_id=@MT; - @dispo_epoch=@MT; - - if ($DBX) {print "\n\n";} - if ($DB) {print " - cleaning up dispo time\n";} - $stmtA = "UPDATE vicidial_agent_log set dispo_sec='0' where dispo_sec>50000;"; - if($DBX){print STDERR "|$stmtA|\n";} - if (!$TEST) - { - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - $affected_rows = $dbhA->get_affected_rows_length; - } - if ($DB) {print STDERR " Bad Dispo times zeroed out: $affected_rows\n";} - - - - - - - - - - - - if ($DB) {print STDERR "\nDONE\n";} - - - - $dbhA->close; - - -exit; - - - - - - diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_conf_update.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_conf_update.pl deleted file mode 100644 index 70d874a9..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_conf_update.pl +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/perl -# -# AST_conf_update.pl version 0.3 -# -# DESCRIPTION: -# uses the Asterisk Manager interface and Net::MySQL to update whether a conference -# is still in use or not. If not in use 3 times in a row the extension in the -# conferences DB record is erased freeing that conference to be used again -# -# SUMMARY: -# This program was designed for people using the Asterisk PBX with conferences -# -# This program should be in the cron running every minute (like AST_vm_update.pl) -# -# For this program to work you need to have the "asterisk" MySQL database -# created with the conferences table in it, also make sure -# that the account running this program has read/write/update/delete access -# to that database -# -# It is recommended that you run this program on the local Asterisk machine -# -# If this script is run ever minute there is a theoretical limit of -# 600 conferences that it can check due to the wait interval. If you have -# more than this either change the cron when this script is run or change the -# wait interval below -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# 50810-1532 - Added database server variable definitions lookup -# 50823-1456 - Added commandline arguments for debug at runtime -# - -# constants -$DB=0; # Debug flag, set to 0 for no debug messages per minute -$US='__'; -$MT[0]=''; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - } - if ($args =~ /-t/i) - { - $TEST=1; - $T=1; - } - } -} -else -{ -# print "no command line options set\n"; -} -### end parsing run-time options ### - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -use lib './lib', '../lib'; -use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second -use Net::MySQL; -use Net::Telnet (); - - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - -### Grab Server values from the database -$stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrUSERNAMElisten,ASTmgrUSERNAMEsend,max_vicidial_trunks,answer_transfer_agent,local_gmt,ext_context FROM servers where server_ip = '$server_ip';"; -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBtelnet_host = "$record->[0]"; - $DBtelnet_port = "$record->[1]"; - $DBASTmgrUSERNAME = "$record->[2]"; - $DBASTmgrSECRET = "$record->[3]"; - $DBASTmgrUSERNAMEupdate = "$record->[4]"; - $DBASTmgrUSERNAMElisten = "$record->[5]"; - $DBASTmgrUSERNAMEsend = "$record->[6]"; - $DBmax_vicidial_trunks = "$record->[7]"; - $DBanswer_transfer_agent= "$record->[8]"; - $DBSERVER_GMT = "$record->[9]"; - $DBext_context = "$record->[10]"; - if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} - if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} - if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} - if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} - if ($DBASTmgrUSERNAMEupdate) {$ASTmgrUSERNAMEupdate = $DBASTmgrUSERNAMEupdate;} - if ($DBASTmgrUSERNAMElisten) {$ASTmgrUSERNAMElisten = $DBASTmgrUSERNAMElisten;} - if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} - if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} - if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} - if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} - if ($DBext_context) {$ext_context = $DBext_context;} - } - } - - - -@PTextensions=@MT; @PT_conf_extens=@MT; @PTmessages=@MT; @PTold_messages=@MT; @NEW_messages=@MT; @OLD_messages=@MT; -$dbhA->query("SELECT extension,conf_exten from conferences where server_ip='$server_ip' and extension is NOT NULL and extension != '';"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $PTextensions[$rec_count] = "$record->[0]"; - $PT_conf_extens[$rec_count] = "$record->[1]"; - $rec_count++; - } - } - -if (!$telnet_port) {$telnet_port = '5038';} - -### connect to asterisk manager through telnet -$t = new Net::Telnet (Port => $telnet_port, - Prompt => '/.*[\$%#>] $/', - Output_record_separator => '',); -#$fh = $t->dump_log("$telnetlog"); # uncomment for telnet log - if (length($ASTmgrUSERNAMEsend) > 3) {$telnet_login = $ASTmgrUSERNAMEsend;} - else {$telnet_login = $ASTmgrUSERNAME;} - -$t->open("$telnet_host"); -$t->waitfor('/0\n$/'); # print login -$t->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRET\n\n"); -$t->waitfor('/Authentication accepted/'); # waitfor auth accepted - - -$i=0; -foreach(@PTextensions) - { - @list_channels=@MT; - $t->buffer_empty; - @list_channels = $t->cmd(String => "Action: Command\nCommand: Meetme list $PT_conf_extens[$i]\n\nAction: Ping\n\n", Prompt => '/Response: Pong.*/'); - - $j=0; - $conf_empty[$i]=0; - $conf_users[$i]=''; - foreach(@list_channels) - { - if($DB){print "|$list_channels[$j]|\n";} - if ($list_channels[$j] =~ /No active conferences|No such conference/i) - {$conf_empty[$i]++;} -# if ($list_channels[$j] =~ /^User /i) -# { -# $userx = ''; -# $userx = $list_channels[$j]; -# $userx =~ s/User \#: //gi; -# $conf_users[$i] .= "$userx|"; -# } - $j++; - } - - if($DB){print "Meetme list $PT_conf_extens[$i]- Exten:|$PTextensions[$i]| Empty:|$conf_empty[$i]| ";} - if (!$conf_empty[$i]) - { - if($DB){print "CONFERENCE STILL HAS PARTICIPANTS, DOING NOTHING FOR THIS CONFERENCE\n";} - if ($PTextensions[$i] =~ /Xtimeout\d$/i) - { - $PTextensions[$i] =~ s/Xtimeout\d$//gi; - $stmtA = "UPDATE conferences set extension='$PTextensions[$i]' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:|$stmtA|\n"; - } - } - else - { - $NEWexten[$i] = $PTextensions[$i]; - if ($PTextensions[$i] =~ /Xtimeout3$/i) {$NEWexten[$i] =~ s/Xtimeout3$/Xtimeout2/gi;} - if ($PTextensions[$i] =~ /Xtimeout2$/i) {$NEWexten[$i] =~ s/Xtimeout2$/Xtimeout1/gi;} - if ($PTextensions[$i] =~ /Xtimeout1$/i) {$NEWexten[$i] = '';} - if ( ($PTextensions[$i] !~ /Xtimeout\d$/i) and (length($PTextensions[$i])> 0) ) {$NEWexten[$i] .= 'Xtimeout3';} - - - $stmtA = "UPDATE conferences set extension='$NEWexten[$i]' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:|$stmtA|\n"; - } - - $i++; - ### sleep for 10 hundredths of a second - usleep(1*100*1000); - } - - -$t->buffer_empty; -@hangup = $t->cmd(String => "Action: Logoff\n\n", Prompt => "/.*/"); -$t->buffer_empty; -$ok = $t->close; - -$dbhA->close; - -if($DB){print "DONE... Exiting... Goodbye... See you later... \n";} - -exit; - - - - diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_flush_DBqueue.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_flush_DBqueue.pl deleted file mode 100644 index cf76ffa7..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_flush_DBqueue.pl +++ /dev/null @@ -1,189 +0,0 @@ -#!/usr/bin/perl -# -# AST_flush_DBqueue.pl version 0.2 -# -# DESCRIPTION: -# - clears out mysql records for this server for the ACQS vicidial_manager table -# - optimizes tables used frequently by VICIDIAL -# -# It is recommended that you run this program on the local Asterisk machine -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# - -$secX = time(); - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); - $year = ($year + 1900); - $yy = $year; $yy =~ s/^..//gi; - $mon++; - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} -$SQLdate_NOW="$year-$mon-$mday $hour:$min:$sec"; - -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time()-3600); - $year = ($year + 1900); - $yy = $year; $yy =~ s/^..//gi; - $mon++; - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} -$SQLdate_NEG_1hour="$year-$mon-$mday $hour:$min:$sec"; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-q] = quiet\n [-t] = test\n [--debug] = debugging messages\n\n"; - } - else - { - if ($args =~ /-q/i) - { - $q=1; $Q=1; - } - if ($args =~ /--debug/i) - { - $DB=1; - print "\n-----DEBUGGING -----\n\n"; - } - if ($args =~ /-t|--test/i) - { - $T=1; $TEST=1; - print "\n-----TESTING -----\n\n"; - } - } -} -else -{ -print "no command line options set\n"; -} -### end parsing run-time options ### - - -if (!$Q) {print "TEST\n\n";} -if (!$Q) {print "NOW DATETIME: $SQLdate_NOW\n";} -if (!$Q) {print "1 HOUR AGO DATETIME: $SQLdate_NEG_1hour\n\n";} - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -use Net::MySQL; - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - - $stmtA = "delete from vicidial_manager where server_ip='$server_ip' and entry_date < '$SQLdate_NEG_1hour';"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if (!$Q) {print " - vicidial_manager 2 hour flush\n";} - - - $stmtA = "update park_log set status='HUNGUP' where hangup_time is not null;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countY=0; - while ($recordA = $iterA->each) - { - if (!$Q) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - if (!$Q) {print " - park_log HUNGUP flush \n";} - - - $stmtA = "optimize table vicidial_manager;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countY=0; - while ($recordA = $iterA->each) - { - if (!$Q) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - if (!$Q) {print " - optimize vicidial_manager \n";} - - - $stmtA = "optimize table vicidial_live_agents;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countY=0; - while ($recordA = $iterA->each) - { - if (!$Q) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - if (!$Q) {print " - optimize vicidial_live_agents \n";} - - - $stmtA = "optimize table vicidial_auto_calls;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countY=0; - while ($recordA = $iterA->each) - { - if (!$Q) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - if (!$Q) {print " - optimize vicidial_auto_calls \n";} - - - $stmtA = "optimize table vicidial_hopper;"; - if($DB){print STDERR "\n|$stmtA|\n";} - if (!$T) {$dbhA->query($stmtA); } - if ($dbhA->has_selected_record) - { - $iterA=$dbhA->create_record_iterator; - $rec_countY=0; - while ($recordA = $iterA->each) - { - if (!$Q) {print "|",$recordA->[0],"|",$recordA->[1],"|",$recordA->[2],"|",$recordA->[3],"|","\n";} - } - } - - if (!$Q) {print " - optimize vicidial_hopper \n";} - - - - - $dbhA->close; - - -exit; - - - - - - diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_kill_hung_congested.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_kill_hung_congested.pl deleted file mode 100644 index 52636af4..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_kill_hung_congested.pl +++ /dev/null @@ -1,335 +0,0 @@ -#!/usr/bin/perl -# -# AST_manager_kill_hung_congested.pl version 0.2 -# -# Part of the Asterisk Central Queue System (ACQS) -# -# DESCRIPTION: -# kills CONGEST local channels every 15 seconds -# -# For the client program to work in ACQS mode, this program must be running -# -# For this program to work you need to have the "asterisk" MySQL database -# created and create the tables listed in the CONF_MySQL.txt file, also make sure -# that the machine running this program has read/write/update/delete access -# to that database -# -# In your Asterisk server setup you also need to have several things activated -# and defined. See the CONF_Asterisk.txt file for details -# -# put this in the cron to run every minute -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# 50823-1525 - Added commandline debug options with debug printouts -# - -# constants -$DB=0; # Debug flag, set to 0 for no debug messages, On an active system this will generate thousands of lines of output per minute -$US='__'; -$MT[0]=''; - - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n[-debugX] = Extra-verbose debug messages\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } - if ($args =~ /-t/i) - { - $TEST=1; - $T=1; - } - } -} -else -{ -# print "no command line options set\n"; -} -### end parsing run-time options ### - - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - - - &get_time_now; - -# $event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; -# &event_logger; - -#use lib './lib', '../lib'; -use Net::MySQL; -#use Net::Telnet (); - -my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass") -or die "Couldn't connect to database: \n"; - -#$event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|'; -#&event_logger; - -$stmtA = "SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and extension = 'CONGEST' and channel LIKE \"Local%\" limit 99"; -# $event_string="SQL_QUERY|$stmtA|"; -# &event_logger; - -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - if($DB){print STDERR $record->[0],"\n";} - $congest_kill[$rec_count] = "$record->[0]"; - $rec_count++; - } - - } - -$i=0; -foreach(@congest_kill) - { - $i_count = $i; - if ($i_count < 10) {$i_count = "0$i_count";} - - if (length($congest_kill[$i])>0) - { - ### use manager middleware-app to zapbarge call being placed from meetme - $KCqueryCID = "KC$i_count$CIDdate"; - - ### insert a NEW record to the vicidial_manager table to be processed - $stmtA = "INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Hangup','$KCqueryCID','Channel: $congest_kill[$i]','','','','','','','','','')"; - - $event_string = "SUBRT|killing_congest|KC|$KCqueryCID|$congest_kill[$i]|$stmtA|"; - event_logger; - - if ($DB) {print "KILLING $congest_kill[$i]\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:\n"; - } - $i++; - } - - -sleep(14); - -######## 22222 starting another loop - &get_time_now; -@congest_kill = @MT; - - - -$stmtA = "SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and extension = 'CONGEST' and channel LIKE \"Local%\" limit 99"; -# $event_string="SQL_QUERY|$stmtA|"; -# &event_logger; - -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - if($DB){print STDERR $record->[0],"\n";} - $congest_kill[$rec_count] = "$record->[0]"; - $rec_count++; - } - - } - -$i=0; -foreach(@congest_kill) - { - $i_count = $i; - if ($i_count < 10) {$i_count = "0$i_count";} - - if (length($congest_kill[$i])>0) - { - ### use manager middleware-app to zapbarge call being placed from meetme - $KCqueryCID = "KC$i_count$CIDdate"; - - ### insert a NEW record to the vicidial_manager table to be processed - $stmtA = "INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Hangup','$KCqueryCID','Channel: $congest_kill[$i]','','','','','','','','','')"; - - $event_string = "SUBRT|killing_congest|KC|$KCqueryCID|$congest_kill[$i]|$stmtA|"; - event_logger; - - if ($DB) {print "KILLING $congest_kill[$i]\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:\n"; - } - $i++; - } - - -sleep(15); - -######## 33333 starting another loop - &get_time_now; -@congest_kill = @MT; - - - - -$stmtA = "SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and extension = 'CONGEST' and channel LIKE \"Local%\" limit 99"; -# $event_string="SQL_QUERY|$stmtA|"; -# &event_logger; - -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - if($DB){print STDERR $record->[0],"\n";} - $congest_kill[$rec_count] = "$record->[0]"; - $rec_count++; - } - - } - -$i=0; -foreach(@congest_kill) - { - $i_count = $i; - if ($i_count < 10) {$i_count = "0$i_count";} - - if (length($congest_kill[$i])>0) - { - ### use manager middleware-app to zapbarge call being placed from meetme - $KCqueryCID = "KC$i_count$CIDdate"; - - ### insert a NEW record to the vicidial_manager table to be processed - $stmtA = "INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Hangup','$KCqueryCID','Channel: $congest_kill[$i]','','','','','','','','','')"; - - $event_string = "SUBRT|killing_congest|KC|$KCqueryCID|$congest_kill[$i]|$stmtA|"; - event_logger; - - if ($DB) {print "KILLING $congest_kill[$i]\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:\n"; - } - $i++; - } - - -sleep(15); - -######## 44444 starting another loop - &get_time_now; -@congest_kill = @MT; - - - - - -$stmtA = "SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and extension = 'CONGEST' and channel LIKE \"Local%\" limit 99"; -# $event_string="SQL_QUERY|$stmtA|"; -# &event_logger; - -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - if($DB){print STDERR $record->[0],"\n";} - $congest_kill[$rec_count] = "$record->[0]"; - $rec_count++; - } - - } - -$i=0; -foreach(@congest_kill) - { - $i_count = $i; - if ($i_count < 10) {$i_count = "0$i_count";} - - if (length($congest_kill[$i])>0) - { - ### use manager middleware-app to zapbarge call being placed from meetme - $KCqueryCID = "KC$i_count$CIDdate"; - - ### insert a NEW record to the vicidial_manager table to be processed - $stmtA = "INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Hangup','$KCqueryCID','Channel: $congest_kill[$i]','','','','','','','','','')"; - - $event_string = "SUBRT|killing_congest|KC|$KCqueryCID|$congest_kill[$i]|$stmtA|"; - event_logger; - - if ($DB) {print "KILLING $congest_kill[$i]\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:\n"; - } - $i++; - } - - - -# $event_string='CLOSING DB CONNECTION|'; -# &event_logger; - - $dbhA->close; - - - if($DB){print "DONE... Exiting... Goodbye... See you later... \n";} - - -exit; - - - - - - - -sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes -{ -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year = ($year + 1900); -$mon++; -if ($mon < 10) {$mon = "0$mon";} -if ($mday < 10) {$mday = "0$mday";} -if ($hour < 10) {$Fhour = "0$hour";} -if ($min < 10) {$min = "0$min";} -if ($sec < 10) {$sec = "0$sec";} - -$now_date_epoch = time(); -$now_date = "$year-$mon-$mday $hour:$min:$sec"; -$action_log_date = "$year-$mon-$mday"; -$CIDdate = "$year$mon$mday$hour$min$sec"; -} - - - - - -sub event_logger { - ### open the log file for writing ### - open(Lout, ">>$KHLOGfile") - || die "Can't open $KHLOGfile: $!\n"; - - print Lout "$now_date|$event_string|\n"; - - close(Lout); - -$event_string=''; -} diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_listen.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_listen.pl deleted file mode 100644 index 6d407cbd..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_listen.pl +++ /dev/null @@ -1,594 +0,0 @@ -#!/usr/bin/perl -# -# AST_manager_listen.pl version 1.1.11 build 60403-1230 -# -# Part of the Asterisk Central Queue System (ACQS) -# -# DESCRIPTION: -# connects to the Asterisk Manager interface and updates records in the -# vicidial_manager table of the asterisk database in MySQL based upon the -# events that it receives -# -# SUMMARY: -# This program was designed as the listen-only part of the ACQS. It's job is to -# look for certain events and based upon either the uniqueid or the callerid of -# the call update the status and information of an action record in the -# vicidial_manager table of the asterisk MySQL database. -# -# Win32 - ActiveState Perl 5.8.0 -# UNIX - Gnome or KDE with Tk/Tcl and perl Tk/Tcl modules loaded -# Both - Net::MySQL, Net::Telnet and Time::HiRes perl modules loaded -# -# For the client program to work in ACQS mode, this program must be running -# -# For this program to work you need to have the "asterisk" MySQL database -# created and create the tables listed in the CONF_MySQL.txt file, also make sure -# that the machine running this program has read/write/update/delete access -# to that database -# -# In your Asterisk server setup you also need to have several things activated -# and defined. See the CONF_Asterisk.txt file for details -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# changes: -# 50322-1300 changed callerid parsing to remove quotes and number -# 50616-1559 Added NewCallerID parsing and updating -# 50621-1406 Added Asterisk server shutdown and connection dead detection -# 50810-1534 Added database server variable definitions lookup -# 50824-1606 Altered CVS/1.2 support for different output -# 50901-2359 Another CVS/1.2 output parsing fix -# 51222-1553 fixed parentheses bug in manager output -# 60403-1230 Added SVN/1.2.6 support for different output -# - -# constants -$DB=1; # Debug flag, set to 0 for no debug messages, lots of output -$US='__'; -$MT[0]=''; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n[-debugX] = Extra-verbose debug messages\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } - if ($args =~ /-t/i) - { - $TEST=1; - $T=1; - } - } -} -else -{ -# print "no command line options set\n"; -} -### end parsing run-time options ### - - - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - - &get_time_now; - - $event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; - &event_logger; - -#use lib './lib', '../lib'; -use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second -use Net::MySQL; -use Net::Telnet (); - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - $event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|'; - &event_logger; - - -### Grab Server values from the database -$stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrUSERNAMElisten,ASTmgrUSERNAMEsend,max_vicidial_trunks,answer_transfer_agent,local_gmt,ext_context FROM servers where server_ip = '$server_ip';"; -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBtelnet_host = "$record->[0]"; - $DBtelnet_port = "$record->[1]"; - $DBASTmgrUSERNAME = "$record->[2]"; - $DBASTmgrSECRET = "$record->[3]"; - $DBASTmgrUSERNAMEupdate = "$record->[4]"; - $DBASTmgrUSERNAMElisten = "$record->[5]"; - $DBASTmgrUSERNAMEsend = "$record->[6]"; - $DBmax_vicidial_trunks = "$record->[7]"; - $DBanswer_transfer_agent= "$record->[8]"; - $DBSERVER_GMT = "$record->[9]"; - $DBext_context = "$record->[10]"; - if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} - if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} - if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} - if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} - if ($DBASTmgrUSERNAMEupdate) {$ASTmgrUSERNAMEupdate = $DBASTmgrUSERNAMEupdate;} - if ($DBASTmgrUSERNAMElisten) {$ASTmgrUSERNAMElisten = $DBASTmgrUSERNAMElisten;} - if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} - if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} - if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} - if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} - if ($DBext_context) {$ext_context = $DBext_context;} - } - } - - -if (!$telnet_port) {$telnet_port = '5038';} - -$one_day_interval = 90; # 1 day loops for 3 months -while($one_day_interval > 0) -{ - - $event_string="STARTING NEW MANAGER TELNET CONNECTION||ATTEMPT|ONE DAY INTERVAL:$one_day_interval|"; - &event_logger; -# Errmode => Return, - - ### connect to asterisk manager through telnet - $tn = new Net::Telnet (Port => $telnet_port, - Prompt => '/.*[\$%#>] $/', - Output_record_separator => '',); - #$fh = $tn->dump_log("$LItelnetlog"); # uncomment for telnet log - if (length($ASTmgrUSERNAMElisten) > 3) {$telnet_login = $ASTmgrUSERNAMElisten;} - else {$telnet_login = $ASTmgrUSERNAME;} - $tn->open("$telnet_host"); - $tn->waitfor('/0\n$/'); # print login - $tn->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRET\n\n"); - $tn->waitfor('/Authentication accepted/'); # waitfor auth accepted - - $tn->buffer_empty; - - $event_string="STARTING NEW MANAGER TELNET CONNECTION|$telnet_login|CONFIRMED CONNECTION|ONE DAY INTERVAL:$one_day_interval|"; - &event_logger; - - $endless_loop=864000; # 1 day at .10 seconds per loop - - while($endless_loop > 0) - { - ### sleep for 10 hundredths of a second - usleep(1*100*1000); - - $msg=''; - $read_input_buf = $tn->get(Errmode => Return, Timeout => 1,); - $input_buf_length = length($read_input_buf); - $msg = $tn->errmsg; - if ($msg =~ /filehandle isn\'t open/i) - { - $endless_loop=0; - $one_day_interval=0; - print "ERRMSG: |$msg|\n"; - print "\nAsterisk server shutting down, PROCESS KILLED... EXITING\n\n"; - $event_string="Asterisk server shutting down, PROCESS KILLED... EXITING|ONE DAY INTERVAL:$one_day_interval|$msg|"; - &event_logger; - } - - if ( ($read_input_buf !~ /\n\n/) or ($input_buf_length < 10) ) - { - # if ($read_input_buf =~ /\n/) {print "\n|||$input_buf_length|||$read_input_buf|||\n";} - $input_buf = "$input_buf$read_input_buf"; - } - else - { - $partial=0; - $partial_input_buf=''; - - if ($read_input_buf !~ /\n\n$/) - { - $read_input_buf =~ s/\(|\)/ /gi; # replace parens with space - $partial_input_buf = $read_input_buf; - $partial_input_buf =~ s/\n/-----/gi; - $partial_input_buf =~ s/\*/\\\*/gi; - $partial_input_buf =~ s/.*----------//gi; - $partial_input_buf =~ s/-----/\n/gi; - $read_input_buf =~ s/$partial_input_buf$//gi; - $partial++; - } - - -# |1 DIALINGs updated| -# Nested quantifiers in regex; marked by <-- HERE in m/Event: Newexten -# Channel: Zap/16-1 -# Context: demo -# Extension: 990009*CL_UMGCOF_L** <-- HERE 1479503*conf*** -# Priority: 2 -# Application: Dial -# AppData: Zap/g3/90009*CL_UMGCOF_L**1479503*conf***|20 -# Uniqueid: 1101224775.6783 -# $/ at /home/cron/AST_manager_listen.pl line 114. - - - $input_buf = "$input_buf$read_input_buf"; - @input_lines = split(/\n\n/, $input_buf); - - if($DB){print "input buffer: $input_buf_length lines: $#input_lines partial: $partial\n";} - if ( ($DB) && ($partial) ) {print "-----[$partial_input_buf]-----\n\n";} - if($DB){print "|$input_buf|\n";} - - $manager_string = "$input_buf"; - &manager_output_logger; - - $input_buf = "$partial_input_buf"; - - - @command_line=@MT; - $ILcount=0; - foreach(@input_lines) - { - if ( ($input_lines[$ILcount] =~ /State: Ringing|State: Up|State: Dialing|Event: Newstate|Event: Hangup|Event: Newcallerid|Event: Shutdown/) && ($input_lines[$ILcount] !~ /ZOMBIE/) ) - { - $input_lines[$ILcount] =~ s/^\n|^\n\n//gi; - @command_line=split(/\n/, $input_lines[$ILcount]); - if ($input_lines[$ILcount] =~ /Event: Shutdown/) - { - $endless_loop=0; - $one_day_interval=0; - print "\nAsterisk server shutting down, PROCESS KILLED... EXITING\n\n"; - $event_string="Asterisk server shutting down, PROCESS KILLED... EXITING|ONE DAY INTERVAL:$one_day_interval|"; - &event_logger; - } - - if ($input_lines[$ILcount] =~ /Event: Hangup/) - { - if ( ($command_line[2] =~ /^Channel: /i) && ($command_line[3] =~ /^Uniqueid: /i) ) ### post 2005-08-07 CVS -- added Privilege line - { - $channel = $command_line[2]; - $channel =~ s/Channel: |\s*$//gi; - $uniqueid = $command_line[3]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='DEAD', channel='$channel' where server_ip = '$server_ip' and uniqueid = '$uniqueid'"; - - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows HANGUPS updated|\n";} - } - else - { - if ( ($command_line[3] =~ /^Channel: /i) && ($command_line[4] =~ /^Uniqueid: /i) ) ### post 2006-03-20 SVN -- Added Timestamp line - { - $channel = $command_line[3]; - $channel =~ s/Channel: |\s*$//gi; - $uniqueid = $command_line[4]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='DEAD', channel='$channel' where server_ip = '$server_ip' and uniqueid = '$uniqueid'"; - - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows HANGUPS updated|\n";} - } - else - { - $channel = $command_line[1]; - $channel =~ s/Channel: |\s*$//gi; - $uniqueid = $command_line[2]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='DEAD', channel='$channel' where server_ip = '$server_ip' and uniqueid = '$uniqueid'"; - - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows HANGUPS updated|\n";} - } - } - } - - if ($input_lines[$ILcount] =~ /State: Dialing/) - { - if ( ($command_line[1] =~ /^Channel: /i) && ($command_line[4] =~ /^Uniqueid: /i) ) ### pre 2004-10-07 CVS - { - $channel = $command_line[1]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[3]; - $callid =~ s/Callerid: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[4]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='SENT', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows DIALINGs updated|\n";} - } - if ( ($command_line[1] =~ /^Channel: /i) && ($command_line[4] =~ /^CalleridName: /i) ) ### post 2004-10-07 CVS - { - $channel = $command_line[1]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[4]; - $callid =~ s/CalleridName: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[5]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='SENT', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows DIALINGs updated|\n";} - } - if ( ($command_line[2] =~ /^Channel: /i) && ($command_line[5] =~ /^CalleridName: /i) ) ### post 2005-08-07 CVS - { - $channel = $command_line[2]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[5]; - $callid =~ s/CalleridName: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[6]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='SENT', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows DIALINGs updated|\n";} - } - if ( ($command_line[3] =~ /^Channel: /i) && ($command_line[6] =~ /^CalleridName: /i) ) ### post 2006-03-20 -- Added Timestamp line - { - $channel = $command_line[3]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[6]; - $callid =~ s/CalleridName: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[7]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='SENT', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows DIALINGs updated|\n";} - } - } - if ($input_lines[$ILcount] =~ /State: Ringing|State: Up/) - { - if ( ($command_line[1] =~ /^Channel: /i) && ($command_line[4] =~ /^Uniqueid: /i) ) ### pre 2004-10-07 CVS - { - $channel = $command_line[1]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[3]; - $callid =~ s/Callerid: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[4]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='UPDATED', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - if ($channel !~ /local/i) - { - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows RINGINGs updated|\n";} - } - } - if ( ($command_line[1] =~ /^Channel: /i) && ($command_line[4] =~ /^CalleridName: /i) ) ### post 2004-10-07 CVS - { - $channel = $command_line[1]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[4]; - $callid =~ s/CalleridName: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[5]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='UPDATED', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - if ($channel !~ /local/i) - { - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows RINGINGs updated|\n";} - } - } - if ( ($command_line[2] =~ /^Channel: /i) && ($command_line[5] =~ /^CalleridName: /i) ) ### post 2005-08-07 CVS - { - $channel = $command_line[2]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[5]; - $callid =~ s/CalleridName: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[6]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='UPDATED', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - if ($channel !~ /local/i) - { - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows RINGINGs updated|\n";} - } - } - if ( ($command_line[3] =~ /^Channel: /i) && ($command_line[6] =~ /^CalleridName: /i) ) ### post 2006-03-20 SVN -- Added Timestamp line - { - $channel = $command_line[3]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[6]; - $callid =~ s/CalleridName: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[7]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='UPDATED', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - if ($channel !~ /local/i) - { - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows RINGINGs updated|\n";} - } - } - } - - if ($input_lines[$ILcount] =~ /Event: Newcallerid/) - { - if ( ($command_line[1] =~ /^Channel: /i) && ($command_line[3] =~ /^Uniqueid: /i) ) - { - $channel = $command_line[1]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[2]; - $callid =~ s/Callerid: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[3]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='UPDATED', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - if ($channel =~ /local/i) - { - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows RINGINGs updated|\n";} - } - } - if ( ($command_line[3] =~ /^Channel: /i) && ($command_line[6] =~ /^Uniqueid: /i) ) ### post 2006-03-20 SVN -- Added Timestamp line - { - $channel = $command_line[3]; - $channel =~ s/Channel: |\s*$//gi; - $callid = $command_line[5]; - $callid =~ s/Callerid: |\s*$//gi; - $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; - $uniqueid = $command_line[6]; - $uniqueid =~ s/Uniqueid: |\s*$//gi; - $stmtA = "UPDATE vicidial_manager set status='UPDATED', channel='$channel', uniqueid = '$uniqueid' where server_ip = '$server_ip' and callerid = '$callid'"; - if ($channel =~ /local/i) - { - print STDERR "|$stmtA|\n"; - $dbhA->query("$stmtA"); - my $affected_rows = $dbhA->get_affected_rows_length; - if($DB){print "|$affected_rows RINGINGs updated|\n";} - } - } - } - - } - $ILcount++; - } - - } - - - $endless_loop--; - $keepalive_count_loop++; - if($DB){print STDERR "loop counter: |$endless_loop|$keepalive_count_loop|\r";} - - ### putting a blank file called "sendmgr.kill" in a directory will automatically safely kill this program - if ( (-e '/home/cron/listenmgr.kill') or ($sendonlyone) ) - { - unlink('/home/cron/listenmgr.kill'); - $endless_loop=0; - $one_day_interval=0; - print "\nPROCESS KILLED MANUALLY... EXITING\n\n"; - } - - ### run a keepalive command to flush whatever is in the buffer through and to keep the connection alive - if ($endless_loop =~ /00$|50$/) - { - &get_time_now; - - @list_lines = $tn->cmd(String => "Action: Command\nCommand: show uptime\n\n", Prompt => '/--END COMMAND--.*/', Errmode => Return, Timeout => 1); - if($DB){print "input lines: $#list_lines\n";} - - if($DB){print "+++++++++++++++++++++++++++++++sending keepalive transmit line $endless_loop|$now_date|\n";} - $keepalive_count_loop=0; - } - - - } - - - if($DB){print "DONE... Exiting... Goodbye... See you later... Not really, initiating next loop...$one_day_interval left\n";} - - $event_string='HANGING UP|'; - &event_logger; - - @hangup = $tn->cmd(String => "Action: Logoff\n\n", Prompt => "/.*/", Errmode => Return, Timeout => 1); - - $ok = $tn->close; - - $one_day_interval--; - -} - - $event_string='CLOSING DB CONNECTION|'; - &event_logger; - - - $dbhA->close; - - - if($DB){print "DONE... Exiting... Goodbye... See you later... Really I mean it this time\n";} - - -exit; - - - - - - - -sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes -{ -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year = ($year + 1900); -$mon++; -if ($mon < 10) {$mon = "0$mon";} -if ($mday < 10) {$mday = "0$mday";} -if ($hour < 10) {$Fhour = "0$hour";} -if ($min < 10) {$min = "0$min";} -if ($sec < 10) {$sec = "0$sec";} - -$now_date_epoch = time(); -$now_date = "$year-$mon-$mday $hour:$min:$sec"; -$action_log_date = "$year-$mon-$mday"; -} - - - - - -sub event_logger { - ### open the log file for writing ### - open(Lout, ">>$LILOGfile") - || die "Can't open $LILOGfile: $!\n"; - - print Lout "$now_date|$event_string|\n"; - - close(Lout); - -$event_string=''; -} - - - - -sub manager_output_logger -{ -open(MOout, ">>/home/cron/listen.$action_log_date") - || die "Can't open /home/cron/listen.$action_log_date: $!\n"; - - print MOout "$now_date|$manager_string|\n"; - - close(MOout); -} diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_send.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_send.pl deleted file mode 100644 index 222b6a9e..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_manager_send.pl +++ /dev/null @@ -1,384 +0,0 @@ -#!/usr/bin/perl -# -# AST_manager_send.pl version 0.2 -# -# Part of the Asterisk Central Queue System (ACQS) -# -# DESCRIPTION: -# spawns child processes (AST_send_action_child.pl) to execute action commands -# on the Asterisk manager interface from records in the vicidial_manager table -# of the asterisk database in MySQL that are marked as a status of NEW -# -# SUMMARY: -# This program was designed as the send-only part of the ACQS. It's job is to -# pick NEW actions from the vicidial_manager table and send them to be executed -# by separate child process. This allows for a higher degree of flexibility and -# scalability over just using a single process. Also, this means that a single -# action execution lock cannot bring the entire system down. -# -# Win32 - ActiveState Perl 5.8.0 -# UNIX - Gnome or KDE with Tk/Tcl and perl Tk/Tcl modules loaded -# Both - Net::MySQL, Net::Telnet and Time::HiRes perl modules loaded -# -# For the client program to work in ACQS mode, this program must be running -# -# For this program to work you need to have the "asterisk" MySQL database -# created and create the tables listed in the CONF_MySQL.txt file, also make sure -# that the machine running this program has read/write/update/delete access -# to that database -# -# In your Asterisk server setup you also need to have several things activated -# and defined. See the CONF_Asterisk.txt file for details -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# 50823-1514 - Added commandline debug options with debug printouts -# 50902-1051 - Added extra debug output launch sub(commented out) -# - -# constants -$COUNTER_OUTPUT=1; # set to 1 to display the counter as the script runs -$US='__'; -$MT[0]=''; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n[-debugX] = Extra-verbose debug messages\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } - if ($args =~ /-sendonlyone/i) - { - $sendonlyone=1; - print "\n-----SEND ONLY ONE COMMAND -----\n\n"; - } - if ($args =~ /-t/i) - { - $TEST=1; - $T=1; - } - } -} -else -{ -# print "no command line options set\n"; -} -### end parsing run-time options ### - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - - &get_time_now; - - $event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; - &event_logger; - -#use lib './lib', '../lib'; -use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second -use Net::MySQL; -#use Net::Telnet (); - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - $event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|'; - &event_logger; - -$one_day_interval = 90; # 1 day loops for 3 months -while($one_day_interval > 0) -{ - - - $endless_loop=864000; # 10 days at .20 seconds per loop - - while($endless_loop > 0) - { - - $affected_rows=0; - $NEW_actions=0; - - $stmtA = "SELECT count(*) from vicidial_manager where server_ip = '$server_ip' and status = 'NEW'"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - if($DB){print STDERR $record->[0]," NEW Actions to send on server $server_ip $endless_loop\n";} - $NEW_actions = "$record->[0]"; - } - } - - if (!$NEW_actions) - { - $affected_rows=0; - } - else - { - $stmtA = "UPDATE vicidial_manager set status='QUEUE' where server_ip = '$server_ip' and status = 'NEW' order by entry_date limit 1"; - $dbhA->query("$stmtA"); - $affected_rows = $dbhA->get_affected_rows_length; - if ($DB) {print STDERR "rows updated to QUEUE: |$affected_rows|\n";} - } - - - if ($affected_rows) - { - $stmtA = "SELECT * FROM vicidial_manager where server_ip = '$server_ip' and status = 'QUEUE' order by entry_date desc limit 1"; - $event_string="SQL_QUERY|$stmtA|"; - &event_logger; - - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - if($DB){print STDERR $record->[0],"|", $record->[1],"|", $record->[6],"|", $record->[7],"|", $record->[8],"\n";} - $man_id = "$record->[0]"; - $uniqueid = "$record->[1]"; - $channel = "$record->[6]"; - $action = "$record->[7]"; - $callid = "$record->[8]"; - $cmd_line_b = "$record->[9]"; - $cmd_line_c = "$record->[10]"; - $cmd_line_d = "$record->[11]"; - $cmd_line_e = "$record->[12]"; - $cmd_line_f = "$record->[13]"; - $cmd_line_g = "$record->[14]"; - $cmd_line_h = "$record->[15]"; - $cmd_line_i = "$record->[16]"; - $cmd_line_j = "$record->[17]"; - $cmd_line_k = "$record->[18]"; - - $originate_command = ''; - $originate_command .= "Action: $action\n"; - if (length($cmd_line_b)>3) {$originate_command .= "$cmd_line_b\n";} - if (length($cmd_line_c)>3) {$originate_command .= "$cmd_line_c\n";} - if (length($cmd_line_d)>3) {$originate_command .= "$cmd_line_d\n";} - if (length($cmd_line_e)>3) {$originate_command .= "$cmd_line_e\n";} - if (length($cmd_line_f)>3) {$originate_command .= "$cmd_line_f\n";} - if (length($cmd_line_g)>3) {$originate_command .= "$cmd_line_g\n";} - if (length($cmd_line_h)>3) {$originate_command .= "$cmd_line_h\n";} - if (length($cmd_line_i)>3) {$originate_command .= "$cmd_line_i\n";} - if (length($cmd_line_j)>3) {$originate_command .= "$cmd_line_j\n";} - if (length($cmd_line_k)>3) {$originate_command .= "$cmd_line_k\n";} - $originate_command .= "\n"; - - $SENDNOW=1; - if ($originate_command =~ /Action: Hangup|Action: Redirect/) - { - $SENDNOW=0; - if($DB){print STDERR "\n|checking for dead call before executing|$callid|$uniqueid|\n";} - $dbhA->query("SELECT count(*) FROM vicidial_manager where server_ip = '$server_ip' and callerid='$callid' and status = 'DEAD'"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_countH=0; - while ( $record = $iter->each) - { - $rec_countH = "$record->[0]"; - } - if (!$rec_countH){$SENDNOW=1;} - else - { - $launch_string = "|not sending command line is dead|$callid|$uniqueid|"; - # &launch_logger; - if($DB){print STDERR "\n$launch_string\n";} - - } - } - - } - - $event_string="----BEGIN NEW COMMAND----\n$originate_command----END NEW COMMAND----\n"; - &event_logger; - - if ($SENDNOW) - { - # $tn->buffer_empty; - - $launch_string = "/home/cron/AST_send_action_child.pl --data1=$man_id $callid $uniqueid $channel"; - # &launch_logger; - - system("/home/cron/AST_send_action_child.pl --data1=$man_id >> /home/cron/action.$action_log_date \&"); - - $launch_string = "SENT $man_id $callid $uniqueid $channel"; - # &launch_logger; - - $stmtA = "UPDATE vicidial_manager set status='SENT' where man_id='$man_id'"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - - $event_string="SQL_QUERY|$stmtA|"; - &event_logger; - } - else - { - $stmtA = "UPDATE vicidial_manager set status='DEAD' where man_id='$man_id'"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $event_string="COMMAND NOT SENT, SQL_QUERY|$stmtA|"; - &event_logger; - } - - } - } - - } - - if ($affected_rows) - { - ### sleep for 10 hundredths of a second - usleep(1*100*1000); - } - else - { - ### sleep for 20 hundredths of a second - usleep(1*200*1000); - } - - $endless_loop--; - if( ($COUNTER_OUTPUT) or ($DB) ){print STDERR "loop counter: |$endless_loop|\r";} - - ### putting a blank file called "sendmgr.kill" in a directory will automatically safely kill this program - if ( (-e '/home/cron/sendmgr.kill') or ($sendonlyone) ) - { - unlink('/home/cron/sendmgr.kill'); - $endless_loop=0; - $one_day_interval=0; - print "\nPROCESS KILLED MANUALLY... EXITING\n\n"; - } - - if ($endless_loop =~ /0$/) - { - &get_time_now; - - if( ($COUNTER_OUTPUT) or ($DB) ){print "checking to see if listener is dead |$sendonlyone|$running_listen|\n";} - #@psoutput = `/bin/ps -f --no-headers -A`; - @psoutput = `/bin/ps -o "%p %a" --no-headers -A`; - - $running_listen = 0; - - $i=0; - foreach (@psoutput) - { - chomp($psoutput[$i]); - - if ($DBX) {print "$i|$psoutput[$i]| \n";} - @psline = split(/\/usr\/bin\/perl /,$psoutput[$i]); - - if ($psline[1] =~ /AST_manager_li/) - { - $running_listen++; - if ($DB) {print "SEND RUNNING: |$psline[1]|\n";} - } - - $i++; - } - - if (!$running_listen) - { - $sendonlyone++; - if( ($COUNTER_OUTPUT) or ($DB) ){print "LISTENER DEAD STOPPING PROGRAM... ATTEMPTING TO START keepalive SCRIPT\n";} - $event_string='LISTENER DEAD STOPPING PROGRAM... ATTEMPTING TO START keepalive SCRIPT|'; - &event_logger; - `/usr/bin/at now < /home/cron/ADMIN_keepalive_send_listen.at 2>/dev/null 1>&2`; - } - } - - - } - - - if( ($COUNTER_OUTPUT) or ($DB) ){print "DONE... Exiting... Goodbye... See you later... Not really, initiating next loop...$one_day_interval left\n";} - - $one_day_interval--; - -} - - $event_string='CLOSING DB CONNECTION|'; - &event_logger; - - - $dbhA->close; - - - if( ($COUNTER_OUTPUT) or ($DB) ){print "DONE... Exiting... Goodbye... See you later... Really I mean it this time\n";} - - -exit; - - - - - - - -sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes -{ -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year = ($year + 1900); -$mon++; -if ($mon < 10) {$mon = "0$mon";} -if ($mday < 10) {$mday = "0$mday";} -if ($hour < 10) {$Fhour = "0$hour";} -if ($min < 10) {$min = "0$min";} -if ($sec < 10) {$sec = "0$sec";} - -$now_date_epoch = time(); -$now_date = "$year-$mon-$mday $hour:$min:$sec"; -$action_log_date = "$year-$mon-$mday"; -} - - - - - -sub event_logger { - ### open the log file for writing ### - open(Lout, ">>$MSLOGfile") - || die "Can't open $MSLOGfile: $!\n"; - - print Lout "$now_date|$event_string|\n"; - - close(Lout); - -$event_string=''; -} - -sub launch_logger { - ### open the log file for writing ### - open(LLout, ">>/home/cron/action_launch.$action_log_date") - || die "Can't open /home/cron/action_launch.$action_log_date: $!\n"; - - print LLout "$now_date|$launch_string|\n"; - - close(LLout); - -$event_string=''; -} diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_reset_mysql_vars.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_reset_mysql_vars.pl deleted file mode 100644 index 0409266a..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_reset_mysql_vars.pl +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/perl -# -# AST_reset_mysql_vars.pl version 0.2 -# -# !!! DO NOT RUN THIS WHILE THERE ARE ACTIVE CALLS ON THE ASTERISK SERVER !!! -# -# DESCRIPTION: -# clears out mysql records for this server -# -# It is recommended that you run this program on the local Asterisk machine -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# - - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -use Net::MySQL; - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - - - $stmtA = "UPDATE conferences set extension='' where server_ip='$server_ip';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - print " - conferences reset\n"; - - $stmtA = "UPDATE vicidial_conferences set extension='' where server_ip='$server_ip';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - print " - vicidial_conferences reset\n"; - -# $stmtA = "UPDATE vicidial_manager set status='DEAD' where server_ip='$server_ip' and status='NEW';"; -# if($DB){print STDERR "\n|$stmtA|\n";} -# $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; -# print " - vicidial_manager queue reset\n"; - - $stmtA = "DELETE from vicidial_manager where server_ip='$server_ip';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - print " - vicidial_manager delete\n"; - - $stmtA = "DELETE from vicidial_auto_calls where server_ip='$server_ip';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - print " - vicidial_manager delete\n"; - - $stmtA = "DELETE from vicidial_live_agents where server_ip='$server_ip';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - print " - vicidial_manager delete\n"; - - $stmtA = "DELETE from vicidial_users where full_name='5555';"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); # or die "Couldn't execute query: |$stmtA|\n"; - print " - vicidial_manager delete\n"; - - $dbhA->close; - - -exit; - - - - - - diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_send_action_child.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_send_action_child.pl deleted file mode 100644 index b15eb8b8..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_send_action_child.pl +++ /dev/null @@ -1,258 +0,0 @@ -#!/usr/bin/perl -# -# AST_send_action_child.pl version 0.2 -# -# Part of the Asterisk Central Queue System (ACQS) -# -# DESCRIPTION: -# This script is spawned every time an action is to be executed by the main -# AST_manager_send.pl script and sends actions blindly to the Asterisk manager -# -# SUMMARY: -# This program was designed as the blind-send part of the ACQS. It's job is to -# be spawned by the AST_manager_send.pl script lookup the record in the MySQL DB -# to be executed. connect to the manager interface, send the action and logoff -# then exit. -# -# Win32 - ActiveState Perl 5.8.0 -# UNIX - Gnome or KDE with Tk/Tcl and perl Tk/Tcl modules loaded -# Both - Net::MySQL, Net::Telnet and Time::HiRes perl modules loaded -# -# For the client program to work in ACQS mode, this program must be running -# -# For this program to work you need to have the "asterisk" MySQL database -# created and create the tables listed in the CONF_MySQL.txt file, also make sure -# that the machine running this program has read/write/update/delete access -# to that database -# -# In your Asterisk server setup you also need to have several things activated -# and defined. See the CONF_Asterisk.txt file for details -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# 50810-1547 - Added database server variable definitions lookup -# 50823-1527 - Altered commandline debug options with debug printouts -# 50902-1032 - Changed default logging to fulllog -# - -$FULL_LOG = 1; # set to 1 for a full response log to be created in /home/cron/action_full.date - -$secX = time(); - -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year = ($year + 1900); -$mon++; -if ($mon < 10) {$mon = "0$mon";} -if ($mday < 10) {$mday = "0$mday";} -if ($hour < 10) {$Fhour = "0$hour";} -if ($min < 10) {$min = "0$min";} -if ($sec < 10) {$sec = "0$sec";} - -$now_date_epoch = time(); -$now_date = "$year-$mon-$mday $hour:$min:$sec"; -$action_log_date = "$year-$mon-$mday"; - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $ARGS = "$ARGS $ARGV[$i]\n"; - $i++; - } - -# print "DB0: |$ARGS|$#ARGV|$i|\n"; - - if ($ARGS =~ /--help/i) - { - print "allowed run time options:\n [-debug] = debug output\n [-debugX] = Extra-debug output\n [-fulllog] = full response logging\n [--data1=XXXXXXX] = vicidial_manager record\n\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - } - if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } - if ($args =~ /-fulllog/i) - { - $FULL_LOG=1; # Full response logging enabled - } - if ($ARGS =~ /--data1=/i) - { - $data1 = $ARGS; -# print "DB1: |$ARGS|\n"; - $data1 =~ s/^.*--data1=//gi; -# print "DB2: |$data1|\n"; - $data1 =~ s/ .*$//gi; -# print "DB3: |$data1|\n"; - } - - } -} -else -{ -#print "no command line options set\n\n"; -} - -if (length($data1)>1) - { -# print "Data1 value = |$data1|\n"; - -use Net::MySQL; -use Net::Telnet (); - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - - ### Grab Server values from the database - $stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEsend FROM servers where server_ip = '$server_ip';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBtelnet_host = "$record->[0]"; - $DBtelnet_port = "$record->[1]"; - $DBASTmgrUSERNAME = "$record->[2]"; - $DBASTmgrSECRET = "$record->[3]"; - $DBASTmgrUSERNAMEsend = "$record->[4]"; - if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} - if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} - if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} - if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} - if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} - } - } - - - $stmtA = "SELECT * FROM vicidial_manager where man_id = '$data1'"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $man_id = "$record->[0]"; - $uniqueid = "$record->[1]"; - $channel = "$record->[6]"; - $action = "$record->[7]"; - $callid = "$record->[8]"; - $cmd_line_b = "$record->[9]"; - $cmd_line_c = "$record->[10]"; - $cmd_line_d = "$record->[11]"; - $cmd_line_e = "$record->[12]"; - $cmd_line_f = "$record->[13]"; - $cmd_line_g = "$record->[14]"; - $cmd_line_h = "$record->[15]"; - $cmd_line_i = "$record->[16]"; - $cmd_line_j = "$record->[17]"; - $cmd_line_k = "$record->[18]"; - - $originate_command = ''; - $originate_command .= "Action: $action\n"; - if (length($cmd_line_b)>3) {$originate_command .= "$cmd_line_b\n";} - if (length($cmd_line_c)>3) {$originate_command .= "$cmd_line_c\n";} - if (length($cmd_line_d)>3) {$originate_command .= "$cmd_line_d\n";} - if (length($cmd_line_e)>3) {$originate_command .= "$cmd_line_e\n";} - if (length($cmd_line_f)>3) {$originate_command .= "$cmd_line_f\n";} - if (length($cmd_line_g)>3) {$originate_command .= "$cmd_line_g\n";} - if (length($cmd_line_h)>3) {$originate_command .= "$cmd_line_h\n";} - if (length($cmd_line_i)>3) {$originate_command .= "$cmd_line_i\n";} - if (length($cmd_line_j)>3) {$originate_command .= "$cmd_line_j\n";} - if (length($cmd_line_k)>3) {$originate_command .= "$cmd_line_k\n";} - $originate_command .= "\n"; - } - } - - $dbhA->close; - - - print "$now_date|$data1|\n$originate_command"; - $event_string = "0|$data1|"; - $event_string .= "\n$originate_command"; - if ($FULL_LOG) {&full_event_logger;} - -if (!$telnet_port) {$telnet_port = '5038';} - - ### connect to asterisk manager through telnet - $tn = new Net::Telnet (Port => $telnet_port, - Prompt => '/.*[\$%#>] $/', - Output_record_separator => '', - Errmode => Return,); - #$fh = $tn->dump_log("$MStelnetlog"); # uncomment for telnet log - if (length($ASTmgrUSERNAMEsend) > 3) {$telnet_login = $ASTmgrUSERNAMEsend;} - else {$telnet_login = $ASTmgrUSERNAME;} - $tn->open("$telnet_host"); - $tn->waitfor('/0\n$/'); # print login - $tn->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRET\n\n"); - $tn->waitfor('/Authentication accepted/'); # waitfor auth accepted - - $tn->buffer_empty; - - @list_channels = $tn->cmd(String => "$originate_command", Prompt => '/.*/'); - -sleep(3); - - if ($FULL_LOG) - { - $event_string = "1|$data1|"; $k=0; - foreach(@list_channels) {$event_string .= "$list_channels[$k]"; $k++;} - $read_input_buf = $tn->get(Errmode => Return, Timeout => 1,); - $event_string .= "$read_input_buf"; - &full_event_logger; - } - - $tn->buffer_empty; - - @hangup = $tn->cmd(String => "Action: Logoff\n\n", Prompt => "/.*/"); - -sleep(2); - - if ($FULL_LOG) - { - $event_string = "2|$data1|"; $k=0; - foreach(@list_channels) {$event_string .= "$list_channels[$k]"; $k++;} - $read_input_buf = $tn->get(Errmode => Return, Timeout => 1,); - $event_string .= "$read_input_buf"; - &full_event_logger; - } - - $tn->buffer_empty; - - $ok = $tn->close; - - - - - } - -$secZ = time(); -$script_time = ($secZ - $secX); -print "DONE execute time: $script_time seconds\n"; - -exit; - -sub full_event_logger { - ### open the log file for writing ### - open(Lout, ">>/home/cron/action_full.$action_log_date") - || die "Can't open /home/cron/action_full.$action_log_date: $!\n"; - - print Lout "$now_date|$event_string|\n"; - - close(Lout); - -$event_string=''; -} diff --git a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_vm_update.pl b/agc_2-X/trunk/Net-MySQL_bin-agi/AST_vm_update.pl deleted file mode 100644 index 6125ad70..00000000 --- a/agc_2-X/trunk/Net-MySQL_bin-agi/AST_vm_update.pl +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/perl -# -# AST_vm_update.pl version 0.3 -# -# DESCRIPTION: -# uses the Asterisk Manager interface and Net::MySQL to update the count of -# voicemail messages for each mailbox (in the phone table) in the voicemail -# table list is used by client apps for voicemail notification -# -# SUMMARY: -# This program was designed for people using the Asterisk PBX with voicemail -# -# For the client program to notify of new messaged, this program must be in the -# cron running every minute -# -# For this program to work you need to have the "asterisk" MySQL database -# created and create the tables listed in the CONF_MySQL.txt file, also make sure -# that the machine running this program has read/write/update/delete access -# to that database -# -# It is recommended that you run this program on the local Asterisk machine -# -# If this script is run ever minute there is a theoretical limit of -# 600 mailboxes that it can check due to the wait interval. If you have -# more than this either change the cron when this script is run or change the -# wait interval below -# -# Copyright (C) 2006 Matt Florell LICENSE: GPLv2 -# -# 50823-1422 - Added database server variable definitions lookup -# 50823-1452 - Added commandline arguments for debug at runtime -# - -# constants -$DB=0; # Debug flag, set to 0 for no debug messages per minute -$US='__'; -$MT[0]=''; - -### begin parsing run-time options ### -if (length($ARGV[0])>1) -{ - $i=0; - while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n\n"; - } - else - { - if ($args =~ /-debug/i) - { - $DB=1; # Debug flag - } - if ($args =~ /-t/i) - { - $TEST=1; - $T=1; - } - } -} -else -{ -# print "no command line options set\n"; -} -### end parsing run-time options ### - -### Make sure this file is in a libs path or put the absolute path to it -require("/home/cron/AST_SERVER_conf.pl"); # local configuration file - -if (!$DB_port) {$DB_port='3306';} - -use lib './lib', '../lib'; -use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second -use Net::MySQL; -use Net::Telnet (); - - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; - -### Grab Server values from the database -$stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrUSERNAMElisten,ASTmgrUSERNAMEsend,max_vicidial_trunks,answer_transfer_agent,local_gmt,ext_context FROM servers where server_ip = '$server_ip';"; -$dbhA->query("$stmtA"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBtelnet_host = "$record->[0]"; - $DBtelnet_port = "$record->[1]"; - $DBASTmgrUSERNAME = "$record->[2]"; - $DBASTmgrSECRET = "$record->[3]"; - $DBASTmgrUSERNAMEupdate = "$record->[4]"; - $DBASTmgrUSERNAMElisten = "$record->[5]"; - $DBASTmgrUSERNAMEsend = "$record->[6]"; - $DBmax_vicidial_trunks = "$record->[7]"; - $DBanswer_transfer_agent= "$record->[8]"; - $DBSERVER_GMT = "$record->[9]"; - $DBext_context = "$record->[10]"; - if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} - if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} - if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} - if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} - if ($DBASTmgrUSERNAMEupdate) {$ASTmgrUSERNAMEupdate = $DBASTmgrUSERNAMEupdate;} - if ($DBASTmgrUSERNAMElisten) {$ASTmgrUSERNAMElisten = $DBASTmgrUSERNAMElisten;} - if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} - if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} - if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} - if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} - if ($DBext_context) {$ext_context = $DBext_context;} - } - } - -@PTextensions=@MT; @PTvoicemail_ids=@MT; @PTmessages=@MT; @PTold_messages=@MT; @NEW_messages=@MT; @OLD_messages=@MT; -$dbhA->query("SELECT extension,voicemail_id,messages,old_messages from phones where server_ip='$server_ip'"); -if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - $rec_count=0; - while ( $record = $iter->each) - { - $PTextensions[$rec_count] = "$record->[0]"; - $PTvoicemail_ids[$rec_count] = "$record->[1]"; - $PTmessages[$rec_count] = "$record->[2]"; - $PTold_messages[$rec_count] = "$record->[3]"; - $rec_count++; - } - } - - -### connect to asterisk manager through telnet -$t = new Net::Telnet (Port => 5038, - Prompt => '/.*[\$%#>] $/', - Output_record_separator => '',); -#$fh = $t->dump_log("$telnetlog"); # uncomment for telnet log - if (length($ASTmgrUSERNAMEsend) > 3) {$telnet_login = $ASTmgrUSERNAMEsend;} - else {$telnet_login = $ASTmgrUSERNAME;} - -$t->open("$telnet_host"); -$t->waitfor('/0\n$/'); # print login -$t->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRET\n\n"); -$t->waitfor('/Authentication accepted/'); # waitfor auth accepted - - -$i=0; -foreach(@PTextensions) - { - @list_channels=@MT; - $t->buffer_empty; - @list_channels = $t->cmd(String => "Action: MailboxCount\nMailbox: $PTvoicemail_ids[$i]\n\nAction: Ping\n\n", Prompt => '/Response: Pong.*/'); - - $j=0; - foreach(@list_channels) - { - if ($list_channels[$j] =~ /Mailbox: $PTvoicemail_ids[$i]/) - { - $NEW_messages[$i] = "$list_channels[$j+1]"; - $NEW_messages[$i] =~ s/NewMessages: |\n//gi; - $OLD_messages[$i] = "$list_channels[$j+2]"; - $OLD_messages[$i] =~ s/OldMessages: |\n//gi; - } - - $j++; - } - - if($DB){print "MailboxCount- $PTvoicemail_ids[$i] NEW:|$NEW_messages[$i]| OLD:|$OLD_messages[$i]| ";} - if ( ($NEW_messages[$i] eq $PTmessages[$i]) && ($OLD_messages[$i] eq $PTold_messages[$i]) ) - { - if($DB){print "MESSAGE COUNT UNCHANGED, DOING NOTHING FOR THIS MAILBOX\n";} - } - else - { - $stmtA = "UPDATE phones set messages='$NEW_messages[$i]', old_messages='$OLD_messages[$i]' where server_ip='$server_ip' and extension='$PTextensions[$i]'"; - if($DB){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA) or die "Couldn't execute query:|$stmtA|\n"; - } - - $i++; - ### sleep for 10 hundredths of a second - usleep(1*100*1000); - } - - -$t->buffer_empty; -@hangup = $t->cmd(String => "Action: Logoff\n\n", Prompt => "/.*/"); -$t->buffer_empty; -$ok = $t->close; - -$dbhA->close; - -if($DB){print "DONE... Exiting... Goodbye... See you later... \n";} - -exit; - - - - diff --git a/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl b/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl index 2274bb2d..407bbbf1 100644 --- a/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl +++ b/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# VICIDIAL_IN_new_leads_file.pl version 0.3 +# VICIDIAL_IN_new_leads_file.pl version 0.4 *DBI-version* # # DESCRIPTION: # script lets you insert leads into the vicidial_list table from a TAB-delimited @@ -15,6 +15,7 @@ # 60615-1543 - Added gmt_offset_now lookup for each lead # - Added option to force a gmt value(field after COMMENTS field) # 60616-0958 - Added listID override feature to force all leads into same list +# 60807-1003 - Changed to DBI # $secX = time(); @@ -159,24 +160,19 @@ require("/home/cron/AST_SERVER_conf.pl"); # local configuration file if (!$DB_port) {$DB_port='3306';} -use Net::MySQL; - - my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port") - or die "Couldn't connect to database: $DB_server - $DB_database\n"; +use DBI; +$dbhA = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass") + or die "Couldn't connect to database: " . DBI->errstr; - ### Grab Server values from the database - $stmtA = "SELECT local_gmt FROM servers where server_ip = '$server_ip';"; - $dbhA->query("$stmtA"); - if ($dbhA->has_selected_record) - { - $iter=$dbhA->create_record_iterator; - while ( $record = $iter->each) - { - $DBSERVER_GMT = "$record->[0]"; - if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} - } - } +### Grab Server values from the database +$stmtA = "SELECT local_gmt FROM servers where server_ip = '$server_ip';"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +@aryA = $sthA->fetchrow_array; +$DBSERVER_GMT = $aryA[0]; +if (length($DBSERVER_GMT)>0) {$SERVER_GMT = $DBSERVER_GMT;} +$sthA->finish(); $LOCAL_GMT_OFF = $SERVER_GMT; $LOCAL_GMT_OFF_STD = $SERVER_GMT; @@ -280,76 +276,84 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC { $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $rec_countW=0; - if ($dbhA->has_selected_record) + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - $gmt_offset = $recordA->[4]; $gmt_offset =~ s/\+| //gi; - $dst = $recordA->[5]; - $dst_range = $recordA->[6]; - $PC_processed++; - } + @aryA = $sthA->fetchrow_array; + $NEW_campaign_leads_to_call = "$aryA[0]"; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; } + $sthA->finish(); } ### MEXICO ### if ($phone_code =~ /^52$/) { $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $rec_countW=0; - if ($dbhA->has_selected_record) + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - $gmt_offset = $recordA->[4]; $gmt_offset =~ s/\+| //gi; - $dst = $recordA->[5]; - $dst_range = $recordA->[6]; - $PC_processed++; - } + @aryA = $sthA->fetchrow_array; + $NEW_campaign_leads_to_call = "$aryA[0]"; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; } + $sthA->finish(); } ### AUSTRALIA ### if ($phone_code =~ /^61$/) { $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and state='$state';"; if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $rec_countW=0; - if ($dbhA->has_selected_record) + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - $gmt_offset = $recordA->[4]; $gmt_offset =~ s/\+| //gi; - $dst = $recordA->[5]; - $dst_range = $recordA->[6]; - $PC_processed++; - } + @aryA = $sthA->fetchrow_array; + $NEW_campaign_leads_to_call = "$aryA[0]"; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; } + $sthA->finish(); } ### ALL OTHER COUNTRY CODES ### if (!$PC_processed) { $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code';"; if($DBX){print STDERR "\n|$stmtA|\n";} - $dbhA->query($stmtA); - $rec_countW=0; - if ($dbhA->has_selected_record) + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) { - $iterA=$dbhA->create_record_iterator; - while ($recordA = $iterA->each) - { - $gmt_offset = $recordA->[4]; $gmt_offset =~ s/\+| //gi; - $dst = $recordA->[5]; - $dst_range = $recordA->[6]; - $PC_processed++; - } + @aryA = $sthA->fetchrow_array; + $NEW_campaign_leads_to_call = "$aryA[0]"; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; } + $sthA->finish(); } ### Find out if DST to raise the gmt offset ### @@ -419,7 +423,7 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC ### insert good deal into pending_transactions table ### $stmtZ = "INSERT INTO vicidial_list values$multistmt('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','0');"; if($DB){print STDERR "\n|$stmtZ|\n";} - if (!$T) {$dbhA->query($stmtZ); } # or die "Couldn't execute query: |$stmtA|\n"; + if (!$T) {$affected_rows = $dbhA->do($stmtA); } # or die "Couldn't execute query: |$stmtA|\n"; $multistmt=''; $multi_insert_counter=0; @@ -460,7 +464,7 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC ### insert good deal into pending_transactions table ### $stmtZ = "INSERT INTO vicidial_list values$multistmt;"; if($DB){print STDERR "\n|$stmtZ|\n";} - if (!$T) {$dbhA->query($stmtZ); } # or die "Couldn't execute query: |$stmtA|\n"; + if (!$T) {$affected_rows = $dbhA->do($stmtA); } # or die "Couldn't execute query: |$stmtA|\n"; $multistmt=''; $multi_insert_counter=0; @@ -507,6 +511,8 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC } +$dbhA->disconnect(); + ### calculate time to run script ### $secY = time(); $secZ = ($secY - $secX);