added one instance of pl.gif
changed several AGI scripts to use new AGI_output setting git-svn-id: svn://192.168.202.10@183 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 276 B |
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# VD_amd_post.agi version 0.2 *DBI-version*
|
# VD_amd_post.agi version 0.3 *DBI-version*
|
||||||
#
|
#
|
||||||
# NOTE: This script is only needed with app_amd enabled systems
|
# NOTE: This script is only needed with app_amd enabled systems
|
||||||
#
|
#
|
||||||
@@ -25,13 +25,30 @@
|
|||||||
# 60217-1119 first build
|
# 60217-1119 first build
|
||||||
# 60731-1403 - changed to use DBI-DBD::mysql
|
# 60731-1403 - changed to use DBI-DBD::mysql
|
||||||
# - changed to use /etc/astguiclient.conf for configs
|
# - changed to use /etc/astguiclient.conf for configs
|
||||||
|
# 60817-1025 - added output options check from database
|
||||||
#
|
#
|
||||||
|
|
||||||
$V = 0; # set to 1 for verbose mode
|
$script = 'VD_amd_post.agi';
|
||||||
$M = 0; # set to 1 for 2 line messages mode
|
|
||||||
$A = 1; # set to 1 for AMD output messages mode
|
$A = 1; # set to 1 for AMD output messages mode
|
||||||
$AMD_LOG = 0; # set to 1 for logfile
|
$AMD_LOG = 0; # set to 1 for logfile
|
||||||
|
|
||||||
|
($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";
|
||||||
|
$start_time=$now_date;
|
||||||
|
$CIDdate = "$mon$mday$hour$min$sec";
|
||||||
|
$tsSQLdate = "$year$mon$mday$hour$min$sec";
|
||||||
|
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||||
|
$SQLdateBEGIN = $SQLdate;
|
||||||
|
|
||||||
# default path to astguiclient configuration file:
|
# default path to astguiclient configuration file:
|
||||||
$PATHconf = '/etc/astguiclient.conf';
|
$PATHconf = '/etc/astguiclient.conf';
|
||||||
@@ -71,42 +88,43 @@ foreach(@conf)
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Customized Variables
|
|
||||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
|
||||||
|
|
||||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||||
|
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
use Asterisk::AGI;
|
use Asterisk::AGI;
|
||||||
$AGI = new Asterisk::AGI;
|
$AGI = new Asterisk::AGI;
|
||||||
|
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||||
$year = ($year + 1900);
|
or die "Couldn't connect to database: " . DBI->errstr;
|
||||||
$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";
|
|
||||||
$start_time=$now_date;
|
|
||||||
$CIDdate = "$mon$mday$hour$min$sec";
|
|
||||||
$tsSQLdate = "$year$mon$mday$hour$min$sec";
|
|
||||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
|
||||||
$SQLdateBEGIN = $SQLdate;
|
|
||||||
|
|
||||||
|
### Grab Server values from the database
|
||||||
|
$stmtA = "SELECT agi_output 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;
|
||||||
|
$rec_count=0;
|
||||||
|
while ($sthArows > $rec_count)
|
||||||
|
{
|
||||||
|
$AGILOG = '0';
|
||||||
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$DBagi_output = "$aryA[0]";
|
||||||
|
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||||
|
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||||
|
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||||
|
$rec_count++;
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
{
|
{
|
||||||
if ($V) {print STDERR "Perl Environment Dump:\n";}
|
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($#ARGV >= $i)
|
while ($#ARGV >= $i)
|
||||||
{
|
{
|
||||||
$args = "$args $ARGV[$i]";
|
$args = "$args $ARGV[$i]";
|
||||||
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
|
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,17 +158,13 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($V) {print "no command line options set\n";}
|
|
||||||
}
|
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
while(<STDIN>)
|
while(<STDIN>)
|
||||||
{
|
{
|
||||||
chomp;
|
chomp;
|
||||||
last unless length($_);
|
last unless length($_);
|
||||||
if ($V)
|
if ($AGILOG)
|
||||||
{
|
{
|
||||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||||
{
|
{
|
||||||
@@ -189,21 +203,19 @@ if ( (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($V)
|
if ($AGILOG) {$agi_string = "AGI Environment Dump:"; &agi_output;}
|
||||||
{
|
|
||||||
|
|
||||||
if ($V) {print STDERR "AGI Environment Dump:\n";}
|
foreach $i (sort keys %AGI)
|
||||||
foreach $i (sort keys %AGI) {
|
{
|
||||||
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
|
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|$calleridname|$priority|"; &agi_output;}
|
||||||
|
|
||||||
$VDADcampaign='';
|
$VDADcampaign='';
|
||||||
$VDADphone='';
|
$VDADphone='';
|
||||||
$VDADphone_code='';
|
$VDADphone_code='';
|
||||||
|
|
||||||
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|$calleridname|$priority|\n";}
|
|
||||||
|
|
||||||
|
|
||||||
$callerid =~ s/\"//gi;
|
$callerid =~ s/\"//gi;
|
||||||
$CIDlead_id = $callerid;
|
$CIDlead_id = $callerid;
|
||||||
@@ -211,13 +223,11 @@ $CIDlead_id = substr($CIDlead_id, 11, 9);
|
|||||||
$CIDlead_id = ($CIDlead_id + 0);
|
$CIDlead_id = ($CIDlead_id + 0);
|
||||||
$VD_lead_id = $CIDlead_id;
|
$VD_lead_id = $CIDlead_id;
|
||||||
|
|
||||||
if ($V) {print STDERR "\nVD_amd_post : $callerid $channel $priority\n";}
|
if ($AGILOG) {$agi_string = "+++++ VD amd START: |$CIDlead_id|$now_date|$AST_ver|"; &agi_output;}
|
||||||
if ($M) {print STDERR "+++++ VD amd START : |$unique_id|$channel|$extension|$type|$callerid|$CIDlead_id|$now_date|$AST_ver|$priority|$calleridname|\n";}
|
|
||||||
|
|
||||||
|
|
||||||
if ( ($channel =~ /Local/i) && ($AST_ver !~ /^1\.0\.8|^1\.0\.9/) )
|
if ( ($channel =~ /Local/i) && ($AST_ver !~ /^1\.0\.8|^1\.0\.9/) )
|
||||||
{
|
{
|
||||||
if ($M) {print STDERR "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority\n";}
|
if ($AGILOG) {$agi_string = "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority"; &agi_output;}
|
||||||
if ($priority > 2) {sleep(1);}
|
if ($priority > 2) {sleep(1);}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -237,19 +247,15 @@ exit;
|
|||||||
########## AMD says it's a machine so modify statuses and hangup call ##########
|
########## AMD says it's a machine so modify statuses and hangup call ##########
|
||||||
########## something will go here later for leaving a message on AMs ##########
|
########## something will go here later for leaving a message on AMs ##########
|
||||||
|
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
|
||||||
|
|
||||||
$stmtA = "UPDATE vicidial_log set status='AL' where lead_id='$VD_lead_id' order by call_date desc limit 1;";
|
$stmtA = "UPDATE vicidial_log set status='AL' where lead_id='$VD_lead_id' order by call_date desc limit 1;";
|
||||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
if ($M) {print STDERR "-- VDAD vicidial_log AM update: |$affected_rows|$uniqueid|\n";}
|
if ($AGILOG) {$agi_string = "-- VDAD vicidial_log AM update: |$affected_rows|$uniqueid|"; &agi_output;}
|
||||||
|
|
||||||
$stmtA = "UPDATE vicidial_list set status='AL' where lead_id='$VD_lead_id';";
|
$stmtA = "UPDATE vicidial_list set status='AL' where lead_id='$VD_lead_id';";
|
||||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
if ($M) {print STDERR "-- VDAD vicidial_list AM update: |$affected_rows|$uniqueid|\n";}
|
if ($AGILOG) {$agi_string = "-- VDAD vicidial_list AM update: |$affected_rows|$uniqueid|"; &agi_output;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
@@ -278,3 +284,21 @@ sub checkresult {
|
|||||||
$fail++;
|
$fail++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub agi_output
|
||||||
|
{
|
||||||
|
if ($AGILOG >=2)
|
||||||
|
{
|
||||||
|
### open the log file for writing ###
|
||||||
|
open(Lout, ">>$AGILOGfile")
|
||||||
|
|| die "Can't open $AGILOGfile: $!\n";
|
||||||
|
print Lout "$now_date|$script|$agi_string\n";
|
||||||
|
close(Lout);
|
||||||
|
}
|
||||||
|
### send to STDERR writing ###
|
||||||
|
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||||
|
{print STDERR "$now_date|$script|$agi_string\n";}
|
||||||
|
$agi_string='';
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# agi-VDAD_pin_IVR.agi version 0.1 *DBI-version*
|
# agi-VDAD_pin_IVR.agi version 0.2 *DBI-version*
|
||||||
#
|
#
|
||||||
# At the end of a call, the agent transfers customer to this script
|
# At the end of a call, the agent transfers customer to this script
|
||||||
#
|
#
|
||||||
@@ -23,11 +23,11 @@
|
|||||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||||
#
|
#
|
||||||
# changes:
|
# changes:
|
||||||
# 60802-1304 - first build
|
# 60802-1304 - first build
|
||||||
|
# 60817-1113 - added output options check from database
|
||||||
#
|
#
|
||||||
|
|
||||||
$V = 1; # set to 1 for verbose mode
|
$script = 'agi-VDAD_pin_IVR.agi';
|
||||||
$M = 1; # set to 1 for 2 line messages mode
|
|
||||||
|
|
||||||
$first_audio_file = '85100003';
|
$first_audio_file = '85100003';
|
||||||
$second_audio_file = '85100004';
|
$second_audio_file = '85100004';
|
||||||
@@ -47,6 +47,16 @@ $product_code = 'ABC';
|
|||||||
$user = '1234';
|
$user = '1234';
|
||||||
$pin = '0';
|
$pin = '0';
|
||||||
|
|
||||||
|
($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";}
|
||||||
|
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||||
|
|
||||||
# default path to astguiclient configuration file:
|
# default path to astguiclient configuration file:
|
||||||
$PATHconf = '/etc/astguiclient.conf';
|
$PATHconf = '/etc/astguiclient.conf';
|
||||||
|
|
||||||
@@ -85,37 +95,44 @@ foreach(@conf)
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Customized Variables
|
|
||||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
|
||||||
|
|
||||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||||
|
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
use Asterisk::AGI;
|
use Asterisk::AGI;
|
||||||
$AGI = new 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
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
$stmtA = "SELECT agi_output FROM servers where server_ip = '$VARserver_ip';";
|
||||||
$year = ($year + 1900);
|
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||||
$mon++;
|
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||||
if ($mon < 10) {$mon = "0$mon";}
|
$sthArows=$sthA->rows;
|
||||||
if ($mday < 10) {$mday = "0$mday";}
|
$rec_count=0;
|
||||||
if ($hour < 10) {$Fhour = "0$hour";}
|
while ($sthArows > $rec_count)
|
||||||
if ($min < 10) {$min = "0$min";}
|
{
|
||||||
if ($sec < 10) {$sec = "0$sec";}
|
$AGILOG = '0';
|
||||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$DBagi_output = "$aryA[0]";
|
||||||
|
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||||
|
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||||
|
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||||
|
$rec_count++;
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
{
|
{
|
||||||
if ($V) {print STDERR "Perl Environment Dump:\n";}
|
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($#ARGV >= $i)
|
while ($#ARGV >= $i)
|
||||||
{
|
{
|
||||||
$args = "$args $ARGV[$i]";
|
$args = "$args $ARGV[$i]";
|
||||||
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
|
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,16 +162,12 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($V) {print "no command line options set\n";}
|
|
||||||
}
|
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
while(<STDIN>) {
|
while(<STDIN>) {
|
||||||
chomp;
|
chomp;
|
||||||
last unless length($_);
|
last unless length($_);
|
||||||
if ($V)
|
if ($AGILOG)
|
||||||
{
|
{
|
||||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||||
{
|
{
|
||||||
@@ -177,7 +190,7 @@ while(<STDIN>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($V) {print STDERR "\nINBOUND IVR PLAY CALL VDCL STARTED\n";}
|
if ($AGILOG) {$agi_string = "INBOUND IVR PLAY CALL VDCL STARTED"; &agi_output;}
|
||||||
|
|
||||||
|
|
||||||
$AGI->stream_file('beep');
|
$AGI->stream_file('beep');
|
||||||
@@ -186,9 +199,6 @@ sleep(1);
|
|||||||
|
|
||||||
$AGI->stream_file("$first_audio_file");
|
$AGI->stream_file("$first_audio_file");
|
||||||
|
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
|
||||||
|
|
||||||
### insert a record into the vicidial_list_pins table
|
### insert a record into the vicidial_list_pins table
|
||||||
$stmtA = "INSERT INTO vicidial_list_pins (entry_time,phone_number,lead_id,campaign_id,product_code,user,digits) values('$SQLdate','$phone_number','$lead_id','$campaign_id','$product_code','$user','IVR');";
|
$stmtA = "INSERT INTO vicidial_list_pins (entry_time,phone_number,lead_id,campaign_id,product_code,user,digits) values('$SQLdate','$phone_number','$lead_id','$campaign_id','$product_code','$user','IVR');";
|
||||||
|
|
||||||
@@ -196,7 +206,7 @@ $affected_rows = $dbhA->do($stmtA);
|
|||||||
|
|
||||||
$insert_pin_id = $dbhA->{'mysql_insertid'};
|
$insert_pin_id = $dbhA->{'mysql_insertid'};
|
||||||
|
|
||||||
if($M){print STDERR "\n|$stmtA|$insert_pin_id|$affected_rows|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|$insert_pin_id|$affected_rows|"; &agi_output;}
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
|
|
||||||
@@ -209,3 +219,19 @@ $AGI->stream_file("$goodbye_audio_file");
|
|||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
|
||||||
|
sub agi_output
|
||||||
|
{
|
||||||
|
if ($AGILOG >=2)
|
||||||
|
{
|
||||||
|
### open the log file for writing ###
|
||||||
|
open(Lout, ">>$AGILOGfile")
|
||||||
|
|| die "Can't open $AGILOGfile: $!\n";
|
||||||
|
print Lout "$now_date|$script|$agi_string\n";
|
||||||
|
close(Lout);
|
||||||
|
}
|
||||||
|
### send to STDERR writing ###
|
||||||
|
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||||
|
{print STDERR "$now_date|$script|$agi_string\n";}
|
||||||
|
$agi_string='';
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# agi-VDADfixCXFER.agi version 0.1 *DBI-version*
|
# agi-VDADfixCXFER.agi version 0.3 *DBI-version*
|
||||||
#
|
#
|
||||||
# runs when a Consultative transfer is released by the vicidial fronter as the
|
# runs when a Consultative transfer is released by the vicidial fronter as the
|
||||||
# call arrives on another channel so that the vicidial_live_agents record is
|
# call arrives on another channel so that the vicidial_live_agents record is
|
||||||
@@ -15,10 +15,20 @@
|
|||||||
#
|
#
|
||||||
# changes:
|
# changes:
|
||||||
# 60809-1749 - first build
|
# 60809-1749 - first build
|
||||||
|
# 60817-1122 - added output options check from database
|
||||||
#
|
#
|
||||||
|
|
||||||
$V = 1; # set to 1 for verbose mode
|
$script = 'agi-VDADfixCXFER.agi';
|
||||||
$M = 1; # set to 1 for 2 line messages mode
|
|
||||||
|
($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";}
|
||||||
|
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||||
|
|
||||||
# default path to astguiclient configuration file:
|
# default path to astguiclient configuration file:
|
||||||
$PATHconf = '/etc/astguiclient.conf';
|
$PATHconf = '/etc/astguiclient.conf';
|
||||||
@@ -58,34 +68,44 @@ foreach(@conf)
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Customized Variables
|
|
||||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
|
||||||
|
|
||||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||||
|
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
use Asterisk::AGI;
|
use Asterisk::AGI;
|
||||||
$AGI = new Asterisk::AGI;
|
$AGI = new Asterisk::AGI;
|
||||||
|
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||||
$year = ($year + 1900);
|
or die "Couldn't connect to database: " . DBI->errstr;
|
||||||
$mon++;
|
|
||||||
if ($mon < 10) {$mon = "0$mon";}
|
### Grab Server values from the database
|
||||||
if ($mday < 10) {$mday = "0$mday";}
|
$stmtA = "SELECT agi_output FROM servers where server_ip = '$VARserver_ip';";
|
||||||
if ($hour < 10) {$Fhour = "0$hour";}
|
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||||
if ($min < 10) {$min = "0$min";}
|
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||||
if ($sec < 10) {$sec = "0$sec";}
|
$sthArows=$sthA->rows;
|
||||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
$rec_count=0;
|
||||||
|
while ($sthArows > $rec_count)
|
||||||
|
{
|
||||||
|
$AGILOG = '0';
|
||||||
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$DBagi_output = "$aryA[0]";
|
||||||
|
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||||
|
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||||
|
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||||
|
$rec_count++;
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
{
|
{
|
||||||
if ($V) {print STDERR "Perl Environment Dump:\n";}
|
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($#ARGV >= $i)
|
while ($#ARGV >= $i)
|
||||||
{
|
{
|
||||||
$args = "$args $ARGV[$i]";
|
$args = "$args $ARGV[$i]";
|
||||||
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
|
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,17 +142,13 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($V) {print "no command line options set\n";}
|
|
||||||
}
|
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
while(<STDIN>)
|
while(<STDIN>)
|
||||||
{
|
{
|
||||||
chomp;
|
chomp;
|
||||||
last unless length($_);
|
last unless length($_);
|
||||||
if ($V)
|
if ($AGILOG)
|
||||||
{
|
{
|
||||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||||
{
|
{
|
||||||
@@ -153,43 +169,39 @@ while(<STDIN>)
|
|||||||
$phone_number = $EXTEN[4];
|
$phone_number = $EXTEN[4];
|
||||||
$campaign_id = $EXTEN[5];
|
$campaign_id = $EXTEN[5];
|
||||||
|
|
||||||
if ($V)
|
if ($AGILOG) {$agi_string = "AGI Environment Dump:"; &agi_output;}
|
||||||
{
|
|
||||||
|
|
||||||
if ($V) {print STDERR "AGI Environment Dump:\n";}
|
foreach $i (sort keys %AGI)
|
||||||
foreach $i (sort keys %AGI) {
|
{
|
||||||
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
|
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|$calleridname|$priority|\n";}
|
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|$calleridname|$priority|"; &agi_output;}
|
||||||
|
|
||||||
|
if ($AGILOG) {$agi_string = "CXFERfix : $lead_id $user $channel $uniqueid"; &agi_output;}
|
||||||
|
|
||||||
if ($V) {print STDERR "\nCXFERfix : $lead_id $user $channel $uniqueid\n";}
|
|
||||||
$CIDlead = sprintf("%010s", $lead_id);
|
$CIDlead = sprintf("%010s", $lead_id);
|
||||||
$CIDlead = "C123412345$CIDlead";
|
$CIDlead = "C123412345$CIDlead";
|
||||||
print "SET CALLERID $CIDlead\n";
|
print "SET CALLERID $CIDlead\n";
|
||||||
checkresult($result);
|
checkresult($result);
|
||||||
print STDERR "callerID changed: $CIDlead\n";
|
if ($AGILOG) {$agi_string = "callerID changed: $CIDlead"; &agi_output;}
|
||||||
|
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
|
||||||
|
|
||||||
########## FIND AND UPDATE vicidial_live_agents ##########
|
########## FIND AND UPDATE vicidial_live_agents ##########
|
||||||
$stmtA = "UPDATE vicidial_live_agents SET channel='$channel',call_server_ip='$server_ip',uniqueid='$uniqueid' where user='$user' and lead_id='$lead_id';";
|
$stmtA = "UPDATE vicidial_live_agents SET channel='$channel',call_server_ip='$VARserver_ip',uniqueid='$uniqueid' where user='$user' and lead_id='$lead_id';";
|
||||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
if ($M) {print STDERR "-- VDAD vicidial_live_agents update: |$affected_rows|$lead_id\n";}
|
if ($AGILOG) {$agi_string = "-- VDAD vicidial_live_agents update: |$affected_rows|$lead_id|"; &agi_output;}
|
||||||
|
|
||||||
########## INSERT NEW vicidial_auto_calls record ##########
|
########## INSERT NEW vicidial_auto_calls record ##########
|
||||||
$stmtA = "INSERT INTO vicidial_auto_calls SET channel='$channel',server_ip='$server_ip',uniqueid='$uniqueid',campaign_id='$campaign_id',status='CLOSER',lead_id='$lead_id',phone_code='$phone_code',phone_number='$phone_number',call_time='$SQLdate',call_type='IN',callerid='$CIDlead';";
|
$stmtA = "INSERT INTO vicidial_auto_calls SET channel='$channel',server_ip='$VARserver_ip',uniqueid='$uniqueid',campaign_id='$campaign_id',status='CLOSER',lead_id='$lead_id',phone_code='$phone_code',phone_number='$phone_number',call_time='$SQLdate',call_type='IN',callerid='$CIDlead';";
|
||||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
if ($M) {print STDERR "-- VDAD vicidial_auto_calls insert: |$affected_rows|$lead_id\n";}
|
if ($AGILOG) {$agi_string = "-- VDAD vicidial_auto_calls insert: |$affected_rows|$lead_id|"; &agi_output;}
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
|
|
||||||
|
|
||||||
print STDERR "\nexiting the CXFERfix app, transferring call to $conf_exten\n";
|
if ($AGILOG) {$agi_string = "exiting the CXFERfix app, transferring call to $conf_exten"; &agi_output;}
|
||||||
#print "SET CONTEXT $ext_context\n";
|
#print "SET CONTEXT $ext_context\n";
|
||||||
# checkresult($result);
|
# checkresult($result);
|
||||||
print "SET EXTENSION $conf_exten\n";
|
print "SET EXTENSION $conf_exten\n";
|
||||||
@@ -223,3 +235,21 @@ sub checkresult {
|
|||||||
$fail++;
|
$fail++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub agi_output
|
||||||
|
{
|
||||||
|
if ($AGILOG >=2)
|
||||||
|
{
|
||||||
|
### open the log file for writing ###
|
||||||
|
open(Lout, ">>$AGILOGfile")
|
||||||
|
|| die "Can't open $AGILOGfile: $!\n";
|
||||||
|
print Lout "$now_date|$script|$agi_string\n";
|
||||||
|
close(Lout);
|
||||||
|
}
|
||||||
|
### send to STDERR writing ###
|
||||||
|
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||||
|
{print STDERR "$now_date|$script|$agi_string\n";}
|
||||||
|
$agi_string='';
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# agi-VDADlisten_DTMF.agi version 0.2 *DBI-version*
|
# agi-VDADlisten_DTMF.agi version 0.3 *DBI-version*
|
||||||
#
|
#
|
||||||
# To be initiated by an agent so during a call. Agent will click a PIN NUMBER
|
# To be initiated by an agent so during a call. Agent will click a PIN NUMBER
|
||||||
# link on a web form webpage that will Originate a new call to this script
|
# link on a web form webpage that will Originate a new call to this script
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
# 60207-1507 - added ability to send AMs to campaign-defined message to leave
|
# 60207-1507 - added ability to send AMs to campaign-defined message to leave
|
||||||
# 60731-1536 - changed to use DBI-DBD::mysql
|
# 60731-1536 - changed to use DBI-DBD::mysql
|
||||||
# - changed to use /etc/astguiclient.conf for configs
|
# - changed to use /etc/astguiclient.conf for configs
|
||||||
|
# 60817-1113 - added output options check from database
|
||||||
#
|
#
|
||||||
|
|
||||||
$V = 1; # set to 1 for verbose mode
|
$script = 'agi-VDADlisten_DTMF.agi';
|
||||||
$M = 1; # set to 1 for 2 line messages mode
|
|
||||||
|
|
||||||
### set defaults for testing
|
### set defaults for testing
|
||||||
$referring_extension = '83009';
|
$referring_extension = '83009';
|
||||||
@@ -43,6 +43,16 @@ $product_code = 'ABC';
|
|||||||
$user = '1234';
|
$user = '1234';
|
||||||
$pin = '0';
|
$pin = '0';
|
||||||
|
|
||||||
|
($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";}
|
||||||
|
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
||||||
|
|
||||||
# default path to astguiclient configuration file:
|
# default path to astguiclient configuration file:
|
||||||
$PATHconf = '/etc/astguiclient.conf';
|
$PATHconf = '/etc/astguiclient.conf';
|
||||||
|
|
||||||
@@ -81,37 +91,44 @@ foreach(@conf)
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Customized Variables
|
|
||||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
|
||||||
|
|
||||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||||
|
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
use Asterisk::AGI;
|
use Asterisk::AGI;
|
||||||
$AGI = new 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
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
$stmtA = "SELECT agi_output FROM servers where server_ip = '$VARserver_ip';";
|
||||||
$year = ($year + 1900);
|
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||||
$mon++;
|
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||||
if ($mon < 10) {$mon = "0$mon";}
|
$sthArows=$sthA->rows;
|
||||||
if ($mday < 10) {$mday = "0$mday";}
|
$rec_count=0;
|
||||||
if ($hour < 10) {$Fhour = "0$hour";}
|
while ($sthArows > $rec_count)
|
||||||
if ($min < 10) {$min = "0$min";}
|
{
|
||||||
if ($sec < 10) {$sec = "0$sec";}
|
$AGILOG = '0';
|
||||||
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$DBagi_output = "$aryA[0]";
|
||||||
|
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||||
|
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||||
|
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||||
|
$rec_count++;
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
{
|
{
|
||||||
if ($V) {print STDERR "Perl Environment Dump:\n";}
|
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($#ARGV >= $i)
|
while ($#ARGV >= $i)
|
||||||
{
|
{
|
||||||
$args = "$args $ARGV[$i]";
|
$args = "$args $ARGV[$i]";
|
||||||
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
|
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,16 +158,12 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($V) {print "no command line options set\n";}
|
|
||||||
}
|
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
while(<STDIN>) {
|
while(<STDIN>) {
|
||||||
chomp;
|
chomp;
|
||||||
last unless length($_);
|
last unless length($_);
|
||||||
if ($V)
|
if ($AGILOG)
|
||||||
{
|
{
|
||||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||||
{
|
{
|
||||||
@@ -173,13 +186,10 @@ while(<STDIN>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($V) {print STDERR "\nINBOUND DTMF CALL VDCL STARTED\n";}
|
if ($AGILOG) {$agi_string = "INBOUND DTMF CALL VDCL STARTED"; &agi_output;}
|
||||||
|
|
||||||
&enter_pin_number;
|
&enter_pin_number;
|
||||||
|
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
|
||||||
|
|
||||||
if (length($pin) < 4) {$AGI->stream_file('buzz');}
|
if (length($pin) < 4) {$AGI->stream_file('buzz');}
|
||||||
else {$AGI->stream_file('ding');}
|
else {$AGI->stream_file('ding');}
|
||||||
|
|
||||||
@@ -190,7 +200,7 @@ $affected_rows = $dbhA->do($stmtA);
|
|||||||
|
|
||||||
$insert_pin_id = $dbhA->{'mysql_insertid'};
|
$insert_pin_id = $dbhA->{'mysql_insertid'};
|
||||||
|
|
||||||
if($M){print STDERR "\n|$stmtA|$insert_pin_id|$affected_rows|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|$insert_pin_id|$affected_rows|"; &agi_output;}
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
|
|
||||||
@@ -214,7 +224,7 @@ while ( ($digit_loop_counter < 4) )
|
|||||||
if ($digit =~ /\d/)
|
if ($digit =~ /\d/)
|
||||||
{
|
{
|
||||||
$totalDTMF = "$totalDTMF$digit";
|
$totalDTMF = "$totalDTMF$digit";
|
||||||
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
|
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
|
||||||
# $AGI->say_digits("$digit");
|
# $AGI->say_digits("$digit");
|
||||||
undef $digit;
|
undef $digit;
|
||||||
}
|
}
|
||||||
@@ -228,7 +238,27 @@ while ( ($digit_loop_counter < 4) )
|
|||||||
|
|
||||||
$totalDTMF =~ s/\D//gi;
|
$totalDTMF =~ s/\D//gi;
|
||||||
$pin = $totalDTMF;
|
$pin = $totalDTMF;
|
||||||
if ($totalDTMF) {print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";}
|
if ($totalDTMF)
|
||||||
|
{
|
||||||
|
if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}
|
||||||
|
}
|
||||||
# $AGI->say_digits("$pin");
|
# $AGI->say_digits("$pin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub agi_output
|
||||||
|
{
|
||||||
|
if ($AGILOG >=2)
|
||||||
|
{
|
||||||
|
### open the log file for writing ###
|
||||||
|
open(Lout, ">>$AGILOGfile")
|
||||||
|
|| die "Can't open $AGILOGfile: $!\n";
|
||||||
|
print Lout "$now_date|$script|$agi_string\n";
|
||||||
|
close(Lout);
|
||||||
|
}
|
||||||
|
### send to STDERR writing ###
|
||||||
|
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||||
|
{print STDERR "$now_date|$script|$agi_string\n";}
|
||||||
|
$agi_string='';
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# call_inbound.agi version 0.2 *DBI-version*
|
# call_inbound.agi version 0.3 *DBI-version*
|
||||||
#
|
#
|
||||||
# runs at the beginning and ending of every inbound call received
|
# runs at the beginning and ending of every inbound call received
|
||||||
#
|
#
|
||||||
@@ -22,10 +22,25 @@
|
|||||||
# changes:
|
# changes:
|
||||||
# 60731-1435 - changed to use DBI-DBD::mysql
|
# 60731-1435 - changed to use DBI-DBD::mysql
|
||||||
# - changed to use /etc/astguiclient.conf for configs
|
# - changed to use /etc/astguiclient.conf for configs
|
||||||
|
# 60817-1102 - added output options check from database
|
||||||
#
|
#
|
||||||
|
|
||||||
$V = 1; # set to 1 for verbose mode
|
$script = 'call_inbound.agi';
|
||||||
$M = 1; # set to 1 for 2 line messages mode
|
|
||||||
|
$US='_';
|
||||||
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||||
|
$year = ($year + 1900);
|
||||||
|
$Y = substr($year, 0, 1);
|
||||||
|
$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";
|
||||||
|
$filedate = "$US$Y$mon$mday$hour$min$sec$US";
|
||||||
|
|
||||||
# default path to astguiclient configuration file:
|
# default path to astguiclient configuration file:
|
||||||
$PATHconf = '/etc/astguiclient.conf';
|
$PATHconf = '/etc/astguiclient.conf';
|
||||||
@@ -65,39 +80,42 @@ foreach(@conf)
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Customized Variables
|
|
||||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
|
||||||
|
|
||||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||||
|
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
|
|
||||||
$US='_';
|
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
or die "Couldn't connect to database: " . DBI->errstr;
|
||||||
$year = ($year + 1900);
|
|
||||||
$Y = substr($year, 0, 1);
|
|
||||||
$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";
|
|
||||||
$filedate = "$US$Y$mon$mday$hour$min$sec$US";
|
|
||||||
|
|
||||||
|
### Grab Server values from the database
|
||||||
|
$stmtA = "SELECT agi_output 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;
|
||||||
|
$rec_count=0;
|
||||||
|
while ($sthArows > $rec_count)
|
||||||
|
{
|
||||||
|
$AGILOG = '0';
|
||||||
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$DBagi_output = "$aryA[0]";
|
||||||
|
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
|
||||||
|
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
|
||||||
|
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
|
||||||
|
$rec_count++;
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
{
|
{
|
||||||
if ($V) {print STDERR "Perl Environment Dump:\n";}
|
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($#ARGV >= $i)
|
while ($#ARGV >= $i)
|
||||||
{
|
{
|
||||||
$args = "$args $ARGV[$i]";
|
$args = "$args $ARGV[$i]";
|
||||||
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
|
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,16 +161,12 @@ if ($V) {print STDERR "Perl Environment Dump:\n";}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($V) {print "no command line options set\n";}
|
|
||||||
}
|
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
while(<STDIN>) {
|
while(<STDIN>) {
|
||||||
chomp;
|
chomp;
|
||||||
last unless length($_);
|
last unless length($_);
|
||||||
if ($V)
|
if ($AGILOG)
|
||||||
{
|
{
|
||||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||||
{
|
{
|
||||||
@@ -186,18 +200,17 @@ while(<STDIN>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($V)
|
if ($AGILOG) {$agi_string = "AGI Environment Dump:"; &agi_output;}
|
||||||
{
|
|
||||||
|
|
||||||
if ($V) {print STDERR "AGI Environment Dump:\n";}
|
foreach $i (sort keys %AGI)
|
||||||
foreach $i (sort keys %AGI) {
|
{
|
||||||
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
|
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$callerid = "\"$calleridname\" <$callerid>";
|
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|"; &agi_output;}
|
||||||
|
|
||||||
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|\n";}
|
|
||||||
|
$callerid = "\"$calleridname\" <$callerid>";
|
||||||
|
|
||||||
if ($extension =~ /h/i) {$stage = 'END';}
|
if ($extension =~ /h/i) {$stage = 'END';}
|
||||||
else {$stage = 'START';}
|
else {$stage = 'START';}
|
||||||
@@ -206,21 +219,17 @@ else {$stage = 'START';}
|
|||||||
if ($stage =~ /START/)
|
if ($stage =~ /START/)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($V) {print STDERR "\nCALL INBOUND STARTED\n";}
|
if ($AGILOG) {$agi_string = "+++++ CALL INBOUND START : |$now_date|"; &agi_output;}
|
||||||
if ($M) {print STDERR "+++++ CALL INBOUND START : |$unique_id|$channel|$extension|$type|$callerid|$now_date\n";}
|
|
||||||
|
|
||||||
# if ($channel =~ /^SIP/) {$channel =~ s/-.*//gi;}
|
# if ($channel =~ /^SIP/) {$channel =~ s/-.*//gi;}
|
||||||
# if ($channel =~ /^Zap\//) {$channel =~ s/-\d$//gi;}
|
# if ($channel =~ /^Zap\//) {$channel =~ s/-\d$//gi;}
|
||||||
|
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
$stmtA = "INSERT INTO live_inbound (uniqueid,channel,server_ip,caller_id,extension,phone_ext,start_time,inbound_number,comment_a,comment_b,comment_c,comment_d,comment_e) values('$unique_id','$channel','$VARserver_ip','$callerid','$extension','$phone_ext','$now_date','$inbound_number','$comment_a','$comment_b','$comment_c','$comment_d','$comment_e')";
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||||
|
|
||||||
$stmtA = "INSERT INTO live_inbound (uniqueid,channel,server_ip,caller_id,extension,phone_ext,start_time,inbound_number,comment_a,comment_b,comment_c,comment_d,comment_e) values('$unique_id','$channel','$server_ip','$callerid','$extension','$phone_ext','$now_date','$inbound_number','$comment_a','$comment_b','$comment_c','$comment_d','$comment_e')";
|
|
||||||
if ($V) {print STDERR "\n|$stmtA|\n";}
|
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
|
|
||||||
$stmtA = "INSERT INTO live_inbound_log (uniqueid,channel,server_ip,caller_id,extension,phone_ext,start_time,inbound_number,comment_a,comment_b,comment_c,comment_d,comment_e) values('$unique_id','$channel','$server_ip','$callerid','$extension','$phone_ext','$now_date','$inbound_number','$comment_a','$comment_b','$comment_c','$comment_d','$comment_e')";
|
$stmtA = "INSERT INTO live_inbound_log (uniqueid,channel,server_ip,caller_id,extension,phone_ext,start_time,inbound_number,comment_a,comment_b,comment_c,comment_d,comment_e) values('$unique_id','$channel','$VARserver_ip','$callerid','$extension','$phone_ext','$now_date','$inbound_number','$comment_a','$comment_b','$comment_c','$comment_d','$comment_e')";
|
||||||
if ($V) {print STDERR "\n|$stmtA|\n";}
|
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
@@ -230,23 +239,15 @@ if ($stage =~ /START/)
|
|||||||
### call end stage
|
### call end stage
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if ($AGILOG) {$agi_string = "CALL INBOUND HUNG UP; deleting live_inbound record for $unique_id"; &agi_output;}
|
||||||
|
|
||||||
if ($V) {print STDERR "\nCALL INBOUND HUNG UP\n";}
|
$stmtA = "DELETE from live_inbound where uniqueid='$unique_id' and server_ip='$VARserver_ip'";
|
||||||
|
|
||||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
|
||||||
|
|
||||||
if ($V) {print STDERR "\nCONNECTED: deleting live_inbound record for $unique_id on $server_ip\n";}
|
|
||||||
|
|
||||||
$stmtA = "DELETE from live_inbound where uniqueid='$unique_id' and server_ip='$server_ip'";
|
|
||||||
$affected_rows = $dbhA->do($stmtA);
|
$affected_rows = $dbhA->do($stmtA);
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
|
|
||||||
|
if ($AGILOG) {$agi_string = "+++++ CALL INBOUND HUNGUP: |$unique_id|$affected_rows|"; &agi_output;}
|
||||||
if ($M) {print STDERR "+++++ CALL INBOUND HUNGUP: |$unique_id|$affected_rows|\n";}
|
|
||||||
}
|
}
|
||||||
if ($V) {print STDERR "\nAll Done Call Inbound Exiting:\n";}
|
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
@@ -272,3 +273,20 @@ sub checkresult {
|
|||||||
$fail++;
|
$fail++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub agi_output
|
||||||
|
{
|
||||||
|
if ($AGILOG >=2)
|
||||||
|
{
|
||||||
|
### open the log file for writing ###
|
||||||
|
open(Lout, ">>$AGILOGfile")
|
||||||
|
|| die "Can't open $AGILOGfile: $!\n";
|
||||||
|
print Lout "$now_date|$script|$agi_string\n";
|
||||||
|
close(Lout);
|
||||||
|
}
|
||||||
|
### send to STDERR writing ###
|
||||||
|
if ( ($AGILOG == '1') || ($AGILOG == '3') )
|
||||||
|
{print STDERR "$now_date|$script|$agi_string\n";}
|
||||||
|
$agi_string='';
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user