update of call_log scripts to use /etc/astguiclient.conf for configs and DBI instead of Net

git-svn-id: svn://192.168.202.10@84 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2006-07-18 21:25:00 +00:00
parent b955c14b76
commit e86220876b
2 changed files with 199 additions and 118 deletions
+99 -63
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# call_log.agi version 0.8
# call_log.agi version 0.9 *DBI-version*
#
# runs at the beginning and ending of every external call made and received
#
@@ -18,27 +18,17 @@
#
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
#
# changes
#
# CHANGES
# 60311-1309 - Fixed CallerID/name for VICIDIAL calls
# 60315-1020 - Added MySQL query fail debug print output
# 60622-0956 - Altered log for Zap client phones for consistent output
# 60718-1638 - changed to use DBI-DBD::mysql
# - changed to use /etc/astguiclient.conf for configs
#
$V = 0; # 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
# Customized Variables <depricated, set in AST_SERVER_conf.pl>
#$server_ip = '10.10.11.14'; # Asterisk server IP
#$DB_server = '10.10.11.10'; # MySQL server IP
#$DB_database = 'asterisk'; # MySQL database name
#$DB_user = 'astcron'; # MySQL user
#$DB_pass = 'astcron'; # MySQL pass
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
@@ -53,6 +43,49 @@ $now_date = "$year-$mon-$mday $hour:$min:$sec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
if (!$VARDB_port) {$VARDB_port='3306';}
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
@@ -174,12 +207,10 @@ else {$stage = 'START';}
### call start stage
if ($stage =~ /START/)
{
use Net::MySQL;
use DBI;
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";
$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 "\nCALL STARTED\n";}
if ($M) {print STDERR "+++++ CALL LOG START : |$unique_id|$channel|$extension|$type|$callerid|$now_date\n";}
@@ -191,14 +222,16 @@ if ($stage =~ /START/)
$channel_line = $channel;
$channel_line =~ s/^Zap\///gi;
$dbh->query("SELECT count(*) FROM phones where server_ip='$server_ip' and extension='$channel_line' and protocol='Zap';");
if ($dbh->has_selected_record) {
$iter=$dbh->create_record_iterator;
while ( $record = $iter->each) {
$is_client_phone = "$record->[0]";
$stmtA = "SELECT count(*) FROM phones where server_ip='$server_ip' and extension='$channel_line' and protocol='Zap';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@aryA = $sthA->fetchrow_array;
if($DB){print STDERR $aryA[0]," NEW Actions to send on server $server_ip $endless_loop\n";}
$is_client_phone = "$aryA[0]";
$sthA->finish();
if ($V) {print STDERR "$is_client_phone|$channel_line|\n";}
}
}
if ($is_client_phone < 1)
{
$channel_group = 'Zap Trunk Line';
@@ -232,9 +265,9 @@ if ($stage =~ /START/)
$stmtA = "INSERT INTO call_log (uniqueid,channel,channel_group,type,server_ip,extension,number_dialed,start_time,start_epoch,end_time,end_epoch,length_in_sec,length_in_min,caller_code) values('$unique_id','$channel','$channel_group','$type','$server_ip','$extension','$number_dialed','$now_date','$now_date_epoch','','','','','$callerid')";
if ($V) {print STDERR "\n|$stmtA|\n";}
$dbh->query($stmtA) or die "Couldn't execute query: |$stmtA|\n";
$affected_rows = $dbhA->do($stmtA);
$dbh->close;
$dbhA->disconnect();
}
@@ -244,27 +277,27 @@ else
if ($V) {print STDERR "\nCALL HUNG UP\n";}
use Net::MySQL;
use DBI;
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";
$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\n";}
$dbh->query("SELECT uniqueid,start_epoch FROM call_log where uniqueid='$unique_id'");
if ($dbh->has_selected_record) {
$iter=$dbh->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each) {
if ($V) {print STDERR $record->[0],"|", $record->[1],"\n";}
$start_time = "$record->[1]";
$rec_count++;
}
}
### get uniqueid and start_epoch from the call_log table
$stmtA = "SELECT uniqueid,start_epoch FROM call_log where uniqueid='$unique_id';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$start_time = "$aryA[1]";
if ($V) {print STDERR $aryA[0],"|", $aryA[1],"\n";}
$rec_count++;
}
$sthA->finish();
if ($rec_count)
{
@@ -277,26 +310,28 @@ else
$stmtA = "UPDATE call_log set end_time='$now_date',end_epoch='$now_date_epoch',length_in_sec=$length_in_sec,length_in_min='$length_in_min' where uniqueid='$unique_id'";
if ($V) {print STDERR "\n|$stmtA|\n";}
$dbh->query($stmtA) or die "Couldn't execute query: |$stmtA|\n";
$affected_rows = $dbhA->do($stmtA);
}
$stmtA = "DELETE from live_inbound where uniqueid='$unique_id' and server_ip='$server_ip'";
$dbh->query($stmtA);
# $dbh->query($stmtA) or die "NO LIVE_INBOUND_ENTRY: |$stmtA|\n";
if ($V) {print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
$dbh->query("SELECT UNIX_TIMESTAMP(parked_time),UNIX_TIMESTAMP(grab_time) FROM park_log where uniqueid='$unique_id' and server_ip='$server_ip' LIMIT 1");
$rec_count=0;
if ($dbh->has_selected_record) {
$iter=$dbh->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each) {
if ($V) {print STDERR $record->[0],"|", $record->[1],"\n";}
$parked_time = "$record->[0]";
$grab_time = "$record->[1]";
$rec_count++;
}
}
##### BEGIN Park Log entry check and update #####
$stmtA = "SELECT UNIX_TIMESTAMP(parked_time),UNIX_TIMESTAMP(grab_time) FROM park_log where uniqueid='$unique_id' and server_ip='$server_ip' LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$parked_time = "$aryA[0]";
$grab_time = "$aryA[1]";
if ($V) {print STDERR $aryA[0],"|", $aryA[1],"\n";}
$rec_count++;
}
$sthA->finish();
if ($rec_count)
{
@@ -313,11 +348,12 @@ else
}
$stmtA = "UPDATE park_log set status='HUNGUP',hangup_time='$now_date',parked_sec='$parked_sec',talked_sec='$talked_sec' where uniqueid='$unique_id' and server_ip='$server_ip'";
$dbh->query($stmtA) or die "NO PARK_LOG_ENTRY: |$stmtA|\n";
$affected_rows = $dbhA->do($stmtA);
}
# else {print STDERR "*****No entry found for $unique_id-$server_ip in park_log\n";}
##### END Park Log entry check and update #####
$dbh->close;
$dbhA->disconnect();
if ($M) {print STDERR "+++++ CALL LOG HUNGUP: |$unique_id|$channel|$extension|$now_date|min: $length_in_min|\n";}
}
+100 -55
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# call_log.agi version 0.6
# call_log.agi version 0.7 *DBI-version*
#
# runs at the beginning and ending of every external call made and received
#
@@ -18,18 +18,15 @@
#
# Copyright (C) 2006 Matt Florell <vicidial@gmail.com> LICENSE: GPLv2
#
# changes
#
# CHANGES
# 60622-0957 - Altered log for Zap client phones for consistent output
# 60718-1638 - changed to use DBI-DBD::mysql
# - changed to use /etc/astguiclient.conf for configs
#
$V = 0; # 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++;
@@ -44,6 +41,52 @@ $now_date = "$year-$mon-$mday $hour:$min:$sec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
if (!$VARDB_port) {$VARDB_port='3306';}
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
@@ -155,12 +198,10 @@ else {$stage = 'START';}
### call start stage
if ($stage =~ /START/)
{
use Net::MySQL;
use DBI;
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";
$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 "\nCALL STARTED\n";}
if ($M) {print STDERR "+++++ CALL LOG START : |$unique_id|$channel|$extension|$type|$callerid|$now_date\n";}
@@ -173,14 +214,16 @@ if ($stage =~ /START/)
$channel_line = $channel;
$channel_line =~ s/^Zap\///gi;
$dbh->query("SELECT count(*) FROM phones where server_ip='$server_ip' and extension='$channel_line' and protocol='Zap';");
if ($dbh->has_selected_record) {
$iter=$dbh->create_record_iterator;
while ( $record = $iter->each) {
$is_client_phone = "$record->[0]";
$stmtA = "SELECT count(*) FROM phones where server_ip='$server_ip' and extension='$channel_line' and protocol='Zap';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@aryA = $sthA->fetchrow_array;
if($DB){print STDERR $aryA[0]," NEW Actions to send on server $server_ip $endless_loop\n";}
$is_client_phone = "$aryA[0]";
$sthA->finish();
if ($V) {print STDERR "$is_client_phone|$channel_line|\n";}
}
}
if ($is_client_phone < 1)
{
$channel_group = 'Zap Trunk Line';
@@ -214,9 +257,9 @@ if ($stage =~ /START/)
$stmtA = "INSERT INTO call_log (uniqueid,channel,channel_group,type,server_ip,extension,number_dialed,start_time,start_epoch,end_time,end_epoch,length_in_sec,length_in_min,caller_code) values('$unique_id','$channel','$channel_group','$type','$server_ip','$extension','$number_dialed','$now_date','$now_date_epoch','','','','','$calleridname')";
if ($V) {print STDERR "\n|$stmtA|\n";}
$dbh->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA);
$dbh->close;
$dbhA->disconnect();
}
@@ -226,27 +269,27 @@ else
if ($V) {print STDERR "\nCALL HUNG UP\n";}
use Net::MySQL;
use DBI;
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";
$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\n";}
$dbh->query("SELECT uniqueid,start_epoch FROM call_log where uniqueid='$unique_id'");
if ($dbh->has_selected_record) {
$iter=$dbh->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each) {
if ($V) {print STDERR $record->[0],"|", $record->[1],"\n";}
$start_time = "$record->[1]";
$rec_count++;
}
}
### get uniqueid and start_epoch from the call_log table
$stmtA = "SELECT uniqueid,start_epoch FROM call_log where uniqueid='$unique_id';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$start_time = "$aryA[1]";
if ($V) {print STDERR $aryA[0],"|", $aryA[1],"\n";}
$rec_count++;
}
$sthA->finish();
if ($rec_count)
{
@@ -259,26 +302,28 @@ else
$stmtA = "UPDATE call_log set end_time='$now_date',end_epoch='$now_date_epoch',length_in_sec=$length_in_sec,length_in_min='$length_in_min' where uniqueid='$unique_id'";
if ($V) {print STDERR "\n|$stmtA|\n";}
$dbh->query($stmtA) or die "Couldn't execute query:\n";
$affected_rows = $dbhA->do($stmtA);
}
$stmtA = "DELETE from live_inbound where uniqueid='$unique_id' and server_ip='$server_ip'";
$dbh->query($stmtA);
# $dbh->query($stmtA) or die "NO LIVE_INBOUND_ENTRY:\n";
if ($V) {print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
##### BEGIN Park Log entry check and update #####
$dbh->query("SELECT UNIX_TIMESTAMP(parked_time),UNIX_TIMESTAMP(grab_time) FROM park_log where uniqueid='$unique_id' and server_ip='$server_ip' LIMIT 1");
$rec_count=0;
if ($dbh->has_selected_record) {
$iter=$dbh->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each) {
if ($V) {print STDERR $record->[0],"|", $record->[1],"\n";}
$parked_time = "$record->[0]";
$grab_time = "$record->[1]";
$rec_count++;
}
}
$stmtA = "SELECT UNIX_TIMESTAMP(parked_time),UNIX_TIMESTAMP(grab_time) FROM park_log where uniqueid='$unique_id' and server_ip='$server_ip' LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$parked_time = "$aryA[0]";
$grab_time = "$aryA[1]";
if ($V) {print STDERR $aryA[0],"|", $aryA[1],"\n";}
$rec_count++;
}
$sthA->finish();
if ($rec_count)
{
@@ -295,12 +340,12 @@ else
}
$stmtA = "UPDATE park_log set status='HUNGUP',hangup_time='$now_date',parked_sec='$parked_sec',talked_sec='$talked_sec' where uniqueid='$unique_id' and server_ip='$server_ip'";
$dbh->query($stmtA) or die "NO PARK_LOG_ENTRY:\n";
$affected_rows = $dbhA->do($stmtA);
}
# else {print STDERR "*****No entry found for $unique_id-$server_ip in park_log\n";}
##### END Park Log entry check and update #####
$dbh->close;
$dbhA->disconnect();
if ($M) {print STDERR "+++++ CALL LOG HUNGUP: |$unique_id|$channel|$extension|$now_date|min: $length_in_min|\n";}
}