aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-08-30 18:41:42 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-08-30 18:41:42 +0000
commit016af61ec235d938207e057eadd1da83d5af2584 (patch)
treeebc8af9b1aa7566eef712cb8a5e6f8ef3121c249 /contrib
parent3c4140b8b100b2e54e8ab6db85354576483c9ec5 (diff)
Add lookup script for people without CIDNAME plus rich variables...
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6455 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/scripts/lookup.agi90
1 files changed, 90 insertions, 0 deletions
diff --git a/contrib/scripts/lookup.agi b/contrib/scripts/lookup.agi
new file mode 100755
index 000000000..4b682b837
--- /dev/null
+++ b/contrib/scripts/lookup.agi
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+#
+# Use Reverse Lookups to populate valuable information
+#
+# Copyright (C) 2005 Digium, Inc.
+#
+# Mark Spencer <markster@digium.com>
+#
+# Based on work of Joe Fratantoni - BrakeDanceJ - Joe@UnrealDestination.com.
+#
+# This program is Free Software distributed under the terms of the GNU
+# General Public License version 2. See LICENSE for details.
+#
+#
+use LWP::UserAgent;
+my %AGI;
+my $debug = 0;
+$|=1;
+sub url_decode {
+ my @args = @_;
+ s/%([0-9A-F]{2})/chr hex $1/egios for @args;
+ s/\"//egios for @args;
+ return wantarray ? @args : $args[0];
+}
+
+while(<STDIN>) {
+ chomp;
+ last unless length($_);
+ if (/^agi_(\w+)\:\s+(.*)$/) {
+ $AGI{$1} = $2;
+ }
+}
+
+alarm(4);
+my $number = $AGI{'callerid'};
+$number =~ /(\d+)/;
+$number = $1;
+die("You must specify a number") unless $number;
+my $ua = LWP::UserAgent->new;
+$ua->agent("Asterisk");
+my $req = HTTP::Request->new(POST => 'http://www.411.com/10668/search/Reverse_Phone');
+$req->content_type('application/x-www-form-urlencoded');
+$req->content("phone=$number");
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $first, $last, $address, $street, $house, $city, $state, $zip, $phone;
+ if ($res->content =~ /PAGE: PHONE_NOT_FOUND/) {
+ # Limited Information
+ $res->content =~ /is a \s+([A-Za-z -]*), ([A-Z]{2}) \s+based phone number and the registered carrier is (.*)\.\s+/;
+ ($city, $state, $last) =
+ map { url_decode($_) } ($1, $2, $3);
+ $cidname = "$city, $state";
+ } else {
+ # Full Information
+ $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=(.*)/;
+ ($first, $last, $address, $street, $house, $city, $state, $zip, $phone) =
+ map { url_decode($_) } ($1, $2, $3, $4, $5, $6, $7, $8, $9);
+ my $cidname = $last;
+ if ($first) {
+ $cidname = $first . " " . $last;
+ } else {
+ $cidname = $last;
+ }
+ }
+ print STDOUT "SET VARIABLE CALLERID(name) \"$cidname\"\n";
+ <STDIN>;
+ print STDOUT "SET VARIABLE CALLER_ZIP \"$zip\"\n";
+ <STDIN>;
+ print STDOUT "SET VARIABLE CALLER_STATE \"$state\"\n";
+ <STDIN>;
+ print STDOUT "SET VARIABLE CALLER_CITY \"$city\"\n";
+ <STDIN>;
+ print STDOUT "SET VARIABLE CALLER_ADDRESS \"$address\"\n";
+ <STDIN>;
+ print STDOUT "SET VARIABLE CALLER_LAST \"$last\"\n";
+ <STDIN>;
+ print STDOUT "SET VARIABLE CALLER_FIRST \"$first\"\n";
+ <STDIN>;
+ print STDERR "First: $first\n" .
+ "Last: $last\n" .
+ "Address: $address\n" .
+ "Street: $street\n" .
+ "House: $house\n" .
+ "City: $city\n" .
+ "State: $state\n" .
+ "Zip: $zip\n" .
+ "Phone: $phone\n" if $debug;
+} else {
+ print STDERR $res->status_line . "\n";
+}