[Astpp-commit] SF.net SVN: astpp:[2203] trunk/contrib/auto_dialer
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2008-11-08 04:36:09
|
Revision: 2203
http://astpp.svn.sourceforge.net/astpp/?rev=2203&view=rev
Author: darrenkw
Date: 2008-11-08 04:36:02 +0000 (Sat, 08 Nov 2008)
Log Message:
-----------
Make a whole bunch of improvements to the autodialer.
M auto_dialer/aleph-autocall.pl
M auto_dialer/aac.conf
M auto_dialer/aleph-aac.sql
M auto_dialer/aleph-aac.agi
M auto_dialer/Makefile
Modified Paths:
--------------
trunk/contrib/auto_dialer/Makefile
trunk/contrib/auto_dialer/aac.conf
trunk/contrib/auto_dialer/aleph-aac.agi
trunk/contrib/auto_dialer/aleph-aac.sql
trunk/contrib/auto_dialer/aleph-autocall.pl
Modified: trunk/contrib/auto_dialer/Makefile
===================================================================
--- trunk/contrib/auto_dialer/Makefile 2008-11-01 22:01:34 UTC (rev 2202)
+++ trunk/contrib/auto_dialer/Makefile 2008-11-08 04:36:02 UTC (rev 2203)
@@ -11,7 +11,8 @@
install:
mkdir -p $(DESTDIR)$(AACDIR)
- $(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 755 aac.conf $(DESTDIR)$(AACDIR)
- $(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 755 aleph-aac.agi $(DESTDIR)$(AGIDIR)
- $(INSTALL) -c -o $(OWNER) -g $(GROUP) -m 755 aleph-autocall.pl $(DESTDIR)$(BINDIR)
+ install -m 755 -o $(OWNER) -g $(GROUP) aac.conf $(DESTDIR)$(AACDIR)
+ install -m 755 -o $(OWNER) -g $(GROUP) aleph-aac.agi $(DESTDIR)$(AGIDIR)
+ install -m 755 -o $(OWNER) -g $(GROUP) aleph-autocall.pl $(DESTDIR)$(BINDIR)
+ install -m 755 -o $(OWNER) -g $(GROUP) aleph-autocall-monitor.pl $(DESTDIR)$(BINDIR)
echo "Aleph Auto Call has now been installed!"
Modified: trunk/contrib/auto_dialer/aac.conf
===================================================================
--- trunk/contrib/auto_dialer/aac.conf 2008-11-01 22:01:34 UTC (rev 2202)
+++ trunk/contrib/auto_dialer/aac.conf 2008-11-08 04:36:02 UTC (rev 2203)
@@ -14,3 +14,5 @@
total_tries = 5
maxretries = 0
maxcalls = 5
+starthour = 9
+endhour = 21
Modified: trunk/contrib/auto_dialer/aleph-aac.agi
===================================================================
--- trunk/contrib/auto_dialer/aleph-aac.agi 2008-11-01 22:01:34 UTC (rev 2202)
+++ trunk/contrib/auto_dialer/aleph-aac.agi 2008-11-08 04:36:02 UTC (rev 2203)
@@ -1,147 +1,164 @@
-#!/usr/bin/perl
-# Aleph Communications Auto Callout
-#
-# Copyright (C) 2006, Aleph Communications
-#
-# Darren Wiebe <da...@al...>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# Contact information can be found @ www.aleph-com.net
-#
-###########################################################################`
-
-use DBI;
-use Asterisk::AGI;
-use POSIX qw(ceil floor);
-use POSIX qw(strftime);
-
-sub load_config {
- my $config;
- open( CONFIG, "</var/lib/aac/aac.conf" );
- while (<CONFIG>) {
- chomp; # no newline
- s/#.*//; # no comments
- s/^\s+//; # no leading white
- s/\s+$//; # no trailing white
- next unless length; # anything left?
- my ( $var, $value ) = split( /\s*=\s*/, $_, 2 );
- $config->{$var} = $value;
- }
- close(CONFIG);
- return $config;
-}
-
-sub timestamp() {
- my $now = strftime "%Y%m%d%H%M%S", gmtime;
- return $now;
-}
-
-sub prettytimestamp() {
- my $now = strftime "%Y-%m-%d %H:%M:%S", gmtime;
- return $now;
-}
-
-sub connect_db() {
- my ( $dbh, $handle, $dsn );
- $dsn = "DBI:mysql:database=$config->{dbname};host=$config->{dbhost}";
- $dbh = DBI->connect( $dsn, $config->{dbuser}, $config->{dbpass} );
- if ( !$dbh ) {
- print STDERR "AAC DATABASE IS DOWN\n";
- exit(0);
- }
- else {
- print STDERR "Connected to AAC Database!" . "\n";
- return $dbh;
- }
-}
-
-sub set_in_use() {
- my ( $number, $status ) = @_;
- my $tmp;
- $tmp =
- "UPDATE callouts SET inuse = "
- . $aac_db->quote($status)
- . " WHERE number = "
- . $aac_db->quote( $number );
- $aac_db->do($tmp);
-}
-
-sub set_timestamp() {
- my ( $number, $timestamp ) = @_;
- my $tmp;
- $tmp =
- "UPDATE callouts SET lasttry = "
- . $aac_db->quote($timestamp)
- . " WHERE number = "
- . $aac_db->quote( $number );
- $aac_db->do($tmp);
-}
-
-sub mark_answered() {
- my ( $number ) = @_;
- my $tmp;
- $tmp =
- "UPDATE callouts SET answered = 1 WHERE number = "
- . $aac_db->quote( $number );
- $aac_db->do($tmp);
-}
-
-sub get_file_to_play() {
- my ($number) = @_;
- my ($tmp,$row);
- $tmp = "SELECT * FROM callouts WHERE number = "
- . $aac_db->quote( $number )
- . " LIMIT 1";
- $sql = $aac_db->prepare($tmp);
- $sql->execute;
- $row = $sql->fetch_hashref;
- $sql->finish;
- return $row->{sound_file};
-}
-
-sub ignore_hup {
- foreach $handle (@output) {
- print $handle "HUP received\n";
- }
-}
-
-
-######################################################################
-# Beginning of Program
-######################################################################
-my ( $number ) = @ARGV;
-
-$verbosity = 2;
-$AGI = new Asterisk::AGI;
-
-my $config = &load_config();
-my $aac_db = &connect_db();
-$SIG{HUP} = 'ignore_hup';
-
-$AGI->answer();
-
-#&set_in_use($number,1);
-
-my $sound_file = &get_file_to_play($number);
-
-$AGI->stream_file($sound_file);
-
-&set_in_use($number,0);
-my $timestamp = ×tamp;
-&set_timestamp($number,$timestamp);
-
-&mark_answered($number);
-
-exit(0);
+#!/usr/bin/perl
+# Auto Callout
+#
+# Copyright (C) 2006, Aleph Communications
+#
+# Darren Wiebe <da...@al...>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Contact information can be found @ www.aleph-com.net
+#
+###########################################################################`
+
+use DBI;
+use Asterisk::AGI;
+use POSIX qw(ceil floor);
+use POSIX qw(strftime);
+$AGI = new Asterisk::AGI;
+
+sub load_config {
+ my $config;
+ open( CONFIG, "</var/lib/aac/aac.conf" );
+ while (<CONFIG>) {
+ chomp; # no newline
+ s/#.*//; # no comments
+ s/^\s+//; # no leading white
+ s/\s+$//; # no trailing white
+ next unless length; # anything left?
+ my ( $var, $value ) = split( /\s*=\s*/, $_, 2 );
+ $config->{$var} = $value;
+ }
+ close(CONFIG);
+ return $config;
+}
+
+sub timestamp() {
+ my $now = strftime "%Y%m%d%H%M%S", gmtime;
+ return $now;
+}
+
+sub prettytimestamp() {
+ my $now = strftime "%Y-%m-%d %H:%M:%S", gmtime;
+ return $now;
+}
+
+sub connect_db() {
+ my ( $dbh, $handle, $dsn );
+ $dsn = "DBI:mysql:database=$config->{dbname};host=$config->{dbhost}";
+ $dbh = DBI->connect( $dsn, $config->{dbuser}, $config->{dbpass} );
+ if ( !$dbh ) {
+ print STDERR "AAC DATABASE IS DOWN\n";
+ $AGI->verbose( "AAC DATABASE IS DOWN\n" , $verbose);
+ exit(0);
+ }
+ else {
+ print STDERR "Connected to AAC Database!" . "\n";
+ $AGI->verbose( "Connected to AAC Database!" , $verbose );
+ return $dbh;
+ }
+}
+
+sub set_in_use() {
+ my ( $id, $status ) = @_;
+ my $tmp;
+ $tmp =
+ "UPDATE callouts SET inuse = "
+ . $aac_db->quote($status)
+ . " WHERE id = "
+ . $aac_db->quote( $id );
+ $aac_db->do($tmp);
+}
+
+sub set_timestamp() {
+ my ( $id, $timestamp ) = @_;
+ my $tmp;
+ $tmp =
+ "UPDATE callouts SET lasttry = "
+ . $aac_db->quote($timestamp)
+ . " WHERE id = "
+ . $aac_db->quote( $id );
+ $aac_db->do($tmp);
+}
+
+sub mark_answered() {
+ my ( $id ) = @_;
+ my $tmp;
+ $tmp =
+ "UPDATE callouts SET answered = 1 WHERE id = "
+ . $aac_db->quote( $id );
+ $aac_db->do($tmp);
+}
+
+sub get_data() {
+ my ($id) = @_;
+ my ($tmp,$row);
+ $tmp = "SELECT series.external_extension AS external_extension, "
+ . "series.external_context AS external_context, "
+ . "series.sound_file AS sound_file "
+ . "FROM callouts,series "
+ . "WHERE callouts.id = " . $id . " AND "
+ . "series.id = callouts.series";
+ $AGI->verbose("$tmp",1);
+ $sql = $aac_db->prepare($tmp);
+ $sql->execute;
+ $row = $sql->fetchrow_hashref;
+ $sql->finish;
+ $AGI->verbose("Sound File: $row->{sound_file}", 1);
+ return ($row->{sound_file},$row->{external_extension},$row->{external_context});
+}
+
+
+sub ignore_hup {
+ foreach $handle (@output) {
+ print $handle "HUP received\n";
+ }
+}
+
+
+######################################################################
+# Beginning of Program
+######################################################################
+my ( $id ) = @ARGV;
+
+$verbosity = 2;
+
+%input = $AGI->ReadParse();
+$config = &load_config();
+$aac_db = &connect_db();
+$SIG{HUP} = 'ignore_hup';
+
+$AGI->answer();
+
+&set_in_use($id,1);
+
+$AGI->verbose("GOT THIS FAR 1",1);
+my ($sound_file,$external_extension,$external_context) = &get_data($id);
+$AGI->verbose("GOT THIS FAR 2",1);
+
+$AGI->stream_file($sound_file);
+
+if ($external_context && $external_extension) {
+ $AGI->exec("DIAL Local/"
+ . $external_extension . "\@"
+ . $external_context . "/n");
+}
+
+&set_in_use($id,0);
+my $timestamp = ×tamp;
+&set_timestamp($id,$timestamp);
+
+&mark_answered($id);
+
+exit(0);
Modified: trunk/contrib/auto_dialer/aleph-aac.sql
===================================================================
--- trunk/contrib/auto_dialer/aleph-aac.sql 2008-11-01 22:01:34 UTC (rev 2202)
+++ trunk/contrib/auto_dialer/aleph-aac.sql 2008-11-08 04:36:02 UTC (rev 2203)
@@ -1,10 +1,42 @@
-CREATE DATABASE IF NOT EXISTS aleph_aac;
-use aleph_aac;
-
-CREATE TABLE callouts (number VARCHAR(12) NOT NULL PRIMARY KEY,
+CREATE TABLE callouts (
+id INTEGER NOT NULL AUTO_INCREMENT,
+series INTEGER NOT NULL,
+number VARCHAR(12) NOT NULL,
inuse INTEGER NOT NULL DEFAULT 0,
-sound_file VARCHAR(60) NOT NULL DEFAULT '',
answered INTEGER NOT NULL DEFAULT 0,
tries INTEGER NOT NULL DEFAULT 0,
-lasttry VARCHAR(80) NOT NULL DEFAULT '');
+lasttry VARCHAR(80) NOT NULL DEFAULT '',
+PRIMARY KEY (`id`)
+);
+
+CREATE TABLE series (
+id INTEGER NOT NULL AUTO_INCREMENT,
+customer INTEGER NOT NULL,
+clidname VARCHAR(80) NOT NULL DEFAULT '',
+clidnumber VARCHAR(80) NOT NULL DEFAULT '',
+starthour INTEGER NOT NULL DEFAULT 0,
+endhour INTEGER NOT NULL DEFAULT 0,
+Sun INTEGER NOT NULL DEFAULT 0,
+Mon INTEGER NOT NULL DEFAULT 0,
+Tue INTEGER NOT NULL DEFAULT 0,
+Wed INTEGER NOT NULL DEFAULT 0,
+Thu INTEGER NOT NULL DEFAULT 0,
+Fri INTEGER NOT NULL DEFAULT 0,
+Sat INTEGER NOT NULL DEFAULT 0,
+try_times INTEGER NOT NULL DEFAULT 3,
+external_extension VARCHAR(40) NOT NULL DEFAULT '',
+external_context VARCHAR(40) NOT NULL DEFAULT '',
+sound_file VARCHAR(60) NOT NULL DEFAULT '',
+creation TIMESTAMP NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+status INTEGER NOT NULL DEFAULT 0,
+email VARCHAR(80) NOT NULL DEFAULT '',
+description VARCHAR(255) NOT NULL DEFAULT '',
+PRIMARY KEY (`id`)
+);
+
+CREATE TABLE customers (
+id INTEGER NOT NULL AUTO_INCREMENT,
+accountcode VARCHAR(80) NOT NULL DEFAULT '',
+PRIMARY KEY (`id`)
+);
Modified: trunk/contrib/auto_dialer/aleph-autocall.pl
===================================================================
--- trunk/contrib/auto_dialer/aleph-autocall.pl 2008-11-01 22:01:34 UTC (rev 2202)
+++ trunk/contrib/auto_dialer/aleph-autocall.pl 2008-11-08 04:36:02 UTC (rev 2203)
@@ -1,164 +1,236 @@
-#!/usr/bin/perl
-# Aleph Communications Auto Callout
-#
-# Copyright (C) 2006, Aleph Communications
-#
-# Darren Wiebe <da...@al...>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# Contact information can be found @ www.aleph-com.net
-#
-###########################################################################`
-use DBI;
-use CGI;
-use strict;
-use Asterisk;
-use Asterisk::Outgoing;
-use Asterisk::Manager;
-use POSIX;
-use POSIX qw(strftime);
-
-my ( $config, $aac_db, $astman );
-
-sub load_config {
- my $config;
- open( CONFIG, "</var/lib/aac/aac.conf" );
- while (<CONFIG>) {
- chomp; # no newline
- s/#.*//; # no comments
- s/^\s+//; # no leading white
- s/\s+$//; # no trailing white
- next unless length; # anything left?
- my ( $var, $value ) = split( /\s*=\s*/, $_, 2 );
- $config->{$var} = $value;
- }
- close(CONFIG);
- return $config;
-}
-
-sub timestamp() {
- my $now = strftime "%Y%m%d%H%M%S", gmtime;
- return $now;
-}
-
-sub prettytimestamp() {
- my $now = strftime "%Y-%m-%d %H:%M:%S", gmtime;
- return $now;
-}
-
-sub connect_db() {
- my ( $dbh, $handle, $dsn );
- $dsn = "DBI:mysql:database=$config->{dbname};host=$config->{dbhost}";
- $dbh = DBI->connect( $dsn, $config->{dbuser}, $config->{dbpass} );
- if ( !$dbh ) {
- print STDERR "AAC DATABASE IS DOWN\n";
- exit(0);
- }
- else {
- print STDERR "Connected to AAC Database!" . "\n";
- return $dbh;
- }
-}
-
-#sub connect_manager() {
-# my $astman = new Asterisk::Manager;
-# $astman->user( $config->{astman_user} );
-# $astman->secret( $config->{astman_secret} );
-# $astman->host( $config->{astman_host} );
-# $astman->connect || die $astman->error . "\n";
-# return $astman;
-#
-# # my %sip_peers0 = $astman->sendcommand( 'sip show peers', '0' );
-# # my @sip_peers2 = $astman->sendcommand( 'sip show peers', '2' );
-#}
-
-sub shutdown() {
- # $astman->disconnect;
-}
-
-sub perform_callout() {
- my ($number) = @_;
- my $out = new Asterisk::Outgoing;
- my $channel = "Local\/" . $number . "\@$config->{destcontext}";
- $out->setvariable( 'Channel', $channel );
- $out->setvariable( 'MaxRetries', $config->{maxretries} );
- $out->setvariable( 'RetryTime', 60 );
- $out->setvariable( 'WaitTime', 60 );
- $out->setvariable( "context", $config->{context} );
- $out->setvariable( "extension", $number );
- $out->setvariable( "CallerID",
- "$config->{outgoingclidname} $config->{clidnumber}" );
- $out->setvariable( "Account", "$config->{accountcode}" );
- $out->outtime( time() + 15 );
- $out->create_outgoing;
-}
-
-sub set_in_use() {
- my ( $number, $status ) = @_;
- my $tmp;
- $tmp =
- "UPDATE callouts SET inuse = "
- . $aac_db->quote($status)
- . " WHERE number = "
- . $aac_db->quote( $number );
- $aac_db->do($tmp);
-}
-
-sub list_dialouts() {
- my ( $tmp, $sql, @numberlist );
- $tmp =
- "SELECT * FROM callouts WHERE answered = 0 AND tries < "
- . $aac_db->quote( $config->{total_tries} );
- $sql = $aac_db->prepare($tmp);
- $sql->execute;
- while ( my $row = $sql->fetchrow_hashref ) {
- push @numberlist, $row;
- }
- return @numberlist;
-}
-
-sub count_in_use() {
- my ( $sql, $count, $record );
- $sql = $aac_db->prepare("SELECT COUNT(*) FROM callouts WHERE inuse = 1");
- $sql->execute;
- $record = $sql->fetchrow_hashref;
- $count = $record->{"COUNT(*)"};
- $sql->finish;
- return $count;
-}
-
-##################################################################
-# Start of Program
-#################################################################
-
-$config = &load_config();
-$aac_db = &connect_db();
-#$astman = &connect_manager();
-
-my @diallist = &list_dialouts();
-foreach my $number (@diallist) {
- &set_in_use($number->{number},1);
- &perform_callout($number->{number});
- my $inuse = &count_in_use();
- while ( $inuse >= $config->{maxcalls} ) {
- print STDERR "COUNT $inuse";
- sleep 60;
- $inuse = &count_in_use();
- }
-}
-
-&shutdown();
-
-exit(0);
+#!/usr/bin/perl
+# Auto Callout
+#
+# Copyright (C) 2006, Aleph Communications
+#
+# Darren Wiebe <da...@al...>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Contact information can be found @ www.aleph-com.net
+#
+###########################################################################`
+use DBI;
+use CGI;
+use strict;
+use Asterisk;
+use Asterisk::Outgoing;
+use Asterisk::Manager;
+use POSIX;
+use POSIX qw(strftime);
+use Time::DayOfWeek qw(:dow);
+
+
+my ( $config, $aac_db, $astman );
+
+sub load_config {
+ my $config;
+ open( CONFIG, "</var/lib/aac/aac.conf" );
+ while (<CONFIG>) {
+ chomp; # no newline
+ s/#.*//; # no comments
+ s/^\s+//; # no leading white
+ s/\s+$//; # no trailing white
+ next unless length; # anything left?
+ my ( $var, $value ) = split( /\s*=\s*/, $_, 2 );
+ $config->{$var} = $value;
+ }
+ close(CONFIG);
+ return $config;
+}
+
+sub timestamp() {
+ my $now = strftime "%Y%m%d%H%M%S", localtime;
+ return $now;
+}
+
+sub prettytimestamp() {
+ my $now = strftime "%Y-%m-%d %H:%M:%S", localtime;
+ return $now;
+}
+
+sub get_hour() {
+ my $now = strftime "%H", localtime;
+ return $now;
+}
+
+sub get_date() {
+ my $year = strftime "%Y", localtime;
+ my $month = strftime "%m", localtime;
+ my $day = strftime "%d", localtime;
+ return ($year,$month,$day);
+}
+
+sub mark_last_try() {
+ my ( $id ) = @_;
+ my $tmp;
+ my $timestamp = ×tamp();
+ $tmp =
+ "UPDATE callouts SET lasttry = "
+ . $aac_db->quote($timestamp)
+ . " WHERE id = "
+ . $aac_db->quote( $id );
+ $aac_db->do($tmp);
+}
+
+sub mark_tried() {
+ my ( $id,$count ) = @_;
+ my $tmp =
+ "UPDATE callouts SET tries = "
+ . $aac_db->quote($count)
+ . " WHERE id = "
+ . $aac_db->quote( $id );
+ $aac_db->do($tmp);
+}
+
+sub connect_db() {
+ my ( $dbh, $handle, $dsn );
+ $dsn = "DBI:mysql:database=$config->{dbname};host=$config->{dbhost}";
+ $dbh = DBI->connect( $dsn, $config->{dbuser}, $config->{dbpass} );
+ if ( !$dbh ) {
+ print STDERR "AAC DATABASE IS DOWN\n";
+ exit(0);
+ }
+ else {
+ print STDERR "Connected to AAC Database!" . "\n";
+ return $dbh;
+ }
+}
+
+#sub connect_manager() {
+# my $astman = new Asterisk::Manager;
+# $astman->user( $config->{astman_user} );
+# $astman->secret( $config->{astman_secret} );
+# $astman->host( $config->{astman_host} );
+# $astman->connect || die $astman->error . "\n";
+# return $astman;
+#
+# # my %sip_peers0 = $astman->sendcommand( 'sip show peers', '0' );
+# # my @sip_peers2 = $astman->sendcommand( 'sip show peers', '2' );
+#}
+
+sub shutdown() {
+ # $astman->disconnect;
+}
+
+sub perform_callout() {
+ my ($number) = @_;
+ my $out = new Asterisk::Outgoing;
+ my $channel = "Local\/" . $number->{number} . "\@$config->{destcontext}";
+ $out->setvariable( 'Channel', $channel );
+ $out->setvariable( 'MaxRetries', $config->{maxretries} );
+ $out->setvariable( 'RetryTime', 60 );
+ $out->setvariable( 'WaitTime', 60 );
+# $out->setvariable( "context", $config->{context} );
+# $out->setvariable( "extension", $number );
+ $out->setvariable( 'Application', "DeadAGI");
+ $out->setvariable( 'Data', "aleph-aac.agi|" . $number->{id});
+ $out->setvariable( "CallerID",
+ "<$number->{clidname}> $number->{clidnumber}" );
+ $out->setvariable( "Account", "$number->{accountcode}" );
+ $out->outtime( time() + 15 );
+ $out->create_outgoing;
+ print STDERR "Created Call to: $number->{number}\n";
+}
+
+sub set_in_use() {
+ my ( $id, $status ) = @_;
+ my $tmp;
+ $tmp =
+ "UPDATE callouts SET inuse = "
+ . $aac_db->quote($status)
+ . " WHERE id = "
+ . $aac_db->quote( $id );
+ $aac_db->do($tmp);
+ print STDERR "SET IN USE $id Status: $status\n";
+}
+
+sub list_dialouts() {
+ my ( $tmp, $sql, @numberlist );
+ $tmp = "SELECT callouts.id AS id, callouts.number AS number,"
+ . "series.clidname AS clidname, series.clidnumber AS clidnumber,"
+ . "series.starthour AS starthour, series.endhour AS endhour,"
+ . "series.Sun as Sun, series.Mon as Mon,"
+ . "series.Tue as Tue, series.Wed as Wed,"
+ . "series.Thu as Thu, series.Fri as Fri,"
+ . "series.Sat as Sat, series.external_extension AS external_extension,"
+ . "series.external_context AS external_context,"
+ . "series.sound_file AS sound_file,"
+ . "customers.accountcode AS accountcode "
+ . "FROM callouts,series,customers "
+ . "WHERE series.status = 1 AND "
+ . "callouts.answered = 0 AND "
+ . "series.id = callouts.series AND "
+ . "customers.id = series.customer AND "
+ . "callouts.tries < series.try_times";
+ print STDERR $tmp;
+ $sql = $aac_db->prepare($tmp);
+ $sql->execute;
+ while ( my $row = $sql->fetchrow_hashref ) {
+ push @numberlist, $row;
+ print STDERR "NUMBERLIST: $row->{number}\n";
+ }
+ return @numberlist;
+}
+
+sub count_in_use() {
+ my ( $sql, $count, $record );
+ $sql = $aac_db->prepare("SELECT COUNT(*) FROM callouts WHERE inuse = 1");
+ $sql->execute;
+ $record = $sql->fetchrow_hashref;
+ $count = $record->{"COUNT(*)"};
+ $sql->finish;
+ return $count;
+}
+
+sub place_calls() {
+ my (@diallist) = @_;
+ foreach my $number (@diallist) {
+ my $hour = &get_hour();
+ if ($number->{Dow(&get_date)} == 1 && $hour > $number->{starthour} && $hour < $number->{endhour}) {
+ &perform_callout($number);
+ &mark_tried($number->{id}, $number->{tries} + 1);
+ &mark_last_try($number->{id});
+ sleep 20;
+ my $inuse = &count_in_use();
+ while ( $inuse >= $config->{maxcalls} ) {
+ print STDERR "COUNT $inuse";
+ sleep 10;
+ $inuse = &count_in_use();
+ }
+ }
+ }
+}
+
+##################################################################
+# Start of Program
+#################################################################
+
+$config = &load_config();
+$aac_db = &connect_db();
+#$astman = &connect_manager();
+
+my $hour = &get_hour();
+#while ($hour < $config->{endhour}) {
+while (0 < 1) {
+ my @diallist = &list_dialouts();
+ &place_calls(@diallist);
+ my $hour = &get_hour();
+ print STDERR "SLEEPING FOR A WHILE\n";
+ sleep 240;
+}
+
+&shutdown();
+
+exit(0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|