Reverse Australia: Difference between revisions
Line 83: | Line 83: | ||
<pre> | <pre> | ||
[incoming-call] | [incoming-call] | ||
exten => | [incoming-call] | ||
same => | exten => _XX.,1,GotoIf($[${CALLERID(num)} = ""]?:4) | ||
same => | same => 2,Set(CALLERID(name)=Unknown) | ||
same => | same => 3,Goto(9) | ||
same => | same => 4,GotoIf($[${CALLERID(name)} = ${CALLERID(num)}]?:7) | ||
same => | same => 5,Set(CALLERID(name)=Unknown) | ||
same => | same => 6,Goto(9) | ||
same => | same => 7,AGI(cid-lookup-v4.agi) | ||
same => 8,NoOp(${CALLERID(num)} : ${CALLERID(name)}) | |||
same => 9,Dial(${EVERYONE},29,tw) | |||
same => 10,VoiceMail(200@default,us) | |||
same => 11,HangUp | |||
</pre> | </pre> | ||
Revision as of 05:15, 7 October 2011
About
Reverse Australia is the premier free reverse look-up service for mobiles and landlines within Australia.
Prerequisite
Asterisk AGI Perl module
wget http://search.cpan.org/CPAN/authors/id/J/JA/JAMESGOL/asterisk-perl-1.01.tar.gz tar xvzf asterisk-perl-1.01.tar.gz cd asterisk-perl-1.01 perl Makefile.PL make all make install
rpmforge
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm rpm -Uhv rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
perl-LWP-UserAgent-Determined
yum -y install perl-LWP-UserAgent-Determined
Reverse Australia Key
Log onto the Reverse Australia web site and select Request an API Key. You will need to log onto the site with a Facebook account. If you don't have one then you'll need to create one otherwise you're screwed.
MySQL Database
Create a database with the name of your choice with a table name of cid.
mysqladmin create reverseau
table
mysql use reverseau; CREATE TABLE `cid` ( `name` text NOT NULL, `number` text NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
modified table
I have a WEB site that allows one to edit the contents of the Database. To use the web site to edit/add/delete entries you will need to use the following table.
CREATE TABLE IF NOT EXISTS `cid` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(60) NOT NULL, `number` varchar(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=81 ;
assign permissions
GRANT ALL ON reverseau.* to ciduser@localhost identified by 'passw0rd'; flush privileges;
cid-lookup.agi
The latest version is available from CRC. Download and move the file to /var/lib/asterisk/agi-bin/ (Thanks Steven Haigh for this wonder script.)
wget http://www.crc.id.au/files/cid-lookup-v4.agi mv cid-lookup-v4.agi /var/lib/asterisk/agi-bin/ chmod +x /var/lib/asterisk/agi-bin/cid-lookup-v4.agi
Edit the file and change the following constants to the required values.
- APIKEY
- db_host
- db_name
- db_username
- db_password
Asterisk Dialplan Implementation
[incoming-call] [incoming-call] exten => _XX.,1,GotoIf($[${CALLERID(num)} = ""]?:4) same => 2,Set(CALLERID(name)=Unknown) same => 3,Goto(9) same => 4,GotoIf($[${CALLERID(name)} = ${CALLERID(num)}]?:7) same => 5,Set(CALLERID(name)=Unknown) same => 6,Goto(9) same => 7,AGI(cid-lookup-v4.agi) same => 8,NoOp(${CALLERID(num)} : ${CALLERID(name)}) same => 9,Dial(${EVERYONE},29,tw) same => 10,VoiceMail(200@default,us) same => 11,HangUp
cid-lookup-v4.agi
#!/usr/bin/perl use strict; use Asterisk::AGI; use LWP::UserAgent; use DBI; #### Your Reverse Australia Developers Key: #### http://www.reverseaustralia.com/developer/ my $APIKEY = ""; my $query_online = 1; ## MySQL Database details. my $db_host = "localhost"; my $db_name = "asterisk"; my $db_username = "username"; my $db_password = "password"; ## If you access the web via a proxy, you can define it here #$ in the format "http://my.proxy.com:8080" my $http_proxy = ""; my $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $number = $input{'callerid'}; ## Open the SQL database and search for the number calling... my $dbh = DBI->connect("dbi:mysql:$db_name;host=$db_host", $db_username, $db_password) or die "Error connecting to database!\n"; my $sth = $dbh->prepare("SELECT name FROM cid WHERE number=?"); $sth->execute($number) or die "SQL Error: $DBI::errstr\n"; my $name = $sth->fetchrow; ## If we still can't find anything, search the online database if enabled. if ( $name eq "" and $name ne "anonymous" ) { if ( $query_online and $APIKEY ne "" ) { my $ua = new LWP::UserAgent; $ua->proxy("http", $http_proxy); $ua->agent("cid-lookup-v4.agi"); my $req = new HTTP::Request GET => 'http://api.reverseaustralia.com/cidlookup.php?format=text&key='.$APIKEY.'&q='.$number.'&extended=0'; my $res = $ua->request($req); if ($res->is_success) { ## We don't need any real parsing on non-extended searches. ## Set the caller ID and add the results to the database as a cache. $name = $res->content; $name =~ s/\t//g; $name =~ s/,//g; $sth = $dbh->prepare("INSERT INTO cid (name,number) VALUES (?,?)"); $sth->execute($name, $number); } else { print("NOOP Error looking up online directory"); } } ## If we got nothing from the database, and nothing from the online directory ## (if enabled) we fall back to this. Add the details to the database so someone ## can come along and add a name later. if ( $name eq "" or $name eq "Not found") { print("NOOP Nothing found. Setting to unknown\n"); $name = "Unknown Caller"; $sth = $dbh->prepare("INSERT INTO cid (name,number) VALUES (?,?)"); $sth->execute($number, $number); } } $AGI->set_callerid("\"$name <$number>\"");