here’s a simple AGI i wrote to determine call blocking for a clients system(there’s lot’s more, this is just one of the AGI scripts) :
[code]#!/usr/bin/perl -w
Call Blocking AGI
Baconbuttie 2006 tony [at] baconbuttie [dot] co [dot] uk
You’re free to use this code, and free to give at to others.
You can’t claim you own it though, nor remove this copyright block.
use DBI;
use Asterisk::AGI;
my $debug = 1; # Debug level, lower to reduce logging
my $dnid; # Called number
my $caller; # Caller for this call
my $priority; # Next priority
my $result; # DB result
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
$dnid = $input{“dnid”};
$caller = $input{“callerid”};
$priority = $input{‘priority’};
if ($debug >= 2) {
foreach $key (keys %input) {
debug("$key = ".$input{$key},3);
}
}
my $dbh = DBI->connect (“dbi:mysql:host=localhost:database=asterisk”,“user”,“password”) or die “Can’t connect to database: $DBI::errstr”;
my $statement = “SELECT * FROM blocklist WHERE caller IN (0,’”.$caller."’) AND callnumber = ‘".$dnid."’ AND patmatch = 0" or die "Couldn’t prepare statement: " . $dbh->errstr;
if ($debug >= 2) {debug("CallBlock Statement = ".$statement,3);}
$result = $dbh->selectall_arrayref($statement);
unless ($result) {
check for errors after every single database call
print “dbh->selectall_arrayref($statement) failed!\n”;
print “DBI::err=[$DBI::err]\n”;
print “DBI::errstr=[$DBI::errstr]\n”;
}
@resultSet = @{$result};
if ( $#resultSet == -1 ) {
check for pattern match entry
my $statement = "SELECT * FROM blocklist WHERE caller IN (0,\'".$caller."\') AND callnumber = \'".substr($dnid,0,4)."\' AND patmatch = 1" or die "Couldn't prepare statement: " . $dbh->errstr;
if ($debug >= 2) {debug("CallBlock Statement = ".$statement,3);}
$result = $dbh->selectall_arrayref($statement);
unless ($result) {
# check for errors after every single database call
print "dbh->selectall_arrayref($statement) failed!\n";
print "DBI::err=[$DBI::err]\n";
print "DBI::errstr=[$DBI::errstr]\n";
}
@resultSet = @{$result};
if ( $#resultSet == -1 ) {
debug("No CallBlock found",3);
$priority = $priority + 1;
debug("Setting priority = ".$priority,3);
$AGI->set_priority($priority);
exit 0;
}
else {
debug("Valid Patternmatch CallBlock found",3);
$priority = $priority + 101;
debug("Setting priority = ".$priority,3);
$AGI->set_priority($priority);
exit 0;
}
}
else {
debug(“Valid CallBlock found”,3);
$priority = $priority + 101;
debug("Setting priority = ".$priority,3);
$AGI->set_priority($priority);
exit 0;
}
$dbh->disconnect;
sub debug
{
my $string = shift;
my $level = shift || 3;
if ($debug) {
$AGI->verbose($string, $level);
}
return(0);
}
exit 0;
[/code]
all fairly simple. and you can use $AGI->set_variable('varname', varvalue);
to set variable values.
does that help ?