Changeset 7721
- Timestamp:
- 05/13/09 15:48:19 (1 year ago)
- Files:
-
- modules/branches/2.6/core/agi-bin/enumlookup.agi (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.6/core/agi-bin/enumlookup.agi
r7630 r7721 3 3 // Replacement for Asterisk's ENUMLOOKUP function. 4 4 // 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 6 7 // 7 8 // FreePBX is free software: you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License as published by9 // the Free Software Foundation, either version 2 of the License, or10 // (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. 11 12 // 12 13 // FreePBX is distributed in the hope that it will be useful, 13 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 15 // 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 License16 // GNU Affero General Public License for more details. 17 // 18 // You should have received a copy of the GNU Affero General Public License 18 19 // along with FreePBX. If not, see <http://www.gnu.org/licenses/>. 19 20 // 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 23 26 24 27 /* --------WARNING--------- 25 28 * 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 */ 30 37 31 38 require_once "phpagi.php"; … … 34 41 $lookup = get_var( $AGI, "DIAL_NUMBER" ); 35 42 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(); 43 44 44 45 $dialstr = ""; 45 46 46 foreach ($enums as $enum) { 47 foreach ($enums as $enum) { // Go through the ENUM providers and look for the number. 47 48 // Are we using php5 and can use get_dns_record? 48 49 if (function_exists("dns_get_record")) { … … 72 73 if (eregi('SIP|IAX', $row['tech'])) { 73 74 $URI = $row['URI']; 74 $dialstr .= $nextURI[$URI]."|"; 75 // string delimiter defined in [macro-dialout-enum] 76 $dialstr .= $nextURI[$URI]."%"; 75 77 } 76 78 } … … 84 86 global $AGI; 85 87 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); 87 89 $arpa = ""; 88 90 for ($i = 0; $i < strlen($lookup); $i++) { … … 157 159 } 158 160 161 function 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 189 function 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 159 225 ?>
