1.1.10 release
git-svn-id: svn://192.168.202.10@1 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# call_park.agi
|
||||
#
|
||||
# runs when a call is to be parked for pickup of customer service
|
||||
#
|
||||
# You need to put lines similar to those below in your extensions.conf file:
|
||||
#
|
||||
# ;inbound calls:
|
||||
# exten => 101,1,AGI(call_park.agi,IN_800_TPP_CS-----8775154104-----Inbound TPP 800 CS-----park-----HANGUP----------)
|
||||
#
|
||||
#
|
||||
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
|
||||
#
|
||||
|
||||
$V = 1; # set to 1 for verbose mode
|
||||
$M = 1; # set to 1 for 2 line messages mode
|
||||
|
||||
### Make sure this file is in a path or put the absolute path to it
|
||||
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
|
||||
|
||||
|
||||
($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";
|
||||
|
||||
|
||||
|
||||
### begin parsing run-time options ###
|
||||
if (length($ARGV[0])>1)
|
||||
{
|
||||
if ($V) {print STDERR "Perl Environment Dump:\n";}
|
||||
$i=0;
|
||||
while ($#ARGV >= $i)
|
||||
{
|
||||
$args = "$args $ARGV[$i]";
|
||||
if ($V) {print STDERR "$i|$ARGV[$i]|\n";}
|
||||
$i++;
|
||||
}
|
||||
|
||||
### list of command-line array arguments:
|
||||
@ARGV_vars = split(/-----/, $ARGV[0]);
|
||||
|
||||
$channel_group = $ARGV_vars[0];
|
||||
$inbound_number = $ARGV_vars[1];
|
||||
$parked_by = $ARGV_vars[2];
|
||||
$park_extension = $ARGV_vars[3];
|
||||
$status = $ARGV_vars[4];
|
||||
$comment_d = $ARGV_vars[5];
|
||||
$comment_e = $ARGV_vars[6];
|
||||
|
||||
|
||||
if ($args =~ /--help/i)
|
||||
{
|
||||
print "allowed run time options:\n [-q] = quiet\n [-t] = test\n [-debug] = verbose debug messages\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($args =~ /-V/i)
|
||||
{
|
||||
$V=1;
|
||||
}
|
||||
if ($args =~ /-debug/i)
|
||||
{
|
||||
$DG=1;
|
||||
}
|
||||
if ($args =~ /-dbAVS/i)
|
||||
{
|
||||
$DGA=1;
|
||||
}
|
||||
if ($args =~ /-q/i)
|
||||
{
|
||||
$q=1;
|
||||
$Q=1;
|
||||
}
|
||||
if ($args =~ /-t/i)
|
||||
{
|
||||
$TEST=1;
|
||||
$T=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($V) {print "no command line options set\n";}
|
||||
}
|
||||
|
||||
$|=1;
|
||||
while(<STDIN>) {
|
||||
chomp;
|
||||
last unless length($_);
|
||||
if ($V)
|
||||
{
|
||||
if (/^agi_(\w+)\:\s+(.*)$/)
|
||||
{
|
||||
$AGI{$1} = $2;
|
||||
}
|
||||
}
|
||||
|
||||
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1;}
|
||||
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 ( (!$callerid) or ($callerid =~ /unknown/) )
|
||||
{$callerid = $calleridname;}
|
||||
|
||||
### allow for ANI being sent with the DNIS "*3125551212*9999*"
|
||||
if ($extension =~ /^\*\d\d\d\d\d\d\d\d\d\d\*/)
|
||||
{
|
||||
$callerid = $extension;
|
||||
$callerid =~ s/\*\d\d\d\d\*$//gi;
|
||||
$callerid =~ s/\*\d\d\d\d$//gi;
|
||||
$callerid =~ s/^\*//gi;
|
||||
$extension =~ s/^\*\d\d\d\d\d\d\d\d\d\d\*//gi;
|
||||
$extension =~ s/\*$//gi;
|
||||
|
||||
### set the callerid if sent with DNIS
|
||||
print "SET CALLERID $callerid\n";
|
||||
checkresult($result);
|
||||
}
|
||||
}
|
||||
|
||||
if ($V)
|
||||
{
|
||||
|
||||
if ($V) {print STDERR "AGI Environment Dump:\n";}
|
||||
foreach $i (sort keys %AGI) {
|
||||
if ($V) {print STDERR " -- $i = $AGI{$i}\n";}
|
||||
}
|
||||
}
|
||||
|
||||
if ($V) {print STDERR "AGI Environment Dump: |$unique_id|$channel|$extension|$type|$callerid|\n";}
|
||||
|
||||
if ($extension =~ /h/i) {$stage = 'END';}
|
||||
else {$stage = 'START';}
|
||||
|
||||
### call start stage
|
||||
if ($status !~ /HANGUP/)
|
||||
{
|
||||
|
||||
if ($V) {print STDERR "\nCALL PARK STARTED\n";}
|
||||
if ($M) {print STDERR "+++++ CALL PARK START : |$unique_id|$channel|$extension|$type|$callerid|$now_date\n";}
|
||||
|
||||
if ($channel =~ /^SIP/) {$channel =~ s/-.*//gi;}
|
||||
# if ($channel =~ /^Zap\//) {$channel =~ s/-\d$//gi;}
|
||||
|
||||
use Net::MySQL;
|
||||
|
||||
if (!$DB_port) {$DB_port='3306';}
|
||||
|
||||
my $mysql = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
|
||||
|
||||
|
||||
$stmtA = "INSERT INTO parked_channels (channel,server_ip,channel_group,extension,parked_by,parked_time) values('$channel','$server_ip','$channel_group','$park_extension','$callerid','$now_date')";
|
||||
if ($V) {print STDERR "\n|$stmtA|\n";}
|
||||
$mysql->query($stmtA) or die "Couldn't execute query:\n";
|
||||
|
||||
|
||||
$stmtA = "INSERT INTO park_log (uniqueid,status,channel,server_ip,parked_time,channel_group) values('$unique_id','PARKED','$channel','$server_ip','$now_date','$channel_group')";
|
||||
if ($V) {print STDERR "\n|$stmtA|\n";}
|
||||
$mysql->query($stmtA) or die "Couldn't execute query:\n";
|
||||
|
||||
$mysql->close;
|
||||
}
|
||||
|
||||
|
||||
### call end stage
|
||||
else
|
||||
{
|
||||
|
||||
if ($V) {print STDERR "\nCALL INBOUND HUNG UP\n";}
|
||||
|
||||
use Net::MySQL;
|
||||
|
||||
if (!$DB_port) {$DB_port='3306';}
|
||||
|
||||
my $dbh = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
|
||||
|
||||
|
||||
if ($V) {print STDERR "\nCONNECTED: deleting parked_channels record for $unique_id on $server_ip\n";}
|
||||
|
||||
$stmtA = "DELETE from parked_channels where channel='$channel' and server_ip='$server_ip'";
|
||||
$dbh->query($stmtA) or die "Couldn't execute query:\n";
|
||||
$dbh->close;
|
||||
|
||||
|
||||
if ($M) {print STDERR "+++++ CALL PARK HUNGUP: |$unique_id|\n";}
|
||||
}
|
||||
if ($V) {print STDERR "\nAll Done Call Park Exiting:\n";}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user