3 # Use Reverse Lookups to populate valuable information
5 # Copyright (C) 2005 Digium, Inc.
7 # Mark Spencer <markster@digium.com>
9 # Based on work of Joe Fratantoni - BrakeDanceJ - Joe@UnrealDestination.com.
11 # This program is Free Software distributed under the terms of the GNU
12 # General Public License version 2. See LICENSE for details.
21 s/%([0-9A-F]{2})/chr hex $1/egios for @args;
22 s/\"//egios for @args;
23 return wantarray ?
@args : $args[0];
28 last unless length($_);
29 if (/^agi_(\w+)\:\s+(.*)$/) {
35 my $number = $AGI{'callerid'};
38 die("You must specify a number") unless $number;
39 my $ua = LWP
::UserAgent
->new;
40 $ua->agent("Asterisk");
41 my $req = HTTP
::Request
->new(POST
=> 'http://www.411.com/10668/search/Reverse_Phone');
42 $req->content_type('application/x-www-form-urlencoded');
43 $req->content("phone=$number");
44 my $res = $ua->request($req);
45 if ($res->is_success) {
46 my $first, $last, $address, $street, $house, $city, $state, $zip, $phone;
47 if ($res->content =~ /PAGE: PHONE_NOT_FOUND/) {
49 $res->content =~ /is a \s+([A-Za-z -]*), ([A-Z]{2}) \s+based phone number and the registered carrier is (.*)\.\s+/;
50 ($city, $state, $last) =
51 map { url_decode
($_) } ($1, $2, $3);
52 $cidname = "$city, $state";
55 $res->content =~ /RM_HTML_FIRST_ESC_=(.*)&_RM_HTML_LAST_ESC_=(.*)&_RM_HTML_ADDRESS_ESC_=(.*)&_RM_HTML_STREET_ESC_=(.*)&_RM_HTML_HOUSE_ESC_=(.*)&_RM_HTML_CITY_ESC_=(.*)&_RM_HTML_STATE_ESC_=(.*)&_RM_HTML_ZIP_ESC_=(.*)&_RM_HTML_PHONE_ESC_=(.*)&CITY=(.*)&STATE=(.*)/;
56 ($first, $last, $address, $street, $house, $city, $state, $zip, $phone) =
57 map { url_decode
($_) } ($1, $2, $3, $4, $5, $6, $7, $8, $9);
60 $cidname = $first . " " . $last;
65 print STDOUT
"SET VARIABLE CALLERID(name) \"$cidname\"\n";
67 print STDOUT
"SET VARIABLE CALLER_ZIP \"$zip\"\n";
69 print STDOUT
"SET VARIABLE CALLER_STATE \"$state\"\n";
71 print STDOUT
"SET VARIABLE CALLER_CITY \"$city\"\n";
73 print STDOUT
"SET VARIABLE CALLER_ADDRESS \"$address\"\n";
75 print STDOUT
"SET VARIABLE CALLER_LAST \"$last\"\n";
77 print STDOUT
"SET VARIABLE CALLER_FIRST \"$first\"\n";
79 print STDERR
"First: $first\n" .
81 "Address: $address\n" .
87 "Phone: $phone\n" if $debug;
89 print STDERR
$res->status_line . "\n";