Added second script for online lookup of numbers
This commit is contained in:
parent
50528ee2a5
commit
0ef128a44b
89
dialplan-scripts/in-get-callerid2.agi
Executable file
89
dialplan-scripts/in-get-callerid2.agi
Executable file
@ -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
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&page=RUECKSUCHE&context=RUECKSUCHE&action=STANDARDSUCHE&la=de&rci=no&ph=$NUMBER" prefix="0">
|
||||
<entry>
|
||||
<name>class="entry">([^<]*)</a></name>
|
||||
<street>([^,>]*),([^<]*)<br/></street>
|
||||
<city>[^,>]*,&nbsp;[^&]*([^<]*)<br/></city>
|
||||
<zipcode>[^,>]*,&nbsp;([^&]*)[^<]*<br/></zipcode>
|
||||
</entry>
|
||||
</website>
|
||||
</country>
|
||||
<country code="+49">
|
||||
<website name="dasoertliche.de" url="http://dasoertliche.de/?form_name=search_inv&ph=$NUMBER&page=5&context=4&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&page=RUECKSUCHE&context=RUECKSUCHE&action=STANDARDSUCHE&la=de&rci=no&ph=$NUMBER" prefix="0">
|
||||
<entry>
|
||||
<name>class="entry">([^<]*)</a></name>
|
||||
<street>([^,>]*),([^<]*)<br/></street>
|
||||
<city>[^,>]*,&nbsp;[^&]*([^<]*)<br/></city>
|
||||
<zipcode>[^,>]*,&nbsp;([^&]*)[^<]*<br/></zipcode>
|
||||
</entry>
|
||||
</website>
|
||||
</country>
|
||||
</reverselookup>
|
Reference in New Issue
Block a user