Ticket #3549: sipiaxchandid.patch

File sipiaxchandid.patch, 11.6 kB (added by Nick_Lewis, 3 years ago)
  • old/functions.inc.php

    old new  
    10091009           
    10101010      } 
    10111011 
    1012       // Now create macro-from-zaptel-nnn for each defined channel to route it to the DID routing 
     1012      // Now create macro-from-channel-nnn for each defined channel to route it to the DID routing 
    10131013      // Send it to from-trunk so it is handled as other dids would be handled. 
    10141014      // 
    10151015      foreach (core_zapchandids_list() as $row) { 
    10161016        $channel = $row['channel']; 
    10171017        $did     = $row['did']; 
    10181018 
    1019         $zap_context = "macro-from-zaptel-{$channel}"; 
    1020         $ext->add($zap_context, 's', '', new ext_noop('Entering '.$zap_context.' with DID = ${DID} and setting to: '.$did)); 
    1021         $ext->add($zap_context, 's', '', new ext_setvar('__FROM_DID',$did)); 
    1022         $ext->add($zap_context, 's', '', new ext_goto('1',$did,'from-trunk')); 
     1019        $channel_context = "macro-from-channel-{$channel}"; 
     1020         
     1021        //magic string 'siptoheader' for extracting DID from sip To: header 
     1022        if ($did == "siptoheader") { 
     1023          $ext->add($channel_context, 's', '', new ext_noop('Entering '.$channel_context.' with DID = ${DID}')); 
     1024          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID','${SIP_HEADER(TO)}')); 
     1025          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID','${CUT(FROM_DID,@,1)}')); 
     1026          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID','${CUT(FROM_DID,:,2)}')); 
     1027          $ext->add($channel_context, 's', '', new ext_noop('Used sip To: header to set DID = ${FROM_DID}')); 
     1028          $ext->add($channel_context, 's', '', new ext_goto('1','${FROM_DID}','from-trunk')); 
     1029        } else { 
     1030          $ext->add($channel_context, 's', '', new ext_noop('Entering '.$channel_context.' with DID = ${DID} and setting to: '.$did)); 
     1031          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID',$did)); 
     1032          $ext->add($channel_context, 's', '', new ext_goto('1',$did,'from-trunk')); 
     1033        } 
    10231034      } 
    10241035 
    10251036      /* user extensions */ 
     
    11341145            case 'IAX2': 
    11351146            case 'SIP': 
    11361147              $trunkgroup = $trunkprops['globalvar']; 
    1137               $trunkcontext  = "from-trunk-".strtolower($trunkprops['tech'])."-".$trunkprops['name']; 
    1138               $ext->add($trunkcontext, '_.', '', new ext_setvar('GROUP()',$trunkgroup)); 
    1139               $ext->add($trunkcontext, '_.', '', new ext_goto('1','${EXTEN}','from-trunk')); 
     1148              $context  = "from-trunk-".strtolower($trunkprops['tech'])."-".$trunkprops['name']; 
     1149              $channeltech = $trunkprops['tech']; 
     1150              //if ($channeltech == "IAX2") {$channeltech = "IAX";} 
     1151 
     1152              $exten = '_.'; 
     1153       
     1154              $ext->add($context, $exten, '', new ext_set('DID', '${EXTEN}')); 
     1155              $ext->add($context, $exten, '', new ext_goto(1, 's')); 
     1156 
     1157              $exten = 's'; 
     1158              $ext->add($context, $exten, '', new ext_noop('Entering '.$context.' with DID == ${DID}')); 
     1159              $ext->add($context, $exten, '', new ext_setvar('GROUP()',$trunkgroup)); 
     1160              // Some trunks _require_ a RINGING be sent before an Answer.  
     1161              $ext->add($context, $exten, '', new ext_ringing()); 
     1162              // If ($did == "") { $did = "s"; } 
     1163              $ext->add($context, $exten, '', new ext_set('DID', '${IF($["${DID}"= ""]?s:${DID})}')); 
     1164              $ext->add($context, $exten, '', new ext_noop('DID is now ${DID}')); 
     1165              $ext->add($context, $exten, '', new ext_gotoif('$["${CHANNEL:0:3}"="'.$channeltech.'"]', 'trunkok', 'nottrunk')); 
     1166              $ext->add($context, $exten, 'nottrunk', new ext_goto('1', '${DID}', 'from-trunk')); 
     1167              // If there's no ext-did,s,1, that means there's not a no did/no cid route. Hangup. 
     1168              $ext->add($context, $exten, '', new ext_macro('Hangupcall', 'dummy')); 
     1169              $ext->add($context, $exten, 'trunkok', new ext_noop('Is a '.$channeltech.' Trunk Channel')); 
     1170              $ext->add($context, $exten, '', new ext_set('CHAN', '${CHANNEL:4}')); 
     1171              $ext->add($context, $exten, '', new ext_set('CHAN', '${CUT(CHAN,-,1)}')); 
     1172              $ext->add($context, $exten, '', new ext_macro('from-channel-${CHAN}', '${DID},1')); 
     1173              // If nothing there, then treat it as a DID 
     1174              $ext->add($context, $exten, '', new ext_noop('Returned from Macro from-channel-${CHAN}')); 
     1175              $ext->add($context, $exten, '', new ext_goto(1, '${DID}', 'from-trunk')); 
     1176 
     1177 
    11401178              break; 
    11411179            default: 
    11421180          } 
     
    18741912        $ext->add($context, $exten, '', new ext_set('CHAN', '${CHANNEL:4}')); 
    18751913      }        
    18761914      $ext->add($context, $exten, '', new ext_set('CHAN', '${CUT(CHAN,-,1)}')); 
    1877       $ext->add($context, $exten, '', new ext_macro('from-zaptel-${CHAN}', '${DID},1')); 
     1915      $ext->add($context, $exten, '', new ext_macro('from-channel-${CHAN}', '${DID},1')); 
    18781916      // If nothing there, then treat it as a DID 
    1879       $ext->add($context, $exten, '', new ext_noop('Returned from Macro from-zaptel-${CHAN}')); 
     1917      $ext->add($context, $exten, '', new ext_noop('Returned from Macro from-channel-${CHAN}')); 
    18801918      $ext->add($context, $exten, '', new ext_goto(1, '${DID}', 'from-pstn')); 
    18811919      $ext->add($context, 'fax', '', new ext_goto(1, 'in_fax', 'ext-fax')); 
    18821920 
     
    30413079  global $db; 
    30423080 
    30433081 
    3044   if (!ctype_digit(trim($channel)) || trim($channel) == '') { 
    3045     echo "<script>javascript:alert('"._("Invalid Channel Number, must be numeric and not blank")."')</script>"; 
     3082  if (trim($channel) == '') { 
     3083    echo "<script>javascript:alert('"._("Invalid Channel Number, must not be blank")."')</script>"; 
    30463084    return false; 
    30473085  } 
    30483086  if (trim($did) == '') { 
     
    30503088    return false; 
    30513089  } 
    30523090 
     3091  //permit non numeric channel names 
     3092  if (!is_numeric($channel)) { 
     3093    $tableinfo = $db->tableinfo('zapchandids'); 
     3094    if ($tableinfo[0]['type'] != 'string') { 
     3095      $sql = "ALTER TABLE zapchandids CHANGE COLUMN channel channel VARCHAR(40)";  
     3096      $results = $db->query($sql); 
     3097      if (DB::IsError($results)) {die_freepbx($results->getMessage()."<br><br>".$sql);} 
     3098    } 
     3099  } 
     3100 
    30533101  $description = q($description); 
    30543102  $channel     = q($channel); 
    30553103  $did         = q($did); 
     
    30703118function core_zapchandids_edit($description, $channel, $did) { 
    30713119  global $db; 
    30723120 
     3121  //permit non numeric channel names 
     3122  if (!is_numeric($channel)) { 
     3123    $tableinfo = $db->tableinfo('zapchandids'); 
     3124    if ($tableinfo[0]['type'] != 'string') { 
     3125      $sql = "ALTER TABLE zapchandids CHANGE COLUMN channel channel VARCHAR(40)";  
     3126      $results = $db->query($sql); 
     3127      if (DB::IsError($results)) {die_freepbx($results->getMessage()."<br><br>".$sql);} 
     3128    } 
     3129  } 
     3130 
    30733131  $description = q($description); 
    30743132  $channel     = q($channel); 
    30753133  $did         = q($did); 
  • old/module.xml

    old new  
    5454    <users needsenginedb="yes" sort="-3">Users</users> 
    5555    <devices needsenginedb="yes" sort="-4">Devices</devices> 
    5656    <did category="Inbound Call Control" sort="-5">Inbound Routes</did> 
    57     <zapchandids category="Inbound Call Control" sort="-5">Zap Channel DIDs</zapchandids> 
     57    <zapchandids category="Inbound Call Control" sort="-5">Channel DIDs</zapchandids> 
    5858    <routing>Outbound Routes</routing> 
    5959    <trunks>Trunks</trunks> 
    6060    <general>General Settings</general> 
  • old/page.zapchandids.php

    old new  
    7171  $channel     = $row['channel']; 
    7272  $did         = $row['did']; 
    7373 
    74   echo "<h2>"._("Edit Zap Channel: ").$channel."</h2>"; 
     74  echo "<h2>"._("Edit Channel: ").$channel."</h2>"; 
    7575} else { 
    76   echo "<h2>"._("Add Zap Channel")."</h2>"; 
     76  echo "<h2>"._("Add Channel")."</h2>"; 
    7777} 
    7878 
    79 $helptext = _("Zap Channel DIDs allow you to assign a DID to specific Zap Channels. You can supply the same DID to multiple channels. This would be a common scenario if you have multiple POTS lines that are on a hunt group from your provider. You MUST assign the channel's context to from-zaptel for these settings to have effect. It will be a line that looks like:<br /><br />context = from-zaptel<br /><br />in your zapata.conf configuration effecting the specified channel(s). Once you have assigned DIDs you can use standard Inbound Routes with the specified DIDs to route your calls."); 
     79$helptext = _("Channel DIDs allow you to assign a DID to specific Channels. You can supply the same DID to multiple channels. This would be a common scenario if you have multiple POTS lines that are on a hunt group from your provider. For DAHDI/ZAP channels, you MUST assign the channel's context to from-zaptel for these settings to have effect. It will be a line that looks like:<br /><br />context = from-zaptel<br /><br />in your zapata.conf configuration effecting the specified channel(s). For sip trunk channels you MUST set the channel's context to from-trunk-sip-TRUNKNAME. Once you have assigned DIDs you can use standard Inbound Routes with the specified DIDs to route your calls."); 
    8080echo "<p>".$helptext."</p>\n"; 
    8181?> 
    8282<form name="editZapchandid" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkZapchandid(editZapchandid);"> 
     
    8989  if ($extdisplay == '') { 
    9090?> 
    9191  <tr> 
    92     <td><a href="#" class="info"><?php echo _("Channel")?>:<span><?php echo _("The Zap Channel number to map to a DID")?></span></a></td> 
    93     <td><input size="5" type="text" name="channel" value="<?php  echo $channel; ?>" tabindex="<?php echo ++$tabindex;?>"></td> 
     92    <td><a href="#" class="info"><?php echo _("Channel")?>:<span><?php echo _("The Channel to map to a DID")?></span></a></td> 
     93    <td><input size="40" type="text" name="channel" value="<?php  echo $channel; ?>" tabindex="<?php echo ++$tabindex;?>"></td> 
    9494  </tr> 
    9595<?php 
    9696  } 
     
    100100    <td><input size="40" type="text" name="description" value="<?php  echo $description; ?>" tabindex="<?php echo ++$tabindex;?>"></td> 
    101101  </tr> 
    102102  <tr> 
    103     <td><a href="#" class="info"><?php echo _("DID")?>:<span><?php echo _("The DID that this channel represents. The incoming call on this channel will be treated as if it came in with this DID and can be managed with Inbound Routing on DIDs")?></span></a></td> 
     103    <td><a href="#" class="info"><?php echo _("DID")?>:<span><?php echo _("The DID that this channel represents. The incoming call on this channel will be treated as if it came in with this DID and can be managed with Inbound Routing on DIDs. For SIP channels you may use the magic string 'siptoheader' if you want the DID to be retrieved dynamically from the To: header of the SIP message.")?></span></a></td> 
    104104    <td><input size="40" type="text" name="did" value="<?php echo $did; ?>"  tabindex="<?php echo ++$tabindex;?>"/></td> 
    105105  </tr> 
    106106 
     
    120120var actionDelete = false; 
    121121 
    122122function checkZapchandid(theForm) { 
    123   var msgInvalidChannel = "<?php echo _('Invalid Channel Number, must be numeric and not blank'); ?>"; 
     123  var msgInvalidChannel = "<?php echo _('Invalid Channel Number, must not be blank'); ?>"; 
    124124  var msgInvalidDID = "<?php echo _('Invalid DID, must be a non-blank DID'); ?>"; 
    125125  var msgConfirmDIDNonStd = "<?php echo _('DID information is normally just an incoming telephone number.\n\nYou have entered a non standard DID pattern.\n\nAre you sure this is correct?'); ?>"; 
    126126  var msgConfirmConvertDID = "<?php echo _('You appear to be using a converted DID in the form of zapchanNN that was automatically generated during an upgrade. You should consider assigning the DID that is normally associated with this channel to take full advantage of the inbound routing abilities. Changing the DID here will require you to make changes in the Inbound Routes tab. Do you want to continue?'); ?>"; 
     
    134134  // form validation 
    135135 
    136136  defaultEmptyOK = false; 
    137   if (!isInteger(theForm.channel.value)) { 
     137  if (isEmpty(theForm.channel.value)) { 
    138138    return warnInvalid(theForm.channel, msgInvalidChannel); 
    139139  } 
    140140  if (isEmpty(theForm.did.value)) {