Added new beta script for faster checking of leave-3way conferences, AST_conf_update_3way.pl, read the comments before using

git-svn-id: svn://192.168.202.10@1499 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2010-08-12 02:52:41 +00:00
parent cf051ed768
commit fc2da0cdad
4 changed files with 735 additions and 316 deletions
+3
View File
@@ -279,6 +279,9 @@ OTHER CHANGES:
Calculation and optionally the announcement of Estimated Hold Time
for X seconds.
60. Added new beta script for faster checking of leave-3way conferences,
AST_conf_update_3way.pl, read the comments before using.
+198 -157
View File
@@ -53,11 +53,13 @@
# 100424-2121 - Added codecs options for phones
# 100616-2245 - Added VIDPROMPT options for call menus, changed INGROUP TIMECHECK routes to special extension like AGI
# 100703-2137 - Added memory table reset nightly
# 100811-2221 - Added --cu3way flag for new optional leave3way cleaning script
#
$DB=0; # Debug flag
$MT[0]=''; $MT[1]='';
@psline=@MT;
$cu3way=0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
@@ -84,7 +86,14 @@ if (length($ARGV[0])>1)
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";
print "allowed run time options:\n";
print " [-t] = test\n";
print " [-cu3way] = keepalive for the optional 3way conference checker\n";
print " [-debug] = verbose debug messages\n";
print " [-debugX] = Extra-verbose debug messages\n";
print " [-debugXXX] = Triple-Extra-verbose debug messages\n";
print "\n";
exit;
}
else
{
@@ -92,16 +101,21 @@ if (length($ARGV[0])>1)
{
$DB=1; # Debug flag
}
if ($args =~ /--debugX/i)
if ($args =~ /-debugX/i)
{
$DBX=1;
print "\n----- SUPER-DUPER DEBUGGING -----\n\n";
}
if ($args =~ /--debugXXX/i)
if ($args =~ /-debugXXX/i)
{
$DBXXX=1;
print "\n----- TRIPLE DEBUGGING -----\n\n";
}
if ($args =~ /-cu3way/i)
{
$cu3way=1;
if ($DB > 0) {print "\n----- cu3way ENABLED -----\n\n";}
}
if ($args =~ /-t/i)
{
$TEST=1;
@@ -171,6 +185,8 @@ $runningAST_VDadapt=0;
$runningFastAGI_log=0;
$runningAST_VDauto_dial_FILL=0;
$runningip_relay=0;
$runningAST_conf_3way=0;
$AST_conf_3way=0;
if ($VARactive_keepalives =~ /1/)
{
@@ -217,6 +233,12 @@ if ($VARactive_keepalives =~ /9/)
$timeclock_auto_logout=1;
if ($DB) {print "Check to see if Timeclock auto logout should run\n";}
}
if ($cu3way > 0)
{
$AST_conf_3way=1;
if ($DB) {print "AST_conf_3way set to keepalive\n";}
}
$REGhome = $PATHhome;
$REGhome =~ s/\//\\\//gi;
@@ -237,10 +259,10 @@ $REGhome =~ s/\//\\\//gi;
$i=0;
foreach (@psoutput)
{
chomp($psoutput[$i]);
if ($DBX) {print "$i|$psoutput[$i]| \n";}
@psline = split(/\/usr\/bin\/perl /,$psoutput[$i]);
{
chomp($psoutput[$i]);
if ($DBX) {print "$i|$psoutput[$i]| \n";}
@psline = split(/\/usr\/bin\/perl /,$psoutput[$i]);
if ($psline[1] =~ /$REGhome\/AST_update\.pl/)
{
@@ -289,8 +311,14 @@ if ($DBX) {print "$i|$psoutput[$i]| \n";}
$runningip_relay++;
if ($DB) {print "ip_relay RUNNING: |$psoutput[$i]|\n";}
}
$i++;
}
if ($psline[1] =~ /$REGhome\/AST_conf_update_3way\.pl/)
{
$runningAST_conf_3way++;
if ($DB) {print "AST_conf_3way RUNNING: |$psline[1]|\n";}
}
$i++;
}
@@ -301,44 +329,44 @@ $i++;
@psoutput=@MT;
@listen_pid=@MT;
if ($runningAST_listen > 1)
{
$runningAST_listen=0;
sleep(1);
### you may have to use a different ps command if you're not using Slackware Linux
# @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 pid,args -A`; ### use this one for FreeBSD
@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]);
$psoutput[$i] =~ s/^ *//gi;
$psoutput[$i] =~ s/ .*|\n|\r|\t| //gi;
$runningAST_listen=0;
if ($psline[1] =~ /AST_manager_li/)
sleep(1);
### you may have to use a different ps command if you're not using Slackware Linux
# @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 pid,args -A`; ### use this one for FreeBSD
@psoutput = `/bin/ps -o "%p %a" --no-headers -A`;
$i=0;
foreach (@psoutput)
{
$listen_pid[$runningAST_listen] = $psoutput[$i];
if ($DB) {print "AST_listen RUNNING: |$psline[1]|$listen_pid[$runningAST_listen]|\n";}
$runningAST_listen++;
chomp($psoutput[$i]);
if ($DBX) {print "$i|$psoutput[$i]| \n";}
@psline = split(/\/usr\/bin\/perl /,$psoutput[$i]);
$psoutput[$i] =~ s/^ *//gi;
$psoutput[$i] =~ s/ .*|\n|\r|\t| //gi;
if ($psline[1] =~ /AST_manager_li/)
{
$listen_pid[$runningAST_listen] = $psoutput[$i];
if ($DB) {print "AST_listen RUNNING: |$psline[1]|$listen_pid[$runningAST_listen]|\n";}
$runningAST_listen++;
}
$i++;
}
$i++;
if ($runningAST_listen > 1)
{
if ($DB) {print "Killing AST_manager_listen... |$listen_pid[1]|\n";}
`/bin/kill -s 9 $listen_pid[1]`;
}
}
if ($runningAST_listen > 1)
{
if ($DB) {print "Killing AST_manager_listen... |$listen_pid[1]|\n";}
`/bin/kill -s 9 $listen_pid[1]`;
}
}
@@ -358,131 +386,144 @@ if (
( ($AST_VDadapt > 0) && ($runningAST_VDadapt < 1) ) ||
( ($FastAGI_log > 0) && ($runningFastAGI_log < 1) ) ||
( ($AST_VDauto_dial_FILL > 0) && ($runningAST_VDauto_dial_FILL < 1) ) ||
( ($ip_relay > 0) && ($runningip_relay < 1) )
( ($ip_relay > 0) && ($runningip_relay < 1) ) ||
( ($AST_conf_3way > 0) && ($runningAST_conf_3way < 1) )
)
{
if ($DB) {print "double check that processes are not running...\n";}
sleep(1);
`PERL5LIB="$PATHhome/libs"; export PERL5LIB`;
### you may have to use a different ps command if you're not using Slackware Linux
# @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 pid,args -A`; ### use this one for FreeBSD
@psoutput2 = `/bin/ps -o "%p %a" --no-headers -A`;
$i=0;
foreach (@psoutput2)
{
chomp($psoutput2[$i]);
if ($DBX) {print "$i|$psoutput2[$i]| \n";}
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
if ($psline[1] =~ /$REGhome\/AST_update\.pl/)
if ($DB) {print "double check that processes are not running...\n";}
sleep(1);
`PERL5LIB="$PATHhome/libs"; export PERL5LIB`;
### you may have to use a different ps command if you're not using Slackware Linux
# @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 pid,args -A`; ### use this one for FreeBSD
@psoutput2 = `/bin/ps -o "%p %a" --no-headers -A`;
$i=0;
foreach (@psoutput2)
{
$runningAST_update++;
if ($DB) {print "AST_update RUNNING: |$psline[1]|\n";}
chomp($psoutput2[$i]);
if ($DBX) {print "$i|$psoutput2[$i]| \n";}
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
if ($psline[1] =~ /$REGhome\/AST_update\.pl/)
{
$runningAST_update++;
if ($DB) {print "AST_update RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /AST_manager_se/)
{
$runningAST_send++;
if ($DB) {print "AST_send RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /AST_manager_li/)
{
$runningAST_listen++;
if ($DB) {print "AST_listen RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDauto_dial\.pl/)
{
$runningAST_VDauto_dial++;
if ($DB) {print "AST_VDauto_dial RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDremote_agents\.pl/)
{
$runningAST_VDremote_agents++;
if ($DB) {print "AST_VDremote_agents RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDadapt\.pl/)
{
$runningAST_VDadapt++;
if ($DB) {print "AST_VDadapt RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/FastAGI_log\.pl/)
{
$runningFastAGI_log++;
if ($DB) {print "FastAGI_log RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDauto_dial_FILL\.pl/)
{
$runningAST_VDauto_dial_FILL++;
if ($DB) {print "AST_VDauto_dial_FILL RUNNING: |$psline[1]|\n";}
}
if ($psoutput2[$i] =~ / ip_relay /)
{
$runningip_relay++;
if ($DB) {print "ip_relay RUNNING: |$psoutput2[$i]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_conf_update_3way\.pl/)
{
$runningAST_conf_3way++;
if ($DB) {print "AST_conf_3way RUNNING: |$psline[1]|\n";}
}
$i++;
}
if ($psline[1] =~ /AST_manager_se/)
{
$runningAST_send++;
if ($DB) {print "AST_send RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /AST_manager_li/)
{
$runningAST_listen++;
if ($DB) {print "AST_listen RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDauto_dial\.pl/)
{
$runningAST_VDauto_dial++;
if ($DB) {print "AST_VDauto_dial RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDremote_agents\.pl/)
{
$runningAST_VDremote_agents++;
if ($DB) {print "AST_VDremote_agents RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDadapt\.pl/)
{
$runningAST_VDadapt++;
if ($DB) {print "AST_VDadapt RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/FastAGI_log\.pl/)
{
$runningFastAGI_log++;
if ($DB) {print "FastAGI_log RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/AST_VDauto_dial_FILL\.pl/)
{
$runningAST_VDauto_dial_FILL++;
if ($DB) {print "AST_VDauto_dial_FILL RUNNING: |$psline[1]|\n";}
}
if ($psoutput2[$i] =~ / ip_relay /)
{
$runningip_relay++;
if ($DB) {print "ip_relay RUNNING: |$psoutput2[$i]|\n";}
}
$i++;
}
if ( ($AST_update > 0) && ($runningAST_update < 1) )
{
if ($DB) {print "starting AST_update...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTupdate $PATHhome/AST_update.pl`;
if ( ($AST_update > 0) && ($runningAST_update < 1) )
{
if ($DB) {print "starting AST_update...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTupdate $PATHhome/AST_update.pl`;
}
if ( ($AST_send_listen > 0) && ($runningAST_send < 1) )
{
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 $PATHhome/AST_manager_send.pl`;
}
if ( ($AST_send_listen > 0) && ($runningAST_listen < 1) )
{
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 $PATHhome/AST_manager_listen.pl`;
}
if ( ($AST_VDauto_dial > 0) && ($runningAST_VDauto_dial < 1) )
{
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 $PATHhome/AST_VDauto_dial.pl`;
}
if ( ($AST_VDremote_agents > 0) && ($runningAST_VDremote_agents < 1) )
{
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 $PATHhome/AST_VDremote_agents.pl --debug`;
}
if ( ($AST_VDadapt > 0) && ($runningAST_VDadapt < 1) )
{
if ($DB) {print "starting AST_VDadapt...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTVDadapt $PATHhome/AST_VDadapt.pl --debug`;
}
if ( ($FastAGI_log > 0) && ($runningFastAGI_log < 1) )
{
if ($DB) {print "starting FastAGI_log...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTfastlog $PATHhome/FastAGI_log.pl --debug`;
}
if ( ($AST_VDauto_dial_FILL > 0) && ($runningAST_VDauto_dial_FILL < 1) )
{
if ($DB) {print "starting AST_VDauto_dial_FILL...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTVDautoFILL $PATHhome/AST_VDauto_dial_FILL.pl`;
}
if ( ($ip_relay > 0) && ($runningip_relay < 1) )
{
if ($DB) {print "starting ip_relay through relay_control...\n";}
`$PATHhome/ip_relay/relay_control start 2>/dev/null 1>&2`;
}
if ( ($AST_conf_3way > 0) && ($runningAST_conf_3way < 1) )
{
if ($DB) {print "starting AST_conf_3way...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTconf3way $PATHhome/AST_conf_update_3way.pl --debug`;
}
}
if ( ($AST_send_listen > 0) && ($runningAST_send < 1) )
{
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 $PATHhome/AST_manager_send.pl`;
}
if ( ($AST_send_listen > 0) && ($runningAST_listen < 1) )
{
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 $PATHhome/AST_manager_listen.pl`;
}
if ( ($AST_VDauto_dial > 0) && ($runningAST_VDauto_dial < 1) )
{
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 $PATHhome/AST_VDauto_dial.pl`;
}
if ( ($AST_VDremote_agents > 0) && ($runningAST_VDremote_agents < 1) )
{
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 $PATHhome/AST_VDremote_agents.pl --debug`;
}
if ( ($AST_VDadapt > 0) && ($runningAST_VDadapt < 1) )
{
if ($DB) {print "starting AST_VDadapt...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTVDadapt $PATHhome/AST_VDadapt.pl --debug`;
}
if ( ($FastAGI_log > 0) && ($runningFastAGI_log < 1) )
{
if ($DB) {print "starting FastAGI_log...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTfastlog $PATHhome/FastAGI_log.pl --debug`;
}
if ( ($AST_VDauto_dial_FILL > 0) && ($runningAST_VDauto_dial_FILL < 1) )
{
if ($DB) {print "starting AST_VDauto_dial_FILL...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTVDautoFILL $PATHhome/AST_VDauto_dial_FILL.pl`;
}
if ( ($ip_relay > 0) && ($runningip_relay < 1) )
{
if ($DB) {print "starting ip_relay through relay_control...\n";}
`$PATHhome/ip_relay/relay_control start 2>/dev/null 1>&2`;
}
}
+176 -159
View File
@@ -14,12 +14,14 @@
# 80914-1533 - Added kickall for leave-3way calls after one hour
# 81008-0937 - Added kickall from vicidial_conferences if only one participant
# 100625-1220 - Added waitfors after logout to fix broken pipe errors in asterisk <MikeC>
# 100811-2054 - Added --no-vc-3way-check flag to use when AST_conf_update_3way.pl script is used
#
# constants
$DB=0; # Debug flag, set to 0 for no debug messages per minute
$US='__';
$MT[0]='';
$no_vc_3way_check=0;
### begin parsing run-time options ###
if (length($ARGV[0])>1)
@@ -33,7 +35,12 @@ if (length($ARGV[0])>1)
if ($args =~ /--help/i)
{
print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n\n";
print "allowed run time options:\n";
print " [-t] = test\n";
print " [-debug] = verbose debug messages\n";
print " [--no-vc-3way-check] = separate 3way script is running\n";
print "\n";
exit;
}
else
{
@@ -42,6 +49,11 @@ if (length($ARGV[0])>1)
$DB=1; # Debug flag
print "-- DEBUGGING ENABLED --\n\n";
}
if ($args =~ /-no-vc-3way-check/i)
{
$no_vc_3way_check=1; # no 3way check flag
if ($DB > 0) {print "-- NO VC 3way check flag ENABLED --\n\n";}
}
if ($args =~ /-t/i)
{
$TEST=1;
@@ -115,17 +127,17 @@ $rec_count=0;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$DBtelnet_host = "$aryA[0]";
$DBtelnet_port = "$aryA[1]";
$DBASTmgrUSERNAME = "$aryA[2]";
$DBASTmgrSECRET = "$aryA[3]";
$DBASTmgrUSERNAMEupdate = "$aryA[4]";
$DBASTmgrUSERNAMElisten = "$aryA[5]";
$DBASTmgrUSERNAMEsend = "$aryA[6]";
$DBmax_vicidial_trunks = "$aryA[7]";
$DBanswer_transfer_agent= "$aryA[8]";
$DBSERVER_GMT = "$aryA[9]";
$DBext_context = "$aryA[10]";
$DBtelnet_host = $aryA[0];
$DBtelnet_port = $aryA[1];
$DBASTmgrUSERNAME = $aryA[2];
$DBASTmgrSECRET = $aryA[3];
$DBASTmgrUSERNAMEupdate = $aryA[4];
$DBASTmgrUSERNAMElisten = $aryA[5];
$DBASTmgrUSERNAMEsend = $aryA[6];
$DBmax_vicidial_trunks = $aryA[7];
$DBanswer_transfer_agent= $aryA[8];
$DBSERVER_GMT = $aryA[9];
$DBext_context = $aryA[10];
if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;}
if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;}
if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;}
@@ -180,8 +192,8 @@ $rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$PT_conf_extens[$rec_count] = "$aryA[0]";
$PT_extensions[$rec_count] = "$aryA[0]";
$PT_conf_extens[$rec_count] = $aryA[0];
$PT_extensions[$rec_count] = $aryA[1];
if ($DB) {print "|$PT_conf_extens[$rec_count]|$PT_extensions[$rec_count]|\n";}
$rec_count++;
}
@@ -206,119 +218,122 @@ while ($k < $rec_count)
######################################################################
##### CHECK vicidial_conferences TABLE #####
######################################################################
@PTextensions=@MT; @PT_conf_extens=@MT; @PTmessages=@MT; @PTold_messages=@MT; @NEW_messages=@MT; @OLD_messages=@MT;
$stmtA = "SELECT extension,conf_exten from vicidial_conferences where server_ip='$server_ip' and leave_3way='1';";
if ($DB) {print "|$stmtA|\n";}
$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;
$PTextensions[$rec_count] = "$aryA[0]";
$PT_conf_extens[$rec_count] = "$aryA[1]";
if ($DB) {print "|$PT_conf_extens[$rec_count]|$PTextensions[$rec_count]|\n";}
$rec_count++;
}
$sthA->finish();
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('/[01]\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)
if ($no_vc_3way_check < 1)
{
@list_channels=@MT;
$t->buffer_empty;
$COMMAND = "Action: Command\nCommand: Meetme list $PT_conf_extens[$i]\n\nAction: Ping\n\n";
if ($DB) {print "|$PT_conf_extens[$i]|$COMMAND|\n";}
@list_channels = $t->cmd(String => "$COMMAND", Prompt => '/Response: Pong.*/');
$j=0;
$conf_empty[$i]=0;
$conf_users[$i]='';
foreach(@list_channels)
######################################################################
##### CHECK vicidial_conferences TABLE #####
######################################################################
@PTextensions=@MT; @PT_conf_extens=@MT; @PTmessages=@MT; @PTold_messages=@MT; @NEW_messages=@MT; @OLD_messages=@MT;
$stmtA = "SELECT extension,conf_exten from vicidial_conferences where server_ip='$server_ip' and leave_3way='1';";
if ($DB) {print "|$stmtA|\n";}
$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)
{
if($DB){print "|$list_channels[$j]|\n";}
### mark all empty conferences and conferences with only one channel as empty
if ($list_channels[$j] =~ /No active conferences|No such conference/i)
{$conf_empty[$i]++;}
if ($list_channels[$j] =~ /1 users in that conference/i)
{$conf_empty[$i]++;}
$j++;
@aryA = $sthA->fetchrow_array;
$PTextensions[$rec_count] = $aryA[0];
$PT_conf_extens[$rec_count] = $aryA[1];
if ($DB) {print "|$PT_conf_extens[$rec_count]|$PTextensions[$rec_count]|\n";}
$rec_count++;
}
$sthA->finish();
if($DB){print "Meetme list $PT_conf_extens[$i]- Exten:|$PTextensions[$i]| Empty:|$conf_empty[$i]| ";}
if (!$conf_empty[$i])
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('/[01]\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)
{
if($DB){print "CONFERENCE STILL HAS PARTICIPANTS, DOING NOTHING FOR THIS CONFERENCE\n";}
if ($PTextensions[$i] =~ /Xtimeout\d$/i)
@list_channels=@MT;
$t->buffer_empty;
$COMMAND = "Action: Command\nCommand: Meetme list $PT_conf_extens[$i]\n\nAction: Ping\n\n";
if ($DB) {print "|$PT_conf_extens[$i]|$COMMAND|\n";}
@list_channels = $t->cmd(String => "$COMMAND", Prompt => '/Response: Pong.*/');
$j=0;
$conf_empty[$i]=0;
$conf_users[$i]='';
foreach(@list_channels)
{
$PTextensions[$i] =~ s/Xtimeout\d$//gi;
$stmtA = "UPDATE vicidial_conferences set extension='$PTextensions[$i]' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';";
if($DB){print "|$list_channels[$j]|\n";}
### mark all empty conferences and conferences with only one channel as empty
if ($list_channels[$j] =~ /No active conferences|No such conference/i)
{$conf_empty[$i]++;}
if ($list_channels[$j] =~ /1 users in that conference/i)
{$conf_empty[$i]++;}
$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 vicidial_conferences set extension='$PTextensions[$i]' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';";
if($DB){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
}
}
else
{
$NEWexten[$i] = $PTextensions[$i];
$leave_3waySQL='1';
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] = ''; $leave_3waySQL='0';}
if ( ($PTextensions[$i] !~ /Xtimeout\d$/i) and (length($PTextensions[$i])> 0) ) {$NEWexten[$i] .= 'Xtimeout3';}
if ($NEWexten[$i] =~ /Xtimeout1$/i)
{
### Kick all participants if there are any left in the conference so it can be reused
$local_DEF = 'Local/5555';
$local_AMP = '@';
$kick_local_channel = "$local_DEF$PT_conf_extens[$i]$local_AMP$ext_context";
$queryCID = "ULGC36$TDnum";
$stmtA="INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Originate','$queryCID','Channel: $kick_local_channel','Context: $ext_context','Exten: 8300','Priority: 1','Callerid: $queryCID','','','','','');";
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
if($DB){print STDERR "\n|$affected_rows|$stmtA|\n";}
}
$stmtA = "UPDATE vicidial_conferences set extension='$NEWexten[$i]',leave_3way='$leave_3waySQL' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';";
if($DB){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
}
}
else
{
$NEWexten[$i] = $PTextensions[$i];
$leave_3waySQL='1';
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] = ''; $leave_3waySQL='0';}
if ( ($PTextensions[$i] !~ /Xtimeout\d$/i) and (length($PTextensions[$i])> 0) ) {$NEWexten[$i] .= 'Xtimeout3';}
if ($NEWexten[$i] =~ /Xtimeout1$/i)
{
### Kick all participants if there are any left in the conference so it can be reused
$local_DEF = 'Local/5555';
$local_AMP = '@';
$kick_local_channel = "$local_DEF$PT_conf_extens[$i]$local_AMP$ext_context";
$queryCID = "ULGC36$TDnum";
$stmtA="INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Originate','$queryCID','Channel: $kick_local_channel','Context: $ext_context','Exten: 8300','Priority: 1','Callerid: $queryCID','','','','','');";
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
if($DB){print STDERR "\n|$affected_rows|$stmtA|\n";}
}
$stmtA = "UPDATE vicidial_conferences set extension='$NEWexten[$i]',leave_3way='$leave_3waySQL' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';";
if($DB){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
$i++;
### sleep for 10 hundredths of a second
usleep(1*100*1000);
}
$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;
$t->waitfor(Match => '/Message:.*\n\n/', Timeout => 10);
$ok = $t->close;
sleep(5);
}
$t->buffer_empty;
@hangup = $t->cmd(String => "Action: Logoff\n\n", Prompt => "/.*/");
$t->buffer_empty;
$t->waitfor(Match => '/Message:.*\n\n/', Timeout => 10);
$ok = $t->close;
sleep(5);
@@ -337,8 +352,8 @@ $rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$PTextensions[$rec_count] = "$aryA[0]";
$PT_conf_extens[$rec_count] = "$aryA[1]";
$PTextensions[$rec_count] = $aryA[0];
$PT_conf_extens[$rec_count] = $aryA[1];
if ($DB) {print "|$PT_conf_extens[$rec_count]|$PTextensions[$rec_count]|\n";}
$rec_count++;
}
@@ -363,57 +378,59 @@ $t->waitfor('/Authentication accepted/'); # waitfor auth accepted
$i=0;
foreach(@PTextensions)
{
@list_channels=@MT;
$t->buffer_empty;
$COMMAND = "Action: Command\nCommand: Meetme list $PT_conf_extens[$i]\n\nAction: Ping\n\n";
if ($DB) {print "|$PT_conf_extens[$i]|$COMMAND|\n";}
@list_channels = $t->cmd(String => "$COMMAND", Prompt => '/Response: Pong.*/');
$j=0;
$conf_empty[$i]=0;
$conf_users[$i]='';
foreach(@list_channels)
if (length($PT_conf_extens[$i]) > 0)
{
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++;
}
@list_channels=@MT;
$t->buffer_empty;
$COMMAND = "Action: Command\nCommand: Meetme list $PT_conf_extens[$i]\n\nAction: Ping\n\n";
if ($DB) {print "|$PT_conf_extens[$i]|$COMMAND|\n";}
@list_channels = $t->cmd(String => "$COMMAND", Prompt => '/Response: Pong.*/');
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)
$j=0;
$conf_empty[$i]=0;
$conf_users[$i]='';
foreach(@list_channels)
{
$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 "|$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";}
$affected_rows = $dbhA->do($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";}
$affected_rows = $dbhA->do($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";}
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
}
$i++;
### sleep for 10 hundredths of a second
usleep(1*100*1000);
+358
View File
@@ -0,0 +1,358 @@
#!/usr/bin/perl
#
# AST_conf_update_3way.pl version 2.4
#
# This script checks leave 3way vicidial_conferences for participants
# This is a constantly running script that is in the keepalive_ALL script, to
# enable this script in the keepalive, add the --cu3way flag to the
# ADMIN_keepalive_ALL.pl entry in the crontab
#
# NOTE: if you are using this script, then you should set the flag in the other
# script's crontab entry that does some of these functions:
# AST_conf_update.pl --no-vc-3way-check
#
# Copyright (C) 2010 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# 100811-2119 - First build, based upon AST_conf_update.pl script
#
# constants
$DB=0; # Debug flag
$DBX=0; # Extra Debug flag
$US='__';
$MT[0]='';
$loops = '100000';
$CLIdelay = '3';
### 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";
print " [--delay=X] = number of seconds between runs, default = 3\n";
print " [-t] = test\n";
print " [--debug] = verbose debug messages\n";
print " [--debugX] = extra verbose debug messages\n";
print "\n";
exit;
}
else
{
if ($args =~ /-debug/i)
{
$DB=1; # Debug flag
print "-- DEBUGGING ENABLED --\n\n";
}
if ($args =~ /-debugX/i)
{
$DBX=1; # Extra Debug flag
print "-- DEBUGGING ENABLED --\n\n";
}
if ($args =~ /--delay=/i) # CLI defined delay
{
@CLIvarARY = split(/--delay=/,$args);
@CLIvarARX = split(/ /,$CLIvarARY[1]);
if (length($CLIvarARX[0])>2)
{
$CLIdelay = $CLIvarARX[0];
$CLIdelay =~ s/\/$| |\r|\n|\t//gi;
$CLIdelay =~ s/\D//gi;
if ($DB > 0) {print "Delay set to $CLIdelay\n";}
}
else
{$CLIdelay = '3';}
@CLIvarARY=@MT; @CLIvarARY=@MT;
}
else
{$CLIdelay = '3';}
if ($args =~ /-t/i)
{
$TEST=1;
$T=1;
}
}
}
else
{
$CLIdelay = '3';
# print "no command line options set\n";
}
### end parsing run-time options ###
if ($CLIdelay < 1) {$CLIdelay = '1';}
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
if (!$VARDB_port) {$VARDB_port='3306';}
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use DBI;
use Net::Telnet ();
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### 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';";
if ($DB) {print "|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$DBtelnet_host = $aryA[0];
$DBtelnet_port = $aryA[1];
$DBASTmgrUSERNAME = $aryA[2];
$DBASTmgrSECRET = $aryA[3];
$DBASTmgrUSERNAMEupdate = $aryA[4];
$DBASTmgrUSERNAMElisten = $aryA[5];
$DBASTmgrUSERNAMEsend = $aryA[6];
$DBmax_vicidial_trunks = $aryA[7];
$DBanswer_transfer_agent= $aryA[8];
$DBSERVER_GMT = $aryA[9];
$DBext_context = $aryA[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;}
}
$sthA->finish();
if (!$telnet_port) {$telnet_port = '5038';}
if (length($ASTmgrUSERNAMEsend) > 3) {$telnet_login = $ASTmgrUSERNAMEsend;}
else {$telnet_login = $ASTmgrUSERNAME;}
$loop_counter=0;
while ($loops > $loop_counter)
{
($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";
$current_hourmin = "$hour$min";
##### Find date-time one hour in the past
$secX = time();
$TDtarget = ($secX - 3600);
($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";
$TDnum = "$Tyear$Tmon$Tmday$Thour$Tmin$Tsec";
######################################################################
##### CHECK vicidial_conferences TABLE #####
######################################################################
@PTextensions=@MT; @PT_conf_extens=@MT; @PTmessages=@MT; @PTold_messages=@MT; @NEW_messages=@MT; @OLD_messages=@MT;
$stmtA = "SELECT extension,conf_exten from vicidial_conferences where server_ip='$server_ip' and leave_3way='1';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($DB) {print "$now_date|$loop_counter|$sthArows|$stmtA|\n";}
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$PTextensions[$rec_count] = $aryA[0];
$PT_conf_extens[$rec_count] = $aryA[1];
if ($DB) {print "$PT_conf_extens[$rec_count]|$PTextensions[$rec_count]|\n";}
$rec_count++;
}
$sthA->finish();
if ($rec_count > 0)
{
### 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
$t->open("$telnet_host");
$t->waitfor('/[01]\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;
$COMMAND = "Action: Command\nCommand: Meetme list $PT_conf_extens[$i]\n\nAction: Ping\n\n";
if ($DBX) {print "|$PT_conf_extens[$i]|$COMMAND|\n";}
@list_channels = $t->cmd(String => "$COMMAND", Prompt => '/Response: Pong.*/');
$j=0;
$conf_empty[$i]=0;
$conf_users[$i]='';
foreach(@list_channels)
{
if($DBX){print "|$list_channels[$j]|\n";}
### mark all empty conferences and conferences with only one channel as empty
if ($list_channels[$j] =~ /No active conferences|No such conference/i)
{$conf_empty[$i]++;}
if ($list_channels[$j] =~ /1 users in that conference/i)
{$conf_empty[$i]++;}
$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 vicidial_conferences set extension='$PTextensions[$i]' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';";
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
if($DB){print STDERR "\n|$affected_rows|$stmtA|\n";}
}
}
else
{
$NEWexten[$i] = $PTextensions[$i];
$leave_3waySQL='1';
if ($PTextensions[$i] =~ /Xtimeout2$/i) {$NEWexten[$i] =~ s/Xtimeout2$/Xtimeout1/gi;}
if ($PTextensions[$i] =~ /Xtimeout1$/i) {$NEWexten[$i] = ''; $leave_3waySQL='0';}
if ( ($PTextensions[$i] !~ /Xtimeout\d$/i) and (length($PTextensions[$i])> 0) ) {$NEWexten[$i] .= 'Xtimeout2';}
if ($NEWexten[$i] =~ /Xtimeout1$/i)
{
### Kick all participants if there are any left in the conference so it can be reused
$local_DEF = 'Local/5555';
$local_AMP = '@';
$kick_local_channel = "$local_DEF$PT_conf_extens[$i]$local_AMP$ext_context";
$queryCID = "ULGC36$TDnum";
$stmtA="INSERT INTO vicidial_manager values('','','$now_date','NEW','N','$server_ip','','Originate','$queryCID','Channel: $kick_local_channel','Context: $ext_context','Exten: 8300','Priority: 1','Callerid: $queryCID','','','','','');";
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
if($DB){print STDERR "\n|$affected_rows|$stmtA|\n";}
}
$stmtA = "UPDATE vicidial_conferences set extension='$NEWexten[$i]',leave_3way='$leave_3waySQL' where server_ip='$server_ip' and conf_exten='$PT_conf_extens[$i]';";
$affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n";
if($DB){print STDERR "\n|$affected_rows|$stmtA|\n";}
### sleep for 10 hundredths of a second
usleep(1*100*1000);
}
$i++;
}
$t->buffer_empty;
@hangup = $t->cmd(String => "Action: Logoff\n\n", Prompt => "/.*/");
$t->buffer_empty;
$t->waitfor(Match => '/Message:.*\n\n/', Timeout => 10);
$ok = $t->close;
}
### sleep for X delay seconds between runs
sleep($CLIdelay);
$loop_counter++;
$timeclock_end_of_day_NOW=0;
### Grab system_settings values from the database
$stmtA = "SELECT count(*) from system_settings where timeclock_end_of_day LIKE \"%$current_hourmin%\";";
if ($DBX) {print "|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$timeclock_end_of_day_NOW = $aryA[0];
}
$sthA->finish();
if ($timeclock_end_of_day_NOW > 0)
{
$event_string = "End of Day, shutting down this script in 10 seconds, script will resume in 60 seconds...";
if ($DB) {print "\n$event_string\n\n\n";}
sleep(10);
$loop_counter=9999999;
}
}
$dbhA->disconnect();
if($DB){print "DONE... Exiting... Goodbye... See you later... \n";}
exit;