Added code for 3-way-press-agent functions in agent screen, more to follow.
git-svn-id: svn://192.168.202.10@3777 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -0,0 +1,633 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# agi-3way_press_agent.agi version 2.14
|
||||
#
|
||||
# Runs when a 3way call using a dial override is placed through a special
|
||||
# extension from the agent screen to an outside-agent where that outside-agent
|
||||
# will have to press-1 to accept the phone call.
|
||||
# An example of the special extension: "49907917275551212" where:
|
||||
# - 49907 is the special extension
|
||||
# - 9 is the dial prefix
|
||||
# - 1 is the phone code
|
||||
# - 7275551212 is the outside-agent number to be dialed
|
||||
#
|
||||
# THIS IS THE FIRST REQUIRED AGI SCRIPT OF 2 FOR THIS FEATURE
|
||||
#
|
||||
# You need to put lines similar to those below in your extensions.conf file:
|
||||
#
|
||||
#; VICIdial agent initation of outside-agent transfer:
|
||||
#exten => _49907.,1,Answer
|
||||
#exten => _49907.,n,NoOp(${CALLERID(name)})
|
||||
#exten => _49907.,n,Playback(sip-silence)
|
||||
#exten => _49907.,n,AGI(agi-3way_press_agent.agi)
|
||||
#exten => _49907.,n,Hangup
|
||||
#
|
||||
#
|
||||
# Copyright (C) 2023 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# changes:
|
||||
# 231113-2016 - First Build
|
||||
#
|
||||
|
||||
$script = 'agi-3way_press_agent.agi';
|
||||
|
||||
$at='@';
|
||||
$S='*';
|
||||
$mel=1; # Mysql Error Log enabled = 1
|
||||
$mysql_log_count=272;
|
||||
$one_mysql_log=0;
|
||||
$MT[0]='';
|
||||
|
||||
|
||||
$now_date_epoch = 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";}
|
||||
$CIDdate = "$mon$mday$hour$min$sec";
|
||||
$tsSQLdate = "$year$mon$mday$hour$min$sec";
|
||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||
$SQLdateBEGIN = $SQLdate;
|
||||
while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959
|
||||
|
||||
# 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++;
|
||||
}
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||
if (!$TPALOGfile) {$TPALOGfile = "$PATHlogs/tpaout.$year-$mon-$mday";}
|
||||
|
||||
use DBI;
|
||||
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
|
||||
use Asterisk::AGI;
|
||||
$AGI = new Asterisk::AGI;
|
||||
|
||||
$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 agi_output,local_gmt FROM servers where server_ip = '$VARserver_ip';";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02001'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
$rec_count=0;
|
||||
while ($sthArows > $rec_count)
|
||||
{
|
||||
$AGILOG = '0';
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$DBagi_output = $aryA[0];
|
||||
$local_gmt = $aryA[1];
|
||||
if ($isdst) {$local_gmt++;}
|
||||
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||
$rec_count++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
#############################################
|
||||
##### START SYSTEM SETTINGS LOOKUP #####
|
||||
$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend,queuemetrics_pe_phone_append,did_agent_log,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,did_ra_extensions_enabled,queuemetrics_socket,queuemetrics_socket_url,enable_did_entry_list_id,enable_drop_lists,inbound_answer_config,agent_search_method,abandon_check_queue,inbound_credits FROM system_settings;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02026'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$enable_queuemetrics_logging = $aryA[0];
|
||||
$queuemetrics_server_ip = $aryA[1];
|
||||
$queuemetrics_dbname = $aryA[2];
|
||||
$queuemetrics_login= $aryA[3];
|
||||
$queuemetrics_pass = $aryA[4];
|
||||
$queuemetrics_log_id = $aryA[5];
|
||||
$queuemetrics_eq_prepend = $aryA[6];
|
||||
$queuemetrics_pe_phone_append = $aryA[7];
|
||||
$did_agent_log = $aryA[8];
|
||||
$alt_log_server_ip = $aryA[9];
|
||||
$alt_log_dbname = $aryA[10];
|
||||
$alt_log_login = $aryA[11];
|
||||
$alt_log_pass = $aryA[12];
|
||||
$tables_use_alt_log_db = $aryA[13];
|
||||
$did_ra_extensions_enabled = $aryA[14];
|
||||
$queuemetrics_socket = $aryA[15];
|
||||
$queuemetrics_socket_url = $aryA[16];
|
||||
$enable_did_entry_list_id = $aryA[17];
|
||||
$enable_drop_lists = $aryA[18];
|
||||
$inbound_answer_config = $aryA[19];
|
||||
$SSagent_search_method = $aryA[20];
|
||||
$SSabandon_check_queue = $aryA[21];
|
||||
$SSinbound_credits = $aryA[22];
|
||||
}
|
||||
$sthA->finish();
|
||||
##### END SYSTEM SETTINGS LOOKUP #####
|
||||
###########################################
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||
$i++;
|
||||
}
|
||||
|
||||
### list of command-line array arguments:
|
||||
@ARGV_vars = split(/---/, $ARGV[0]);
|
||||
|
||||
$stage = $ARGV_vars[0];
|
||||
}
|
||||
|
||||
$|=1;
|
||||
while(<STDIN>)
|
||||
{
|
||||
chomp;
|
||||
last unless length($_);
|
||||
if ($AGILOG)
|
||||
{
|
||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||
{
|
||||
$AGI{$1} = $2;
|
||||
}
|
||||
}
|
||||
|
||||
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;}
|
||||
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
|
||||
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
|
||||
if (/^agi_type\:\s+(.*)$/) {$type = $1;}
|
||||
if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;}
|
||||
if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;}
|
||||
if (/^agi_context\:\s+(.*)$/) {$context = $1;}
|
||||
}
|
||||
$callerid =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi;
|
||||
$calleridname =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi;
|
||||
$extension =~ s/\'|\"|\\\\|\\\|\\|\\;|\\\;|\;|;//gi;
|
||||
$original_cid = $callerid;
|
||||
|
||||
if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
|
||||
{
|
||||
$lead_id = substr($calleridname, 10, 10);
|
||||
$lead_id = ($lead_id + 0);
|
||||
}
|
||||
if ($calleridname =~ /^DC\d\d\d\d\d\dW\d\d\d\d\d\d\d\d\d\dW/)
|
||||
{
|
||||
$lead_id = substr($calleridname, 9, 10);
|
||||
$lead_id = ($lead_id + 0);
|
||||
}
|
||||
|
||||
if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
|
||||
{$callerid = $calleridname;}
|
||||
|
||||
if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) )
|
||||
{
|
||||
$calleridname = $callerid;
|
||||
$calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi;
|
||||
$calleridname =~ s/\"|\" //gi;
|
||||
}
|
||||
|
||||
if ($callerid !~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
|
||||
{
|
||||
$callerid =~ s/\D|\'//gi;
|
||||
$calleridname =~ s/unknown|\'//gi;
|
||||
if ( (!$callerid) or ($callerid =~ /unknown/) )
|
||||
{$callerid = $calleridname;}
|
||||
}
|
||||
|
||||
foreach $i (sort keys %AGI)
|
||||
{
|
||||
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
|
||||
}
|
||||
|
||||
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|$stage|"; &agi_output;}
|
||||
|
||||
$CALLvendor_lead_code = $AGI->get_variable('vendor_lead_code');
|
||||
$CALLlead_id = $AGI->get_variable('lead_id');
|
||||
|
||||
if ($AGILOG) {$agi_string = "CALL Variables: |Lead ID: $lead_id($CALLlead_id) VLC: $CALLvendor_lead_code $callerid|"; &agi_output;}
|
||||
|
||||
|
||||
if ($AGILOG) {$agi_string = "+++++ 3WAY PRESS AGENT STARTED: |$channel_group|$callerid|$now_date"; &agi_output;}
|
||||
|
||||
$VDADphone='';
|
||||
$VDADphone_code='';
|
||||
$VCcallerid = $channel_group;
|
||||
$VD_campaign_id = $channel_group;
|
||||
if (length($VCcallerid)<2)
|
||||
{$VCcallerid = 'ViciDial Inbound';}
|
||||
|
||||
$phone_number = substr($extension, -10);
|
||||
$dialstring = $extension;
|
||||
$dialstring =~ s/^49907//gi;
|
||||
|
||||
if ($AGILOG) {$agi_string = "+++++ 3WAY PRESS AGENT VARIABLES: |phone: $phone_number|dialstring: $dialstring|CID: $original_cid|"; &agi_output;}
|
||||
|
||||
|
||||
### Grab Server values from the database
|
||||
$cbc=0;
|
||||
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks,voicemail_dump_exten_no_inst,routing_prefix FROM servers where server_ip = '$VARserver_ip';";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02004'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
while ($sthArows > $cbc)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$DBvoicemail_dump_exten = $aryA[0];
|
||||
$DBext_context = $aryA[1];
|
||||
$DBanswer_transfer_agent = $aryA[2];
|
||||
$DBSERVER_GMT = $aryA[3];
|
||||
$asterisk_version = $aryA[4];
|
||||
$DBmax_vicidial_trunks = $aryA[5];
|
||||
$voicemail_dump_exten_no_inst = $aryA[6];
|
||||
$routing_prefix = $aryA[7];
|
||||
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
|
||||
if ($DBext_context) {$ext_context = $DBext_context;}
|
||||
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
|
||||
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
|
||||
if ($asterisk_version) {$AST_ver = $asterisk_version;}
|
||||
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
|
||||
|
||||
$LOCAL_GMT_OFF = $SERVER_GMT;
|
||||
$LOCAL_GMT_OFF_STD = $SERVER_GMT;
|
||||
|
||||
if ($isdst) {$LOCAL_GMT_OFF++;}
|
||||
if ($DB) {print "SEED TIME $now_date_epoch : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";}
|
||||
|
||||
$cbc++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
|
||||
|
||||
$AGI->stream_file('sip-silence');
|
||||
$AGI->stream_file('sip-silence');
|
||||
|
||||
|
||||
### Grab call details based on vicidial_manager record
|
||||
$CALLserver_ip='';
|
||||
$CALLsession_id='';
|
||||
$CALLuser='';
|
||||
$stmtA = "SELECT server_ip,cmd_line_d FROM vicidial_manager where callerid='$calleridname' order by entry_date desc limit 1;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLserver_ip = $aryA[0];
|
||||
$CALLsession_id = $aryA[1];
|
||||
$CALLsession_id =~ s/Exten:| //gi;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$stmtA = "SELECT user FROM vicidial_live_agents where lead_id='$lead_id' and server_ip='$CALLserver_ip' order by live_agent_id desc limit 1;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLuser = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ( (length($CALLuser) < 1) || (length($CALLserver_ip) < 5) || (length($CALLsession_id) < 1) )
|
||||
{
|
||||
if ($AGILOG) {$agi_string = "3-WAY AGENT ERROR: no user/server/session found, exiting... |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;}
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($AGILOG) {$agi_string = "3-WAY DEBUG: user/server/session found: |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;}
|
||||
|
||||
|
||||
$PADlead_id = sprintf("%010s", $lead_id); while (length($PADlead_id) > 10) {chop($PADlead_id);}
|
||||
$VIDqueryCID = "T$CIDdate$PADlead_id";
|
||||
$newcallerid = "\"$VIDqueryCID <$original_cid>\"";
|
||||
$CALLcontext = '@default';
|
||||
|
||||
|
||||
### Insert the call to vicidial_3way_press_live
|
||||
$stmtA="INSERT INTO vicidial_3way_press_live SET call_date=NOW(),caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$phone_number',dialstring='$dialstring',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',status='NEW';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live INSERT: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Log the call to vicidial_3way_press_log
|
||||
$stmtA="INSERT INTO vicidial_3way_press_log SET call_date=NOW(),caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$phone_number',dialstring='$dialstring',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',result='Started: $SQLdate';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsB = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log LOG INSERT: |$affected_rowsB|$stmtA|"; &agi_output;}
|
||||
|
||||
### Insert the outside-agent call into vicidial_manager
|
||||
$stmtA="INSERT INTO vicidial_manager values('','',NOW(),'NEW','N','$CALLserver_ip','','Originate','$VIDqueryCID','Channel: Local/$dialstring$CALLcontext','Context: xfer_press_dialplan','Exten: s','Priority: 1','Callerid: $newcallerid','Variable: __lead_id=$lead_id','','','','');";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsG = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_manager INSERT: |$affected_rowsG|$stmtA|"; &agi_output;}
|
||||
|
||||
|
||||
# loop every second until vicidial_3way_press_live record changes to status='ACCEPTED', then grab an unused session, update record and go into it
|
||||
$CALLstatus='';
|
||||
$wait_loop=0;
|
||||
while ($wait_loop < 100)
|
||||
{
|
||||
usleep(1*990*1000);
|
||||
if ($wait_loop =~ /0$|5$/)
|
||||
{
|
||||
$AGI->stream_file('hold_tone');
|
||||
}
|
||||
|
||||
$stmtA = "SELECT status FROM vicidial_3way_press_live where call_3way_id='$VIDqueryCID' order by call_date desc limit 1;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLstatus = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ($CALLstatus =~ /ACCEPTED/)
|
||||
{
|
||||
#grab open session
|
||||
$free_session_count=0;
|
||||
$stmtA="SELECT count(*) FROM vicidial_conferences where server_ip='$CALLserver_ip' and ((extension='') or (extension is null)) and conf_exten != '$CALLsession_id';";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$free_session_count = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ($free_session_count < 1)
|
||||
{
|
||||
if ($AGILOG) {$agi_string = "-- ERROR: no sessions available! |$CALLserver_ip|$stmtA|"; &agi_output;}
|
||||
}
|
||||
else
|
||||
{
|
||||
### Update vicidial_conferences to grab available session
|
||||
$stmtA="UPDATE vicidial_conferences set extension='Local/8300$CALLuser$tsSQLdate', leave_3way='0' where server_ip='$CALLserver_ip' and ((extension='') or (extension is null)) and conf_exten != '$CALLsession_id' limit 1;";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsC = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_conferences UPDATE: |$affected_rowsC|$stmtA|"; &agi_output;}
|
||||
|
||||
# Grab the session_id that was reserved
|
||||
$CALLconf_exten='';
|
||||
$stmtA="SELECT conf_exten from vicidial_conferences where server_ip='$CALLserver_ip' and extension='Local/8300$CALLuser$tsSQLdate' and conf_exten != '$CALLsession_id';";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLconf_exten = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if (length($CALLconf_exten) < 1)
|
||||
{
|
||||
if ($AGILOG) {$agi_string = "-- ERROR: no valid session available! |$CALLserver_ip|$stmtA|"; &agi_output;}
|
||||
}
|
||||
else
|
||||
{
|
||||
### Update the call in vicidial_3way_press_live
|
||||
$stmtA="UPDATE vicidial_3way_press_live SET status='RESERVED',session_id_3way='$CALLconf_exten' where call_3way_id='$VIDqueryCID';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live reserved UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update the call in vicidial_3way_press_log
|
||||
$stmtA="UPDATE vicidial_3way_press_log SET session_id_3way='$CALLconf_exten', result=CONCAT(result,'|Reserved: ',NOW()) where call_3way_id='$VIDqueryCID';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log reserved UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update vicidial_conferences to leave_3way
|
||||
# $stmtA="UPDATE vicidial_conferences set leave_3way='1', leave_3way_datetime=NOW(), extension='3WAY_$CALLuser' where server_ip='$CALLserver_ip' and conf_exten='$CALLconf_exten';";
|
||||
# if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
# $affected_rowsD = $dbhA->do($stmtA);
|
||||
# if ($AGILOG) {$agi_string = "-- vicidial_conferences UPDATE: |$affected_rowsD|$stmtA|"; &agi_output;}
|
||||
|
||||
if ($AGILOG) {$agi_string = "3-WAY AGENT TRANSFER: |$CALLuser|$CALLserver_ip|$CALLconf_exten|$calleridname|$VIDqueryCID|"; &agi_output;}
|
||||
print "SET CONTEXT $ext_context\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
print "SET EXTENSION 7$CALLconf_exten\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
print "SET PRIORITY 1\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
|
||||
$wait_loop=1000;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($CALLstatus =~ /DECLINED/)
|
||||
{
|
||||
### Delete the call in vicidial_3way_press_live
|
||||
$stmtA="DELETE from vicidial_3way_press_live where call_3way_id='$VIDqueryCID';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsE = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live declined DELETE: |$affected_rowsE|$stmtA|"; &agi_output;}
|
||||
|
||||
if ($AGILOG) {$agi_string = "3-WAY AGENT TRANSFER DECLINED: |$CALLuser|$CALLserver_ip|$CALLconf_exten|$calleridname|$VIDqueryCID|"; &agi_output;}
|
||||
$AGI->stream_file('buzz');
|
||||
usleep(1*490*1000);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$wait_loop++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# send call to special extension with lead_id defined and handle_method set to CLOSER
|
||||
exit;
|
||||
|
||||
|
||||
sub checkresult
|
||||
{
|
||||
my ($res) = @_;
|
||||
my $retval;
|
||||
$tests++;
|
||||
chomp $res;
|
||||
if ($res =~ /^200/)
|
||||
{
|
||||
$res =~ /result=(-?\d+)/;
|
||||
if (!length($1))
|
||||
{
|
||||
# print STDERR "FAIL ($res)\n";
|
||||
$fail++;
|
||||
}
|
||||
else
|
||||
{
|
||||
# print STDERR "PASS ($1)\n";
|
||||
$pass++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# print STDERR "FAIL (unexpected result '$res')\n";
|
||||
$fail++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub leading_zero($)
|
||||
{
|
||||
$_ = $_[0];
|
||||
s/^(\d)$/0$1/;
|
||||
s/^(\d\d)$/0$1/;
|
||||
return $_;
|
||||
} # End of the leading_zero() routine.
|
||||
|
||||
|
||||
sub agi_output
|
||||
{
|
||||
($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time);
|
||||
if ($Lhour < 10) {$Lhour = "0$Lhour";}
|
||||
if ($Lmin < 10) {$Lmin = "0$Lmin";}
|
||||
if ($Lsec < 10) {$Lsec = "0$Lsec";}
|
||||
$LOGtime = "$Lhour:$Lmin:$Lsec";
|
||||
|
||||
if ($AGILOG >=2)
|
||||
{
|
||||
### open the log file for writing ###
|
||||
open(Lout, ">>$AGILOGfile")
|
||||
|| die "Can't open $AGILOGfile: $!\n";
|
||||
print Lout "$now_date|$LOGtime|$script|$agi_string\n";
|
||||
close(Lout);
|
||||
}
|
||||
### send to STDERR writing ###
|
||||
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||
{print STDERR "$now_date|$LOGtime|$script|$agi_string\n";}
|
||||
$agi_string='';
|
||||
}
|
||||
|
||||
|
||||
sub mysql_error_logging
|
||||
{
|
||||
($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time);
|
||||
if ($Lhour < 10) {$Lhour = "0$Lhour";}
|
||||
if ($Lmin < 10) {$Lmin = "0$Lmin";}
|
||||
if ($Lsec < 10) {$Lsec = "0$Lsec";}
|
||||
$LOGtime = "$Lhour:$Lmin:$Lsec";
|
||||
|
||||
$errno='';
|
||||
$error='';
|
||||
if ( ($mel > 0) || ($one_mysql_log > 0) )
|
||||
{
|
||||
$errno = $dbhP->err();
|
||||
if ( ($errno > 0) || ($mel > 1) || ($one_mysql_log > 0) )
|
||||
{
|
||||
$error = $dbhP->errstr();
|
||||
### open the log file for writing ###
|
||||
open(Eout, ">>$ERRLOGfile")
|
||||
|| die "Can't open $ERRLOGfile: $!\n";
|
||||
print Eout "$now_date|$LOGtime|$script|$mysql_count|$MEL_aff_rows|$errno|$error|$stmtA|$callerid|$insert_lead_id|\n";
|
||||
close(Eout);
|
||||
}
|
||||
}
|
||||
$one_mysql_log=0;
|
||||
}
|
||||
|
||||
# subroutine to parse the asterisk version
|
||||
# and return a hash with the various part
|
||||
sub parse_asterisk_version
|
||||
{
|
||||
# grab the arguments
|
||||
my $ast_ver_str = $_[0];
|
||||
|
||||
# get everything after the - and put it in $ast_ver_postfix
|
||||
my @hyphen_parts = split( /-/ , $ast_ver_str );
|
||||
|
||||
my $ast_ver_postfix = $hyphen_parts[1];
|
||||
|
||||
# now split everything before the - up by the .
|
||||
my @dot_parts = split( /\./ , $hyphen_parts[0] );
|
||||
|
||||
my %ast_ver_hash;
|
||||
|
||||
if ( $dot_parts[0] <= 1 )
|
||||
{
|
||||
%ast_ver_hash = (
|
||||
"major" => $dot_parts[0],
|
||||
"minor" => $dot_parts[1],
|
||||
"build" => $dot_parts[2],
|
||||
"revision" => $dot_parts[3],
|
||||
"postfix" => $ast_ver_postfix
|
||||
);
|
||||
}
|
||||
|
||||
# digium dropped the 1 from asterisk 10 but we still need it
|
||||
if ( $dot_parts[0] > 1 )
|
||||
{
|
||||
%ast_ver_hash = (
|
||||
"major" => 1,
|
||||
"minor" => $dot_parts[0],
|
||||
"build" => $dot_parts[1],
|
||||
"revision" => $dot_parts[2],
|
||||
"postfix" => $ast_ver_postfix
|
||||
);
|
||||
}
|
||||
|
||||
return ( %ast_ver_hash );
|
||||
}
|
||||
@@ -0,0 +1,627 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# agi-3way_press_outside.agi version 2.14
|
||||
#
|
||||
# Runs when a 3way call using a dial override is placed through a special
|
||||
# extension from the agent screen to an outside-agent where that outside-agent
|
||||
# will have to press-1 to accept the phone call.
|
||||
# An example of the special extension: "49907917275551212" where:
|
||||
# - 49907 is the special extension
|
||||
# - 9 is the dial prefix
|
||||
# - 1 is the phone code
|
||||
# - 7275551212 is the outside-agent number to be dialed
|
||||
#
|
||||
# THIS IS THE SECOND REQUIRED AGI SCRIPT OF 2 FOR THIS FEATURE
|
||||
#
|
||||
# You need to put lines similar to those below in your extensions.conf file:
|
||||
# ; Below are the parameters needed for the script to be run properly
|
||||
# ; 1. the stage of the outside-agent phone call:
|
||||
# ; answered - outside-agent has answered the phone call
|
||||
# ; declined - outside-agent has not pressed-1 in time and the call is to hung up
|
||||
# ; accepted - outside-agent has pressed-1 and is to be sent to the agent
|
||||
#
|
||||
#; VICIdial outside-agent transfer after initiated by agent:
|
||||
#[xfer_press_dialplan]
|
||||
#exten => s,1,Answer
|
||||
#exten => s,n,NoOp(${call_3way_id})
|
||||
#exten => s,n,NoOp(${CALLERID(name)})
|
||||
#exten => s,n,AGI(agi-3way_press_outside.agi,answered)
|
||||
#exten => s,n,Playback(sip-silence)
|
||||
#exten => s,n,Wait(1)
|
||||
#exten => s,n,Background(outside-sales)
|
||||
#exten => s,n,Background(press-1)
|
||||
#exten => s,n,Background(now)
|
||||
#exten => s,n,Wait(10)
|
||||
#exten => s,n,AGI(agi-3way_press_outside.agi,declined)
|
||||
#exten => s,n,Hangup
|
||||
#
|
||||
#exten => 1,1,NoOp(${call_3way_id})
|
||||
#exten => 1,n,NoOp(${CALLERID(name)})
|
||||
#exten => 1,n,AGI(agi-3way_press_outside.agi,accepted)
|
||||
#exten => 1,n,Hangup()
|
||||
#
|
||||
#exten => t,1,Playback(buzz)
|
||||
#exten => t,n,Hangup()
|
||||
#
|
||||
#exten => i,1,Playback(buzz)
|
||||
#exten => i,n,Hangup()
|
||||
#
|
||||
#
|
||||
# Copyright (C) 2023 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# changes:
|
||||
# 231113-2041 - First Build
|
||||
#
|
||||
|
||||
$script = 'agi-3way_press_outside.agi';
|
||||
|
||||
$at='@';
|
||||
$S='*';
|
||||
$mel=1; # Mysql Error Log enabled = 1
|
||||
$mysql_log_count=272;
|
||||
$one_mysql_log=0;
|
||||
$MT[0]='';
|
||||
|
||||
|
||||
$now_date_epoch = 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";}
|
||||
$CIDdate = "$mon$mday$hour$min$sec";
|
||||
$tsSQLdate = "$year$mon$mday$hour$min$sec";
|
||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||
$SQLdateBEGIN = $SQLdate;
|
||||
while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959
|
||||
|
||||
# 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++;
|
||||
}
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||
if (!$TPALOGfile) {$TPALOGfile = "$PATHlogs/tpaout.$year-$mon-$mday";}
|
||||
|
||||
use DBI;
|
||||
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
|
||||
use Asterisk::AGI;
|
||||
$AGI = new Asterisk::AGI;
|
||||
|
||||
$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 agi_output,local_gmt FROM servers where server_ip = '$VARserver_ip';";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02001'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
$rec_count=0;
|
||||
while ($sthArows > $rec_count)
|
||||
{
|
||||
$AGILOG = '0';
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$DBagi_output = $aryA[0];
|
||||
$local_gmt = $aryA[1];
|
||||
if ($isdst) {$local_gmt++;}
|
||||
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||
$rec_count++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
#############################################
|
||||
##### START SYSTEM SETTINGS LOOKUP #####
|
||||
$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend,queuemetrics_pe_phone_append,did_agent_log,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,did_ra_extensions_enabled,queuemetrics_socket,queuemetrics_socket_url,enable_did_entry_list_id,enable_drop_lists,inbound_answer_config,agent_search_method,abandon_check_queue,inbound_credits FROM system_settings;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02026'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$enable_queuemetrics_logging = $aryA[0];
|
||||
$queuemetrics_server_ip = $aryA[1];
|
||||
$queuemetrics_dbname = $aryA[2];
|
||||
$queuemetrics_login= $aryA[3];
|
||||
$queuemetrics_pass = $aryA[4];
|
||||
$queuemetrics_log_id = $aryA[5];
|
||||
$queuemetrics_eq_prepend = $aryA[6];
|
||||
$queuemetrics_pe_phone_append = $aryA[7];
|
||||
$did_agent_log = $aryA[8];
|
||||
$alt_log_server_ip = $aryA[9];
|
||||
$alt_log_dbname = $aryA[10];
|
||||
$alt_log_login = $aryA[11];
|
||||
$alt_log_pass = $aryA[12];
|
||||
$tables_use_alt_log_db = $aryA[13];
|
||||
$did_ra_extensions_enabled = $aryA[14];
|
||||
$queuemetrics_socket = $aryA[15];
|
||||
$queuemetrics_socket_url = $aryA[16];
|
||||
$enable_did_entry_list_id = $aryA[17];
|
||||
$enable_drop_lists = $aryA[18];
|
||||
$inbound_answer_config = $aryA[19];
|
||||
$SSagent_search_method = $aryA[20];
|
||||
$SSabandon_check_queue = $aryA[21];
|
||||
$SSinbound_credits = $aryA[22];
|
||||
}
|
||||
$sthA->finish();
|
||||
##### END SYSTEM SETTINGS LOOKUP #####
|
||||
###########################################
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||
$i++;
|
||||
}
|
||||
|
||||
### list of command-line array arguments:
|
||||
@ARGV_vars = split(/---/, $ARGV[0]);
|
||||
|
||||
$stage = $ARGV_vars[0];
|
||||
}
|
||||
|
||||
$|=1;
|
||||
while(<STDIN>)
|
||||
{
|
||||
chomp;
|
||||
last unless length($_);
|
||||
if ($AGILOG)
|
||||
{
|
||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||
{
|
||||
$AGI{$1} = $2;
|
||||
}
|
||||
}
|
||||
|
||||
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;}
|
||||
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
|
||||
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
|
||||
if (/^agi_type\:\s+(.*)$/) {$type = $1;}
|
||||
if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;}
|
||||
if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;}
|
||||
if (/^agi_context\:\s+(.*)$/) {$context = $1;}
|
||||
}
|
||||
$callerid =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi;
|
||||
$calleridname =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi;
|
||||
$extension =~ s/\'|\"|\\\\|\\\|\\|\\;|\\\;|\;|;//gi;
|
||||
|
||||
|
||||
if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^T\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
|
||||
{
|
||||
$lead_id = substr($calleridname, 10, 10);
|
||||
$lead_id = ($lead_id + 0);
|
||||
}
|
||||
if ($calleridname =~ /^DC\d\d\d\d\d\dW\d\d\d\d\d\d\d\d\d\dW/)
|
||||
{
|
||||
$lead_id = substr($calleridname, 9, 10);
|
||||
$lead_id = ($lead_id + 0);
|
||||
}
|
||||
|
||||
if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^T\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
|
||||
{$callerid = $calleridname;}
|
||||
|
||||
if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) )
|
||||
{
|
||||
$calleridname = $callerid;
|
||||
$calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi;
|
||||
$calleridname =~ s/\"|\" //gi;
|
||||
}
|
||||
|
||||
if ($callerid !~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^T\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
|
||||
{
|
||||
$callerid =~ s/\D|\'//gi;
|
||||
$calleridname =~ s/unknown|\'//gi;
|
||||
if ( (!$callerid) or ($callerid =~ /unknown/) )
|
||||
{$callerid = $calleridname;}
|
||||
}
|
||||
|
||||
foreach $i (sort keys %AGI)
|
||||
{
|
||||
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
|
||||
}
|
||||
|
||||
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|$stage|"; &agi_output;}
|
||||
|
||||
|
||||
$CALLvendor_lead_code = $AGI->get_variable('vendor_lead_code');
|
||||
$CALLlead_id = $AGI->get_variable('lead_id');
|
||||
|
||||
if ($AGILOG) {$agi_string = "CALL Variables: |Lead ID: $lead_id($CALLlead_id) VLC: $CALLvendor_lead_code $callerid|"; &agi_output;}
|
||||
|
||||
|
||||
if ($AGILOG) {$agi_string = "+++++ 3WAY PRESS OUTSIDE-AGENT STARTED : |$channel_group|$callerid|$now_date"; &agi_output;}
|
||||
|
||||
$VDADphone='';
|
||||
$VDADphone_code='';
|
||||
$VCcallerid = $channel_group;
|
||||
$VD_campaign_id = $channel_group;
|
||||
if (length($VCcallerid)<2)
|
||||
{$VCcallerid = 'ViciDial Inbound';}
|
||||
|
||||
|
||||
### Grab Server values from the database
|
||||
$cbc=0;
|
||||
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks,voicemail_dump_exten_no_inst,routing_prefix FROM servers where server_ip = '$VARserver_ip';";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02004'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
while ($sthArows > $cbc)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$DBvoicemail_dump_exten = $aryA[0];
|
||||
$DBext_context = $aryA[1];
|
||||
$DBanswer_transfer_agent = $aryA[2];
|
||||
$DBSERVER_GMT = $aryA[3];
|
||||
$asterisk_version = $aryA[4];
|
||||
$DBmax_vicidial_trunks = $aryA[5];
|
||||
$voicemail_dump_exten_no_inst = $aryA[6];
|
||||
$routing_prefix = $aryA[7];
|
||||
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
|
||||
if ($DBext_context) {$ext_context = $DBext_context;}
|
||||
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
|
||||
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
|
||||
if ($asterisk_version) {$AST_ver = $asterisk_version;}
|
||||
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
|
||||
|
||||
$LOCAL_GMT_OFF = $SERVER_GMT;
|
||||
$LOCAL_GMT_OFF_STD = $SERVER_GMT;
|
||||
|
||||
if ($isdst) {$LOCAL_GMT_OFF++;}
|
||||
if ($DB) {print "SEED TIME $now_date_epoch : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";}
|
||||
|
||||
$cbc++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
|
||||
$AGI->stream_file('sip-silence');
|
||||
$AGI->stream_file('sip-silence');
|
||||
|
||||
### Grab call details based on vicidial_3way_press_live record
|
||||
$CALLserver_ip='';
|
||||
$CALLsession_id='';
|
||||
$CALLuser='';
|
||||
$CALLlead_id='';
|
||||
$CALLsession_id_3way='';
|
||||
$stmtA = "SELECT server_ip,session_id,user,lead_id,session_id_3way FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLserver_ip = $aryA[0];
|
||||
$CALLsession_id = $aryA[1];
|
||||
$CALLuser = $aryA[2];
|
||||
$CALLlead_id = $aryA[3];
|
||||
$CALLsession_id_3way = $aryA[4];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$stmtA = "SELECT user FROM vicidial_live_agents where lead_id='$lead_id' and server_ip='$CALLserver_ip' order by live_agent_id desc limit 1;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLuser = $aryA[0];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ( (length($CALLuser) < 1) || (length($CALLserver_ip) < 5) || (length($CALLsession_id) < 1) )
|
||||
{
|
||||
if ($AGILOG) {$agi_string = "3-WAY AGENT ERROR: no user/server/session found, exiting... |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;}
|
||||
print "SET CONTEXT $context\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
print "SET EXTENSION i\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
print "SET PRIORITY 1\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($AGILOG) {$agi_string = "3-WAY DEBUG: user/server/session found: |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;}
|
||||
|
||||
if ($stage =~ /answered/i)
|
||||
{
|
||||
### Update the call in vicidial_3way_press_live
|
||||
$stmtA="UPDATE vicidial_3way_press_live SET status='ANSWERED' where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live answered UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update the call in vicidial_3way_press_log
|
||||
$stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Answered: $SQLdate') where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log answered UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
}
|
||||
|
||||
if ($stage =~ /accepted/i)
|
||||
{
|
||||
### Update the call in vicidial_3way_press_live
|
||||
$stmtA="UPDATE vicidial_3way_press_live SET status='ACCEPTED' where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live accepted UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update the call in vicidial_3way_press_log
|
||||
$stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Accepted: $SQLdate') where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log accepted UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
|
||||
# loop until session_id_3way is populated
|
||||
$CALLstatus='';
|
||||
$CALLconf_exten='';
|
||||
$wait_loop=0;
|
||||
while ($wait_loop < 100)
|
||||
{
|
||||
usleep(1*990*1000);
|
||||
if ($wait_loop =~ /0$|5$/)
|
||||
{
|
||||
$AGI->stream_file('hold_tone');
|
||||
}
|
||||
|
||||
$stmtA = "SELECT status,session_id_3way FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
|
||||
if ($sthArows > 0)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$CALLstatus = $aryA[0];
|
||||
$CALLconf_exten = $aryA[1];
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ( ($CALLstatus =~ /RESERVED/) && (length($CALLconf_exten) > 0) )
|
||||
{
|
||||
### Update the call in vicidial_3way_press_live
|
||||
$stmtA="UPDATE vicidial_3way_press_live SET status='TRANSFER' where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live transfer UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update the call in vicidial_3way_press_log
|
||||
$stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Transfer: ',NOW()) where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log transfer UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update vicidial_conferences to leave_3way=1
|
||||
$stmtA="UPDATE vicidial_conferences set leave_3way='1', leave_3way_datetime=NOW(), extension='3WAY_$CALLuser' where server_ip='$CALLserver_ip' and conf_exten='$CALLconf_exten';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsD = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_conferences UPDATE: |$affected_rowsD|$stmtA|"; &agi_output;}
|
||||
|
||||
### Delete the call in vicidial_3way_press_live
|
||||
$stmtA="DELETE from vicidial_3way_press_live where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsE = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live transfer DELETE: |$affected_rowsE|$stmtA|"; &agi_output;}
|
||||
|
||||
if ($AGILOG) {$agi_string = "3-WAY AGENT TRANSFER: |$CALLuser|$CALLserver_ip|$CALLconf_exten|$calleridname|"; &agi_output;}
|
||||
print "SET CONTEXT $ext_context\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
print "SET EXTENSION 7$CALLconf_exten\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
print "SET PRIORITY 1\n";
|
||||
$result = <STDIN>;
|
||||
checkresult($result);
|
||||
|
||||
$wait_loop=1000;
|
||||
exit;
|
||||
}
|
||||
|
||||
$wait_loop++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($stage =~ /declined/i)
|
||||
{
|
||||
### Update the call in vicidial_3way_press_live
|
||||
$stmtA="UPDATE vicidial_3way_press_live SET status='DECLINED' where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live declined UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
|
||||
### Update the call in vicidial_3way_press_log
|
||||
$stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Declined: $SQLdate') where call_3way_id='$calleridname';";
|
||||
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||
$affected_rowsA = $dbhA->do($stmtA);
|
||||
if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log declined UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
sub checkresult
|
||||
{
|
||||
my ($res) = @_;
|
||||
my $retval;
|
||||
$tests++;
|
||||
chomp $res;
|
||||
if ($res =~ /^200/)
|
||||
{
|
||||
$res =~ /result=(-?\d+)/;
|
||||
if (!length($1))
|
||||
{
|
||||
# print STDERR "FAIL ($res)\n";
|
||||
$fail++;
|
||||
}
|
||||
else
|
||||
{
|
||||
# print STDERR "PASS ($1)\n";
|
||||
$pass++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# print STDERR "FAIL (unexpected result '$res')\n";
|
||||
$fail++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub leading_zero($)
|
||||
{
|
||||
$_ = $_[0];
|
||||
s/^(\d)$/0$1/;
|
||||
s/^(\d\d)$/0$1/;
|
||||
return $_;
|
||||
} # End of the leading_zero() routine.
|
||||
|
||||
|
||||
sub agi_output
|
||||
{
|
||||
($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time);
|
||||
if ($Lhour < 10) {$Lhour = "0$Lhour";}
|
||||
if ($Lmin < 10) {$Lmin = "0$Lmin";}
|
||||
if ($Lsec < 10) {$Lsec = "0$Lsec";}
|
||||
$LOGtime = "$Lhour:$Lmin:$Lsec";
|
||||
|
||||
if ($AGILOG >=2)
|
||||
{
|
||||
### open the log file for writing ###
|
||||
open(Lout, ">>$AGILOGfile")
|
||||
|| die "Can't open $AGILOGfile: $!\n";
|
||||
print Lout "$now_date|$LOGtime|$script|$agi_string\n";
|
||||
close(Lout);
|
||||
}
|
||||
### send to STDERR writing ###
|
||||
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||
{print STDERR "$now_date|$LOGtime|$script|$agi_string\n";}
|
||||
$agi_string='';
|
||||
}
|
||||
|
||||
|
||||
sub mysql_error_logging
|
||||
{
|
||||
($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time);
|
||||
if ($Lhour < 10) {$Lhour = "0$Lhour";}
|
||||
if ($Lmin < 10) {$Lmin = "0$Lmin";}
|
||||
if ($Lsec < 10) {$Lsec = "0$Lsec";}
|
||||
$LOGtime = "$Lhour:$Lmin:$Lsec";
|
||||
|
||||
$errno='';
|
||||
$error='';
|
||||
if ( ($mel > 0) || ($one_mysql_log > 0) )
|
||||
{
|
||||
$errno = $dbhP->err();
|
||||
if ( ($errno > 0) || ($mel > 1) || ($one_mysql_log > 0) )
|
||||
{
|
||||
$error = $dbhP->errstr();
|
||||
### open the log file for writing ###
|
||||
open(Eout, ">>$ERRLOGfile")
|
||||
|| die "Can't open $ERRLOGfile: $!\n";
|
||||
print Eout "$now_date|$LOGtime|$script|$mysql_count|$MEL_aff_rows|$errno|$error|$stmtA|$callerid|$insert_lead_id|\n";
|
||||
close(Eout);
|
||||
}
|
||||
}
|
||||
$one_mysql_log=0;
|
||||
}
|
||||
|
||||
# subroutine to parse the asterisk version
|
||||
# and return a hash with the various part
|
||||
sub parse_asterisk_version
|
||||
{
|
||||
# grab the arguments
|
||||
my $ast_ver_str = $_[0];
|
||||
|
||||
# get everything after the - and put it in $ast_ver_postfix
|
||||
my @hyphen_parts = split( /-/ , $ast_ver_str );
|
||||
|
||||
my $ast_ver_postfix = $hyphen_parts[1];
|
||||
|
||||
# now split everything before the - up by the .
|
||||
my @dot_parts = split( /\./ , $hyphen_parts[0] );
|
||||
|
||||
my %ast_ver_hash;
|
||||
|
||||
if ( $dot_parts[0] <= 1 )
|
||||
{
|
||||
%ast_ver_hash = (
|
||||
"major" => $dot_parts[0],
|
||||
"minor" => $dot_parts[1],
|
||||
"build" => $dot_parts[2],
|
||||
"revision" => $dot_parts[3],
|
||||
"postfix" => $ast_ver_postfix
|
||||
);
|
||||
}
|
||||
|
||||
# digium dropped the 1 from asterisk 10 but we still need it
|
||||
if ( $dot_parts[0] > 1 )
|
||||
{
|
||||
%ast_ver_hash = (
|
||||
"major" => 1,
|
||||
"minor" => $dot_parts[0],
|
||||
"build" => $dot_parts[1],
|
||||
"revision" => $dot_parts[2],
|
||||
"postfix" => $ast_ver_postfix
|
||||
);
|
||||
}
|
||||
|
||||
return ( %ast_ver_hash );
|
||||
}
|
||||
Reference in New Issue
Block a user