moving of executables into bin directory
git-svn-id: svn://192.168.202.10@26 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# ADMIN_keepalive_AST_VDauto_dial.pl version 0.3
|
||||
#
|
||||
# designed to keep the AST_update processes aline and check every minute
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 50810-1452 - removed '-L' flag for screen logging of output (optimization)
|
||||
# 50823-1454 - Added commandline debug options with debug printouts
|
||||
#
|
||||
|
||||
$DB=0; # Debug flag
|
||||
$MT[0]=''; $MT[1]='';
|
||||
@psline=@MT;
|
||||
|
||||
### 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 ###
|
||||
|
||||
|
||||
#@psoutput = `ps -f -C AST_update --no-headers`;
|
||||
#@psoutput = `ps -f -C AST_updat* --no-headers`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
|
||||
$running_VDAD = 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] =~ /\/home\/cron\/AST_VDauto_dial\.pl/)
|
||||
{
|
||||
$running_VDAD++;
|
||||
if ($DB) {print "VDAD RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
if (!$running_VDAD)
|
||||
{
|
||||
# print "double check that VDAD is not running\n";
|
||||
|
||||
sleep(4);
|
||||
|
||||
#@psoutput = `ps -f -C AST_update --no-headers`;
|
||||
#@psoutput = `ps -f -C AST_updat* --no-headers`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
$i=0;
|
||||
foreach (@psoutput2)
|
||||
{
|
||||
chomp($psoutput2[$i]);
|
||||
if ($DBX) {print "$i|$psoutput[$i]| \n";}
|
||||
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
|
||||
|
||||
if ($psline[1] =~ /\/home\/cron\/AST_VDauto_dial\.pl/)
|
||||
{
|
||||
$running_VDAD++;
|
||||
if ($DB) {print "VDAD RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_VDAD)
|
||||
{
|
||||
if ($DB) {print "starting AST_VDauto_dial...\n";}
|
||||
# add a '-L' to the command below to activate logging
|
||||
`/usr/bin/screen -d -m -S ASTVDauto /home/cron/AST_VDauto_dial.pl`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($DB) {print "DONE\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# ADMIN_keepalive_AST_VDremote_agents.pl version 0.3
|
||||
#
|
||||
# designed to keep the AST_update processes aline and check every minute
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 50810-1453 - removed '-L' flag for screen logging of output (optimization)
|
||||
# 50823-1459 - Added commandline debug options with debug printouts
|
||||
#
|
||||
|
||||
$DB=0; # Debug flag
|
||||
$MT[0]=''; $MT[1]='';
|
||||
@psline=@MT;
|
||||
|
||||
### 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 ###
|
||||
|
||||
#@psoutput = `ps -f -C AST_update --no-headers`;
|
||||
#@psoutput = `ps -f -C AST_updat* --no-headers`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
|
||||
$running_VDra = 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] =~ /\/home\/cron\/AST_VDremote_agents\.pl/)
|
||||
{
|
||||
$running_VDra++;
|
||||
if ($DB) {print "VDra RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
if (!$running_VDra)
|
||||
{
|
||||
# print "double check that update is not running\n";
|
||||
|
||||
sleep(5);
|
||||
|
||||
#@psoutput = `ps -f -C AST_update --no-headers`;
|
||||
#@psoutput = `ps -f -C AST_updat* --no-headers`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
$i=0;
|
||||
foreach (@psoutput2)
|
||||
{
|
||||
chomp($psoutput2[$i]);
|
||||
if ($DBX) {print "$i|$psoutput[$i]| \n";}
|
||||
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
|
||||
|
||||
if ($psline[1] =~ /\/home\/cron\/AST_VDremote_agents\.pl/)
|
||||
{
|
||||
$running_VDra++;
|
||||
if ($DB) {print "VDra RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_VDra)
|
||||
{
|
||||
if ($DB) {print "starting AST_VDremote_agents...\n";}
|
||||
# add a '-L' to the command below to activate logging
|
||||
`/usr/bin/screen -d -m -S ASTVDremote /home/cron/AST_VDremote_agents.pl`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($DB) {print "DONE\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,169 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# ADMIN_keepalive_AST_send_listen.pl version 0.3
|
||||
#
|
||||
# designed to keep the AST_manager_listen and manager_send processes alive and check every minute
|
||||
#
|
||||
# if you are on an older system you may need to change the @psoutput lines to fit your ps version
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 50810-1450 - removed '-L' flag for screen logging of output (optimization)
|
||||
# 50823-1440 - Added commandline debug options with debug printouts
|
||||
#
|
||||
|
||||
$DB=0; # Debug flag
|
||||
$MT[0]=''; $MT[1]='';
|
||||
@psline=@MT;
|
||||
|
||||
### 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 ###
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
||||
#@psoutput = `ps -f -C AST_manager --no-headers`;
|
||||
#@psoutput = `ps -f --no-headers -C AST_manager_s*; ps -f --no-headers -C AST_manager_l*`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
|
||||
$running_listen = 0;
|
||||
$running_send = 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 "LISTEN RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
if ($psline[1] =~ /AST_manager_se/)
|
||||
{
|
||||
$running_send++;
|
||||
if ($DB) {print "SEND RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!$running_listen)
|
||||
{
|
||||
# print "double check that update_11 is not running\n";
|
||||
|
||||
sleep(1);
|
||||
|
||||
#@psoutput = `ps -f -C AST_manager --no-headers`;
|
||||
#@psoutput = `ps -f --no-headers -C AST_manager_s*; ps -f --no-headers -C AST_manager_l*`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
|
||||
$i=0;
|
||||
foreach (@psoutput2)
|
||||
{
|
||||
chomp($psoutput2[$i]);
|
||||
if ($DBX) {print "$i|$psoutput[$i]| \n";}
|
||||
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
|
||||
|
||||
if ($psline[1] =~ /AST_manager_li/)
|
||||
{
|
||||
$running_listen++;
|
||||
if ($DB) {print "LISTEN RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_listen)
|
||||
{
|
||||
if ($DB) {print "starting AST_manager_listen...\n";}
|
||||
# add a '-L' to the command below to activate logging
|
||||
`/usr/bin/screen -d -m -S ASTlisten /home/cron/AST_manager_listen.pl`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!$running_send)
|
||||
{
|
||||
# print "double check that update_12 is not running\n";
|
||||
|
||||
sleep(1);
|
||||
|
||||
#@psoutput = `ps -f -C AST_manager --no-headers`;
|
||||
#@psoutput = `ps -f --no-headers -C AST_manager_s*; ps -f --no-headers -C AST_manager_l*`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
$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_se/)
|
||||
{
|
||||
$running_send++;
|
||||
if ($DB) {print "SEND RUNNING: |$psline[1]|";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_send)
|
||||
{
|
||||
if ($DB) {print "starting AST_manager_send...\n";}
|
||||
# add a '-L' to the command below to activate logging
|
||||
`/usr/bin/screen -d -m -S ASTsend /home/cron/AST_manager_send.pl`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($DB) {print "DONE\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# ADMIN_keepalive_AST_update.pl version 0.4
|
||||
#
|
||||
# designed to keep the AST_update processes aline and check every minute
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 50810-1451 - removed '-L' flag for screen logging of output (optimization)
|
||||
# 50823-1446 - Added commandline debug options with debug printouts
|
||||
# 51229-1027 - fixed typo of array name
|
||||
#
|
||||
|
||||
$DB=0; # Debug flag
|
||||
$MT[0]=''; $MT[1]='';
|
||||
@psline=@MT;
|
||||
|
||||
### 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 ###
|
||||
|
||||
|
||||
#@psoutput = `ps -f -C AST_update --no-headers`;
|
||||
#@psoutput = `ps -f -C AST_updat* --no-headers`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
|
||||
$running_update = 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] =~ /\/home\/cron\/AST_update\.pl/)
|
||||
{
|
||||
$running_update++;
|
||||
if ($DB) {print "UPDATE RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
if (!$running_update)
|
||||
{
|
||||
# print "double check that update is not running\n";
|
||||
|
||||
sleep(5);
|
||||
|
||||
#@psoutput = `ps -f -C AST_update --no-headers`;
|
||||
#@psoutput = `ps -f -C AST_updat* --no-headers`;
|
||||
#@psoutput = `/bin/ps -f --no-headers -A`;
|
||||
@psoutput2 = `/bin/ps -o "%p %a" --no-headers -A`;
|
||||
$i=0;
|
||||
foreach (@psoutput2)
|
||||
{
|
||||
chomp($psoutput2[$i]);
|
||||
if ($DBX) {print "$i|$psoutput[$i]| \n";}
|
||||
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
|
||||
|
||||
if ($psline[1] =~ /\/home\/cron\/AST_update\.pl/)
|
||||
{
|
||||
$running_update++;
|
||||
if ($DB) {print "UPDATE RUNNING: |$psline[1]|\n";}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_update)
|
||||
{
|
||||
if ($DB) {print "starting AST_update...\n";}
|
||||
# add a '-L' to the command below to activate logging
|
||||
`/usr/bin/screen -d -m -S ASTupdate /home/cron/AST_update.pl`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($DB) {print "DONE\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
/home/cron/ADMIN_keepalive_AST_send_listen.pl
|
||||
|
||||
exit
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/perl
|
||||
# ADMIN_restart_roll_logs.pl - script to roll the Asterisk logs on machine restart
|
||||
# have this run on the astersik server
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
|
||||
($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";
|
||||
|
||||
|
||||
print "rolling AST_update log...\n";
|
||||
`mv -f /home/cron/LOG_AST_update.log /home/cron/LOGS/LOG_AST_update.log.$now_date`;
|
||||
|
||||
print "rolling MSAST_update log...\n";
|
||||
`mv -f /home/cron/MSLOG_AST_update.log /home/cron/LOGS/MSLOG_AST_update.log.$now_date`;
|
||||
|
||||
print "rolling LIAST_update log...\n";
|
||||
`mv -f /home/cron/LILOG_AST_update.log /home/cron/LOGS/LILOG_AST_update.log.$now_date`;
|
||||
|
||||
print "rolling VDAST_update log...\n";
|
||||
`mv -f /home/cron/VDLOG_AST_update.log /home/cron/LOGS/VDLOG_AST_update.log.$now_date`;
|
||||
|
||||
print "rolling Asterisk messages log...\n";
|
||||
`mv -f /var/log/asterisk/messages /var/log/asterisk/messages.$now_date`;
|
||||
|
||||
print "rolling Asterisk event log...\n";
|
||||
`mv -f /var/log/asterisk/event_log /var/log/asterisk/event_log.$now_date`;
|
||||
|
||||
print "rolling Asterisk cdr logs...\n";
|
||||
`mv -f /var/log/asterisk/cdr-csv/Master.csv /var/log/asterisk/cdr-csv/Master.csv.$now_date`;
|
||||
`mv -f /var/log/asterisk/cdr-custom/Master.csv /var/log/asterisk/cdr-custom/Master.csv.$now_date`;
|
||||
|
||||
print "rolling Asterisk screen log...\n";
|
||||
`mv -f /screenlog.0 /screenlog.0.$now_date`;
|
||||
|
||||
print "rolling Asterisk root screen log...\n";
|
||||
`mv -f /root/screenlog.0 /root/screenlog.0.$now_date`;
|
||||
|
||||
|
||||
print "FINISHED... EXITING\n";
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_CRON_mix_recordings.pl
|
||||
# runs every 5 minutes and mixes the call recordings in the monitor together
|
||||
# and puts the resulting ALL file into the DONE directory in the "monitor" dir
|
||||
#
|
||||
# soxmix is REQUIRED to use this script, soxmix is available only as part of
|
||||
# the sox audio package, and only in newer versions. Make sure you have soxmix
|
||||
# installed properly and in your path
|
||||
#
|
||||
# put an entry into the cron of of your asterisk machine to run this script
|
||||
# every 5 minutes or however often you desire
|
||||
#
|
||||
# make sure that the following directories exist:
|
||||
# /var/spool/asterisk/monitor # default Asterisk recording directory
|
||||
# /var/spool/asterisk/monitor/DONE # where the combined files are put
|
||||
# /var/spool/asterisk/monitor/ORIG # where the original in/out files are put
|
||||
#
|
||||
# This program assumes that recordings are saved as .wav
|
||||
# should be easy to change this code if you use .gsm instead
|
||||
#
|
||||
# This program also sends the ALL combined file to an FTP server for archival
|
||||
# purposes, you can comment out the Net::Ping and Net::FTP lines as well as the
|
||||
# file transfer section of the code to deactivate remote copying of the
|
||||
# recording files
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 51021-1058 Added quotes around CLI executed commands
|
||||
# 51122-1458 Added soxmix binary path check
|
||||
# 60318-0921 Added ability to mix gsm audio files
|
||||
#
|
||||
|
||||
|
||||
#$v=1;
|
||||
|
||||
# Customize variables for FTP
|
||||
$FTP_host = '10.0.0.4';
|
||||
$FTP_user = 'cron';
|
||||
$FTP_pass = 'test';
|
||||
$FTP_dir = 'RECORDINGS';
|
||||
|
||||
### directory where in/out recordings are saved to by Asterisk
|
||||
$dir1 = '/var/spool/asterisk/monitor';
|
||||
|
||||
$soxmixbin = '';
|
||||
if ( -e ('/usr/bin/soxmix')) {$soxmixbin = '/usr/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
if ( -e ('/usr/local/bin/soxmix')) {$soxmixbin = '/usr/local/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
print "Can't find soxmix binary! Exiting...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
use Net::Ping;
|
||||
use Net::FTP;
|
||||
|
||||
|
||||
opendir(FILE, "$dir1/");
|
||||
@FILES = readdir(FILE);
|
||||
|
||||
$i=0;
|
||||
foreach(@FILES)
|
||||
{
|
||||
$size1 = 0;
|
||||
$size2 = 0;
|
||||
|
||||
if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) )
|
||||
{
|
||||
|
||||
$size1 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size1\n";}
|
||||
sleep(1);
|
||||
$size2 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size2\n\n";}
|
||||
|
||||
if ( ($FILES[$i] !~ /out\.wav|out\.gsm/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4))
|
||||
{
|
||||
$INfile = $FILES[$i];
|
||||
$OUTfile = $FILES[$i];
|
||||
$OUTfile =~ s/-in\.wav/-out.wav/gi;
|
||||
$OUTfile =~ s/-in\.gsm/-out.gsm/gi;
|
||||
$ALLfile = $FILES[$i];
|
||||
$ALLfile =~ s/-in\.wav/-all.wav/gi;
|
||||
$ALLfile =~ s/-in\.gsm/-all.gsm/gi;
|
||||
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
|
||||
`$soxmixbin "$dir1/$INfile" "$dir1/$OUTfile" "$dir1/$ALLfile"`;
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
if (!$T)
|
||||
{
|
||||
`mv -f "$dir1/$INfile" "$dir1/ORIG/$INfile"`;
|
||||
`mv -f "$dir1/$OUTfile" "$dir1/ORIG/$OUTfile"`;
|
||||
`mv -f "$dir1/$ALLfile" "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
|
||||
### BEGIN Remote file transfer
|
||||
$p = Net::Ping->new();
|
||||
$ping_good = $p->ping("$FTP_host");
|
||||
|
||||
if ($ping_good)
|
||||
{
|
||||
$ftp = Net::FTP->new("$FTP_host", Port => 21);
|
||||
$ftp->login("$FTP_user","$FTP_pass");
|
||||
$ftp->cwd("$FTP_dir");
|
||||
$ftp->binary();
|
||||
$ftp->put("$dir1/DONE/$ALLfile", "$ALLfile");
|
||||
$ftp->quit;
|
||||
}
|
||||
### END Remote file transfer
|
||||
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($v) {print "DONE... EXITING\n\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_CRON_mix_recordings_BASIC.pl
|
||||
# runs every 5 minutes and mixes the call recordings in the monitor together
|
||||
# and puts the resulting ALL file into the DONE directory in the "monitor" dir
|
||||
#
|
||||
# soxmix is REQUIRED to use this script, soxmix is available only as part of
|
||||
# the sox audio package, and only in newer versions. Make sure you have soxmix
|
||||
# installed properly and in your path
|
||||
#
|
||||
# put an entry into the cron of of your asterisk machine to run this script
|
||||
# every 5 minutes or however often you desire
|
||||
#
|
||||
# make sure that the following directories exist:
|
||||
# /var/spool/asterisk/monitor # default Asterisk recording directory
|
||||
# /var/spool/asterisk/monitor/DONE # where the combined files are put
|
||||
# /var/spool/asterisk/monitor/ORIG # where the original in/out files are put
|
||||
#
|
||||
# This program assumes that recordings are saved as .wav
|
||||
# should be easy to change this code if you use .gsm instead
|
||||
#
|
||||
# This program also sends the ALL combined file to an FTP server for archival
|
||||
# purposes, you can comment out the Net::Ping and Net::FTP lines as well as the
|
||||
# file transfer section of the code to deactivate remote copying of the
|
||||
# recording files
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 51021-1058 Added quotes around CLI executed commands
|
||||
# 51122-1456 Added soxmix binary path check
|
||||
# 60318-0921 Added ability to mix gsm audio files
|
||||
#
|
||||
|
||||
|
||||
#$v=1;
|
||||
|
||||
|
||||
### directory where in/out recordings are saved to by Asterisk
|
||||
$dir1 = '/var/spool/asterisk/monitor';
|
||||
|
||||
$soxmixbin = '';
|
||||
if ( -e ('/usr/bin/soxmix')) {$soxmixbin = '/usr/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
if ( -e ('/usr/local/bin/soxmix')) {$soxmixbin = '/usr/local/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
print "Can't find soxmix binary! Exiting...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
opendir(FILE, "$dir1/");
|
||||
@FILES = readdir(FILE);
|
||||
|
||||
$i=0;
|
||||
foreach(@FILES)
|
||||
{
|
||||
$size1 = 0;
|
||||
$size2 = 0;
|
||||
|
||||
if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) )
|
||||
{
|
||||
|
||||
$size1 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size1\n";}
|
||||
sleep(1);
|
||||
$size2 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size2\n\n";}
|
||||
|
||||
|
||||
if ( ($FILES[$i] !~ /out\.wav|out\.gsm/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4))
|
||||
{
|
||||
$INfile = $FILES[$i];
|
||||
$OUTfile = $FILES[$i];
|
||||
$OUTfile =~ s/-in\.wav/-out.wav/gi;
|
||||
$OUTfile =~ s/-in\.gsm/-out.gsm/gi;
|
||||
$ALLfile = $FILES[$i];
|
||||
$ALLfile =~ s/-in\.wav/-all.wav/gi;
|
||||
$ALLfile =~ s/-in\.gsm/-all.gsm/gi;
|
||||
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
|
||||
`$soxmixbin "$dir1/$INfile" "$dir1/$OUTfile" "$dir1/$ALLfile"`;
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
if (!$T)
|
||||
{
|
||||
`mv -f "$dir1/$INfile" "$dir1/ORIG/$INfile"`;
|
||||
`mv -f "$dir1/$OUTfile" "$dir1/ORIG/$OUTfile"`;
|
||||
`mv -f "$dir1/$ALLfile" "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($v) {print "DONE... EXITING\n\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_CRON_mix_recordings_GSM.pl
|
||||
# runs every 5 minutes and mixes the call recordings in the monitor together
|
||||
# and puts the resulting ALL file into the DONE directory in the "monitor" dir
|
||||
# and converts the ALL file to GSM format to save space.
|
||||
#
|
||||
# soxmix is REQUIRED to use this script, soxmix is available only as part of
|
||||
# the sox audio package, and only in newer versions. Make sure you have soxmix
|
||||
# installed properly and in your path
|
||||
#
|
||||
# put an entry into the cron of of your asterisk machine to run this script
|
||||
# every 5 minutes or however often you desire
|
||||
#
|
||||
# make sure that the following directories exist:
|
||||
# /var/spool/asterisk/monitor # default Asterisk recording directory
|
||||
# /var/spool/asterisk/monitor/DONE # where the combined files are put
|
||||
# /var/spool/asterisk/monitor/ORIG # where the original in/out files are put
|
||||
#
|
||||
# This program assumes that recordings are saved as .wav
|
||||
# should be easy to change this code if you use .gsm instead
|
||||
#
|
||||
# This program also sends the ALL combined file to an FTP server for archival
|
||||
# purposes, you can comment out the Net::Ping and Net::FTP lines as well as the
|
||||
# file transfer section of the code to deactivate remote copying of the
|
||||
# recording files
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# 51021-1058 Added quotes around CLI executed commands
|
||||
# 51122-1455 Added soxmix and sox binary path check
|
||||
#
|
||||
|
||||
|
||||
#$v=1;
|
||||
|
||||
# Customize variables for FTP
|
||||
$FTP_host = '10.0.0.4';
|
||||
$FTP_user = 'cron';
|
||||
$FTP_pass = 'test';
|
||||
$FTP_dir = 'RECORDINGS';
|
||||
$FTP_port = '21';
|
||||
|
||||
### directory where in/out recordings are saved to by Asterisk
|
||||
$dir1 = '/var/spool/asterisk/monitor';
|
||||
|
||||
$soxmixbin = '';
|
||||
if ( -e ('/usr/bin/soxmix')) {$soxmixbin = '/usr/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
if ( -e ('/usr/local/bin/soxmix')) {$soxmixbin = '/usr/local/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
print "Can't find soxmix binary! Exiting...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$soxbin = '';
|
||||
if ( -e ('/usr/bin/sox')) {$soxbin = '/usr/bin/sox';}
|
||||
else
|
||||
{
|
||||
if ( -e ('/usr/local/bin/sox')) {$soxbin = '/usr/local/bin/sox';}
|
||||
else
|
||||
{
|
||||
print "Can't find sox binary! Exiting...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
use Net::Ping;
|
||||
use Net::FTP;
|
||||
|
||||
|
||||
opendir(FILE, "$dir1/");
|
||||
@FILES = readdir(FILE);
|
||||
|
||||
$i=0;
|
||||
foreach(@FILES)
|
||||
{
|
||||
$size1 = 0;
|
||||
$size2 = 0;
|
||||
|
||||
if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) )
|
||||
{
|
||||
|
||||
$size1 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size1\n";}
|
||||
sleep(1);
|
||||
$size2 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size2\n\n";}
|
||||
|
||||
|
||||
if ( ($FILES[$i] !~ /out\.wav/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4))
|
||||
{
|
||||
$INfile = $FILES[$i];
|
||||
$OUTfile = $FILES[$i];
|
||||
$OUTfile =~ s/-in\.wav/-out.wav/gi;
|
||||
$ALLfile = $FILES[$i];
|
||||
$ALLfile =~ s/-in\.wav/-all.wav/gi;
|
||||
$GSMfile = $ALLfile;
|
||||
$GSMfile =~ s/-all\.wav/-all.gsm/gi;
|
||||
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
|
||||
`$soxmixbin "$dir1/$INfile" "$dir1/$OUTfile" "$dir1/$ALLfile"`;
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
if (!$T)
|
||||
{
|
||||
`mv -f "$dir1/$INfile" "$dir1/ORIG/$INfile"`;
|
||||
`mv -f "$dir1/$OUTfile" "$dir1/ORIG/$OUTfile"`;
|
||||
`mv -f "$dir1/$ALLfile" "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
else
|
||||
{
|
||||
`cp -f "$dir1/$ALLfile" "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
|
||||
`$soxbin "$dir1/DONE/$ALLfile" "$dir1/DONE/$GSMfile"`;
|
||||
|
||||
if (!$T)
|
||||
{
|
||||
`rm -f "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
|
||||
if($DB){print STDERR "\n|/usr/bin/sox $live_folder/$filename[$k]$WAV $arch_folder/$filename[$k]$GSM|\n";}
|
||||
chmod 0755, "$dir1/DONE/$GSMfile";
|
||||
|
||||
### BEGIN Remote file transfer
|
||||
# $p = Net::Ping->new();
|
||||
# $ping_good = $p->ping("$FTP_host");
|
||||
|
||||
# if ($ping_good)
|
||||
# {
|
||||
$ftp = Net::FTP->new("$FTP_host", Port => $FTP_port, Debug => 0, Passive => 1);
|
||||
$ftp->login("$FTP_user","$FTP_pass");
|
||||
$ftp->cwd("$FTP_dir");
|
||||
$ftp->binary();
|
||||
$ftp->put("$dir1/DONE/$GSMfile", "$GSMfile");
|
||||
$ftp->quit;
|
||||
# }
|
||||
### END Remote file transfer
|
||||
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($v) {print "DONE... EXITING\n\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_CRON_mix_recordings_MP3.pl
|
||||
# runs every 5 minutes and mixes the call recordings in the monitor together
|
||||
# and puts the resulting ALL file into the DONE directory in the "monitor" dir
|
||||
# and converts the ALL file to GSM format to save space.
|
||||
#
|
||||
# soxmix is REQUIRED to use this script, soxmix is available only as part of
|
||||
# the sox audio package, and only in newer versions. Make sure you have soxmix
|
||||
# installed properly and in your path
|
||||
#
|
||||
# put an entry into the cron of of your asterisk machine to run this script
|
||||
# every 5 minutes or however often you desire
|
||||
#
|
||||
# make sure that the following directories exist:
|
||||
# /var/spool/asterisk/monitor # default Asterisk recording directory
|
||||
# /var/spool/asterisk/monitor/DONE # where the combined files are put
|
||||
# /var/spool/asterisk/monitor/ORIG # where the original in/out files are put
|
||||
#
|
||||
# This program assumes that recordings are saved as .wav
|
||||
# should be easy to change this code if you use .gsm instead
|
||||
#
|
||||
# This program also sends the ALL combined file to an FTP server for archival
|
||||
# purposes, you can comment out the Net::Ping and Net::FTP lines as well as the
|
||||
# file transfer section of the code to deactivate remote copying of the
|
||||
# recording files
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
# Contributions by Mike Lord <mike@channelblend.com>
|
||||
#
|
||||
# 51021-1058 - Added quotes around CLI executed commands
|
||||
# 51122-1455 - Added soxmix and sox binary path check
|
||||
# 60616-1027 - Modified to convert to MP3 format
|
||||
#
|
||||
|
||||
|
||||
#$v=1;
|
||||
|
||||
# Customize variables for FTP
|
||||
$FTP_host = '10.0.0.4';
|
||||
$FTP_user = 'cron';
|
||||
$FTP_pass = 'test';
|
||||
$FTP_dir = 'recordings';
|
||||
$FTP_port = '21';
|
||||
|
||||
### directory where in/out recordings are saved to by Asterisk
|
||||
$dir1 = '/var/spool/asterisk/monitor';
|
||||
|
||||
$soxmixbin = '';
|
||||
if ( -e ('/usr/bin/soxmix')) {$soxmixbin = '/usr/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
if ( -e ('/usr/local/bin/soxmix')) {$soxmixbin = '/usr/local/bin/soxmix';}
|
||||
else
|
||||
{
|
||||
print "Can't find soxmix binary! Exiting...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$lamebin = '';
|
||||
if ( -e ('/usr/bin/lame')) {$lamebin = '/usr/bin/lame';}
|
||||
else
|
||||
{
|
||||
if ( -e ('/usr/local/bin/lame')) {$lamebin = '/usr/local/bin/lame';}
|
||||
else
|
||||
{
|
||||
print "Can't find lame binary! Exiting...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
use Net::Ping;
|
||||
use Net::FTP;
|
||||
|
||||
|
||||
opendir(FILE, "$dir1/");
|
||||
@FILES = readdir(FILE);
|
||||
|
||||
$i=0;
|
||||
foreach(@FILES)
|
||||
{
|
||||
$size1 = 0;
|
||||
$size2 = 0;
|
||||
|
||||
if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) )
|
||||
{
|
||||
|
||||
$size1 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size1\n";}
|
||||
sleep(1);
|
||||
$size2 = (-s "$dir1/$FILES[$i]");
|
||||
if ($v) {print "$FILES[$i] $size2\n\n";}
|
||||
|
||||
|
||||
if ( ($FILES[$i] !~ /out\.wav/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4))
|
||||
{
|
||||
$INfile = $FILES[$i];
|
||||
$OUTfile = $FILES[$i];
|
||||
$OUTfile =~ s/-in\.wav/-out.wav/gi;
|
||||
$ALLfile = $FILES[$i];
|
||||
$ALLfile =~ s/-in\.wav/-all.wav/gi;
|
||||
$MP3file = $ALLfile;
|
||||
$MP3file =~ s/-all\.wav/-all.mp3/gi;
|
||||
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
|
||||
`$soxmixbin "$dir1/$INfile" "$dir1/$OUTfile" "$dir1/$ALLfile"`;
|
||||
if ($v) {print "|$INfile| |$OUTfile| |$ALLfile|\n\n";}
|
||||
if (!$T)
|
||||
{
|
||||
`mv -f "$dir1/$INfile" "$dir1/ORIG/$INfile"`;
|
||||
`mv -f "$dir1/$OUTfile" "$dir1/ORIG/$OUTfile"`;
|
||||
`mv -f "$dir1/$ALLfile" "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
else
|
||||
{
|
||||
`cp -f "$dir1/$ALLfile" "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
|
||||
`$lamebin -b 16 -m m --silent "$dir1/DONE/$ALLfile" "$dir1/DONE/$MP3file"`;
|
||||
|
||||
if (!$T)
|
||||
{
|
||||
`rm -f "$dir1/DONE/$ALLfile"`;
|
||||
}
|
||||
|
||||
if($DB){print STDERR "\n|/usr/bin/sox $live_folder/$filename[$k]$WAV $arch_folder/$filename[$k]$GSM|\n";}
|
||||
chmod 0755, "$dir1/DONE/$MP3file";
|
||||
|
||||
### BEGIN Remote file transfer
|
||||
# $p = Net::Ping->new();
|
||||
# $ping_good = $p->ping("$FTP_host");
|
||||
|
||||
# if ($ping_good)
|
||||
# {
|
||||
$ftp = Net::FTP->new("$FTP_host", Port => $FTP_port, Debug => 0, Passive => 1);
|
||||
$ftp->login("$FTP_user","$FTP_pass");
|
||||
$ftp->cwd("$FTP_dir");
|
||||
$ftp->binary();
|
||||
$ftp->put("$dir1/DONE/$MP3file", "$MP3file");
|
||||
$ftp->quit;
|
||||
# }
|
||||
### END Remote file transfer
|
||||
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($v) {print "DONE... EXITING\n\n";}
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,153 @@
|
||||
#!/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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# AST_SERVER_conf.pl
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
|
||||
# Customized Variables
|
||||
$server_ip = '10.10.10.15'; # Asterisk server IP
|
||||
$DB_server = 'localhost'; # MySQL server IP
|
||||
$DB_database = 'asterisk'; # MySQL database name
|
||||
$DB_user = 'cron'; # MySQL user
|
||||
$DB_pass = '1234'; # MySQL pass
|
||||
$DB_port = '3306'; # MySQL connection port
|
||||
|
||||
$LOGfile = '/home/cron/LOG_AST_update.log';
|
||||
$telnetlog = '/home/cron/telnetlog.log';
|
||||
$MSLOGfile = '/home/cron/MSLOG_AST_update.log';
|
||||
$MStelnetlog = '/home/cron/MStelnetlog.log';
|
||||
$LILOGfile = '/home/cron/LILOG_AST_update.log';
|
||||
$LItelnetlog = '/home/cron/LItelnetlog.log';
|
||||
$KHLOGfile = '/home/cron/KHLOG_AST_update.log';
|
||||
$VDADLOGfile = '/home/cron/VDLOG_AST_update.log';
|
||||
|
||||
return 1;
|
||||
@@ -0,0 +1,887 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_VDauto_dial.pl version 0.11
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# uses Net::MySQL to place auto_dial calls on the VICIDIAL dialer system
|
||||
#
|
||||
# SUMMARY:
|
||||
# This program was designed for people using the Asterisk PBX with VICIDIAL
|
||||
#
|
||||
# For the client to use VICIDIAL, this program must be in the cron constantly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# This script is to run perpetually querying every second to place new phone
|
||||
# calls from the vicidial_hopper based upon how many available agents there are
|
||||
# and the value of the auto_dial_level setting in the campaign screen of the
|
||||
# admin web page
|
||||
#
|
||||
# It is good practice to keep this program running by placing the associated
|
||||
# KEEPALIVE script running every minute to ensure this program is always running
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
# changes:
|
||||
# 50125-1201 - Changed dial timeout to 120 seconds from 180 seconds
|
||||
# 50317-0954 - Added duplicate check per cycle to account for DB lockups
|
||||
# 50322-1302 - Added campaign custom callerid feature
|
||||
# 50324-1353 - Added optional variable to record ring time thru separate diap prefix
|
||||
# 50606-2308 - Added code to ensure no calls placed out on inactive campaign
|
||||
# 50617-1248 - Added code to place LOGOUT entry in auto-paused user logs
|
||||
# 50620-1349 - Added custom vdad transfer AGI extension per campaign
|
||||
# 50810-1610 - Added database server variable definitions lookup
|
||||
# 50810-1630 - Added max_vicidial_trunks server limiter on active lines
|
||||
# 50812-0957 - corrected max_trunks logic, added update of server every 25 sec
|
||||
# 60120-1522 - corrected time error for hour variable, caused agi problems
|
||||
# 60427-1223 - Fixed Blended in/out CLOSER campaign issue
|
||||
# 60608-1134 - Altered vac table field of call_type for IN OUT distinction
|
||||
# 60612-1324 - Altered dead call section to accept BUSY detection from VD_hangup
|
||||
# - Altered dead call section to accept DISCONNECT detection from VD_hangup
|
||||
# 60614-1142 - Added code to work with recycled leads, multi called_since_last_reset values
|
||||
# - Removed gmt lead validation because it is already done by VDhopper
|
||||
#
|
||||
|
||||
|
||||
### 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 [--delay=XXX] = delay of XXX seconds per loop, default 2.5 seconds\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /--delay=/i)
|
||||
{
|
||||
@data_in = split(/--delay=/,$args);
|
||||
$loop_delay = $data_in[1];
|
||||
print " LOOP DELAY OVERRIDE!!!!! = $loop_delay seconds\n\n";
|
||||
$loop_delay = ($loop_delay * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
$loop_delay = '2500';
|
||||
}
|
||||
if ($args =~ /-debug/i)
|
||||
{
|
||||
$DB=1; # Debug flag, set to 0 for no debug messages, On an active system this will generate hundreds of lines of output per minute
|
||||
}
|
||||
if ($args =~ /-t/i)
|
||||
{
|
||||
$TEST=1;
|
||||
$T=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set\n";
|
||||
$loop_delay = '2500';
|
||||
$DB=1;
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
|
||||
# constants
|
||||
$US='__';
|
||||
$MT[0]='';
|
||||
$RECcount=''; ### leave blank for no REC count
|
||||
$RECprefix='7'; ### leave blank for no REC prefix
|
||||
|
||||
### 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; # update time/date variables
|
||||
|
||||
$event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
|
||||
&event_logger; # writes to the log and if debug flag is set prints to STDOUT
|
||||
|
||||
use lib './lib', '../lib';
|
||||
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
|
||||
use Net::MySQL;
|
||||
|
||||
### connect to MySQL database defined in the AST_SERVER_conf.pl file
|
||||
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;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|';
|
||||
&event_logger;
|
||||
|
||||
$one_day_interval = 12; # 1 month loops for one year
|
||||
while($one_day_interval > 0)
|
||||
{
|
||||
|
||||
$endless_loop=5760000; # 30 days minutes at XXX seconds per loop
|
||||
|
||||
while($endless_loop > 0)
|
||||
{
|
||||
&get_time_now;
|
||||
|
||||
###############################################################################
|
||||
###### first figure out how many calls should be placed for each campaign per server
|
||||
###############################################################################
|
||||
@DBlive_user=@MT;
|
||||
@DBlive_server_ip=@MT;
|
||||
@DBlive_campaign=@MT;
|
||||
@DBlive_conf_exten=@MT;
|
||||
@DBcampaigns=@MT;
|
||||
@DBIPaddress=@MT;
|
||||
@DBIPcampaign=@MT;
|
||||
@DBIPactive=@MT;
|
||||
@DBIPvdadexten=@MT;
|
||||
@DBIPcount=@MT;
|
||||
@DBIPadlevel=@MT;
|
||||
@DBIPdialtimeout=@MT;
|
||||
@DBIPdialprefix=@MT;
|
||||
@DBIPcampaigncid=@MT;
|
||||
@DBIPexistcalls=@MT;
|
||||
@DBIPgoalcalls=@MT;
|
||||
@DBIPmakecalls=@MT;
|
||||
@DBIPclosercamp=@MT;
|
||||
|
||||
$active_line_counter=0;
|
||||
$user_counter=0;
|
||||
$user_campaigns = '|';
|
||||
$user_campaigns_counter = 0;
|
||||
$user_campaignIP = '|';
|
||||
$user_CIPct = 0;
|
||||
|
||||
##### Get a listing of the users that are active and ready to take calls
|
||||
##### Also get a listing of the campaigns and campaigns/serverIP that will be used
|
||||
$dbhA->query("SELECT user,server_ip,campaign_id,conf_exten FROM vicidial_live_agents where status IN('READY','QUEUE','INCALL','DONE') and server_ip='$server_ip' and last_update_time > '$BDtsSQLdate' order by last_call_time");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$DBlive_user[$user_counter] = "$record->[0]";
|
||||
$DBlive_server_ip[$user_counter] = "$record->[1]";
|
||||
$DBlive_campaign[$user_counter] = "$record->[2]";
|
||||
$DBlive_conf_exten[$user_counter] = "$record->[3]";
|
||||
|
||||
if ($user_campaigns !~ /\|$DBlive_campaign[$user_counter]\|/i)
|
||||
{
|
||||
$user_campaigns .= "$DBlive_campaign[$user_counter]|";
|
||||
$DBcampaigns[$user_campaigns_counter] = $DBlive_campaign[$user_counter];
|
||||
$user_campaigns_counter++;
|
||||
}
|
||||
if ($user_campaignIP !~ /\|$DBlive_campaign[$user_counter]__$DBlive_server_ip[$user_counter]\|/i)
|
||||
{
|
||||
$user_campaignIP .= "$DBlive_campaign[$user_counter]__$DBlive_server_ip[$user_counter]|";
|
||||
$DBIPcampaign[$user_CIPct] = "$DBlive_campaign[$user_counter]";
|
||||
$DBIPaddress[$user_CIPct] = "$DBlive_server_ip[$user_counter]";
|
||||
$user_CIPct++;
|
||||
}
|
||||
$user_counter++;
|
||||
}
|
||||
}
|
||||
|
||||
$event_string="LIVE AGENTS LOGGED IN: $user_counter";
|
||||
&event_logger;
|
||||
|
||||
$user_CIPct = 0;
|
||||
foreach(@DBIPcampaign)
|
||||
{
|
||||
$user_counter=0;
|
||||
foreach(@DBlive_campaign)
|
||||
{
|
||||
if ( ($DBlive_campaign[$user_counter] =~ /$DBIPcampaign[$user_CIPct]/i) && ($DBlive_server_ip[$user_counter] =~ /$DBIPaddress[$user_CIPct]/i) )
|
||||
{
|
||||
$DBIPcount[$user_CIPct]++
|
||||
}
|
||||
$user_counter++;
|
||||
}
|
||||
|
||||
### grab the dial_level and multiply by active agents to get your goalcalls
|
||||
$DBIPadlevel[$user_CIPct]=0;
|
||||
$dbhA->query("SELECT auto_dial_level,local_call_time,dial_timeout,dial_prefix,campaign_cid,active,campaign_vdad_exten,closer_campaigns FROM vicidial_campaigns where campaign_id='$DBIPcampaign[$user_CIPct]'");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$DBIPadlevel[$user_CIPct] = "$record->[0]";
|
||||
$DBIPcalltime[$user_CIPct] = "$record->[1]";
|
||||
$DBIPdialtimeout[$user_CIPct] = "$record->[2]";
|
||||
$DBIPdialprefix[$user_CIPct] = "$record->[3]";
|
||||
$DBIPcampaigncid[$user_CIPct] = "$record->[4]";
|
||||
$DBIPactive[$user_CIPct] = "$record->[5]";
|
||||
$DBIPvdadexten[$user_CIPct] = "$record->[6]";
|
||||
$DBIPclosercamp[$user_CIPct] = "$record->[7]";
|
||||
}
|
||||
}
|
||||
|
||||
$DBIPgoalcalls[$user_CIPct] = ($DBIPadlevel[$user_CIPct] * $DBIPcount[$user_CIPct]);
|
||||
if ($DBIPactive[$user_CIPct] =~ /N/) {$DBIPgoalcalls[$user_CIPct] = 0;}
|
||||
$DBIPgoalcalls[$user_CIPct] = sprintf("%.0f", $DBIPgoalcalls[$user_CIPct]);
|
||||
|
||||
$event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: agents: $DBIPcount[$user_CIPct] dial_level: $DBIPadlevel[$user_CIPct]";
|
||||
&event_logger;
|
||||
|
||||
$active_line_counter=0;
|
||||
$active_line_goal=0;
|
||||
### see how many total VDAD calls are going on right now for max limiter
|
||||
$dbhA->query("SELECT count(*) FROM vicidial_auto_calls where server_ip='$DBIPaddress[$user_CIPct]' and status IN('SENT','RINGING','LIVE','XFER');");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$active_line_counter = "$record->[0]";
|
||||
}
|
||||
}
|
||||
|
||||
### see how many calls are alrady active per campaign per server and
|
||||
### subtract that number from goalcalls to determine how many new
|
||||
### calls need to be placed in this loop
|
||||
if ($DBIPcampaign[$user_CIPct] =~ /CLOSER/)
|
||||
{
|
||||
if (length($DBIPclosercamp[$user_CIPct]) > 2)
|
||||
{
|
||||
$DBIPclosercamp[$user_CIPct] =~ s/^ | -$//gi;
|
||||
$DBIPclosercamp[$user_CIPct] =~ s/ /','/gi;
|
||||
$DBIPclosercamp[$user_CIPct] = "'$DBIPclosercamp[$user_CIPct]'";
|
||||
}
|
||||
else {$DBIPclosercamp[$user_CIPct]=''}
|
||||
|
||||
$campaign_query = "( (call_type='IN' and campaign_id IN($DBIPclosercamp[$user_CIPct])) or (campaign_id='$DBIPcampaign[$user_CIPct]' and call_type='OUT') )";
|
||||
}
|
||||
else {$campaign_query = "(campaign_id='$DBIPcampaign[$user_CIPct]' and call_type='OUT')";}
|
||||
$dbhA->query("SELECT count(*) FROM vicidial_auto_calls where $campaign_query and server_ip='$DBIPaddress[$user_CIPct]' and status IN('SENT','RINGING','LIVE','XFER','CLOSER');");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$DBIPexistcalls[$user_CIPct] = "$record->[0]";
|
||||
}
|
||||
}
|
||||
|
||||
$DBIPmakecalls[$user_CIPct] = ($DBIPgoalcalls[$user_CIPct] - $DBIPexistcalls[$user_CIPct]);
|
||||
$MVT_msg = '';
|
||||
$active_line_goal = ($active_line_counter + $DBIPmakecalls[$user_CIPct]);
|
||||
if ($active_line_goal > $max_vicidial_trunks)
|
||||
{
|
||||
$MVT_msg = "MVT override: $max_vicidial_trunks";
|
||||
$DBIPmakecalls[$user_CIPct] = ($max_vicidial_trunks - $active_line_counter);
|
||||
}
|
||||
$event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: Calls to place: $DBIPmakecalls[$user_CIPct] ($DBIPgoalcalls[$user_CIPct] - $DBIPexistcalls[$user_CIPct]) $MVT_msg";
|
||||
&event_logger;
|
||||
|
||||
$user_CIPct++;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
###### second lookup leads and place calls for each campaign/server_ip
|
||||
###### go one lead at a time and place the call by inserting a record into vicidial_manager
|
||||
###############################################################################
|
||||
|
||||
$user_CIPct = 0;
|
||||
foreach(@DBIPcampaign)
|
||||
{
|
||||
$event_string="$DBIPcampaign[$user_CIPct] $DBIPaddress[$user_CIPct]: CALLING";
|
||||
&event_logger;
|
||||
$call_CMPIPct=0;
|
||||
$lead_id_call_list='|';
|
||||
my $UDaffected_rows=0;
|
||||
if ($call_CMPIPct < $DBIPmakecalls[$user_CIPct])
|
||||
{
|
||||
$stmtA = "UPDATE vicidial_hopper set status='QUEUE', user='VDAD_$server_ip' where campaign_id='$DBIPcampaign[$user_CIPct]' and status='READY' order by hopper_id LIMIT $DBIPmakecalls[$user_CIPct]";
|
||||
print "|$stmtA|\n";
|
||||
$dbhA->query("$stmtA");
|
||||
my $UDaffected_rows = $dbhA->get_affected_rows_length;
|
||||
print "hopper rows updated to QUEUE: |$UDaffected_rows|\n";
|
||||
|
||||
if ($UDaffected_rows)
|
||||
{
|
||||
$lead_id=''; $phone_code=''; $phone_number=''; $called_count='';
|
||||
while ($call_CMPIPct < $UDaffected_rows)
|
||||
{
|
||||
$stmtA = "SELECT lead_id FROM vicidial_hopper where campaign_id='$DBIPcampaign[$user_CIPct]' and status='QUEUE' and user='VDAD_$server_ip' LIMIT 1";
|
||||
print "|$stmtA|\n";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$lead_id = "$record->[0]";
|
||||
}
|
||||
}
|
||||
|
||||
if ($lead_id_call_list =~ /\|$lead_id\|/)
|
||||
{
|
||||
print "!!!!!!!!!!!!!!!!duplicate lead_id for this run: |$lead_id| $lead_id_call_list\n";
|
||||
open(DUPout, ">>/home/cron/VDAD_DUPLICATE.$file_date")
|
||||
|| die "Can't open /home/cron/VDAD_DUPLICATE.$file_date: $!\n";
|
||||
print DUPout "$now_date-----$lead_id_call_list-----$lead_id\n";
|
||||
close(DUPout);
|
||||
}
|
||||
else
|
||||
{
|
||||
$stmtA = "UPDATE vicidial_hopper set status='INCALL' where lead_id='$lead_id'";
|
||||
print "|$stmtA|\n";
|
||||
$dbhA->query("$stmtA");
|
||||
my $UQaffected_rows = $dbhA->get_affected_rows_length;
|
||||
print "hopper row updated to INCALL: |$UQaffected_rows|$lead_id|\n";
|
||||
|
||||
$stmtA = "SELECT * FROM vicidial_list where lead_id='$lead_id';";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$gmt_offset_now = "$record->[8]";
|
||||
$called_since_last_reset = "$record->[9]";
|
||||
$phone_code = "$record->[10]";
|
||||
$phone_number = "$record->[11]";
|
||||
$called_count = "$record->[30]";
|
||||
|
||||
$rec_countCUSTDATA++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rec_countCUSTDATA)
|
||||
{
|
||||
### update called_count
|
||||
$called_count++;
|
||||
if ($called_since_last_reset =~ /^Y/)
|
||||
{
|
||||
if ($called_since_last_reset =~ /^Y$/) {$CSLR = 'Y1';}
|
||||
else
|
||||
{
|
||||
$called_since_last_reset =~ s/^Y//gi;
|
||||
$called_since_last_reset++;
|
||||
$CSLR = "Y$called_since_last_reset";
|
||||
}
|
||||
}
|
||||
else {$CSLR = 'Y';}
|
||||
|
||||
$stmtA = "UPDATE vicidial_list set called_since_last_reset='$CSLR', called_count='$called_count',user='VDAD' where lead_id='$lead_id'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$stmtA = "DELETE FROM vicidial_hopper where lead_id='$lead_id'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$CCID_on=0; $CCID='';
|
||||
$local_DEF = 'Local/';
|
||||
$local_AMP = '@';
|
||||
$Local_out_prefix = '9';
|
||||
$Local_dial_timeout = '60';
|
||||
if ($DBIPdialtimeout[$user_CIPct] > 4) {$Local_dial_timeout = $DBIPdialtimeout[$user_CIPct];}
|
||||
$Local_dial_timeout = ($Local_dial_timeout * 1000);
|
||||
if (length($DBIPdialprefix[$user_CIPct]) > 0) {$Local_out_prefix = "$DBIPdialprefix[$user_CIPct]";}
|
||||
if (length($DBIPvdadexten[$user_CIPct]) > 0) {$VDAD_dial_exten = "$DBIPvdadexten[$user_CIPct]";}
|
||||
else {$VDAD_dial_exten = "$answer_transfer_agent";}
|
||||
|
||||
if (length($DBIPcampaigncid[$user_CIPct]) > 6) {$CCID = "$DBIPcampaigncid[$user_CIPct]"; $CCID_on++;}
|
||||
if ($DBIPdialprefix[$user_CIPct] =~ /x/i) {$Local_out_prefix = '';}
|
||||
|
||||
if ($RECcount)
|
||||
{
|
||||
if ( (length($RECprefix)>0) && ($called_count < $RECcount) )
|
||||
{$Local_out_prefix .= "$RECprefix";}
|
||||
}
|
||||
$PADlead_id = sprintf("%09s", $lead_id); while (length($PADlead_id) > 9) {chop($PADlead_id);}
|
||||
|
||||
$lead_id_call_list .= "$lead_id|";
|
||||
|
||||
### use manager middleware-app to connect the next call to the meetme room
|
||||
# VmmddhhmmssLLLLLLLLL
|
||||
$VqueryCID = "V$CIDdate$PADlead_id";
|
||||
if ($CCID_on) {$CIDstring = "\"$VqueryCID\" <$CCID>";}
|
||||
else {$CIDstring = "$VqueryCID";}
|
||||
|
||||
### insert a NEW record to the vicidial_manager table to be processed
|
||||
$stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$DBIPaddress[$user_CIPct]','','Originate','$VqueryCID','Exten: $VDAD_dial_exten','Context: $ext_context','Channel: $local_DEF$Local_out_prefix$phone_code$phone_number$local_AMP$ext_context','Priority: 1','Callerid: $CIDstring','Timeout: $Local_dial_timeout','','','','')";
|
||||
$dbhA->query($stmtA);
|
||||
|
||||
$event_string = "| number call dialed|$DBIPcampaign[$user_CIPct]|$VqueryCID|$stmtA|$gmt_offset_now|";
|
||||
&event_logger;
|
||||
|
||||
### insert a SENT record to the vicidial_auto_calls table
|
||||
$stmtA = "INSERT INTO vicidial_auto_calls (server_ip,campaign_id,status,lead_id,callerid,phone_code,phone_number,call_time,call_type) values('$DBIPaddress[$user_CIPct]','$DBIPcampaign[$user_CIPct]','SENT','$lead_id','$VqueryCID','$phone_code','$phone_number','$SQLdate','OUT')";
|
||||
$dbhA->query($stmtA);
|
||||
|
||||
### sleep for a tenth of a second to not flood the server with new calls
|
||||
usleep(1*100*1000);
|
||||
|
||||
}
|
||||
}
|
||||
$call_CMPIPct++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$user_CIPct++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
&get_time_now;
|
||||
|
||||
###############################################################################
|
||||
###### third we will grab the callerids of the vicidial_auto_calls records and check for dead calls
|
||||
###### we also check to make sure that it isn't a call that has been transferred,
|
||||
###### if it has been we need to leave the vicidial_list status alone
|
||||
###############################################################################
|
||||
|
||||
@KLcallerid = @MT;
|
||||
@KLserver_ip = @MT;
|
||||
@KLchannel = @MT;
|
||||
$kill_vac=0;
|
||||
|
||||
$stmtA = "SELECT callerid,server_ip,channel,uniqueid FROM vicidial_auto_calls where server_ip='$server_ip' order by call_time;";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$KLcallerid[$kill_vac] = "$record->[0]";
|
||||
$KLserver_ip[$kill_vac] = "$record->[1]";
|
||||
$KLchannel[$kill_vac] = "$record->[2]";
|
||||
$KLuniqueid[$kill_vac] = "$record->[3]";
|
||||
|
||||
$kill_vac++;
|
||||
}
|
||||
}
|
||||
|
||||
$kill_vac=0;
|
||||
foreach(@KLcallerid)
|
||||
{
|
||||
if (length($KLserver_ip[$kill_vac]) > 7)
|
||||
{
|
||||
$end_epoch=0; $CLuniqueid='';
|
||||
|
||||
$stmtA = "SELECT end_epoch,uniqueid FROM call_log where caller_code='$KLcallerid[$kill_vac]' and server_ip='$KLserver_ip[$kill_vac]' order by end_epoch, start_time desc limit 1;";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$end_epoch = "$record->[0]";
|
||||
$CLuniqueid = "$record->[1]";
|
||||
}
|
||||
}
|
||||
|
||||
if ( (length($KLuniqueid[$kill_vac]) > 15) && (length($CLuniqueid) < 15) )
|
||||
{
|
||||
$stmtA = "SELECT end_epoch,uniqueid FROM call_log where uniqueid='$KLuniqueid[$kill_vac]' and server_ip='$KLserver_ip[$kill_vac]' order by end_epoch, start_time desc limit 1;";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$end_epoch = "$record->[0]";
|
||||
$CLuniqueid = "$record->[1]";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($end_epoch > 1000)
|
||||
{
|
||||
$CLlead_id=''; $auto_call_id=''; $CLstatus=''; $CLcampaign_id=''; $CLphone_number=''; $CLphone_code='';
|
||||
|
||||
$stmtA = "SELECT auto_call_id,lead_id,phone_number,status,campaign_id,phone_code FROM vicidial_auto_calls where callerid='$KLcallerid[$kill_vac]'";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$auto_call_id = "$record->[0]";
|
||||
$CLlead_id = "$record->[1]";
|
||||
$CLphone_number = "$record->[2]";
|
||||
$CLstatus = "$record->[3]";
|
||||
$CLcampaign_id = "$record->[4]";
|
||||
$CLphone_code = "$record->[5]";
|
||||
}
|
||||
}
|
||||
$stmtA = "DELETE from vicidial_auto_calls where auto_call_id='$auto_call_id'";
|
||||
# $stmtA = "UPDATE vicidial_auto_calls set status='PAUSED' where callerid='$KLcallerid[$kill_vac]'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| dead call vac deleted|$auto_call_id|$CLlead_id|$KLcallerid[$kill_vac]|$end_epoch|$affected_rows|$KLchannel[$kill_vac]|";
|
||||
&event_logger;
|
||||
|
||||
if ($CLstatus !~ /XFER|CLOSER/)
|
||||
{
|
||||
if ($CLstatus =~ /BUSY/) {$CLnew_status = 'B';}
|
||||
else
|
||||
{
|
||||
if ($CLstatus =~ /DISCONNECT/) {$CLnew_status = 'DC';}
|
||||
else {$CLnew_status = 'NA';}
|
||||
}
|
||||
if ($CLstatus =~ /LIVE/) {$CLnew_status = 'DROP';}
|
||||
else
|
||||
{
|
||||
$end_epoch = ($now_date_epoch + 1);
|
||||
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed,length_in_sec,end_epoch) values('$CLuniqueid','$CLlead_id','$CLcampaign_id','$SQLdate','$now_date_epoch','$CLnew_status','$CLphone_code','$CLphone_number','VDAD','N','1','$end_epoch')";
|
||||
if($M){print STDERR "\n|$stmtA|\n";}
|
||||
$dbhA->query($stmtA);
|
||||
|
||||
$event_string = "| dead NA call added to log $CLuniqueid|$CLlead_id|$CLphone_number|$CLstatus|$CLnew_status|";
|
||||
&event_logger;
|
||||
|
||||
}
|
||||
|
||||
$stmtA = "UPDATE vicidial_list set status='$CLnew_status' where lead_id='$CLlead_id'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| dead call vac lead marked $CLnew_status|$CLlead_id|$CLphone_number|$CLstatus|";
|
||||
&event_logger;
|
||||
|
||||
$stmtA = "UPDATE vicidial_live_agents set status='PAUSED',random_id='10' where callerid='$KLcallerid[$kill_vac]';";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| dead call vla agent PAUSED $affected_rows|$CLlead_id|$CLphone_number|$CLstatus|";
|
||||
&event_logger;
|
||||
}
|
||||
else
|
||||
{
|
||||
$event_string = "| dead call vac XFERd do nothing|$CLlead_id|$CLphone_number|$CLstatus|";
|
||||
&event_logger;
|
||||
}
|
||||
}
|
||||
}
|
||||
$kill_vac++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
### pause agents that have disconnected or closed their apps over 30 seconds ago
|
||||
$stmtA = "UPDATE vicidial_live_agents set status='PAUSED',random_id='10' where server_ip='$server_ip' and last_update_time < '$PDtsSQLdate' and status NOT IN('PAUSED')";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| lagged call vla agent PAUSED $affected_rows|$PDtsSQLdate|$BDtsSQLdate|$tsSQLdate|";
|
||||
&event_logger;
|
||||
|
||||
if ($affected_rows > 0)
|
||||
{
|
||||
@VALOuser=@MT; @VALOcampaign=@MT; @VALOtimelog=@MT; @VALOextension=@MT;
|
||||
$logcount=0;
|
||||
$stmtA = "SELECT user,campaign_id,last_update_time,extension FROM vicidial_live_agents where server_ip='$server_ip' and status = 'PAUSED' and random_id='10' order by last_update_time desc limit $affected_rows";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$VALOuser[$logcount] = "$record->[0]";
|
||||
$VALOcampaign[$logcount] = "$record->[1]";
|
||||
$VALOtimelog[$logcount] = "$record->[2]";
|
||||
$VALOextension[$logcount] = "$record->[3]";
|
||||
$logcount++;
|
||||
}
|
||||
}
|
||||
$logrun=0;
|
||||
foreach(@VALOuser)
|
||||
{
|
||||
$stmtA = "INSERT INTO vicidial_user_log (user,event,campaign_id,event_date,event_epoch) values('$VALOuser[$logrun]','LOGOUT','$VALOcampaign[$logrun]','$SQLdate','$now_date_epoch');";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| lagged agent LOGOUT entry inserted $VALOuser[$logrun]|$VALOcampaign[$logrun]|$VALOextension[$logcount]|";
|
||||
&event_logger;
|
||||
|
||||
$logrun++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
### delete call records that are SENT for over 3 minutes
|
||||
$stmtA = "DELETE FROM vicidial_auto_calls where server_ip='$server_ip' and call_time < '$XDSQLdate' and status NOT IN('XFER','CLOSER','LIVE')";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| lagged call vac agent DELETED $affected_rows|$XDSQLdate|";
|
||||
&event_logger;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
###### last, wait for a little bit and repeat the loop
|
||||
###############################################################################
|
||||
|
||||
### sleep for 2 and a half seconds before beginning the loop again
|
||||
usleep(1*$loop_delay*1000);
|
||||
|
||||
$endless_loop--;
|
||||
if($DB){print STDERR "\nloop counter: |$endless_loop|\n";}
|
||||
|
||||
### putting a blank file called "VDAD.kill" in the directory will automatically safely kill this program
|
||||
if (-e '/home/cron/VDAD.kill')
|
||||
{
|
||||
unlink('/home/cron/VDAD.kill');
|
||||
$endless_loop=0;
|
||||
$one_day_interval=0;
|
||||
print "\nPROCESS KILLED MANUALLY... EXITING\n\n"
|
||||
}
|
||||
if ($endless_loop =~ /0$/) # run every ten cycles (about 25 seconds)
|
||||
{
|
||||
### delete call records that are LIVE for over 10 minutes
|
||||
$stmtA = "DELETE FROM vicidial_auto_calls where server_ip='$server_ip' and call_time < '$TDSQLdate' and status NOT IN('XFER','CLOSER')";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| lagged call vac agent DELETED $affected_rows|$TDSQLdate|LIVE|";
|
||||
&event_logger;
|
||||
|
||||
### Grab Server values from the database in case they've changed
|
||||
$stmtA = "SELECT 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)
|
||||
{
|
||||
$DBmax_vicidial_trunks = "$record->[0]";
|
||||
$DBanswer_transfer_agent= "$record->[1]";
|
||||
$DBSERVER_GMT = "$record->[2]";
|
||||
$DBext_context = "$record->[3]";
|
||||
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;}
|
||||
}
|
||||
}
|
||||
|
||||
$event_string = "| updating server parameters $max_vicidial_trunks|$answer_transfer_agent|$SERVER_GMT|$ext_context|";
|
||||
&event_logger;
|
||||
|
||||
&get_time_now;
|
||||
|
||||
#@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]);
|
||||
|
||||
@psline = split(/\/usr\/bin\/perl /,$psoutput[$i]);
|
||||
|
||||
if ($psline[1] =~ /AST_manager_li/) {$running_listen++;}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_listen)
|
||||
{
|
||||
$endless_loop=0;
|
||||
$one_day_interval=0;
|
||||
print "\nPROCESS KILLED NO LISTENER RUNNING... EXITING\n\n";
|
||||
}
|
||||
|
||||
if($DB){print "checking to see if listener is dead |$running_listen|\n";}
|
||||
}
|
||||
|
||||
$bad_grabber_counter=0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if($DB){print "DONE... Exiting... Goodbye... See you later... Not really, initiating next loop...\n";}
|
||||
|
||||
$event_string='HANGING UP|';
|
||||
&event_logger;
|
||||
|
||||
$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
|
||||
{
|
||||
$secX = time();
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secX);
|
||||
$LOCAL_GMT_OFF = $SERVER_GMT;
|
||||
$LOCAL_GMT_OFF_STD = $SERVER_GMT;
|
||||
if ($isdst) {$LOCAL_GMT_OFF++;}
|
||||
|
||||
$GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600));
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now);
|
||||
if ($hour < 10) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
|
||||
if ($DB) {print "TIME DEBUG: $LOCAL_GMT_OFF_STD|$LOCAL_GMT_OFF|$isdst| GMT: $hour:$min\n";}
|
||||
|
||||
($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) {$hour = "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";
|
||||
$file_date = "$year-$mon-$mday";
|
||||
$CIDdate = "$mon$mday$hour$min$sec";
|
||||
$tsSQLdate = "$year$mon$mday$hour$min$sec";
|
||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||
|
||||
$BDtarget = ($secX - 10);
|
||||
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
|
||||
$Byear = ($Byear + 1900);
|
||||
$Bmon++;
|
||||
if ($Bmon < 10) {$Bmon = "0$Bmon";}
|
||||
if ($Bmday < 10) {$Bmday = "0$Bmday";}
|
||||
if ($Bhour < 10) {$Bhour = "0$Bhour";}
|
||||
if ($Bmin < 10) {$Bmin = "0$Bmin";}
|
||||
if ($Bsec < 10) {$Bsec = "0$Bsec";}
|
||||
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
|
||||
|
||||
$PDtarget = ($secX - 30);
|
||||
($Psec,$Pmin,$Phour,$Pmday,$Pmon,$Pyear,$Pwday,$Pyday,$Pisdst) = localtime($PDtarget);
|
||||
$Pyear = ($Pyear + 1900);
|
||||
$Pmon++;
|
||||
if ($Pmon < 10) {$Pmon = "0$Pmon";}
|
||||
if ($Pmday < 10) {$Pmday = "0$Pmday";}
|
||||
if ($Phour < 10) {$Phour = "0$Phour";}
|
||||
if ($Pmin < 10) {$Pmin = "0$Pmin";}
|
||||
if ($Psec < 10) {$Psec = "0$Psec";}
|
||||
$PDtsSQLdate = "$Pyear$Pmon$Pmday$Phour$Pmin$Psec";
|
||||
|
||||
$XDtarget = ($secX - 120);
|
||||
($Xsec,$Xmin,$Xhour,$Xmday,$Xmon,$Xyear,$Xwday,$Xyday,$Xisdst) = localtime($XDtarget);
|
||||
$Xyear = ($Xyear + 1900);
|
||||
$Xmon++;
|
||||
if ($Xmon < 10) {$Xmon = "0$Xmon";}
|
||||
if ($Xmday < 10) {$Xmday = "0$Xmday";}
|
||||
if ($Xhour < 10) {$Xhour = "0$Xhour";}
|
||||
if ($Xmin < 10) {$Xmin = "0$Xmin";}
|
||||
if ($Xsec < 10) {$Xsec = "0$Xsec";}
|
||||
$XDSQLdate = "$Xyear-$Xmon-$Xmday $Xhour:$Xmin:$Xsec";
|
||||
|
||||
$TDtarget = ($secX - 600);
|
||||
($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TDtarget);
|
||||
$Tyear = ($Tyear + 1900);
|
||||
$Tmon++;
|
||||
if ($Tmon < 10) {$Tmon = "0$Tmon";}
|
||||
if ($Tmday < 10) {$Tmday = "0$Tmday";}
|
||||
if ($Thour < 10) {$Thour = "0$Thour";}
|
||||
if ($Tmin < 10) {$Tmin = "0$Tmin";}
|
||||
if ($Tsec < 10) {$Tsec = "0$Tsec";}
|
||||
$TDSQLdate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub event_logger
|
||||
{
|
||||
|
||||
if ($DB) {print "$now_date|$event_string|\n";}
|
||||
### open the log file for writing ###
|
||||
open(Lout, ">>$VDADLOGfile")
|
||||
|| die "Can't open $VDADLOGfile: $!\n";
|
||||
|
||||
print Lout "$now_date|$event_string|\n";
|
||||
|
||||
close(Lout);
|
||||
|
||||
$event_string='';
|
||||
}
|
||||
+1188
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,493 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# AST_VDremote_agents.pl version 0.1
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# uses Net::MySQL to keep remote agents logged in to the VICIDIAL system
|
||||
#
|
||||
# SUMMARY:
|
||||
# This program was designed for people using the Asterisk PBX with VICIDIAL
|
||||
#
|
||||
# For the client to use VICIDIAL with remote agents, this must always be running
|
||||
#
|
||||
# It is recommended that you run this program on the local Asterisk machine
|
||||
#
|
||||
# This script is to run perpetually querying every second to update the remote
|
||||
# agents that should appear to be logged in so that the calls can be transferred
|
||||
# out to them properly.
|
||||
#
|
||||
# It is good practice to keep this program running by placing the associated
|
||||
# KEEPALIVE script running every minute to ensure this program is always running
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
# changes:
|
||||
# 50215-0954 - First version of script
|
||||
# 50810-1615 - Added database server variable definitions lookup
|
||||
#
|
||||
|
||||
### 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 [-v] = verbose debug messages\n [--delay=XXX] = delay of XXX seconds per loop, default 2 seconds\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /--delay=/i)
|
||||
{
|
||||
@data_in = split(/--delay=/,$args);
|
||||
$loop_delay = $data_in[1];
|
||||
print " LOOP DELAY OVERRIDE!!!!! = $loop_delay seconds\n\n";
|
||||
$loop_delay = ($loop_delay * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
$loop_delay = '2000';
|
||||
}
|
||||
if ($args =~ /-v/i)
|
||||
{
|
||||
$V=1; # Debug flag, set to 0 for no debug messages, On an active system this will generate hundreds of lines of output per minute
|
||||
}
|
||||
if ($args =~ /-t/i)
|
||||
{
|
||||
$TEST=1;
|
||||
$T=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set\n";
|
||||
$loop_delay = '2000';
|
||||
$V=1;
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
|
||||
# constants
|
||||
$US='__';
|
||||
$MT[0]='';
|
||||
|
||||
### 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;
|
||||
|
||||
### connect to MySQL database defined in the AST_SERVER_conf.pl file
|
||||
my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port")
|
||||
or die "Couldn't connect to database: $DB_server - $DB_database\n";
|
||||
|
||||
### Grab Server values from the database
|
||||
$stmtA = "SELECT local_gmt FROM servers where server_ip = '$server_ip';";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$DBSERVER_GMT = "$record->[0]";
|
||||
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
&get_time_now; # update time/date variables
|
||||
|
||||
$event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
|
||||
&event_logger; # writes to the log and if debug flag is set prints to STDOUT
|
||||
|
||||
|
||||
$event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|';
|
||||
&event_logger;
|
||||
|
||||
$one_day_interval = 12; # 1 month loops for one year
|
||||
while($one_day_interval > 0)
|
||||
{
|
||||
|
||||
$endless_loop=5760000; # 30 days minutes at XXX seconds per loop
|
||||
|
||||
while($endless_loop > 0)
|
||||
{
|
||||
&get_time_now;
|
||||
|
||||
if ($endless_loop =~ /0$|5$/)
|
||||
{
|
||||
### delete call records that are LIVE for over 10 minutes and last_update_time < '$PDtsSQLdate'
|
||||
$stmtA = "DELETE FROM vicidial_live_agents where server_ip='$server_ip' and status IN('PAUSED') and extension LIKE \"R/%\"";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| lagged call vla agent DELETED $affected_rows";
|
||||
&event_logger;
|
||||
|
||||
|
||||
$stmtA = "UPDATE vicidial_live_agents set status='INCALL', last_call_time='$SQLdate' where server_ip='$server_ip' and status IN('QUEUE') and extension LIKE \"R/%\"";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
|
||||
$event_string = "| QUEUEd call listing vla UPDATEd $affected_rows";
|
||||
&event_logger;
|
||||
|
||||
#@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]);
|
||||
|
||||
@psline = split(/\/usr\/bin\/perl /,$psoutput[$i]);
|
||||
|
||||
if ($psline[1] =~ /AST_manager_li/) {$running_listen++;}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$running_listen)
|
||||
{
|
||||
$endless_loop=0;
|
||||
$one_day_interval=0;
|
||||
print "\nPROCESS KILLED NO LISTENER RUNNING... EXITING\n\n";
|
||||
}
|
||||
|
||||
if($DB){print "checking to see if listener is dead |$running_listen|\n";}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$user_counter=0;
|
||||
@DBremote_user=@MT;
|
||||
@DBremote_server_ip=@MT;
|
||||
@DBremote_campaign=@MT;
|
||||
@DBremote_conf_exten=@MT;
|
||||
@DBremote_closer=@MT;
|
||||
@DBremote_random=@MT;
|
||||
@loginexistsRANDOM=@MT;
|
||||
@loginexistsALL=@MT;
|
||||
@VD_user=@MT;
|
||||
@VD_extension=@MT;
|
||||
@VD_status=@MT;
|
||||
@VD_uniqueid=@MT;
|
||||
@VD_callerid=@MT;
|
||||
@VD_random=@MT;
|
||||
###############################################################################
|
||||
###### first grab all of the ACTIVE remote agents information from the database
|
||||
###############################################################################
|
||||
$dbhA->query("SELECT * FROM vicidial_remote_agents where status IN('ACTIVE') and server_ip='$server_ip' order by user_start");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$user_start = "$record->[1]";
|
||||
$number_of_lines = "$record->[2]";
|
||||
$conf_exten = "$record->[4]";
|
||||
$campaign_id = "$record->[6]";
|
||||
$closer_campaigns = "$record->[7]";
|
||||
|
||||
$y=0;
|
||||
while ($y < $number_of_lines)
|
||||
{
|
||||
$random = int( rand(9999999)) + 10000000;
|
||||
$user_id = ($user_start + $y);
|
||||
$DBremote_user[$user_counter] = "$user_id";
|
||||
$DBremote_server_ip[$user_counter] = "$server_ip";
|
||||
$DBremote_campaign[$user_counter] = "$campaign_id";
|
||||
$DBremote_conf_exten[$user_counter] = "$conf_exten";
|
||||
$DBremote_closer[$user_counter] = "$closer_campaigns";
|
||||
$DBremote_random[$user_counter] = "$random";
|
||||
|
||||
$y++;
|
||||
$user_counter++;
|
||||
}
|
||||
|
||||
}
|
||||
if ($V) {print STDERR "$user_counter live remote agents ACTIVE\n";}
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
###### second traverse array of remote agents to be active and insert or update
|
||||
###### in vicidial_live_agents table
|
||||
###############################################################################
|
||||
$h=0;
|
||||
foreach(@DBremote_user)
|
||||
{
|
||||
if (length($DBremote_user[$h])>1)
|
||||
{
|
||||
|
||||
### check to see if the record exists and only needs random number update
|
||||
$dbhA->query("SELECT count(*) FROM vicidial_live_agents where user='$DBremote_user[$h]' and server_ip='$server_ip' and campaign_id='$DBremote_campaign[$h]' and conf_exten='$DBremote_conf_exten[$h]' and closer_campaigns='$DBremote_closer[$h]'");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$loginexistsRANDOM[$h] = "$record->[0]";
|
||||
}
|
||||
}
|
||||
if ($loginexistsRANDOM[$h] > 0)
|
||||
{
|
||||
$stmtA = "UPDATE vicidial_live_agents set random_id='$DBremote_random[$h]' where user='$DBremote_user[$h]' and server_ip='$server_ip' and campaign_id='$DBremote_campaign[$h]' and conf_exten='$DBremote_conf_exten[$h]' and closer_campaigns='$DBremote_closer[$h]'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
if ($V) {print STDERR "$DBremote_user[$h] $DBremote_campaign[$h] ONLY RANDOM ID UPDATE: $affected_rows\n";}
|
||||
}
|
||||
### check if record for user on server exists at all in vicidial_live_agents
|
||||
else
|
||||
{
|
||||
$dbhA->query("SELECT count(*) FROM vicidial_live_agents where user='$DBremote_user[$h]' and server_ip='$server_ip'");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$loginexistsALL[$h] = "$record->[0]";
|
||||
}
|
||||
}
|
||||
if ($loginexistsALL[$h] > 0)
|
||||
{
|
||||
$stmtA = "UPDATE vicidial_live_agents set random_id='$DBremote_random[$h]',campaign_id='$DBremote_campaign[$h]',conf_exten='$DBremote_conf_exten[$h]',closer_campaigns='$DBremote_closer[$h]', status='READY' where user='$DBremote_user[$h]' and server_ip='$server_ip'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
if ($V) {print STDERR "$DBremote_user[$h] ALL UPDATE: $affected_rows\n";}
|
||||
}
|
||||
### no records exist so insert a new one
|
||||
else
|
||||
{
|
||||
$stmtA = "INSERT INTO vicidial_live_agents (user,server_ip,conf_exten,extension,status,campaign_id,random_id,last_call_time,last_update_time,last_call_finish,closer_campaigns,channel,uniqueid,callerid) values('$DBremote_user[$h]','$server_ip','$DBremote_conf_exten[$h]','R/$DBremote_user[$h]','READY','$DBremote_campaign[$h]','$DBremote_random[$h]','$SQLdate','$tsSQLdate','$SQLdate','$DBremote_closer[$h]','','','')";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($V) {print STDERR "$DBremote_user[$h] NEW INSERT\n";}
|
||||
}
|
||||
}
|
||||
}
|
||||
$h++;
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
###### third validate that the calls that the vicidial_live_agents are on are not dead
|
||||
###### and if they are wipe out the values and set the agent record back to READY
|
||||
###############################################################################
|
||||
$dbhA->query("SELECT user,extension,status,uniqueid,callerid FROM vicidial_live_agents where extension LIKE \"R/%\" and server_ip='$server_ip' and uniqueid > 10");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
$z=0;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$VDuser = "$record->[0]";
|
||||
$VDextension = "$record->[1]";
|
||||
$VDstatus = "$record->[2]";
|
||||
$VDuniqueid = "$record->[3]";
|
||||
$VDcallerid = "$record->[4]";
|
||||
$VDrandom = int( rand(9999999)) + 10000000;
|
||||
|
||||
$VD_user[$z] = "$VDuser";
|
||||
$VD_extension[$z] = "$VDextension";
|
||||
$VD_status[$z] = "$VDstatus";
|
||||
$VD_uniqueid[$z] = "$VDuniqueid";
|
||||
$VD_callerid[$z] = "$VDcallerid";
|
||||
$VD_random[$z] = "$VDrandom";
|
||||
|
||||
$z++;
|
||||
}
|
||||
if ($V) {print STDERR "$z remote agents on calls\n";}
|
||||
}
|
||||
$z=0;
|
||||
foreach(@VD_user)
|
||||
{
|
||||
$dbhA->query("SELECT count(*) FROM vicidial_auto_calls where uniqueid='$VD_uniqueid[$z]' and server_ip='$server_ip'");
|
||||
if ($dbhA->has_selected_record)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$autocallexists[$z] = "$record->[0]";
|
||||
}
|
||||
}
|
||||
if ($autocallexists[$z] < 1)
|
||||
{
|
||||
$stmtA = "UPDATE vicidial_live_agents set random_id='$VD_random[$z]',status='READY', last_call_finish='$SQLdate',lead_id='',uniqueid='',callerid='',channel='' where user='$VD_user[$z]' and server_ip='$server_ip'";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
if ($V) {print STDERR "$VD_user[$z] CALL WIPE UPDATE: $affected_rows|$VD_uniqueid[$z]\n";}
|
||||
}
|
||||
|
||||
$z++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
###### last, wait for a little bit and repeat the loop
|
||||
###############################################################################
|
||||
|
||||
### sleep for X seconds before beginning the loop again
|
||||
usleep(1*$loop_delay*1000);
|
||||
|
||||
$endless_loop--;
|
||||
if($DB){print STDERR "\nloop counter: |$endless_loop|\n";}
|
||||
|
||||
### putting a blank file called "VDAD.kill" in the directory will automatically safely kill this program
|
||||
if (-e '/home/cron/VDAD.kill')
|
||||
{
|
||||
unlink('/home/cron/VDAD.kill');
|
||||
$endless_loop=0;
|
||||
$one_day_interval=0;
|
||||
print "\nPROCESS KILLED MANUALLY... EXITING\n\n"
|
||||
}
|
||||
|
||||
$bad_grabber_counter=0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if($DB){print "DONE... Exiting... Goodbye... See you later... Not really, initiating next loop...\n";}
|
||||
|
||||
$event_string='HANGING UP|';
|
||||
&event_logger;
|
||||
|
||||
$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
|
||||
{
|
||||
$secX = time();
|
||||
$secX = time();
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secX);
|
||||
$LOCAL_GMT_OFF = $SERVER_GMT;
|
||||
$LOCAL_GMT_OFF_STD = $SERVER_GMT;
|
||||
if ($isdst) {$LOCAL_GMT_OFF++;}
|
||||
|
||||
$GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600));
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now);
|
||||
if ($hour < 10) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
|
||||
if ($DB) {print "TIME DEBUG: $LOCAL_GMT_OFF_STD|$LOCAL_GMT_OFF|$isdst| GMT: $hour:$min\n";}
|
||||
|
||||
($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";
|
||||
$CIDdate = "$mon$mday$hour$min$sec";
|
||||
$tsSQLdate = "$year$mon$mday$hour$min$sec";
|
||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||
$filedate = "$year-$mon-$mday";
|
||||
|
||||
$BDtarget = ($secX - 10);
|
||||
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
|
||||
$Byear = ($Byear + 1900);
|
||||
$Bmon++;
|
||||
if ($Bmon < 10) {$Bmon = "0$Bmon";}
|
||||
if ($Bmday < 10) {$Bmday = "0$Bmday";}
|
||||
if ($Bhour < 10) {$Bhour = "0$Bhour";}
|
||||
if ($Bmin < 10) {$Bmin = "0$Bmin";}
|
||||
if ($Bsec < 10) {$Bsec = "0$Bsec";}
|
||||
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
|
||||
|
||||
$PDtarget = ($secX - 30);
|
||||
($Psec,$Pmin,$Phour,$Pmday,$Pmon,$Pyear,$Pwday,$Pyday,$Pisdst) = localtime($PDtarget);
|
||||
$Pyear = ($Pyear + 1900);
|
||||
$Pmon++;
|
||||
if ($Pmon < 10) {$Pmon = "0$Pmon";}
|
||||
if ($Pmday < 10) {$Pmday = "0$Pmday";}
|
||||
if ($Phour < 10) {$Phour = "0$Phour";}
|
||||
if ($Pmin < 10) {$Pmin = "0$Pmin";}
|
||||
if ($Psec < 10) {$Psec = "0$Psec";}
|
||||
$PDtsSQLdate = "$Pyear$Pmon$Pmday$Phour$Pmin$Psec";
|
||||
|
||||
$XDtarget = ($secX - 120);
|
||||
($Xsec,$Xmin,$Xhour,$Xmday,$Xmon,$Xyear,$Xwday,$Xyday,$Xisdst) = localtime($XDtarget);
|
||||
$Xyear = ($Xyear + 1900);
|
||||
$Xmon++;
|
||||
if ($Xmon < 10) {$Xmon = "0$Xmon";}
|
||||
if ($Xmday < 10) {$Xmday = "0$Xmday";}
|
||||
if ($Xhour < 10) {$Xhour = "0$Xhour";}
|
||||
if ($Xmin < 10) {$Xmin = "0$Xmin";}
|
||||
if ($Xsec < 10) {$Xsec = "0$Xsec";}
|
||||
$XDSQLdate = "$Xyear-$Xmon-$Xmday $Xhour:$Xmin:$Xsec";
|
||||
|
||||
$TDtarget = ($secX - 600);
|
||||
($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TDtarget);
|
||||
$Tyear = ($Tyear + 1900);
|
||||
$Tmon++;
|
||||
if ($Tmon < 10) {$Tmon = "0$Tmon";}
|
||||
if ($Tmday < 10) {$Tmday = "0$Tmday";}
|
||||
if ($Thour < 10) {$Thour = "0$Thour";}
|
||||
if ($Tmin < 10) {$Tmin = "0$Tmin";}
|
||||
if ($Tsec < 10) {$Tsec = "0$Tsec";}
|
||||
$TDSQLdate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub event_logger
|
||||
{
|
||||
|
||||
if ($DB) {print "$now_date|$event_string|\n";}
|
||||
### open the log file for writing ###
|
||||
open(Lout, ">>/home/cron/remote.$filedate")
|
||||
|| die "Can't open /home/cron/remote.$filedate: $!\n";
|
||||
|
||||
print Lout "$now_date|$event_string|\n";
|
||||
|
||||
close(Lout);
|
||||
|
||||
$event_string='';
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# AST_agent_week.pl
|
||||
#
|
||||
# This script is designed to gather stats for all agent activity over the course
|
||||
# of a week(Sunday to Saturday) and print it in an ASCI text file to be placed
|
||||
# on a web server for viewing.
|
||||
#
|
||||
# CHANGES
|
||||
# 60517-1100 - First version
|
||||
#
|
||||
|
||||
$txt = '.txt';
|
||||
$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 [-q] = quiet\n [-t] = test\n\n";
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /--debug/i)
|
||||
{
|
||||
$DB=1;
|
||||
print "\n-----DEBUG MODE-----\n\n";
|
||||
}
|
||||
if ($args =~ /-q/i)
|
||||
{
|
||||
$q=1; $Q=1;
|
||||
}
|
||||
if ($args =~ /-t/i)
|
||||
{
|
||||
$T=1; $TEST=1;
|
||||
print "\n-----TESTING-----\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
|
||||
$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) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
if ($sec < 10) {$sec = "0$sec";}
|
||||
$filedate = "$year$mon$mday-$hour$min$sec";
|
||||
$ABIfiledate = "$mon-$mday-$year$us$hour$min$sec";
|
||||
$shipdate = "$year-$mon-$mday";
|
||||
$datestamp = "$year/$mon/$mday $hour:$min";
|
||||
|
||||
$STARTtarget = ($secX - (86400 * $wday));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($STARTtarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$START_week = (($Syday/7)+1); $START_week = sprintf("%2d", $START_week);
|
||||
$STARTtarget_date = "$Syear-$Smon-$Smday";
|
||||
|
||||
$ENDtarget = ($STARTtarget + (86400 * 6));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($ENDtarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$ENDtarget_date = "$Syear-$Smon-$Smday";
|
||||
|
||||
$PAST_STARTtarget = ($STARTtarget - (86400 * 7));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_STARTtarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_START_week = (($Syday/7)+1); $PAST_START_week = sprintf("%2d", $PAST_START_week);
|
||||
$PAST_STARTtarget_date = "$Syear-$Smon-$Smday";
|
||||
|
||||
$PAST_ENDtarget = ($ENDtarget - (86400 * 7));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_ENDtarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_ENDtarget_date = "$Syear-$Smon-$Smday";
|
||||
|
||||
$PAST_date[0] = $PAST_STARTtarget_date;
|
||||
$PAST_day[0] = 'Sunday ';
|
||||
$PAST_date[6] = $PAST_ENDtarget_date;
|
||||
$PAST_day[6] = 'Saturday ';
|
||||
|
||||
$PAST_Mondaytarget = ($STARTtarget - (86400 * 6));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_Mondaytarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_date[1] = "$Syear-$Smon-$Smday";
|
||||
$PAST_day[1] = 'Monday ';
|
||||
|
||||
$PAST_Tuesdaytarget = ($STARTtarget - (86400 * 5));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_Tuesdaytarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_date[2] = "$Syear-$Smon-$Smday";
|
||||
$PAST_day[2] = 'Tuesday ';
|
||||
|
||||
$PAST_Wednesdaytarget = ($STARTtarget - (86400 * 4));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_Wednesdaytarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_date[3] = "$Syear-$Smon-$Smday";
|
||||
$PAST_day[3] = 'Wednesday';
|
||||
|
||||
$PAST_Thursdaytarget = ($STARTtarget - (86400 * 3));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_Thursdaytarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_date[4] = "$Syear-$Smon-$Smday";
|
||||
$PAST_day[4] = 'Thursday ';
|
||||
|
||||
$PAST_Fridaytarget = ($STARTtarget - (86400 * 2));
|
||||
($Ssec,$Smin,$Shour,$Smday,$Smon,$Syear,$Swday,$Syday,$Sisdst) = localtime($PAST_Fridaytarget);
|
||||
$Syear = ($Syear + 1900); $Smon++;
|
||||
if ($Smon < 10) {$Smon = "0$Smon";}
|
||||
if ($Smday < 10) {$Smday = "0$Smday";}
|
||||
$PAST_date[5] = "$Syear-$Smon-$Smday";
|
||||
$PAST_day[5] = 'Friday ';
|
||||
|
||||
print "\n\n\n\n\n\n\n\n\n\n\n\n-- AST_agent_week.pl --\n\n";
|
||||
print "This program is designed to print stats to a file for agents' activity for the previous week. \n\n";
|
||||
|
||||
$TLoutfile = '';
|
||||
$TLoutfile .= "TODAY: $shipdate\n";
|
||||
$TLoutfile .= "THIS WEEK: week $START_week $STARTtarget_date - $ENDtarget_date\n";
|
||||
$TLoutfile .= "LAST WEEK: week $PAST_START_week $PAST_STARTtarget_date - $PAST_ENDtarget_date\n\n";
|
||||
|
||||
#$h=0;
|
||||
#foreach(@PAST_date)
|
||||
#{
|
||||
#$TLoutfile .= "$PAST_day[$h] $PAST_date[$h]\n";
|
||||
#$h++;
|
||||
#}
|
||||
|
||||
#print "$TLoutfile";
|
||||
|
||||
|
||||
$outfile = "AGENT_HOURS_$PAST_STARTtarget_date$US$PAST_ENDtarget_date$txt";
|
||||
|
||||
#$dir = '/usr/local/apache2/htdocs';
|
||||
$dir = '/home/www/htdocs';
|
||||
|
||||
### open the X out file for writing ###
|
||||
open(out, ">$dir/vicidial/agent_reports/$outfile")
|
||||
|| die "Can't open $outfile: $!\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 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;
|
||||
|
||||
$dbhB = DBI->connect("DBI:mysql:$DB_database:$DB_server:$DB_port", "$DB_user", "$DB_pass")
|
||||
or die "Couldn't connect to database: " . DBI->errstr;
|
||||
|
||||
#$vicidial_agent_log = 'vicidial_agent_log_archive';
|
||||
$vicidial_agent_log = 'vicidial_agent_log';
|
||||
|
||||
###########################################################################
|
||||
########### PAST WEEK STAT GATHERING LOOP #################################
|
||||
###########################################################################
|
||||
$h=0;
|
||||
foreach(@PAST_date)
|
||||
{
|
||||
print out "\n$PAST_day[$h] $PAST_date[$h]\n\n";
|
||||
print out "AGENT USER CALLS TALK PAUSE WAIT DISPO ACTIVE LOGTIME FIRST LAST \n";
|
||||
print "\n$PAST_day[$h] $PAST_date[$h]\n\n";
|
||||
print "AGENT USER CALLS TALK PAUSE WAIT DISPO ACTIVE LOGTIME FIRST LAST \n";
|
||||
|
||||
$stmtA = "select count(*) as calls, full_name,vicidial_users.user,sum(talk_sec),sum(pause_sec),sum(wait_sec),sum(dispo_sec) from vicidial_users,$vicidial_agent_log where event_time <= '$PAST_date[$h] 23:59:59' and event_time >= '$PAST_date[$h] 00:00:00' and vicidial_users.user=$vicidial_agent_log.user and pause_sec<48800 and wait_sec<48800 and talk_sec<48800 and dispo_sec<48800 group by vicidial_users.user order by full_name limit 10000;";
|
||||
$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)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
|
||||
$calls = sprintf("%7s", $aryA[0]);
|
||||
$name = sprintf("%-20s", $aryA[1]); while(length($name)>20) {chop($name);}
|
||||
$user = sprintf("%-8s", $aryA[2]);
|
||||
|
||||
### TOTAL ACTIVE TIME
|
||||
$active = ($aryA[3] + $aryA[4] + $aryA[5] + $aryA[6]);
|
||||
$TIME_S = $active;
|
||||
$TIME_H = int($TIME_S / 3600);
|
||||
$TIME_S = ($TIME_S - ($TIME_H * 3600));
|
||||
$TIME_M = int($TIME_S / 60);
|
||||
$TIME_S = ($TIME_S - ($TIME_M * 60));
|
||||
if ($TIME_S < 10) {$TIME_S = "0$TIME_S";}
|
||||
if ($TIME_M < 10) {$TIME_M = "0$TIME_M";}
|
||||
$TIME_HMS = "$TIME_H:$TIME_M:$TIME_S";
|
||||
$active = sprintf("%9s", $TIME_HMS);
|
||||
|
||||
### TOTAL TALK TIME
|
||||
$TIME_S = $aryA[3];
|
||||
$TIME_H = int($TIME_S / 3600);
|
||||
$TIME_S = ($TIME_S - ($TIME_H * 3600));
|
||||
$TIME_M = int($TIME_S / 60);
|
||||
$TIME_S = ($TIME_S - ($TIME_M * 60));
|
||||
if ($TIME_S < 10) {$TIME_S = "0$TIME_S";}
|
||||
if ($TIME_M < 10) {$TIME_M = "0$TIME_M";}
|
||||
$TIME_HMS = "$TIME_H:$TIME_M:$TIME_S";
|
||||
$talk = sprintf("%9s", $TIME_HMS);
|
||||
|
||||
### TOTAL PAUSE TIME
|
||||
$TIME_S = $aryA[4];
|
||||
$TIME_H = int($TIME_S / 3600);
|
||||
$TIME_S = ($TIME_S - ($TIME_H * 3600));
|
||||
$TIME_M = int($TIME_S / 60);
|
||||
$TIME_S = ($TIME_S - ($TIME_M * 60));
|
||||
if ($TIME_S < 10) {$TIME_S = "0$TIME_S";}
|
||||
if ($TIME_M < 10) {$TIME_M = "0$TIME_M";}
|
||||
$TIME_HMS = "$TIME_H:$TIME_M:$TIME_S";
|
||||
$pause = sprintf("%9s", $TIME_HMS);
|
||||
|
||||
### TOTAL WAIT TIME
|
||||
$TIME_S = $aryA[5];
|
||||
$TIME_H = int($TIME_S / 3600);
|
||||
$TIME_S = ($TIME_S - ($TIME_H * 3600));
|
||||
$TIME_M = int($TIME_S / 60);
|
||||
$TIME_S = ($TIME_S - ($TIME_M * 60));
|
||||
if ($TIME_S < 10) {$TIME_S = "0$TIME_S";}
|
||||
if ($TIME_M < 10) {$TIME_M = "0$TIME_M";}
|
||||
$TIME_HMS = "$TIME_H:$TIME_M:$TIME_S";
|
||||
$wait = sprintf("%9s", $TIME_HMS);
|
||||
|
||||
### TOTAL DISPO TIME
|
||||
$TIME_S = $aryA[6];
|
||||
$TIME_H = int($TIME_S / 3600);
|
||||
$TIME_S = ($TIME_S - ($TIME_H * 3600));
|
||||
$TIME_M = int($TIME_S / 60);
|
||||
$TIME_S = ($TIME_S - ($TIME_M * 60));
|
||||
if ($TIME_S < 10) {$TIME_S = "0$TIME_S";}
|
||||
if ($TIME_M < 10) {$TIME_M = "0$TIME_M";}
|
||||
$TIME_HMS = "$TIME_H:$TIME_M:$TIME_S";
|
||||
$dispo = sprintf("%9s", $TIME_HMS);
|
||||
|
||||
$stmtB = "select event_time,UNIX_TIMESTAMP(event_time) from $vicidial_agent_log where event_time <= '$PAST_date[$h] 23:59:59' and event_time >= '$PAST_date[$h] 00:00:00' and user='$aryA[2]' order by event_time limit 1;";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtA ", $dbhB->errstr;
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$first_time = sprintf("%21s", $aryB[0]);
|
||||
$first_log = $aryB[1];
|
||||
|
||||
$stmtB = "select event_time,UNIX_TIMESTAMP(event_time) from $vicidial_agent_log where event_time <= '$PAST_date[$h] 23:59:59' and event_time >= '$PAST_date[$h] 00:00:00' and user='$aryA[2]' order by event_time desc limit 1;";
|
||||
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
|
||||
$sthB->execute or die "executing: $stmtA ", $dbhB->errstr;
|
||||
@aryB = $sthB->fetchrow_array;
|
||||
$last_time = sprintf("%21s", $aryB[0]);
|
||||
$last_log = $aryB[1];
|
||||
|
||||
$TIME_S = ($last_log - $first_log);
|
||||
$TIME_H = int($TIME_S / 3600);
|
||||
$TIME_S = ($TIME_S - ($TIME_H * 3600));
|
||||
$TIME_M = int($TIME_S / 60);
|
||||
$TIME_S = ($TIME_S - ($TIME_M * 60));
|
||||
if ($TIME_S < 10) {$TIME_S = "0$TIME_S";}
|
||||
if ($TIME_M < 10) {$TIME_M = "0$TIME_M";}
|
||||
$TIME_HMS = "$TIME_H:$TIME_M:$TIME_S";
|
||||
$login_time = sprintf("%9s", $TIME_HMS);
|
||||
|
||||
|
||||
|
||||
print out "$name$user$calls$talk$pause$wait$dispo$active$login_time$first_time$last_time\n";
|
||||
print "$name$user$calls$talk$pause$wait$dispo$active$login_time$first_time$last_time\n";
|
||||
|
||||
|
||||
$rec_count++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if ($h=='1')
|
||||
# {
|
||||
# exit;
|
||||
# }
|
||||
|
||||
$h++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
close(out);
|
||||
|
||||
### calculate time to run script ###
|
||||
$secY = time();
|
||||
$secZ = ($secY - $secX);
|
||||
$secZm = ($secZ /60);
|
||||
|
||||
print "script execution time in seconds: $secZ minutes: $secZm\n";
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
#!/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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
#!/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;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
#!/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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
#!/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='';
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
#!/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);
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
#!/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='';
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#!/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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
#!/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='';
|
||||
}
|
||||
+1110
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,202 @@
|
||||
#!/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;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,867 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# VICIDIAL_IN_new_leads_file.pl version 0.3
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# script lets you insert leads into the vicidial_list table from a TAB-delimited
|
||||
# lead file that is in the proper format. (for format see --help)
|
||||
#
|
||||
# It is recommended that you run this program on the local Asterisk machine
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
#
|
||||
# CHANGES
|
||||
# 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
|
||||
#
|
||||
|
||||
$secX = time();
|
||||
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||
$year = ($year + 1900);
|
||||
$mon++;
|
||||
if ($hour < 10) {$hour = "0$hour";}
|
||||
if ($min < 10) {$min = "0$min";}
|
||||
if ($sec < 10) {$sec = "0$sec";}
|
||||
if ($mon < 10) {$mon = "0$mon";}
|
||||
if ($mday < 10) {$mday = "0$mday";}
|
||||
$pulldate0 = "$year-$mon-$mday $hour:$min:$sec";
|
||||
$inSD = $pulldate0;
|
||||
$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec );
|
||||
|
||||
|
||||
print "\n\n\n\n\n\n\n\n\n\n\n\n-- VICIDIAL_IN_new_leads_file.pl --\n\n";
|
||||
print "This program is designed to take a tab delimited file and import it into the VICIDIAL system. \n\n";
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($args =~ /--help|-h/i)
|
||||
{
|
||||
print "allowed run time options:\n [-q] = quiet\n [-t] = test\n [-forcegmt] = forces gmt value of column after comments column\n [-debug] = debug output\n [-forcelistid=1234] = overrides the listID given in the file with the 1234\n [-h] = this help screen\n\n";
|
||||
print "This script takes in lead files in the following order when they are placed in the /home/cron/VICIDIAL/LEADS_IN directory to be imported into the vicidial_list table:\n\n";
|
||||
print "vendor_lead_code|source_code|list_id|phone_code|phone_number|title|first_name|middle|last_name|address1|address2|address3|city|state|province|postal_code|country|gender|date_of_birth|alt_phone|email|security_phrase|COMMENTS\n\n";
|
||||
print "3857822|31022|105|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
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 =~ /-q/i)
|
||||
{
|
||||
$q=1;
|
||||
}
|
||||
if ($args =~ /-t/i)
|
||||
{
|
||||
$T=1;
|
||||
$TEST=1;
|
||||
print "\n----- TESTING -----\n\n";
|
||||
}
|
||||
if ($args =~ /-forcegmt/i)
|
||||
{
|
||||
$forcegmt=1;
|
||||
print "\n----- FORCE GMT -----\n\n";
|
||||
}
|
||||
if ($args =~ /--forcelistid=/i)
|
||||
{
|
||||
@data_in = split(/--forcelistid=/,$args);
|
||||
$forcelistid = $data_in[1];
|
||||
print "\n----- FORCE LISTID OVERRIDE: $forcelistid -----\n\n";
|
||||
}
|
||||
else
|
||||
{$forcelistid = '';}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no command line options set\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
|
||||
$suf = '.txt';
|
||||
$people_packages_id_update='';
|
||||
$dir1 = '/home/cron/VICIDIAL/LEADS_IN';
|
||||
$dir2 = '/home/cron/VICIDIAL/LEADS_IN/DONE';
|
||||
|
||||
|
||||
opendir(FILE, "$dir1/");
|
||||
@FILES = readdir(FILE);
|
||||
|
||||
foreach(@FILES)
|
||||
{
|
||||
$size1 = 0;
|
||||
$size2 = 0;
|
||||
$person_id_delete = '';
|
||||
$transaction_id_delete = '';
|
||||
|
||||
if (length($FILES[$i]) > 4)
|
||||
{
|
||||
|
||||
$size1 = (-s "$dir1/$FILES[$i]");
|
||||
if (!$q) {print "$FILES[$i] $size1\n";}
|
||||
sleep(2);
|
||||
$size2 = (-s "$dir1/$FILES[$i]");
|
||||
if (!$q) {print "$FILES[$i] $size2\n\n";}
|
||||
|
||||
|
||||
if ( ($FILES[$i] !~ /^TRANSFERRED/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4))
|
||||
{
|
||||
$GOODfname = $FILES[$i];
|
||||
$FILES[$i] =~ s/ /_/gi;
|
||||
$FILES[$i] =~ s/\(|\)|\||\\|\/|\'|\"|//gi;
|
||||
rename("$dir1/$GOODfname","$dir1/$FILES[$i]");
|
||||
$FILEname = $FILES[$i];
|
||||
|
||||
$Routfile = "ERR_$source$FILES[$i]";
|
||||
$Soutfile = "STS_$source$FILES[$i]";
|
||||
$Toutfile = "SQL_$source$FILES[$i]";
|
||||
$Doutfile = "DEL_$source$FILES[$i]";
|
||||
|
||||
`cp -f $dir1/$FILES[$i] $dir2/$source$FILES[$i]`;
|
||||
|
||||
### open the in file for reading ###
|
||||
open(infile, "$dir2/$source$FILES[$i]")
|
||||
|| die "Can't open $source$FILES[$i]: $!\n";
|
||||
|
||||
### open the error out file for writing ###
|
||||
open(Rout, ">>$dir2/$Routfile")
|
||||
|| die "Can't open $Routfile: $!\n";
|
||||
|
||||
### open the error out file for writing ###
|
||||
open(Tout, ">>$dir2/$Toutfile")
|
||||
|| die "Can't open $Toutfile: $!\n";
|
||||
|
||||
### open the error out file for writing ###
|
||||
open(Dout, ">>$dir2/$Doutfile")
|
||||
|| die "Can't open $Doutfile: $!\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";
|
||||
|
||||
|
||||
### 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;}
|
||||
}
|
||||
}
|
||||
|
||||
$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";}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print "\n\n SQL inserts will be put in $Toutfile\n\n";
|
||||
|
||||
$a=0; ### each line of input file counter ###
|
||||
$b=0; ### status of 'APPROVED' counter ###
|
||||
$c=0; ### status of 'DECLINED' counter ###
|
||||
$d=0; ### status of 'REFERRED' counter ###
|
||||
$e=0; ### status of 'ERROR' counter ###
|
||||
$f=0; ### number of modified packages ###
|
||||
$g=0; ### number of credits ###
|
||||
|
||||
$multi_insert_counter=0;
|
||||
$multistmt='';
|
||||
|
||||
while (<infile>)
|
||||
{
|
||||
|
||||
# print "$a| $number\n";
|
||||
$number = $_;
|
||||
chomp($number);
|
||||
# $number =~ s/,/\|/gi;
|
||||
$number =~ s/\t/\|/gi;
|
||||
$number =~ s/\'|\t|\r|\n|\l//gi;
|
||||
$number =~ s/\'|\t|\r|\n|\l//gi;
|
||||
$number =~ s/\",,,,,,,\"/\|\|\|\|\|\|\|/gi;
|
||||
$number =~ s/\",,,,,,\"/\|\|\|\|\|\|/gi;
|
||||
$number =~ s/\",,,,,\"/\|\|\|\|\|/gi;
|
||||
$number =~ s/\",,,,\"/\|\|\|\|/gi;
|
||||
$number =~ s/\",,,\"/\|\|\|/gi;
|
||||
$number =~ s/\",,\"/\|\|/gi;
|
||||
$number =~ s/\",\"/\|/gi;
|
||||
$number =~ s/\"//gi;
|
||||
@m = split(/\|/, $number);
|
||||
|
||||
# This is the format for the lead files
|
||||
#3857822|31022|105|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS
|
||||
|
||||
|
||||
$vendor_lead_code = $m[0]; chomp($vendor_lead_code);
|
||||
$source_code = $m[1]; chomp($source_code); $source_id = $source_code;
|
||||
$list_id = $m[2]; chomp($list_id);
|
||||
$phone_code = $m[3]; chomp($phone_code); $phone_code =~ s/\D//gi;
|
||||
$phone_number = $m[4]; chomp($phone_number); $phone_number =~ s/\D//gi;
|
||||
$USarea = substr($phone_number, 0, 3);
|
||||
$title = $m[5]; chomp($title);
|
||||
$first_name = $m[6]; chomp($first_name);
|
||||
$middle_initial = $m[7]; chomp($middle_initial);
|
||||
$last_name = $m[8]; chomp($last_name);
|
||||
$address1 = $m[9]; chomp($address1);
|
||||
$address2 = $m[10]; chomp($address2);
|
||||
$address3 = $m[11]; chomp($address3);
|
||||
$city = $m[12]; chomp($city);
|
||||
$state = $m[13]; chomp($state);
|
||||
$province = $m[14]; chomp($province);
|
||||
$postal_code = $m[15]; chomp($postal_code);
|
||||
$country = $m[16]; chomp($country);
|
||||
$gender = $m[17];
|
||||
$date_of_birth = $m[18];
|
||||
$alt_phone = $m[19];
|
||||
$email = $m[20];
|
||||
$security_phrase = $m[21];
|
||||
$comments = $m[22];
|
||||
|
||||
|
||||
if (length($phone_number)>8)
|
||||
{
|
||||
# set default values
|
||||
$entry_date = "$pulldate0";
|
||||
$modify_date = "";
|
||||
$status = "NEW";
|
||||
$user = "";
|
||||
$called_since_last_reset='N';
|
||||
$gmt_offset = '0';
|
||||
|
||||
if (length($forcelistid) > 0)
|
||||
{
|
||||
$list_id = $forcelistid; # set list_id to override value
|
||||
}
|
||||
if ($forcegmt > 0)
|
||||
{
|
||||
$gmt_offset = $m[23]; # set GMT offset value to 24th field value
|
||||
}
|
||||
else
|
||||
{
|
||||
$PC_processed=0;
|
||||
### UNITED STATES ###
|
||||
if ($phone_code =~ /^1$/)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
### 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)
|
||||
{
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
### 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)
|
||||
{
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
### 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)
|
||||
{
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Find out if DST to raise the gmt offset ###
|
||||
$AC_GMT_diff = ($gmt_offset - $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) && ($dst_range =~ /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) {$gmt_offset++;}
|
||||
$AC_processed++;
|
||||
}
|
||||
if ( (!$AC_processed) && ($dst_range =~ /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) {$gmt_offset++;}
|
||||
$AC_processed++;
|
||||
}
|
||||
if ( (!$AC_processed) && ($dst_range =~ /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) {$gmt_offset++;}
|
||||
$AC_processed++;
|
||||
}
|
||||
if ( (!$AC_processed) && ($dst_range =~ /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) {$gmt_offset++;}
|
||||
$AC_processed++;
|
||||
}
|
||||
if ( (!$AC_processed) && ($dst_range =~ /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) {$gmt_offset++;}
|
||||
$AC_processed++;
|
||||
}
|
||||
if (!$AC_processed)
|
||||
{
|
||||
if ($DBX) {print " No DST Method Found\n";}
|
||||
if ($DBX) {print " DST: 0\n";}
|
||||
$AC_processed++;
|
||||
}
|
||||
|
||||
}
|
||||
if ($multi_insert_counter > 8)
|
||||
{
|
||||
### 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";
|
||||
|
||||
$multistmt='';
|
||||
$multi_insert_counter=0;
|
||||
$c++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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'),";
|
||||
$multi_insert_counter++;
|
||||
}
|
||||
|
||||
$b++;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "BAD Home_Phone: $phone|$vendor_id";
|
||||
$e++;
|
||||
}
|
||||
|
||||
$a++;
|
||||
|
||||
if ($a =~ /100$/i) {print STDERR "0 $a\r";}
|
||||
if ($a =~ /200$/i) {print STDERR "+ $a\r";}
|
||||
if ($a =~ /300$/i) {print STDERR "| $a\r";}
|
||||
if ($a =~ /400$/i) {print STDERR "\\ $a\r";}
|
||||
if ($a =~ /500$/i) {print STDERR "- $a\r";}
|
||||
if ($a =~ /600$/i) {print STDERR "/ $a\r";}
|
||||
if ($a =~ /700$/i) {print STDERR "| $a\r";}
|
||||
if ($a =~ /800$/i) {print STDERR "+ $a\r";}
|
||||
if ($a =~ /900$/i) {print STDERR "0 $a\r";}
|
||||
if ($a =~ /000$/i) {print "$a|$b|$c|$d|$e|$phone_number|\n";}
|
||||
|
||||
}
|
||||
|
||||
if (length($multistmt) > 10)
|
||||
{
|
||||
chop($multistmt);
|
||||
### 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";
|
||||
|
||||
$multistmt='';
|
||||
$multi_insert_counter=0;
|
||||
$c++;
|
||||
}
|
||||
|
||||
### open the stats out file for writing ###
|
||||
open(Sout, ">>/$dir2/$Soutfile")
|
||||
|| die "Can't open $Soutfile: $!\n";
|
||||
|
||||
|
||||
### close file handler and DB connections ###
|
||||
print "\n\nTOTALS FOR $FILEname:\n";
|
||||
print "Transactions sent:$a\n";
|
||||
print "INSERTED: $b\n";
|
||||
print "INSERT STATEMENTS:$c\n";
|
||||
print "ERROR: $e\n";
|
||||
# print "Modified PAID NS: $f\n";
|
||||
# print "Credits: $g\n\n";
|
||||
|
||||
print Sout "\nTOTALS FOR $FILEname:\n";
|
||||
print Sout "Transactions sent:$a\n";
|
||||
print Sout "INSERTED: $b\n";
|
||||
print Sout "INSERT STATEMENTS:$c\n";
|
||||
print Sout "ERROR: $e\n";
|
||||
# print Sout "Modified PAID NS: $f\n";
|
||||
# print Sout "Credits: $g\n\n";
|
||||
|
||||
close(infile);
|
||||
close(Rout);
|
||||
chmod 0777, "$dir2/$Routfile";
|
||||
close(Sout);
|
||||
chmod 0777, "$dir2/$Soutfile";
|
||||
close(Tout);
|
||||
chmod 0777, "$dir2/$Toutfile";
|
||||
close(Dout);
|
||||
chmod 0777, "$dir2/$Doutfile";
|
||||
|
||||
if (!$T) {`mv -f $dir1/$FILEname $dir2/$FILEname`;}
|
||||
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
### calculate time to run script ###
|
||||
$secY = time();
|
||||
$secZ = ($secY - $secX);
|
||||
$secZm = ($secZ /60);
|
||||
|
||||
print "script execution time in seconds: $secZ minutes: $secZm\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
|
||||
@@ -0,0 +1,510 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# install_server_files.pl
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
|
||||
############################################
|
||||
# install_server_files.pl - puts server files in the right places
|
||||
#
|
||||
# modify the variables below to customize for your system.
|
||||
#
|
||||
# path to home directory: (assumes it already exists)
|
||||
$home = '/home/cron';
|
||||
|
||||
# path to agi-bin directory: (assumes it already exists)
|
||||
$agibin = '/var/lib/asterisk/agi-bin';
|
||||
|
||||
# path to web root directory: (assumes it already exists)
|
||||
#$webroot = '/var/www/html';
|
||||
#$webroot = '/home/www/htdocs';
|
||||
$webroot = '/usr/local/apache2/htdocs';
|
||||
|
||||
# path to asterisk sounds directory: (assumes it already exists)
|
||||
$sounds = '/var/lib/asterisk/sounds';
|
||||
|
||||
# path to asterisk recordings directory: (assumes it already exists)
|
||||
$monitor = '/var/spool/asterisk';
|
||||
|
||||
############################################
|
||||
|
||||
$secX = time();
|
||||
|
||||
# constants
|
||||
$DB=1; # Debug flag, set to 0 for no debug messages, lots of output
|
||||
$US='_';
|
||||
$MT[0]='';
|
||||
$language_admin_file = 'language_admin.txt';
|
||||
$language_file = 'language.txt';
|
||||
|
||||
### 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[--admin-only] = only translate admin pages\n[--client-only] = only translate client pages\n[--without-en] = only translate non-english\n[--language=] = which language to build, 2 letter code, defaults to es-spanish\n\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /-debug/i)
|
||||
{
|
||||
$DB=1; # Debug flag
|
||||
}
|
||||
if ($args =~ /--language/i)
|
||||
{
|
||||
$LANG=1;
|
||||
print "\n----- LANGUAGE WEB SCRIPT ONLY BUILD -----\n\n";
|
||||
}
|
||||
if ($args =~ /--language=/i)
|
||||
{
|
||||
@data_in = split(/--language=/,$args);
|
||||
$CLIlanguage = $data_in[1];
|
||||
}
|
||||
else
|
||||
{$CLIlanguage = 'es';} # default to build all languages
|
||||
if ($args =~ /-admin-only/i)
|
||||
{
|
||||
$admin_only=1; # Admin flag
|
||||
print "\n----- ADMIN PAGES ONLY BUILD -----\n\n";
|
||||
}
|
||||
if ($args =~ /-client-only/i)
|
||||
{
|
||||
$client_only=1; # Client flag
|
||||
print "\n----- CLIENT PAGES ONLY BUILD -----\n\n";
|
||||
}
|
||||
if ($args =~ /-without-en/i)
|
||||
{
|
||||
print "\n----- NON-ENGLISH ONLY BUILD -----\n\n";
|
||||
$without_en=1;
|
||||
}
|
||||
if ($args =~ /-t/i)
|
||||
{
|
||||
$TEST=1;
|
||||
$T=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# print "no command line options set\n";
|
||||
}
|
||||
### end parsing run-time options ###
|
||||
|
||||
|
||||
if ($LANG)
|
||||
{
|
||||
if ( (!$admin_only) && (!$client_only) )
|
||||
{$admin_only=1; $client_only=1;}
|
||||
|
||||
if ($admin_only==1)
|
||||
{
|
||||
print "\n----- LANGUAGE BUILD: $CLIlanguage -----\n\n";
|
||||
$LANG_FILE_ADMIN = "./translations/$CLIlanguage$US$language_admin_file";
|
||||
open(lang, "$LANG_FILE_ADMIN") || die "can't open $LANG_FILE_ADMIN: $!\n";
|
||||
@lang = <lang>;
|
||||
close(lang);
|
||||
&translate_pages;
|
||||
}
|
||||
|
||||
@lang=@MT;
|
||||
@LANGUAGES=@MT;
|
||||
@FILES=@MT;
|
||||
@TRANSLATIONS=@MT;
|
||||
@TRANSLATIONS_RAW=@MT;
|
||||
|
||||
if ($client_only==1)
|
||||
{
|
||||
$LANG_FILE = "./translations/$CLIlanguage$US$language_file";
|
||||
open(lang, "$LANG_FILE") || die "can't open $LANG_FILE: $!\n";
|
||||
@lang = <lang>;
|
||||
close(lang);
|
||||
&translate_pages;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
print "INSTALLING SERVER SIDE COMPONENTS...\n";
|
||||
|
||||
print "Creating cron/LOGS directory...\n";
|
||||
`mkdir $home/LOGS/`;
|
||||
|
||||
print "setting LOGS directory to executable...\n";
|
||||
`chmod 0766 $home/LOGS`;
|
||||
|
||||
print "Creating $home/VICIDIAL/LEADS_IN/DONE directory...\n";
|
||||
`mkdir $home/VICIDIAL`;
|
||||
`mkdir $home/VICIDIAL/LEADS_IN`;
|
||||
`mkdir $home/VICIDIAL/LEADS_IN/DONE`;
|
||||
`chmod -R 0766 $home/VICIDIAL`;
|
||||
|
||||
print "Creating $monitor directories...\n";
|
||||
`mkdir $monitor/monitor`;
|
||||
`mkdir $monitor/monitor/ORIG`;
|
||||
`mkdir $monitor/monitor/DONE`;
|
||||
`chmod -R 0766 $monitor/monitor`;
|
||||
|
||||
print "Copying cron scripts...\n";
|
||||
`cp -f ./ADMIN_adjust_GMTnow_on_leads.pl $home/`;
|
||||
`cp -f ./ADMIN_area_code_populate.pl $home/`;
|
||||
`cp -f ./ADMIN_keepalive_AST_send_listen.pl $home/`;
|
||||
`cp -f ./ADMIN_keepalive_send_listen.at $home/`;
|
||||
`cp -f ./ADMIN_keepalive_AST_update.pl $home/`;
|
||||
`cp -f ./ADMIN_keepalive_AST_VDautodial.pl $home/`;
|
||||
`cp -f ./ADMIN_keepalive_AST_VDremote_agents.pl $home/`;
|
||||
`cp -f ./ADMIN_restart_roll_logs.pl $home/`;
|
||||
`cp -f ./AST_agent_week.pl $home/`;
|
||||
`cp -f ./AST_cleanup_agent_log.pl $home/`;
|
||||
`cp -f ./AST_conf_update.pl $home/`;
|
||||
`cp -f ./AST_CRON_mix_recordings.pl $home/`;
|
||||
`cp -f ./AST_CRON_mix_recordings_BASIC.pl $home/`;
|
||||
`cp -f ./AST_CRON_mix_recordings_GSM.pl $home/`;
|
||||
`cp -f ./AST_DB_optimize.pl $home/`;
|
||||
`cp -f ./AST_flush_DBqueue.pl $home/`;
|
||||
`cp -f ./AST_manager_kill_hung_congested.pl $home/`;
|
||||
`cp -f ./AST_manager_listen.pl $home/`;
|
||||
`cp -f ./AST_manager_send.pl $home/`;
|
||||
`cp -f ./AST_reset_mysql_vars.pl $home/`;
|
||||
`cp -f ./AST_send_action_child.pl $home/`;
|
||||
`cp -f ./AST_SERVER_conf.pl $home/`;
|
||||
`cp -f ./AST_update.pl $home/`;
|
||||
`cp -f ./AST_VDauto_dial.pl $home/`;
|
||||
`cp -f ./AST_VDhopper.pl $home/`;
|
||||
`cp -f ./AST_VDremote_agents.pl $home/`;
|
||||
`cp -f ./AST_vm_update.pl $home/`;
|
||||
`cp -f ./phone_codes_GMT.txt $home/`;
|
||||
`cp -f ./start_asterisk_boot.pl $home/`;
|
||||
`cp -f ./VICIDIAL_IN_new_leads_file.pl $home/`;
|
||||
`cp -f ./test_VICIDIAL_lead_file.txt $home/VICIDIAL/LEADS_IN/`;
|
||||
|
||||
|
||||
print "setting cron scripts to executable...\n";
|
||||
`chmod 0755 $home/*`;
|
||||
|
||||
print "Copying agi-bin scripts...\n";
|
||||
`cp -f ./agi-dtmf.agi $agibin/`;
|
||||
`cp -f ./agi-record_prompts.agi $agibin/`;
|
||||
`cp -f ./agi-VDAD_LB_closer.agi $agibin/`;
|
||||
`cp -f ./agi-VDAD_LB_closer_inbound.agi $agibin/`;
|
||||
`cp -f ./agi-VDAD_LB_transfer.agi $agibin/`;
|
||||
`cp -f ./agi-VDAD_LO_closer.agi $agibin/`;
|
||||
`cp -f ./agi-VDAD_LO_closer_inbound.agi $agibin/`;
|
||||
`cp -f ./agi-VDAD_LO_transfer.agi $agibin/`;
|
||||
`cp -f ./agi-VDADautoREMINDER.agi $agibin/`;
|
||||
`cp -f ./agi-VDADautoREMINDERxfer.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_inbound.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_inbound_5ID.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_inbound_NOCID.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_inboundANI.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_inboundCID.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_inboundCIDlookup.agi $agibin/`;
|
||||
`cp -f ./agi-VDADcloser_PHONE.agi $agibin/`;
|
||||
`cp -f ./agi-VDADtransfer.agi $agibin/`;
|
||||
`cp -f ./agi-VDADtransferSURVEY.agi $agibin/`;
|
||||
`cp -f ./call_inbound.agi $agibin/`;
|
||||
`cp -f ./call_log.agi $agibin/`;
|
||||
`cp -f ./call_logCID.agi $agibin/`;
|
||||
`cp -f ./call_park.agi $agibin/`;
|
||||
`cp -f ./call_park_EXT.agi $agibin/`;
|
||||
`cp -f ./call_park_I.agi $agibin/`;
|
||||
`cp -f ./call_park_L.agi $agibin/`;
|
||||
`cp -f ./call_park_W.agi $agibin/`;
|
||||
`cp -f ./debug_speak.agi $agibin/`;
|
||||
`cp -f ./invalid_speak.agi $agibin/`;
|
||||
`cp -f ./park_CID.agi $agibin/`;
|
||||
`cp -f ./VD_amd.agi $agibin/`;
|
||||
`cp -f ./VD_amd_post.agi $agibin/`;
|
||||
`cp -f ./VD_hangup.agi $agibin/`;
|
||||
|
||||
|
||||
print "setting agi-bin scripts to executable...\n";
|
||||
`chmod 0755 $agibin/*`;
|
||||
|
||||
print "Copying sounds...\n";
|
||||
`cp -f ./DTMF_sounds/* $sounds/`;
|
||||
|
||||
print "Creating vicidial web directory...\n";
|
||||
`mkdir $webroot/vicidial/`;
|
||||
`mkdir $webroot/vicidial/ploticus/`;
|
||||
`mkdir $webroot/vicidial/agent_reports/`;
|
||||
|
||||
print "Copying VICIDIALweb php files...\n";
|
||||
`cp -f ./VICIDIAL_web/* $webroot/vicidial/`;
|
||||
|
||||
print "setting VICIDIALweb scripts to executable...\n";
|
||||
`chmod -R 0755 $webroot/vicidial/`;
|
||||
`chmod 0777 $webroot/vicidial/`;
|
||||
`chmod 0777 $webroot/vicidial/ploticus/`;
|
||||
`chmod 0777 $webroot/vicidial/agent_reports/`;
|
||||
|
||||
print "Creating agc web directory...\n";
|
||||
`mkdir $webroot/agc/`;
|
||||
|
||||
print "Copying agc php files...\n";
|
||||
`cp -R -f ./agc/* $webroot/agc/`;
|
||||
|
||||
print "setting agc scripts to executable...\n";
|
||||
`chmod -R 0755 $webroot/agc/`;
|
||||
`chmod 0777 $webroot/agc/`;
|
||||
|
||||
print "Creating astguiclient web directory...\n";
|
||||
`mkdir $webroot/astguiclient/`;
|
||||
|
||||
print "Copying astguiclient web php files...\n";
|
||||
`cp -f ./astguiclient_web/* $webroot/astguiclient/`;
|
||||
|
||||
print "setting astguiclient web scripts to executable...\n";
|
||||
`chmod -R 0755 $webroot/astguiclient/`;
|
||||
`chmod 0777 $webroot/astguiclient/`;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$secy = time(); $secz = ($secy - $secX); $minz = ($secz/60); # calculate script runtime so far
|
||||
print "\n - process runtime ($secz sec) ($minz minutes)\n";
|
||||
print "\n\nDONE and EXITING\n";
|
||||
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
sub translate_pages
|
||||
{
|
||||
#***LANGUAGES***
|
||||
#en-English|es-Espaol|
|
||||
#***FILES***
|
||||
#agc/astguiclient.php
|
||||
#agc/vicidial.php
|
||||
#***TRANSLATIONS***
|
||||
#English|Ingls|
|
||||
#Spanish|Espaol|
|
||||
|
||||
##### PARSE THE LANGUAGES SETTING FILE #####
|
||||
$section='';
|
||||
$i=0;
|
||||
$Lct=0; $Fct=0; $Tct=0;
|
||||
foreach(@lang)
|
||||
{
|
||||
if ($lang[$i] !~ /^\#/)
|
||||
{
|
||||
if ($lang[$i] =~ /^\*\*\*/)
|
||||
{
|
||||
$section = $lang[$i];
|
||||
$section =~ s/\*|\n|\r//gi;
|
||||
# print "section heading: $section: $lang[$i]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($section =~ /LANGUAGES/)
|
||||
{
|
||||
$LANGUAGES = $lang[$i];
|
||||
$Lct++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($section =~ /FILES/)
|
||||
{
|
||||
# print "section: $section line: $lang[$i]";
|
||||
$FILES[$Fct] = $lang[$i];
|
||||
$Fct++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($section =~ /TRANSLATIONS/)
|
||||
{
|
||||
# print "section: $section line: $lang[$i]";
|
||||
@TRANSlineX = split(/\|/, $lang[$i]);
|
||||
$ORIGtextX = "$TRANSlineX[0]";
|
||||
$lengthX = length($ORIGtextX);
|
||||
$lengthX = sprintf("%04d",$lengthX);
|
||||
$TRANSLATIONS_RAW[$Tct] = "$lengthX|$lang[$i]";
|
||||
$Tct++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($DB)
|
||||
{
|
||||
print "LANGUAGE FILE PARSE RESULTS: $#lang lines in file\n";
|
||||
print "LANGUAGES: $LANGUAGES\n";
|
||||
print "FILES: $Fct\n";
|
||||
print "TRANSLATIONS: $Tct\n";
|
||||
}
|
||||
|
||||
#@TRANSLATIONS = sort { length($b) <=> length($a) } @TRANSLATIONS_RAW;
|
||||
@TRANSLATIONS = sort { $b <=> $a } @TRANSLATIONS_RAW;
|
||||
|
||||
#$k=0;
|
||||
#foreach(@TRANSLATIONS)
|
||||
# {
|
||||
# $length = length($TRANSLATIONS[$k]);
|
||||
# print "$TRANSLATIONS[$k]|$length|\n";
|
||||
# $k++;
|
||||
# }
|
||||
|
||||
##### LOOP THROUGH THE LANGUAGES
|
||||
@lang_list = split(/\|/, $LANGUAGES);
|
||||
@lang_link_list = @lang_list;
|
||||
$i=0;
|
||||
$gif = '.gif';
|
||||
foreach(@lang_list)
|
||||
{
|
||||
if (length($lang_list[$i]) > 2)
|
||||
{
|
||||
@lang_detail = split(/-/, $lang_list[$i]);
|
||||
$lang_abb = $lang_detail[0];
|
||||
$lang_name = $lang_detail[1];
|
||||
|
||||
if ( ($without_en==1) && ($lang_abb =~ /en/) )
|
||||
{
|
||||
print "SKIPPING ENGLISH COPYING: $lang_abb|$i\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
##### LOOP THROUGH THE FILES
|
||||
$Fct=0;
|
||||
foreach(@FILES)
|
||||
{
|
||||
$a=0;
|
||||
@file_detail = split(/\|/, $FILES[$Fct]);
|
||||
$file_path = $file_detail[0];
|
||||
$file_name = $file_detail[1];
|
||||
$file_name =~ s/\t|\r|\n//gi;
|
||||
$file_passthru = $file_detail[2];
|
||||
$file_passthru =~ s/\t|\r|\n//gi;
|
||||
if (-e "$webroot/$file_path/$file_name")
|
||||
{
|
||||
open(file, "$webroot/$file_path/$file_name") || die "can't open $webroot/$file_path/$file_name: $!\n";
|
||||
@file = @MT;
|
||||
@file = <file>;
|
||||
close(file);
|
||||
|
||||
print "File exists: ./$file_path/$file_name\n";
|
||||
if (-e "$webroot/$file_path$US$lang_abb")
|
||||
{
|
||||
print "Lang Directory exists: $webroot/$file_path$US$lang_abb\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
`mkdir $webroot/$file_path$US$lang_abb`;
|
||||
`chmod 0777 $webroot/$file_path$US$lang_abb`;
|
||||
print "Lang Directory created: $webroot/$file_path$US$lang_abb\n";
|
||||
}
|
||||
|
||||
if ($file_passthru < 1)
|
||||
{
|
||||
##### LOOP THROUGH THE TRANSLATIONS
|
||||
$Tct=0;
|
||||
foreach(@TRANSLATIONS)
|
||||
{
|
||||
@TRANSline = split(/\|/, $TRANSLATIONS[$Tct]);
|
||||
$ORIGtext = "$TRANSline[1]";
|
||||
$TRANStext = "$TRANSline[$i+1]";
|
||||
$LINESct=0;
|
||||
foreach(@file)
|
||||
{
|
||||
if ($file[$LINESct] !~ /^\#|^\s*function |'INCALL'|'PAUSED'|'READY'|'NEW'|xmlhttp|ILPV |ILPA |SELECT cmd_line_f|=\"SELECT/)
|
||||
{
|
||||
if ($file[$LINESct] =~ /INTERNATIONALIZATION-LINKS-PLACEHOLDER-VICIDIAL/)
|
||||
{
|
||||
$file[$LINESct] =~ s/INTERNATIONALIZATION-LINKS-PLACEHOLDER-VICIDIAL/ILPV/g;
|
||||
$e=0;
|
||||
$gif = '.gif';
|
||||
foreach(@lang_link_list)
|
||||
{
|
||||
if (length($lang_link_list[$e]) > 2)
|
||||
{
|
||||
@lang_list_detail = split(/-/, $lang_link_list[$e]);
|
||||
$lang_list_abb = $lang_list_detail[0];
|
||||
$lang_list_name = $lang_list_detail[1];
|
||||
if ($lang_list_abb =~ /$lang_abb/) {$list_bgcolor = ' BGCOLOR=\"#CCFFCC\"';}
|
||||
else {$list_bgcolor = '';}
|
||||
$file[$LINESct] .= "echo \"<TD WIDTH=100 ALIGN=RIGHT VALIGN=TOP $list_bgcolor NOWRAP><a href=\\\"../$file_path$US$lang_list_abb/$file_name?relogin=YES&VD_login=\$VD_login&VD_campaign=\$VD_campaign&phone_login=\$phone_login&phone_pass=\$phone_pass&VD_pass=\$VD_pass\\\">$lang_list_name <img src=\\\"../agc/images/$lang_list_abb$gif\\\" BORDER=0 HEIGHT=14 WIDTH=20></a></TD>\\n\";";
|
||||
}
|
||||
$e++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($file[$LINESct] =~ /INTERNATIONALIZATION-LINKS-PLACEHOLDER-AGC/)
|
||||
{
|
||||
$file[$LINESct] =~ s/INTERNATIONALIZATION-LINKS-PLACEHOLDER-AGC/ILPA/g;
|
||||
$e=0;
|
||||
$gif = '.gif';
|
||||
foreach(@lang_link_list)
|
||||
{
|
||||
if (length($lang_link_list[$e]) > 2)
|
||||
{
|
||||
@lang_list_detail = split(/-/, $lang_link_list[$e]);
|
||||
$lang_list_abb = $lang_list_detail[0];
|
||||
$lang_list_name = $lang_list_detail[1];
|
||||
if ($lang_list_abb =~ /$lang_abb/) {$list_bgcolor = ' BGCOLOR=\"#CCFFCC\"';}
|
||||
else {$list_bgcolor = '';}
|
||||
$file[$LINESct] .= "echo \"<TD WIDTH=100 ALIGN=RIGHT VALIGN=TOP $list_bgcolor NOWRAP><a href=\\\"../$file_path$US$lang_list_abb/$file_name?relogin=YES&user=\$user&pass=\$pass&phone_login=\$phone_login&phone_pass=\$phone_pass\\\">$lang_list_name <img src=\\\"../agc/images/$lang_list_abb$gif\\\" BORDER=0 HEIGHT=14 WIDTH=20></a></TD>\\n\";";
|
||||
}
|
||||
$e++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ($lang_abb =~ /^en/) && ($Tct > 2) )
|
||||
{
|
||||
$file[$LINESct] =~ s/\.\/images\//\.\.\/agc\/images\//g;
|
||||
$file[$LINESct] =~ s/\"help.gif/\"..\/astguiclient\/help.gif/g;
|
||||
}
|
||||
if ($lang_abb !~ /^en/)
|
||||
{$file[$LINESct] =~ s/$ORIGtext/$TRANStext/g;}
|
||||
}
|
||||
}
|
||||
}
|
||||
$LINESct++;
|
||||
|
||||
if ($a =~ /00000$/i) {print "$a $file[$LINESct]\n|$ORIGtext|$TRANStext|";}
|
||||
$a++;
|
||||
}
|
||||
$Tct++;
|
||||
}
|
||||
}
|
||||
### open the translation result file for writing ###
|
||||
open(out, ">$webroot/$file_path$US$lang_abb/$file_name")
|
||||
|| die "Can't open $webroot/$file_path$US$lang_abb/$file_name: $!\n";
|
||||
# print out "Header(\"Content-type: text/html; charset=utf-8\");\n";
|
||||
$LINESct=0;
|
||||
foreach(@file)
|
||||
{
|
||||
print out "$file[$LINESct]";
|
||||
$LINESct++;
|
||||
}
|
||||
close(out);
|
||||
print "\n";
|
||||
print "File Written: $webroot/$file_path$US$lang_abb/$file_name\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "File does not exist: $webroot/$file_path/$file_name\n";
|
||||
}
|
||||
$Fct++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user