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
This commit is contained in:
@@ -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 <vicidial@gmail.com> 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 = <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
|
||||
@@ -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 <vicidial@gmail.com> 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 <vicidial@gmail.com> 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <vicidial@gmail.com> 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;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <vicidial@gmail.com> 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <vicidial@gmail.com> 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='';
|
||||
}
|
||||
@@ -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 <vicidial@gmail.com> 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);
|
||||
}
|
||||
@@ -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 <vicidial@gmail.com> 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='';
|
||||
}
|
||||
@@ -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 <vicidial@gmail.com> 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <vicidial@gmail.com> 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='';
|
||||
}
|
||||
@@ -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 <vicidial@gmail.com> 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;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user