updated VD_amd.agi to use /etc/astguiclient.conf and DBI
fixed errors in other AGI scripts git-svn-id: svn://192.168.202.10@98 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
+101
-53
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# VD_amd.agi version 0.3
|
||||
# VD_amd.agi version 0.4 *DBI-version*
|
||||
#
|
||||
# NOTE: This script is only needed with app_amd enabled systems
|
||||
#
|
||||
@@ -25,6 +25,9 @@
|
||||
# 60206-1434 first build
|
||||
# 60207-1205 added database records entries/modifications
|
||||
# 60207-1507 added ability to send AMs to campaign-defined message to leave
|
||||
# 60731-1407 - changed to use DBI-DBD::mysql
|
||||
# - changed to use /etc/astguiclient.conf for configs
|
||||
#
|
||||
|
||||
|
||||
$V = 0; # set to 1 for verbose mode
|
||||
@@ -32,10 +35,50 @@ $M = 0; # set to 1 for 2 line messages mode
|
||||
$A = 1; # set to 1 for AMD output messages mode
|
||||
$AMD_LOG = 1; # set to 1 for logfile
|
||||
|
||||
### 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
|
||||
# default path to astguiclient configuration file:
|
||||
$PATHconf = '/etc/astguiclient.conf';
|
||||
|
||||
use Net::MySQL;
|
||||
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
|
||||
@conf = <conf>;
|
||||
close(conf);
|
||||
$i=0;
|
||||
foreach(@conf)
|
||||
{
|
||||
$line = $conf[$i];
|
||||
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
|
||||
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
|
||||
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
|
||||
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
|
||||
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
|
||||
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
|
||||
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
|
||||
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
|
||||
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
|
||||
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
|
||||
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
|
||||
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
|
||||
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
|
||||
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
|
||||
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
|
||||
$i++;
|
||||
}
|
||||
|
||||
# Customized Variables
|
||||
$server_ip = $VARserver_ip; # Asterisk server IP
|
||||
|
||||
if (!$VARDB_port) {$VARDB_port='3306';}
|
||||
|
||||
use DBI;
|
||||
use Asterisk::AGI;
|
||||
$AGI = new Asterisk::AGI;
|
||||
|
||||
@@ -194,8 +237,8 @@ if ($A) {print STDERR "AAAAA AMD results: |$AMDSTATUS|$AMDCAUSE|\n";}
|
||||
|
||||
if ($AMD_LOG)
|
||||
{
|
||||
open(Lout, ">>/home/cron/AMD_log.txt")
|
||||
|| die "Can't open /home/cron/AMD_log.txt: $!\n";
|
||||
open(Lout, ">>$PATHlogs/AMD_log.txt")
|
||||
|| die "Can't open $PATHlogs/AMD_log.txt: $!\n";
|
||||
print Lout "$now_date|$VD_lead_id| |$AMDSTATUS|$AMDCAUSE|$calleridnum|\n";
|
||||
close(Lout);
|
||||
}
|
||||
@@ -214,98 +257,105 @@ else
|
||||
################################################################################
|
||||
########## AMD says it's a machine so modify statuses and hangup call ##########
|
||||
########## something will go here later for leaving a message on AMs ##########
|
||||
if (!$DB_port) {$DB_port='3306';}
|
||||
|
||||
my $dbhA = Net::MySQL->new(hostname=>"$DB_server", database=>"$DB_database", user=>"$DB_user", password=>"$DB_pass", port => "$DB_port") or die "Couldn't connect to database: $DB_server - $DB_database\n";
|
||||
$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 ext_context from the servers table ##########
|
||||
$stmtA = "SELECT ext_context FROM servers where server_ip = '$server_ip';";
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$rec_count=0;
|
||||
while ($sthArows > $rec_count)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$DBext_context = "$record->[1]";
|
||||
if ($DBext_context) {$ext_context = $DBext_context;}
|
||||
}
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$DBext_context = "$aryA[0]";
|
||||
if ($DBext_context) {$ext_context = $DBext_context;}
|
||||
$rec_count++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
|
||||
########## FIND vicidial_auto_calls record ##########
|
||||
$stmtA = "SELECT campaign_id,phone_code,phone_number FROM vicidial_auto_calls where callerid='$callerid' order by auto_call_id desc limit 1;";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
$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)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$VD_campaign_id = "$record->[0]";
|
||||
$VD_phone_code = "$record->[1]";
|
||||
$VD_phone_number = "$record->[2]";
|
||||
}
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$VD_campaign_id = "$aryA[0]";
|
||||
$VD_phone_code = "$aryA[1]";
|
||||
$VD_phone_number = "$aryA[2]";
|
||||
$rec_count++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
|
||||
########## UPDATE vicidial_list ##########
|
||||
$stmtA = "UPDATE vicidial_list set status='A' where lead_id = '$VD_lead_id';";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
if ($M) {print STDERR "-- VDAD vicidial_list update: |$affected_rows|$VD_lead_id\n";}
|
||||
|
||||
########## DELETE vicidial_auto_calls entry ##########
|
||||
$stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' order by auto_call_id desc limit 1;";
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
if ($M) {print STDERR "-- VDAC record deleted: |$affected_rows| |$VD_lead_id|$uniqueid|$VD_callerid|$server_ip\n";}
|
||||
|
||||
########## FIND AND UPDATE vicidial_log ##########
|
||||
$stmtA = "SELECT start_epoch FROM vicidial_log where uniqueid='$uniqueid' and lead_id='$VD_lead_id' order by call_date desc limit 1;";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$epc_countCUSTDATA=0;
|
||||
if ($dbhA->has_selected_record)
|
||||
while ($sthArows > $epc_countCUSTDATA)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$VD_start_epoch = "$record->[0]";
|
||||
$epc_countCUSTDATA++;
|
||||
}
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$VD_start_epoch = "$aryA[0]";
|
||||
$epc_countCUSTDATA++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if (!$epc_countCUSTDATA)
|
||||
{
|
||||
if($M){print STDERR "\nVD amd: no VDL record found: $uniqueid $calleridname $VD_lead_id $uniqueid\n";}
|
||||
$end_epoch = ($now_date_epoch + 3);
|
||||
$stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed,length_in_sec,end_epoch) values('$uniqueid','$VD_lead_id','$VD_campaign_id','$now_date','$now_date_epoch','A','$VD_phone_code','$VD_phone_number','VDAD','N','3','$end_epoch')";
|
||||
if($M){print STDERR "\n|$stmtA|\n";}
|
||||
$dbhA->query($stmtA);
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
}
|
||||
else
|
||||
{
|
||||
$VD_seconds = ($now_date_epoch - $VD_start_epoch);
|
||||
$stmtA = "UPDATE vicidial_log set status='A',end_epoch='$now_date_epoch',length_in_sec='$VD_seconds' where uniqueid='$uniqueid' and lead_id='$VD_lead_id' order by call_date desc limit 1;";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
if ($M) {print STDERR "-- VDAD vicidial_log update: |$affected_rows|$uniqueid|\n";}
|
||||
}
|
||||
|
||||
|
||||
### Grab vmail forward message values from the database
|
||||
$stmtA = "SELECT am_message_exten,amd_send_to_vmx FROM vicidial_campaigns where campaign_id = '$VD_campaign_id';";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
if ($dbhA->has_selected_record)
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$epc_countCUSTDATA=0;
|
||||
while ($sthArows > $epc_countCUSTDATA)
|
||||
{
|
||||
$iter=$dbhA->create_record_iterator;
|
||||
while ( $record = $iter->each)
|
||||
{
|
||||
$DB_am_message_exten = "$record->[0]";
|
||||
$DB_amd_send_to_vmx = "$record->[1]";
|
||||
}
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$DB_am_message_exten = "$aryA[0]";
|
||||
$DB_amd_send_to_vmx = "$aryA[1]";
|
||||
$epc_countCUSTDATA++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
if ($M) {print STDERR "-- AMD campaign values: |$VD_campaign_id|$DB_am_message_exten|$DB_amd_send_to_vmx|\n";}
|
||||
|
||||
@@ -313,14 +363,12 @@ if ( ($DB_amd_send_to_vmx =~ /Y/) && (length($DB_am_message_exten) > 0) )
|
||||
{
|
||||
$stmtA = "UPDATE vicidial_log set status='AM' where uniqueid='$uniqueid' and lead_id='$VD_lead_id' order by call_date desc limit 1;";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
if ($M) {print STDERR "-- VDAD vicidial_log AM update: |$affected_rows|$uniqueid|\n";}
|
||||
|
||||
$stmtA = "UPDATE vicidial_list set status='AM' where lead_id='$VD_lead_id';";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$dbhA->query("$stmtA");
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
if ($M) {print STDERR "-- VDAD vicidial_list AM update: |$affected_rows|$uniqueid|\n";}
|
||||
|
||||
print STDERR "\nexiting the AMD app, transferring call to $DB_am_message_exten";
|
||||
|
||||
@@ -248,7 +248,6 @@ if ($M) {print STDERR "-- VDAD vicidial_log AM update: |$affected_rows|$uniqu
|
||||
$stmtA = "UPDATE vicidial_list set status='AL' where lead_id='$VD_lead_id';";
|
||||
if($M){print STDERR "\n\n|$stmtA|\n";}
|
||||
$affected_rows = $dbhA->do($stmtA);
|
||||
my $affected_rows = $dbhA->get_affected_rows_length;
|
||||
if ($M) {print STDERR "-- VDAD vicidial_list AM update: |$affected_rows|$uniqueid|\n";}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -284,7 +284,7 @@ $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$rec_countCUSTDATA=0;
|
||||
while ($sthArows > $rec_count)
|
||||
while ($sthArows > $rec_countCUSTDATA)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$VD_lead_id = "$aryA[0]";
|
||||
@@ -312,7 +312,7 @@ $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$epc_countCUSTDATA=0;
|
||||
$VD_closecallid='';
|
||||
while ($sthArows > $rec_count)
|
||||
while ($sthArows > $rec_countCUSTDATA)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$VD_start_epoch = "$aryA[0]";
|
||||
@@ -344,7 +344,7 @@ if (!$epc_countCUSTDATA)
|
||||
$sthArows=$sthA->rows;
|
||||
$epc_countCUSTDATA=0;
|
||||
$VD_closecallid='';
|
||||
while ($sthArows > $rec_count)
|
||||
while ($sthArows > $rec_countCUSTDATA)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
$VD_start_epoch = "$aryA[0]";
|
||||
|
||||
Reference in New Issue
Block a user