1
0

Added second script for online lookup of numbers

This commit is contained in:
Markus Birth 2009-06-17 10:25:57 +02:00
parent 50528ee2a5
commit 0ef128a44b
4 changed files with 125 additions and 2 deletions

@ -0,0 +1,89 @@
#!/usr/bin/php -q
<?php
define( 'GS_VALID', true ); /// this is a parent file
require_once( dirName(__FILE__) .'/../inc/conf.php' );
require_once( GS_DIR .'inc/agi-fns.php' );
ini_set('implicit_flush', 1);
ob_implicit_flush(1);
$number = trim(@$argv[1]);
if (empty($number)) die();
gs_agi_verbose( '### Number identification for ' . $number );
$intlnum = $number;
if (substr($intlnum, 0, 2) == '00') {
// int'l number
$intlnum = '+' . substr($intlnum, 2);
} elseif ($number{0} == '0') {
// local number
$intlnum = '+' . GS_CANONIZE_COUNTRY_CODE . substr($intlnum, 1);
} else {
// plain number
$intlnum = '+' . GS_CANONIZE_COUNTRY_CODE . GS_CANONIZE_AREA_CODE . $intlnum;
}
gs_agi_verbose( '### Canonized number is ' . $intlnum );
$config_file = GS_DIR . 'etc/jf-reverse-lookup.xml';
$xml = new DOMDocument();
if (!file_exists($config_file)) echo 'No config!';
$xml->load($config_file);
$countries =& $xml->getElementsByTagName('country'); // first country entry
for ($i=0; $i<$countries->length; $i++) {
$country =& $countries->item($i);
$cc = $country->attributes->getNamedItem('code')->nodeValue;
if ( $cc == substr($intlnum, 0, strlen($cc)) ) break;
}
$websites =& $country->getElementsByTagName('website');
for ($i=0; $i<$websites->length; $i++) {
$website =& $websites->item($i);
$wname = $website->attributes->getNamedItem('name')->nodeValue;
$wurl = $website->attributes->getNamedItem('url')->nodeValue;
$wpref = $website->attributes->getNamedItem('prefix')->nodeValue;
$wentry = $website->getElementsByTagName('entry')->item(0);
$checknum = $wpref . substr($intlnum, strlen($cc)); // replace int'l prefix by local prefix
gs_agi_verbose('Searching ' . $wname . ' (' . ($i+1) . '/' . $websites->length . ')');
$url = str_replace('$NUMBER', $checknum, $wurl);
// Had to use wget b/c PHP's file_get_contents() and other tricks didn't succeed (returned wrong data!)
exec('wget -q -O - "' . $url . '"', $data);
$data = implode("\n", $data);
gs_agi_verbose('-> got ' . strlen($data) . ' Bytes');
$lastPos = 0;
$details = array();
foreach ($wentry->childNodes as $child) {
if ($child->nodeType == XML_TEXT_NODE) continue;
$ntitle = $child->nodeName;
$pattern = $child->nodeValue;
$matchct = preg_match('/'.$pattern.'/', $data, &$matches, PREG_OFFSET_CAPTURE, $lastPos);
if ($matchct == 0) {
gs_agi_verbose('NO MATCH FOUND!');
break;
}
$details[$ntitle] = rawurldecode($matches[1][0]);
$lastPos = $matches[0][1];
}
if (count($details) > 0) break;
}
// print_r($details);
if (isset($details['name']) && !empty($details['name'])) {
echo 'SET VARIABLE CALLERID(name) ' . gs_agi_str_esc($details['name']) . "\n";
}
?>

@ -1,2 +1,5 @@
// add this line:
AGI(/opt/gemeinschaft/dialplan-scripts/in-get-callerid.agi,${CALLERID(num)});
// add this line: (country/city lookup)
AGI(/opt/gemeinschaft/dialplan-scripts/in-get-callerid1.agi,${CALLERID(num)});
// or this line: (online service lookup)
AGI(/opt/gemeinschaft/dialplan-scripts/in-get-callerid2.agi,${CALLERID(num)});

31
etc/jf-reverse-lookup.xml Normal file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<reverselookup>
<country code="+1">
<website name="dasoertliche.de" url="http://dasoertliche.de/?form_name=search_inv&amp;page=RUECKSUCHE&amp;context=RUECKSUCHE&amp;action=STANDARDSUCHE&amp;la=de&amp;rci=no&amp;ph=$NUMBER" prefix="0">
<entry>
<name>class="entry"&gt;([^&lt;]*)&lt;/a&gt;</name>
<street>([^,&gt;]*),([^&lt;]*)&lt;br/&gt;</street>
<city>[^,&gt;]*,&amp;nbsp;[^&amp;]*([^&lt;]*)&lt;br/&gt;</city>
<zipcode>[^,&gt;]*,&amp;nbsp;([^&amp;]*)[^&lt;]*&lt;br/&gt;</zipcode>
</entry>
</website>
</country>
<country code="+49">
<website name="dasoertliche.de" url="http://dasoertliche.de/?form_name=search_inv&amp;ph=$NUMBER&amp;page=5&amp;context=4&amp;action=43" prefix="0">
<entry>
<zipcode>pc: "([^"]*)",</zipcode>
<city>ci: "([^"]*)",</city>
<name>na: "([^"]*)",</name>
<street>st: "([^"]*)",</street>
</entry>
</website>
<website name="dasoertliche.de" url="http://dasoertliche.de/?form_name=search_inv&amp;page=RUECKSUCHE&amp;context=RUECKSUCHE&amp;action=STANDARDSUCHE&amp;la=de&amp;rci=no&amp;ph=$NUMBER" prefix="0">
<entry>
<name>class="entry"&gt;([^&lt;]*)&lt;/a&gt;</name>
<street>([^,&gt;]*),([^&lt;]*)&lt;br/&gt;</street>
<city>[^,&gt;]*,&amp;nbsp;[^&amp;]*([^&lt;]*)&lt;br/&gt;</city>
<zipcode>[^,&gt;]*,&amp;nbsp;([^&amp;]*)[^&lt;]*&lt;br/&gt;</zipcode>
</entry>
</website>
</country>
</reverselookup>