Changeset 9125
- Timestamp:
- 03/10/10 20:20:09 (2 years ago)
- Files:
-
- modules/branches/2.8/core/functions.inc.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.8/core/functions.inc.php
r9104 r9125 1602 1602 $cid = $pattern['match_cid']; 1603 1603 1604 //TODO: does the plus need to be backslashed? 1605 if (!preg_match("/^[0-9*+]+$/",$exten)) { 1606 // note # is not here, as asterisk doesn't recoginize it as a normal digit, thus it requires _ pattern matching 1607 // it's not strictly digits, so it must have patterns, so prepend a _ 1608 $exten = "_".$exten; 1609 } 1610 if ($cid != '' && !preg_match("/^[0-9*+]+$/",$cid)) { 1611 // note # is not here, as asterisk doesn't recoginize it as a normal digit, thus it requires _ pattern matching 1612 // it's not strictly digits, so it must have patterns, so prepend a _ 1613 $cid = "_".$cid; 1614 } 1615 if ($cid != '') { 1616 $exten .= '/'.$cid; 1617 } 1604 // returns: 1605 // array('prepend_digits' => $pattern['prepend_digits'], 'dial_pattern' => $exten, 'offset' => $pos); 1606 // 1607 $fpattern = core_routing_formatpattern($pattern); 1608 $exten = $fpattern['dial_pattern']; 1609 $offset = $fpattern['offset'] == 0 ? '':':'.$fpattern['offset']; 1618 1610 1619 1611 $ext->add($context, $exten, '', new ext_noop('Macro(user-callerid): executed in outbound-allroutes PRI 1')); … … 1637 1629 $ext->add($context, $exten, '', new ext_macro('record-enable,${AMPUSER},OUT')); 1638 1630 1639 // ticket #3998: the $pos is incorrect if a range is included such as1640 // 9[0-3]|NXX.1641 // in this case we end up with EXTEN:6 instead of the correct EXTEN:21642 //1643 $pos = strlen(preg_replace('/(\[[^\]]*\])/','X',$pattern['match_pattern_prefix']));1644 $pos = $pos == 0 ? '':':'.$pos;1645 1646 1631 $password = $route['password']; 1647 1632 foreach ($trunks as $trunk_id) { … … 1657 1642 break; 1658 1643 } 1659 $ext->add($context, $exten, '', new ext_macro($trunk_macro,$trunk_id.','.$pattern['prepend_digits'].'${EXTEN'.$ pos.'},'.$password));1644 $ext->add($context, $exten, '', new ext_macro($trunk_macro,$trunk_id.','.$pattern['prepend_digits'].'${EXTEN'.$offset.'},'.$password)); 1660 1645 $password = ''; 1661 1646 } … … 4815 4800 function core_routing_get($route_id) { 4816 4801 global $db; 4817 $sql = 'SELECT a.*, b.seq FROM `outbound_routes` a JOIN `outbound_route_sequence` b ON a.route_id = b.route_id WHERE a.route_id='. $db->escapeSimple($route_id);4802 $sql = 'SELECT a.*, b.seq FROM `outbound_routes` a JOIN `outbound_route_sequence` b ON a.route_id = b.route_id WHERE a.route_id='.q($db->escapeSimple($route_id)); 4818 4803 $route = sql($sql,"getRow",DB_FETCHMODE_ASSOC); 4819 4804 return $route; … … 4874 4859 return false; 4875 4860 } 4876 if ($seq >= count($sequence) ) {4861 if ($seq >= count($sequence)-1) { 4877 4862 unset($sequence[$key]); 4878 4863 $sequence[] = $route_id; … … 4911 4896 function core_routing_delbyid($route_id) { 4912 4897 global $db; 4913 $route_id = $db->escapeSimple($route_id);4898 $route_id = q($db->escapeSimple($route_id)); 4914 4899 sql('DELETE FROM `outbound_routes` WHERE `route_id` ='.$route_id); 4915 4900 sql('DELETE FROM `outbound_route_patterns` WHERE `route_id` ='.$route_id); … … 4921 4906 function core_routing_trunk_delbyid($trunk_id) { 4922 4907 global $db; 4923 $trunk_id = $db->escapeSimple($trunk_id);4908 $trunk_id = q($db->escapeSimple($trunk_id)); 4924 4909 sql('DELETE FROM `outbound_route_trunks` WHERE `trunk_id` ='.$trunk_id); 4925 4910 } … … 4928 4913 function core_routing_renamebyid($route_id, $new_name) { 4929 4914 global $db; 4930 $route_id = $db->escapeSimple($route_id);4915 $route_id = q($db->escapeSimple($route_id)); 4931 4916 $new_name = $db->escapeSimple($new_name); 4932 4917 sql("UPDATE `outbound_routes` SET `name = '$new_name' WHERE `route_id` = $route_id"); … … 4936 4921 function core_routing_getroutepatternsbyid($route_id) { 4937 4922 global $db; 4938 $route_id = $db->escapeSimple($route_id);4923 $route_id = q($db->escapeSimple($route_id)); 4939 4924 $sql = "SELECT * FROM `outbound_route_patterns` WHERE `route_id` = $route_id ORDER BY `match_pattern_prefix`, `match_pattern_pass`"; 4940 4925 $patterns = sql($sql,"getAll",DB_FETCHMODE_ASSOC); … … 4942 4927 } 4943 4928 4929 /* Utility function to determine required dialpattern and offsets for a specific dialpattern record. 4930 * Used when generating the dialplan and can be used by other modules that may be splicing into the 4931 * dialplan such as pinsets or others. 4932 */ 4933 function core_routing_formatpattern($pattern) { 4934 $exten = $pattern['match_pattern_prefix'].$pattern['match_pattern_pass']; 4935 $cid = $pattern['match_cid']; 4936 if (!preg_match("/^[0-9*+]+$/",$exten)) { 4937 // if # is detected above (as not in the list of acceptable patterns) then _ is appended due to Asterisk 4938 // particulars in dealing with # 4939 $exten = "_".$exten; 4940 } 4941 if ($cid != '' && !preg_match("/^[0-9*+]+$/",$cid)) { 4942 // same comment as above wrt to # 4943 $cid = "_".$cid; 4944 } 4945 if ($cid != '') { 4946 $exten .= '/'.$cid; 4947 } 4948 // ticket #3998: the $pos is incorrect if a range is included such as 9[0-3]|NXX in the prefix. 4949 // in this example we end up with EXTEN:6 instead of the correct EXTEN:2 4950 // 4951 $pos = strlen(preg_replace('/(\[[^\]]*\])/','X',$pattern['match_pattern_prefix'])); 4952 return array('prepend_digits' => $pattern['prepend_digits'], 'dial_pattern' => $exten, 'offset' => $pos); 4953 } 4954 4944 4955 // function core_routing_getroutetrunks($route) 4945 4956 function core_routing_getroutetrunksbyid($route_id) { 4946 4957 global $db; 4947 $route_id = $db->escapeSimple($route_id);4958 $route_id = q($db->escapeSimple($route_id)); 4948 4959 $sql = "SELECT `trunk_id` FROM `outbound_route_trunks` WHERE `route_id` = $route_id ORDER BY `seq`"; 4949 4960 $trunks = $db->getCol($sql); … … 4966 4977 $intracompany_route = $db->escapeSimple($intracompany_route); 4967 4978 $mohclass = $db->escapeSimple($mohclass); 4979 $seq = $db->escapeSimple($seq); 4968 4980 $time_group_id = $time_group_id == ''? 'NULL':$db->escapeSimple($time_group_id); 4969 4981 $sql = "UPDATE `outbound_routes` SET 4970 4982 `name`='$name', `outcid`='$outcid', `outcid_mode`='$outcid_mode', `password`='$password', 4971 4983 `emergency_route`='$emergency_route', `intracompany_route`='$intracompany_route', `mohclass`='$mohclass', 4972 `time_group_id`='$time_group_id' WHERE `route_id` = $route_id";4984 `time_group_id`='$time_group_id' WHERE `route_id` = ".q($route_id); 4973 4985 sql($sql); 4974 4986 … … 4982 4994 // function core_routing_add($name,$patterns,$trunks,$method,$pass,$emergency="",$intracompany="",$mohsilence="",$routecid="",$routecid_mode="") 4983 4995 function core_routing_addbyid($name, $outcid, $outcid_mode, $password, $emergency_route, $intracompany_route, $mohclass, $time_group_id, $patterns, $trunks, $seq = 'new') { 4996 global $amp_conf; 4984 4997 global $db; 4985 4998 … … 4995 5008 VALUES ('$name', '$outcid', '$outcid_mode', '$password', '$emergency_route', '$intracompany_route', '$mohclass', '$time_group_id')"; 4996 5009 sql($sql); 4997 $route_id = mysql_insert_id($db->connection); 5010 5011 // TODO: sqlite_last_insert_rowid() un-tested and php5 ??? 5012 // 5013 $route_id = $amp_conf["AMPDBENGINE"] == "sqlite3" ? sqlite_last_insert_rowid($db->connection) : mysql_insert_id($db->connection); 4998 5014 4999 5015 core_routing_updatepatterns($route_id, $patterns); … … 5008 5024 } 5009 5025 5026 /* TODO: duplicate prepend_patterns is a problem as only one will win. We need to catch this and filter it out. We can silently trap it 5027 by hashing without the prepend (since a blank prepend is similar to no prepend) at a minimum and decide if we want to catch 5028 this and throw an error... 5029 */ 5010 5030 function core_routing_updatepatterns($route_id, &$patterns, $delete = false) { 5011 5031 global $db; 5012 5032 5033 $route_id = $db->escapeSimple($route_id); 5013 5034 $filter = '/[^0-9\-\.\[\]xXnNzZ]/'; 5014 5035 $insert_pattern = array(); … … 5019 5040 $prepend_digits = $db->escapeSimple(preg_replace($filter,'',strtoupper($pattern['prepend_digits']))); 5020 5041 5021 $hash_index = md5($match_pattern_prefix.$match_pattern_pass.$match_cid .$prepend_digits);5042 $hash_index = md5($match_pattern_prefix.$match_pattern_pass.$match_cid); 5022 5043 $insert_pattern[$hash_index] = array($match_pattern_prefix, $match_pattern_pass, $match_cid, $prepend_digits); 5023 5044 } 5024 5045 5025 5046 if ($delete) { 5026 sql('DELETE FROM `outbound_route_patterns` WHERE `route_id`='. $route_id);5047 sql('DELETE FROM `outbound_route_patterns` WHERE `route_id`='.q($route_id)); 5027 5048 } 5028 5049 $compiled = $db->prepare('INSERT INTO `outbound_route_patterns` (`route_id`, `match_pattern_prefix`, `match_pattern_pass`, `match_cid`, `prepend_digits`) VALUES ('.$route_id.',?,?,?,?)'); … … 5036 5057 global $db; 5037 5058 5059 $route_id = $db->escapeSimple($route_id); 5038 5060 $insert_trunk = array(); 5039 5061 $seq = 0; … … 5043 5065 } 5044 5066 if ($delete) { 5045 sql('DELETE FROM `outbound_route_trunks` WHERE `route_id`='. $route_id);5067 sql('DELETE FROM `outbound_route_trunks` WHERE `route_id`='.q($route_id)); 5046 5068 } 5047 5069 $compiled = $db->prepare("INSERT INTO `outbound_route_trunks` (`route_id`, `trunk_id`, `seq`) VALUES ($route_id,?,?)"); … … 5057 5079 function core_timegroups_usage($group_id) { 5058 5080 5081 $group_id = q($group_id); 5059 5082 $results = sql("SELECT route_id, name FROM outbound_routes WHERE time_group_id = $group_id","getAll",DB_FETCHMODE_ASSOC); 5060 5083 if (empty($results)) {
