Changeset 7721

Show
Ignore:
Timestamp:
05/13/09 17:48:19 (3 years ago)
Author:
xrobau
Message:

Apply fixes from #3423

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.6/core/agi-bin/enumlookup.agi

    r7630 r7721  
    33// Replacement for Asterisk's ENUMLOOKUP function.  
    44// Written by Rob Thomas <xrobau@gmail.com> 
    5 //This file is part of FreePBX. 
     5// 
     6//    This file is part of FreePBX. http://www.freepbx.org 
    67// 
    78//    FreePBX is free software: you can redistribute it and/or modify 
    8 //    it under the terms of the GNU General Public License as published by 
    9 //    the Free Software Foundation, either version 2 of the License, or 
    10 //    (at your option) any later version. 
     9//    it under the terms of the GNU Affero General Public License as 
     10//    published by the Free Software Foundation, either version 3 of the 
     11//    License, or (at your option) any later version. 
    1112// 
    1213//    FreePBX is distributed in the hope that it will be useful, 
    1314//    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1415//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    15 //    GNU General Public License for more details. 
    16 // 
    17 //    You should have received a copy of the GNU General Public License 
     16//    GNU Affero General Public License for more details. 
     17// 
     18//    You should have received a copy of the GNU Affero General Public License 
    1819//    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>. 
    1920// 
    20 //    Copyright 2007 Rob Thomas 
    21 // 
    22 // Based on e164.org's enum.php script, available on http://www.e164.org/enum.phps 
     21//    Copyright 2009 Rob Thomas 
     22//    Additional patch to support enum.conf by matka 
     23// 
     24//    Originally based on e164.org's enum.php script, available from 
     25//        http://www.e164.org/enum.phps 
    2326 
    2427/* --------WARNING--------- 
    2528 *  
    26  * This script is auto-copied from an included module and will get overwritten. 
    27  * If you modify it, you must change it to write only, in the agi-bin directory, 
    28  * to keep it from getting changed. 
    29  */ 
     29 * This script is automatically copied from $ASTMODULES/core/agi-bin and will be  
     30 * overwritten any time you do any module changes. To avoid this, either set this 
     31 * file to READ ONLY (chmod a-w enumlookup.agi) or alter the file in core. 
     32 * It's probably better to submit any changes or enhancements to the freepbx tracker 
     33 * and they'll be rolled into core! 
     34 * 
     35 * --------WARNING--------- 
     36*/ 
    3037 
    3138require_once "phpagi.php"; 
     
    3441$lookup = get_var( $AGI, "DIAL_NUMBER" ); 
    3542 
    36 $enums = Array( 
    37   'e164.org',  
    38   //'e164.arpa',  
    39   //'e164.info', 
    40 ); 
    41  
    42 // Go through the ENUM providers and look for the number. 
     43$enums = get_enum_providers(); 
    4344 
    4445$dialstr = ""; 
    4546 
    46 foreach ($enums as $enum) { 
     47foreach ($enums as $enum) {  // Go through the ENUM providers and look for the number. 
    4748  // Are we using php5 and can use get_dns_record? 
    4849    if (function_exists("dns_get_record")) { 
     
    7273      if (eregi('SIP|IAX', $row['tech'])) { 
    7374        $URI = $row['URI']; 
    74         $dialstr .= $nextURI[$URI]."|"; 
     75        // string delimiter defined in [macro-dialout-enum] 
     76        $dialstr .= $nextURI[$URI]."%"; 
    7577      } 
    7678    } 
     
    8486  global $AGI; 
    8587 
    86   $AGI->verbose("Looking up $lookup on $enum via shell command DIG",3);; 
     88  $AGI->verbose("Looking up $lookup on $enum via shell command DIG",3); 
    8789  $arpa = ""; 
    8890  for ($i = 0; $i < strlen($lookup); $i++) { 
     
    157159} 
    158160 
     161function get_enum_providers() { 
     162  // parse enum.conf config file  
     163  $localprefix_file = get_var($AGI, "ASTETCDIR")."/enum.conf";  
     164  if (file_exists($localprefix_file)) {  
     165    $section="general";  
     166    parse_conf($localprefix_file, $conf, $section);  
     167    if (count($conf) == 0) {  
     168      $AGI->verbose("Could not parse config file $localprefix_file - using default e164.org", 0);  
     169      return Array("e164.org"); 
     170    }  
     171  } else {  
     172    $AGI->verbose("Could not open config file $localprefix_file - using default e164.org", 0);  
     173    return Array("e164.org"); 
     174  }  
     175 
     176  $enums = Array();  
     177  // pickup search org from the conf array  
     178  if (isset($conf["general"])) {  
     179    foreach ($conf["general"] as $key=>$options) {  
     180      if (isset($options["search"])) {  
     181        foreach($options as $enumorgs) {  
     182          $enums[]=$enumorgs;  
     183        } // store each enumorg in array          
     184      } // else, diff option   
     185    } // else, this isn't the section we want  
     186  } // else, no config for this section  
     187} 
     188 
     189function parse_conf($filename, &$conf, &$section) {  
     190  global $AGI;  
     191  $AGI->verbose("Parsing config file $filename",3);  
     192 
     193  if (is_null($conf)) { $conf = array(); }  
     194 
     195  if (is_null($section)) { $section = "general"; }  
     196 
     197  if (file_exists($filename)) {  
     198    $fd = fopen($filename, "r");  
     199    while ($line = fgets($fd, 1024)) {  
     200      if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=>\s*(.*?)\s*([;#].*)?$/",$line,$matches)) {  
     201        // name => => value  
     202        // keep [] to allow for duplicate options like search  
     203        // could extend options to include for example:  
     204        // skipgateway => slow-sip-gateway.com  
     205        // earlyexit => yes (to return only 1 enum from dns lookup)   
     206        $conf[$section][][$matches[1]] = $matches[2];  
     207      } else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) {  
     208        // section name  
     209        $section = strtolower($matches[1]);  
     210      } else if (preg_match("/^\s*#include\s+(.*)\s*([;#].*)?/",$line,$matches)) {  
     211        // include another file  
     212        if ($matches[1][0] == "/") {  
     213          // absolute path  
     214          $filename = $matches[1];  
     215        } else {  
     216          // relative path  
     217          $filename =  dirname($filename)."/".$matches[1];  
     218        }  
     219        parse_conf($filename, $conf, $section);  
     220      }  
     221    } 
     222  } 
     223} 
     224 
    159225?>