diff --git a/dialplan-scripts/in-get-callerid.agi b/dialplan-scripts/in-get-callerid1.agi similarity index 100% rename from dialplan-scripts/in-get-callerid.agi rename to dialplan-scripts/in-get-callerid1.agi diff --git a/dialplan-scripts/in-get-callerid2.agi b/dialplan-scripts/in-get-callerid2.agi new file mode 100755 index 0000000..e686128 --- /dev/null +++ b/dialplan-scripts/in-get-callerid2.agi @@ -0,0 +1,89 @@ +#!/usr/bin/php -q +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"; +} + +?> \ No newline at end of file diff --git a/etc/asterisk/e-internal.ael-add b/etc/asterisk/e-internal.ael-add index 16a8e0e..44720e4 100644 --- a/etc/asterisk/e-internal.ael-add +++ b/etc/asterisk/e-internal.ael-add @@ -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)}); diff --git a/etc/jf-reverse-lookup.xml b/etc/jf-reverse-lookup.xml new file mode 100644 index 0000000..283d19e --- /dev/null +++ b/etc/jf-reverse-lookup.xml @@ -0,0 +1,31 @@ + + + + + + class="entry">([^<]*)</a> + ([^,>]*),([^<]*)<br/> + [^,>]*,&nbsp;[^&]*([^<]*)<br/> + [^,>]*,&nbsp;([^&]*)[^<]*<br/> + + + + + + + pc: "([^"]*)", + ci: "([^"]*)", + na: "([^"]*)", + st: "([^"]*)", + + + + + class="entry">([^<]*)</a> + ([^,>]*),([^<]*)<br/> + [^,>]*,&nbsp;[^&]*([^<]*)<br/> + [^,>]*,&nbsp;([^&]*)[^<]*<br/> + + + +