Changeset 9125

Show
Ignore:
Timestamp:
03/10/10 20:20:09 (2 years ago)
Author:
p_lindheimer
Message:

more updates core_routing_xxx re #4110 (now and over the next couple days these check-ins may start to break trunk, BEWARE)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.8/core/functions.inc.php

    r9104 r9125  
    16021602          $cid = $pattern['match_cid']; 
    16031603 
    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']; 
    16181610 
    16191611          $ext->add($context, $exten, '', new ext_noop('Macro(user-callerid): executed in outbound-allroutes PRI 1'));  
     
    16371629          $ext->add($context, $exten, '', new ext_macro('record-enable,${AMPUSER},OUT')); 
    16381630 
    1639           // ticket #3998: the $pos is incorrect if a range is included such as 
    1640           // 9[0-3]|NXX. 
    1641           // in this case we end up with EXTEN:6 instead of the correct EXTEN:2 
    1642           // 
    1643           $pos = strlen(preg_replace('/(\[[^\]]*\])/','X',$pattern['match_pattern_prefix'])); 
    1644           $pos = $pos == 0 ? '':':'.$pos; 
    1645  
    16461631          $password = $route['password']; 
    16471632          foreach ($trunks as $trunk_id) { 
     
    16571642              break; 
    16581643            } 
    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)); 
    16601645            $password = ''; 
    16611646          } 
     
    48154800function core_routing_get($route_id) { 
    48164801  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)); 
    48184803  $route = sql($sql,"getRow",DB_FETCHMODE_ASSOC); 
    48194804  return $route; 
     
    48744859      return false; 
    48754860    } 
    4876     if ($seq >= count($sequence)) { 
     4861    if ($seq >= count($sequence)-1) { 
    48774862      unset($sequence[$key]); 
    48784863      $sequence[] = $route_id; 
     
    49114896function core_routing_delbyid($route_id) { 
    49124897  global $db; 
    4913   $route_id = $db->escapeSimple($route_id); 
     4898  $route_id = q($db->escapeSimple($route_id)); 
    49144899  sql('DELETE FROM `outbound_routes` WHERE `route_id` ='.$route_id); 
    49154900  sql('DELETE FROM `outbound_route_patterns` WHERE `route_id` ='.$route_id); 
     
    49214906function core_routing_trunk_delbyid($trunk_id) { 
    49224907  global $db; 
    4923   $trunk_id = $db->escapeSimple($trunk_id); 
     4908  $trunk_id = q($db->escapeSimple($trunk_id)); 
    49244909  sql('DELETE FROM `outbound_route_trunks` WHERE `trunk_id` ='.$trunk_id); 
    49254910} 
     
    49284913function core_routing_renamebyid($route_id, $new_name) { 
    49294914  global $db; 
    4930   $route_id = $db->escapeSimple($route_id); 
     4915  $route_id = q($db->escapeSimple($route_id)); 
    49314916  $new_name = $db->escapeSimple($new_name); 
    49324917  sql("UPDATE `outbound_routes` SET `name = '$new_name'  WHERE `route_id` = $route_id"); 
     
    49364921function core_routing_getroutepatternsbyid($route_id) { 
    49374922  global $db; 
    4938   $route_id = $db->escapeSimple($route_id); 
     4923  $route_id = q($db->escapeSimple($route_id)); 
    49394924  $sql = "SELECT * FROM `outbound_route_patterns` WHERE `route_id` = $route_id ORDER BY `match_pattern_prefix`, `match_pattern_pass`"; 
    49404925  $patterns = sql($sql,"getAll",DB_FETCHMODE_ASSOC); 
     
    49424927} 
    49434928 
     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 */ 
     4933function 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 
    49444955// function core_routing_getroutetrunks($route) 
    49454956function core_routing_getroutetrunksbyid($route_id) { 
    49464957  global $db; 
    4947   $route_id = $db->escapeSimple($route_id); 
     4958  $route_id = q($db->escapeSimple($route_id)); 
    49484959  $sql = "SELECT `trunk_id` FROM `outbound_route_trunks` WHERE `route_id` = $route_id ORDER BY `seq`"; 
    49494960  $trunks = $db->getCol($sql);  
     
    49664977  $intracompany_route = $db->escapeSimple($intracompany_route); 
    49674978  $mohclass = $db->escapeSimple($mohclass); 
     4979  $seq = $db->escapeSimple($seq); 
    49684980  $time_group_id = $time_group_id == ''? 'NULL':$db->escapeSimple($time_group_id); 
    49694981  $sql = "UPDATE `outbound_routes` SET  
    49704982    `name`='$name', `outcid`='$outcid', `outcid_mode`='$outcid_mode', `password`='$password',  
    49714983    `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)
    49734985  sql($sql); 
    49744986 
     
    49824994// function core_routing_add($name,$patterns,$trunks,$method,$pass,$emergency="",$intracompany="",$mohsilence="",$routecid="",$routecid_mode="") 
    49834995function core_routing_addbyid($name, $outcid, $outcid_mode, $password, $emergency_route, $intracompany_route, $mohclass, $time_group_id, $patterns, $trunks, $seq = 'new') { 
     4996  global $amp_conf; 
    49844997  global $db; 
    49854998 
     
    49955008    VALUES ('$name', '$outcid', '$outcid_mode', '$password', '$emergency_route', '$intracompany_route', '$mohclass', '$time_group_id')"; 
    49965009  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); 
    49985014 
    49995015  core_routing_updatepatterns($route_id, $patterns); 
     
    50085024} 
    50095025 
     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 */ 
    50105030function core_routing_updatepatterns($route_id, &$patterns, $delete = false) { 
    50115031  global $db; 
    50125032 
     5033  $route_id =  $db->escapeSimple($route_id); 
    50135034  $filter = '/[^0-9\-\.\[\]xXnNzZ]/'; 
    50145035  $insert_pattern = array(); 
     
    50195040    $prepend_digits = $db->escapeSimple(preg_replace($filter,'',strtoupper($pattern['prepend_digits']))); 
    50205041 
    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); 
    50225043    $insert_pattern[$hash_index] = array($match_pattern_prefix, $match_pattern_pass, $match_cid, $prepend_digits); 
    50235044  } 
    50245045 
    50255046  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)); 
    50275048  } 
    50285049  $compiled = $db->prepare('INSERT INTO `outbound_route_patterns` (`route_id`, `match_pattern_prefix`, `match_pattern_pass`, `match_cid`, `prepend_digits`) VALUES ('.$route_id.',?,?,?,?)'); 
     
    50365057  global $db; 
    50375058 
     5059  $route_id = $db->escapeSimple($route_id); 
    50385060  $insert_trunk = array(); 
    50395061  $seq = 0; 
     
    50435065  } 
    50445066  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)); 
    50465068  } 
    50475069  $compiled = $db->prepare("INSERT INTO `outbound_route_trunks` (`route_id`, `trunk_id`, `seq`) VALUES ($route_id,?,?)"); 
     
    50575079function core_timegroups_usage($group_id) { 
    50585080 
     5081  $group_id = q($group_id); 
    50595082  $results = sql("SELECT route_id, name FROM outbound_routes WHERE time_group_id = $group_id","getAll",DB_FETCHMODE_ASSOC); 
    50605083  if (empty($results)) {