root/modules/branches/2.5/core/page.trunks.php

Revision 5972, 37.3 kB (checked in by p_lindheimer, 5 years ago)

more add and delete icons on links

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 // routing.php Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca)
3 // Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
4 //
5 //This program is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU General Public License
7 //as published by the Free Software Foundation; either version 2
8 //of the License, or (at your option) any later version.
9 //
10 //This program is distributed in the hope that it will be useful,
11 //but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //GNU General Public License for more details.
14
15
16 $display='trunks';
17 $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:'';
18 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
19 $tech = strtolower(isset($_REQUEST['tech'])?$_REQUEST['tech']:'');
20
21 $trunknum = ltrim($extdisplay,'OUT_');
22
23
24 // populate some global variables from the request string
25 $set_globals = array("outcid","maxchans","dialoutprefix","channelid","peerdetails","usercontext","userconfig","register","keepcid","failtrunk","disabletrunk");
26 foreach ($set_globals as $var) {
27     if (isset($_REQUEST[$var])) {
28         $$var = stripslashes( $_REQUEST[$var] );
29     }
30 }
31
32 // ensure that keepcid is set to something:
33 if (!isset($keepcid)) {
34     $keepcid = "off";
35 }
36 // ensure that failtrunk is set to something:
37 if (!isset($failtrunk)) {
38     $failtrunk = "";
39 }
40 $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
41
42 if (!isset($disabletrunk)) {
43     $disabletrunk = "off";
44 }
45
46 if (isset($_REQUEST["dialrules"])) {
47     //$dialpattern = $_REQUEST["dialpattern"];
48     $dialrules = explode("\n",$_REQUEST["dialrules"]);
49
50     if (is_array($dialrules))
51         foreach (array_keys($dialrules) as $key) {
52             //trim it
53             $dialrules[$key] = trim($dialrules[$key]);
54             
55             // remove blanks
56             if ($dialrules[$key] == "") unset($dialrules[$key]);
57             
58             // remove leading underscores (we do that on backend)
59             if ($dialrules[$key][0] == "_") $dialrules[$key] = substr($dialrules[$key],1);
60         }
61     
62     // check for duplicates, and re-sequence
63     $dialrules = array_values(array_unique($dialrules));
64 } else {
65     $dialrules = array();
66 }
67
68 //if submitting form, update database
69 switch ($action) {
70     case "addtrunk":
71         if (!isset($failtrunk))
72             $failtrunk="";
73         $trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk),$disabletrunk);
74         
75         core_trunks_addDialRules($trunknum, $dialrules);
76         needreload();
77         redirect_standard();
78     break;
79     case "edittrunk":
80         if (!isset($failtrunk))
81             $failtrunk="";
82         core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk);
83         
84         /* //DIALRULES
85         deleteTrunkRules($channelid);
86         addTrunkRules($channelid, $dialrules);
87         */
88         
89         // this can rewrite too, so edit is the same
90         core_trunks_addDialRules($trunknum, $dialrules);
91         needreload();
92         redirect_standard('extdisplay');
93     break;
94     case "deltrunk":
95     
96         core_trunks_del($trunknum);
97         
98         /* //DIALRULES
99         deleteTrunkRules($channelid);
100         */
101         core_trunks_deleteDialRules($trunknum);
102         needreload();
103         redirect_standard();
104     break;
105     case "populatenpanxx7":
106     case "populatenpanxx10":
107         if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) {
108             // first thing we do is grab the exch:
109             $ch = curl_init();
110             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
111             curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]);
112             curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)");
113             $str = curl_exec($ch);
114             curl_close($ch);
115
116             // quick 'n dirty - nabbed from PEAR
117             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php');
118             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php');
119
120             $xml = new xml_unserializer;
121             $xml->unserialize($str);
122             $xmldata = $xml->getUnserializedData();
123
124             if (isset($xmldata['lca-data']['prefix'])) {
125                 
126                 if ($action == 'populatenpanxx10') {
127                     // 10 digit dialing
128                     // - add area code to 7 digits
129                     // - match local 10 digits
130                     // - add 1 to anything else
131                     $dialrules[] = $matches[1].'NXXXXXX';
132                     // add NPA to 7-digits
133                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
134                         $dialrules[] = $prefix['npa'].'+'.$prefix['nxx'].'XXXX';
135                     }
136                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
137                         $dialrules[] = $prefix['npa'].$prefix['nxx'].'XXXX';
138                     }
139                     // if a number was not matched as local, dial it with '1' prefix
140                     $dialrules[] = '1+NXXNXXXXXX';
141                 } else {
142                     // 7 digit dialing
143                     // - drop area code from local numbers
144                     // - match local 7 digit numbers
145                     // - add 1 to everything else
146                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
147                         $dialrules[] = $prefix['npa'].'|'.$prefix['nxx'].'XXXX';
148                     }
149                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
150                         $dialrules[] = $prefix['nxx'].'XXXX';
151                     }
152                     $dialrules[] = '1+NXXNXXXXXX';
153                     $dialrules[] = '1'.$matches[1].'+NXXXXXX';
154                 }
155
156                 // check for duplicates, and re-sequence
157                 $dialrules = array_values(array_unique($dialrules));
158             } else {
159                 $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"];
160             }
161
162         } else {
163             // what a horrible error message... :p
164             $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)");
165         }
166         
167         if (isset($errormsg)) {
168             echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>";
169             unset($errormsg);
170         }
171     break;
172 }
173     
174 //get all rows from globals
175 $sql = "SELECT * FROM globals";
176 $globals = $db->getAll($sql);
177 if(DB::IsError($globals)) {
178     die_freepbx($globals->getMessage());
179 }
180
181 //create a set of variables that match the items in global[0]
182 foreach ($globals as $global) {
183     ${trim($global[0])} = htmlentities($global[1]);
184 }
185
186 ?>
187 </div>
188
189 <div class="rnav">
190 <ul>
191     <li><a <?php  echo ($extdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Trunk")?></a></li>
192 <?php
193 //get existing trunk info
194 $tresults = core_trunks_list();
195
196 foreach ($tresults as $tresult) {
197     $background = ($tresult[2] == 'on')?'#DDD':'';
198     echo "\t<li><a ".($extdisplay==$tresult[0] ? 'class="current"':'')." href=\"config.php?display=".urlencode($display)."&amp;extdisplay=".urlencode($tresult[0])."\" title=\"".urlencode($tresult[1])."\" style=\"background: $background;\" >"._("Trunk")." ".substr(str_replace('AMP:', '', $tresult[1]),0,15)."</a></li>\n";
199 }
200
201 ?>
202 </ul>
203 </div>
204
205 <div class="content">
206
207 <?php
208 if (!$tech && !$extdisplay) {
209 ?>
210     <h2><?php echo _("Add a Trunk")?></h2>
211 <?php
212     $baseURL   = $_SERVER['PHP_SELF'].'?display='.urlencode($display).'&';
213     $trunks = array(
214         array('url'=> $baseURL.'tech=ZAP', 'tlabel' =>  _("Add Zap Trunk")),
215         array('url'=> $baseURL.'tech=IAX2', 'tlabel' =>  _("Add IAX2 Trunk")),
216         array('url'=> $baseURL.'tech=SIP', 'tlabel' =>  _("Add SIP Trunk")),
217         array('url'=> $baseURL.'tech=ENUM', 'tlabel' =>  _("Add ENUM Trunk")),
218         array('url'=> $baseURL.'tech=DUNDI', 'tlabel' =>  _("Add DUNDi Trunk")),
219         array('url'=> $baseURL.'tech=CUSTOM', 'tlabel' =>  _("Add Custom Trunk")),
220     );
221     foreach ($trunks as $trunk) {
222         $label = '<span><img width="16" height="16" border="0" title="'.$trunk['tlabel'].'" alt="" src="images/core_add.png"/>&nbsp;'.$trunk['tlabel'].'</span>';
223         echo "<a href=".$trunk['url'].">".$label."</a><br /><br /";
224     }
225 } else {
226     if ($extdisplay) {
227         //list($trunk_tech, $trunk_name) = explode("/",$tname);
228         //if ($trunk_tech == "IAX2") $trunk_tech = "IAX"; // same thing
229         $tech = core_trunks_getTrunkTech($trunknum);
230
231         $outcid = ${"OUTCID_".$trunknum};
232         $maxchans = ${"OUTMAXCHANS_".$trunknum};
233         $dialoutprefix = ${"OUTPREFIX_".$trunknum};
234         $keepcid = isset(${"OUTKEEPCID_".$trunknum})?${"OUTKEEPCID_".$trunknum}:'';
235         $failtrunk = isset(${"OUTFAIL_".$trunknum})?${"OUTFAIL_".$trunknum}:'';
236         $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
237         $disabletrunk = isset(${"OUTDISABLE_".$trunknum})?${"OUTDISABLE_".$trunknum}:'';
238
239         
240         if ($tech!="enum") {
241     
242             if (!isset($channelid)) {
243                 $channelid = core_trunks_getTrunkTrunkName($trunknum);
244             }
245
246             if ($tech!="custom" && $tech!="dundi") {  // custom trunks will not have user/peer details in database table
247                 // load from db
248                 if (!isset($peerdetails)) {   
249                     $peerdetails = core_trunks_getTrunkPeerDetails($trunknum);
250                 }
251     
252                 if (!isset($usercontext)) {   
253                     $usercontext = core_trunks_getTrunkUserContext($trunknum);
254                 }
255     
256                 if (!isset($userconfig)) {   
257                     $userconfig = core_trunks_getTrunkUserConfig($trunknum);
258                 }
259                     
260                 if (!isset($register)) {   
261                     $register = core_trunks_getTrunkRegister($trunknum);
262                 }
263             }
264         }
265         
266         if (count($dialrules) == 0) {
267             if ($temp = core_trunks_getDialRules($trunknum)) {
268                 foreach ($temp as $key=>$val) {
269                     // extract all ruleXX keys
270                     if (preg_match("/^rule\d+$/",$key)) {
271                         $dialrules[] = $val;
272                     }
273                 }
274             }
275             unset($temp);
276         }
277
278         echo "<h2>".sprintf(_("Edit %s Trunk"),strtoupper($tech))."</h2>";
279         $tlabel = sprintf(_("Delete Trunk %s"),substr($channelid,0,20));
280         $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/>&nbsp;'.$tlabel.'</span>';
281 ?>
282         <p><a href="config.php?display=<?php echo urlencode($display) ?>&extdisplay=<?php echo urlencode($extdisplay) ?>&action=deltrunk"><?php echo $label ?></a></p>
283 <?php
284
285         // find which routes use this trunk
286         $routes = core_trunks_gettrunkroutes($trunknum);
287         $num_routes = count($routes);
288         if ($num_routes > 0) {
289             echo "<a href=# class=\"info\">&nbsp;"._("In use by")." ".$num_routes." ".($num_routes == 1 ? _("route") : _("routes"))."<span>";
290             foreach($routes as $route=>$priority) {
291                 echo _("Route")." <b>".$route."</b>: "._("Sequence")." <b>".$priority."</b><br>";
292             }
293             echo "</span></a>";
294         } else {
295             echo "&nbsp;<b>"._("WARNING:")."</b> <a href=# class=\"info\">"._("This trunk is not used by any routes!")."<span>";
296             echo _("This trunk will not be able to be used for outbound calls until a route is setup that uses it. Click on <b>Outbound Routes</b> to setup routing.");
297             echo "</span></a>";
298         }
299
300     } else {
301         // set defaults
302         $outcid = "";
303         $maxchans = "";
304         $dialoutprefix = "";
305         
306         if ($tech == "zap") {
307             $channelid = "g0";
308         } else {
309             $channelid = "";
310         }
311         
312         // only for iax2/sip
313         $peerdetails = "host=***provider ip address***\nusername=***userid***\nsecret=***password***\ntype=peer";
314         $usercontext = "";
315         $userconfig = "secret=***password***\ntype=user\ncontext=from-trunk";
316         $register = "";
317         
318         $localpattern = "NXXXXXX";
319         $lddialprefix = "1";
320         $areacode = "";
321     
322         echo "<h2>".sprintf("Add %s Trunk",strtoupper($tech))."</h2>";
323
324     }
325 switch ($tech) {
326     case 'dundi':
327         $helptext = _('FreePBX offers limited support for DUNDi trunks and additional manual configuration is required. The trunk name should correspond to the [mappings] section of the remote dundi.conf systems. For example, you may have a mapping on the remote system, and corresponding configurations in dundi.conf locally, that looks as follows:<br /><br />[mappings]<br />priv => dundi-extens,0,IAX2,priv:${SECRET}@218.23.42.26/${NUMBER},noparital<br /><br />In this example, you would create this trunk and name it priv. You would then create the corresponding IAX2 trunk with proper settings to work with DUNDi. This can be done by making an IAX2 trunk in FreePBX or by using the iax_custom.conf file.<br />The dundi-extens context in this example must be created in extensions_custom.conf. This can simply include contexts such as ext-local, ext-intercom-users, ext-paging and so forth to provide access to the corresponding extensions and features provided by these various contexts and generated by FreePBX.');
328         break;
329     default:
330         $helptext = '';
331 }
332 if ($helptext != '') {
333     if ($extdisplay) {
334         echo "<br /><br />";
335     }
336     echo $helptext;
337 }
338         
339 ?>
340    
341         <form name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');">
342             <input type="hidden" name="display" value="<?php echo $display?>"/>
343             <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>
344             <input type="hidden" name="action" value=""/>
345             <input type="hidden" name="tech" value="<?php echo $tech?>"/>
346             <table>
347             <tr>
348                 <td colspan="2">
349                     <h4><?php echo _("General Settings")?></h4>
350                 </td>
351             </tr>
352             <tr>
353                 <td>
354                     <a href=# class="info"><?php echo _("Outbound Caller ID")?><span><br><?php echo _("Caller ID for calls placed out on this trunk<br><br>Format: <b>\"caller name\" &lt;#######&gt;</b>. You can also use the magic string 'hidden' to hide the CallerID sent out over Digital lines ONLY (E1/T1/J1/BRI/SIP/IAX)")?><br><br></span></a>:
355                 </td><td>
356                     <input type="text" size="20" name="outcid" value="<?php echo $outcid;?>" tabindex="<?php echo ++$tabindex;?>"/>
357                 </td>
358             </tr>
359             <tr>
360                 <td>
361                     <a href="#" class="info"><?php echo _("Never Override CallerID")?><span><br><?php echo _("Some VoIP providers will drop the call if you try to send an invalid CallerID (one you don't 'own.' Use this to never send a CallerID that you haven't explicitly specified in this trunk or in the outbound callerid field of an extension/user. You might notice this problem if you discover that Follow-Me or RingGroups with external numbers don't work properly. Checking this box has the effect of disabling 'foreign' callerids from going out this trunk. You must define an Outbound Caller ID on the this trunk when checking this.");?><br /><br /></span></a>:
362                 </td><td>
363                     <input type="checkbox" name="keepcid" <?php if ($keepcid=="on") {echo "checked";}?> tabindex="<?php echo ++$tabindex;?>"/>
364                 </td>
365             <tr>
366                 <td>
367 <?php
368     if ($tech == "sip" || substr($tech,0,3) == "iax") {
369         $pr_tech = ($tech == "iax") ? "iax2":$tech;
370 ?>
371                     <a href=# class="info"><?php echo _("Maximum Channels")?><span><?php echo sprintf(_("Controls the maximum number of outbound channels (simultaneous calls) that can be used on this trunk. To count inbound calls against this maximum, use the auto-generated context: %s as the inbound trunk's context. (see extensions_additional.conf) Leave blank to specify no maximum."),((isset($channelid) && trim($channelid)!="")?"from-trunk-$pr_tech-$channelid":"from-trunk-[trunkname]"))?></span></a>:
372 <?php
373     } else {
374 ?>
375                     <a href=# class="info"><?php echo _("Maximum Channels")?><span><?php echo _("Controls the maximum number of outbound channels (simultaneous calls) that can be used on this trunk. Inbound calls are not counted against the maximum. Leave blank to specify no maximum.")?></span></a>:
376 <?php
377     }
378 ?>
379                 </td><td>
380                     <input type="text" size="3" name="maxchans" value="<?php echo htmlspecialchars($maxchans); ?>" tabindex="<?php echo ++$tabindex;?>"/>
381                 </td>
382             </tr>
383
384             <tr>
385                 <td><a class="info" href="#"><?php echo _("Disable Trunk")?><span><?php echo _("Check this to disable this trunk in all routes where it is used.")?></span></a>:
386                 </td>
387                 <td>
388                 <input type='checkbox'  tabindex="<?php echo ++$tabindex;?>"name='disabletrunk' id="disabletrunk" <?php if ($disabletrunk=="on") { echo 'CHECKED'; }?> OnClick='disable_verify(disabletrunk); return true;'><small><?php echo _("Disable")?></small>
389                 </td>
390             </tr>
391
392             <tr>
393                 <td><a class="info" href="#"><?php echo _("Monitor Trunk Failures")?><span><?php echo _("If checked, supply the name of a custom AGI Script that will be called to report, log, email or otherwise take some action on trunk failures that are not caused by either NOANSWER or CANCEL.")?></span></a>:
394                 </td>
395                 <td>
396                 <input <?php if (!$failtrunk_enable) echo "disabled style='background: #DDD;'"?> type="text" size="20" name="failtrunk" value="<?php echo htmlspecialchars($failtrunk)?>"/>
397                 <input type='checkbox' tabindex="<?php echo ++$tabindex;?>" name='failtrunk_enable' id="failtrunk_enable" value='1' <?php if ($failtrunk_enable) { echo 'CHECKED'; }?> OnClick='disable_field(failtrunk,failtrunk_enable); return true;'><small><?php echo _("Enable")?></small>
398                 </td>
399             </tr>
400
401             <tr>
402                 <td colspan="2">
403                     <h4><?php echo _("Outgoing Dial Rules")?></h4>
404                 </td>
405             </tr>
406             <tr>
407                 <td valign="top">
408                     <a href=# class="info"><?php echo _("Dial Rules")?><span><?php echo _("A Dial Rule controls how calls will be dialed on this trunk. It can be used to add or remove prefixes. Numbers that don't match any patterns defined here will be dialed as-is. Note that a pattern without a + or | (to add or remove a prefix) will not make any changes but will create a match. Only the first matched rule will be executed and the remaining rules will not be acted on.")?><br /><br /><b><?php echo _("Rules:")?></b><br />
409     <strong>X</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br />
410     <strong>Z</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br />
411     <strong>N</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br />
412     <strong>[1237-9]</strong>&nbsp;   <?php echo _("matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)")?><br />
413     <strong>.</strong>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more characters (not allowed before a | or +)")?><br />
414     <strong>|</strong>&nbsp;&nbsp;&nbsp; <?php echo _("removes a dialing prefix from the number (for example, 613|NXXXXXX would match when some dialed \"6135551234\" but would only pass \"5551234\" to the trunk)")?>
415     <strong>+</strong>&nbsp;&nbsp;&nbsp; <?php echo _("adds a dialing prefix from the number (for example, 1613+NXXXXXX would match when some dialed \"5551234\" and would pass \"16135551234\" to the trunk)")?><br /><br />
416     <?php echo _("You can also use both + and |, for example: 01+0|1ZXXXXXXXXX would match \"016065551234\" and dial it as \"0116065551234\" Note that the order does not matter, eg. 0|01+1ZXXXXXXXXX does the same thing."); ?>
417                     </span></a>:
418                 </td><td valign="top">
419                     <textarea id="dialrules" cols="20"  tabindex="<?php echo ++$tabindex;?>" rows="<?php 
420                         if (is_array($dialrules)) {
421                             $rows = count($dialrules)+1;
422                             echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) );
423                         } else {
424                             echo "5";
425                         } ?>" name="dialrules"><?php if(is_array($dialrules)) { echo implode("\n",$dialrules); } ?></textarea><br>
426                    
427                     <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>"  tabindex="<?php echo ++$tabindex;?>"/>
428                 </td>
429             </tr>
430             <tr>
431                 <td>
432                     <a href=# class="info"><?php echo _("Dial Rules Wizards")?><span>
433                     <strong><?php echo _("Always dial with prefix")?></strong> <?php echo _("is useful for VoIP trunks, where if a number is dialed as \"5551234\", it can be converted to \"16135551234\".")?><br>
434                     <strong><?php echo _("Remove prefix from local numbers")?></strong> <?php echo _("is useful for ZAP trunks, where if a local number is dialed as \"6135551234\", it can be converted to \"555-1234\".")?><br>
435                     <strong><?php echo _("Lookup numbers for local trunk")?></strong> <?php echo _("This looks up your local number on www.localcallingguide.com (NA-only), and sets up so you can dial either 7 or 10 digits (regardless of what your PSTN is) on a local trunk (where you have to dial 1+areacode for long distance, but only 5551234 (7-digit dialing) or 6135551234 (10-digit dialing) for local calls")?><br>
436                     </span></a>:
437                 </td><td valign="top"><select id="autopop"  tabindex="<?php echo ++$tabindex;?>" name="autopop" onChange="changeAutoPop(); ">
438                         <option value="" SELECTED><?php echo _("(pick one)")?></option>
439                         <option value="always"><?php echo _("Always dial with prefix")?></option>
440                         <option value="remove"><?php echo _("Remove prefix from local numbers")?></option>
441                         <option value="lookup7"><?php echo _("Lookup numbers for local trunk (7-digit dialing)")?></option>
442                         <option value="lookup10"><?php echo _("Lookup numbers for local trunk (10-digit dialing)")?></option>
443                     </select>
444                 </td>
445             </tr>
446             <input id="npanxx" name="npanxx" type="hidden" />
447             <script language="javascript">
448            
449             function disable_field(field, field_enable) {
450                 if (field_enable.checked) {
451                 field.style.backgroundColor = '#FFF';
452                 field.disabled = false;
453                 }
454                 else {
455                 field.style.backgroundColor = '#DDD';
456                 field.disabled = true;
457                 }
458             }
459
460             function disable_verify(field) {
461                 if (field.checked) {
462                 var answer=confirm("Are you sure you want to disable this trunk in all routes it is used?");
463                 if (!answer) {
464                     field.checked = false;
465                 }
466                 }
467                 else {
468                 alert("You have enabled this trunk in all routes it is used");
469                 }
470             }
471
472             function populateLookup(digits) {
473 <?php
474     if (function_exists("curl_init")) { // curl is installed
475 ?>                
476                 //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
477                 do {
478                     var npanxx = <?php echo 'prompt("'._("What is your areacode + prefix (NPA-NXX)?\\n\\n(Note: this database contains North American numbers only, and is not guaranteed to be 100% accurate. You will still have the option of modifying results.)\\n\\nThis may take a few seconds.".'")')?>;
479                     if (npanxx == null) return;
480                 } while (!npanxx.match("^[2-9][0-9][0-9][-]?[2-9][0-9][0-9]$") && <?php echo '!alert("'._("Invalid NPA-NXX. Must be of the format \'NXX-NXX\'").'")'?>);
481                
482                 document.getElementById('npanxx').value = npanxx;
483                 if (digits == 10) {
484                     document.trunkEdit.action.value = "populatenpanxx10";
485                 } else {
486                     document.trunkEdit.action.value = "populatenpanxx7";
487                 }
488                 document.trunkEdit.submit();
489 <?php 
490     } else { // curl is not installed
491 ?>
492                 <?php echo 'alert("'._("Error: Cannot continue!\\n\\nPrefix lookup requires cURL support in PHP on the server. Please install or enable cURL support in your PHP installation to use this function. See http://www.php.net/curl for more information.").'")'?>;
493 <?php
494     }
495 ?>
496             }
497            
498             function populateAlwaysAdd() {
499                 do {
500                     var localpattern = <?php echo 'prompt("'._("What is the local dialing pattern?\\n\\n(ie. NXXNXXXXXX for US/CAN 10-digit dialing, NXXXXXX for 7-digit)").'"'?>,"NXXXXXX");
501                     if (localpattern == null) return;
502                 } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
503                
504                 do {
505                     var localprefix = <?php echo 'prompt("'._("What prefix should be added to the dialing pattern?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')?").'")'?>;
506                     if (localprefix == null) return;
507                 } while (!localprefix.match('^[0-9#*]+$') && <?php echo '!alert("'._("Invalid prefix. Only dialable characters (0-9, #, and *) are allowed.").'")'?>);
508
509                 dialrules = document.getElementById('dialrules');
510                 if (dialrules.value[dialrules.value.length-1] != '\n') {
511                     dialrules.value = dialrules.value + '\n';
512                 }
513                 dialrules.value = dialrules.value + localprefix + '+' + localpattern + '\n';
514             }
515            
516             function populateRemove() {
517                 do {
518                     var localprefix = <?php echo 'prompt("'._("What prefix should be removed from the number?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')").'")'?>;
519                     if (localprefix == null) return;
520                 } while (!localprefix.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._('Invalid prefix. Only 0-9, #, *, Z, N, and X are allowed.').'")'?>);
521                
522                 do {
523                     var localpattern = <?php echo 'prompt("'._("What is the dialing pattern for local numbers after")?> "+localprefix+"? \n\n<?php echo _("(ie. NXXNXXXXXX for US/CAN 10-digit dialing, NXXXXXX for 7-digit)").'"'?>,"NXXXXXX");
524                     if (localpattern == null) return;
525                 } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
526                
527                 dialrules = document.getElementById('dialrules');
528                 if (dialrules.value[dialrules.value.length-1] != '\n') {
529                     dialrules.value = dialrules.value + '\n';
530                 }
531                 dialrules.value = dialrules.value + localprefix + '|' + localpattern + '\n';
532             }
533            
534             function changeAutoPop() {
535                 switch(document.getElementById('autopop').value) {
536                     case "always":
537                         populateAlwaysAdd();
538                     break;
539                     case "remove":
540                         populateRemove();
541                     break;
542                     case "lookup7":
543                         populateLookup(7);
544                     break;
545                     case "lookup10":
546                         populateLookup(10);
547                     break;
548                 }
549                 document.getElementById('autopop').value = '';
550             }
551             </script>
552 <?php /* //DIALRULES
553             <tr>
554                 <td>
555                     <a href=# class="info">Dial rules<span>The area code this trunk is in.</span></a>:
556                 </td><td>&nbsp;
557                     <select id="dialrulestype" name="dialrulestype" onChange="changeRulesType();">
558 <?php
559                     $rules = array( "asis" => "Don't change number",
560                             "always" => "Always dial prefix+areacode",
561                             "local" => "Local 7-digit dialing",
562                             "local10" => "Local 10-digit dialing");
563
564                     foreach ($rules as $value=>$display) {
565                         echo "<option value=\"".$value."\" ".(($value == $dialrulestype) ? "SELECTED" : "").">".$display."</option>";
566                     }
567 ?>
568                     </select>
569                     
570                 </td>
571             </tr>
572             <tr>
573                 <td>
574                     <a href=# class="info"><?php echo _("Local dialing pattern<span>The dialing pattern to make a 'local' call.</span>")</a>:
575                 </td><td>
576                     <input id="localpattern" type="text" size="10" maxlength="20" name="localpattern" value="<?php echo $localpattern ?>"/>
577                     
578                 </td>
579             </tr>
580             <tr>
581                 <td>
582                     <a href=# class="info"><?php echo _("Long-distance dial prefix<span>The prefix for dialing long-distance numbers. In north america, this should be \"1\".</span>")?></a>:
583                 </td><td>
584                     <input id="lddialprefix" type="text" size="3" maxlength="6" name="lddialprefix" value="<?php echo $lddialprefix ?>"/>
585                     
586                 </td>
587             </tr>
588             <tr>
589                 <td>
590                     <a href=# class="info"><?php echo _("Local LD prefix<span>The area code this trunk is in. Any 7-digit numbers that don't match a number in the below list will have dialprefix+areacode added to them. </span>")?></a>:
591                 </td><td>
592                     <input id="areacode" type="text" size="3" maxlength="6" name="areacode" value="<?php echo $areacode ?>"/>
593                     
594                 </td>
595             </tr>
596             <tr>
597                 <td valign="top">
598                     <a href=# class="info"><?php echo _("Local prefixes<span>This should be a list of local areacodes + prefixes to use for local dialing.</span>")?></a>:
599                 </td><td valign="top">&nbsp;
600                     <textarea id="localprefixes" cols="8" rows="<?php  $rows = count($localprefixes)+1; echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) ); ?>" name="localprefixes"><?php echo  implode("\n",$localprefixes);?></textarea><br>
601                     
602                     <input id="npanxx" name="npanxx" type="hidden" /><br>
603                     <a href=# class="info"><?php echo _("Populate with local rules<span>Do a lookup from http://members.dandy.net/~czg/search.html to find all local-reachable area codes and phone numbers.</span>")?></a>: <input type="button" value="Go" onClick="checkPopulate();" />
604                     <br><br>
605                 </td>
606             </tr>
607             <script language="javascript">
608             
609             function checkPopulate() {
610                 //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
611                 var npanxx = <?php echo 'prompt("'._("What is your areacode + prefix (NPA-NXX)?").'")'?>;
612                 
613                 if (npanxx.match("^[2-9][0-9][0-9][-]?[2-9][0-9][0-9]$")) {
614                     document.getElementById('npanxx').value = npanxx;
615                     trunkEdit.action.value = "populatenpanxx";
616                     trunkEdit.submit();
617                 } else if (npanxx != null) {
618                     <?php echo 'alert("'._("Invalid format for NPA-NXX code (must be format: NXXNXX)").'")'?>;
619                 }
620             }
621             
622             function changeRulesType() {
623                 switch(document.getElementById('dialrulestype').value) {
624                     case "always":
625                         document.getElementById('lddialprefix').disabled = false;
626                         document.getElementById('areacode').disabled = false;
627                         document.getElementById('localprefixes').disabled = true;
628                     break;
629                     case "local":
630                     case "local10":
631                         document.getElementById('lddialprefix').disabled = false;
632                         document.getElementById('areacode').disabled = false;
633                         document.getElementById('localprefixes').disabled = false;
634                     break;
635                     case "asis":
636                     default:
637                         document.getElementById('lddialprefix').disabled = true;
638                         document.getElementById('areacode').disabled = true;
639                         document.getElementById('localprefixes').disabled = true;
640                     break;
641                 }
642             }
643             changeRulesType();
644             </script>
645 */?>
646             <tr>
647                 <td>
648                     <a href=# class="info"><?php echo _("Outbound Dial Prefix")?><span><?php echo _("The outbound dialing prefix is used to prefix a dialing string to all outbound calls placed on this trunk. For example, if this trunk is behind another PBX or is a Centrex line, then you would put 9 here to access an outbound line. Another common use is to prefix calls with 'w' on a POTS line that need time to obtain dialtone to avoid eating digits.<br><br>Most users should leave this option blank.")?></span></a>:
649                 </td><td>
650                     <input type="text" size="8" name="dialoutprefix" value="<?php echo htmlspecialchars($dialoutprefix) ?>" tabindex="<?php echo ++$tabindex;?>"/>
651                 </td>
652             </tr>
653             <?php if ($tech != "enum") { ?>
654             <tr>
655                 <td colspan="2">
656                     <h4><?php echo _("Outgoing Settings")?></h4>
657                 </td>
658             </tr>
659             <?php } ?>
660
661     <?php
662     switch ($tech) {
663         case "zap":
664     ?>
665                 <tr>
666                     <td>
667                         <a href=# class="info"><?php echo _("Zap Identifier (trunk name)")?><span><br><?php echo _("ZAP channels are referenced either by a group number or channel number (which is defined in zapata.conf).  <br><br>The default setting is <b>g0</b> (group zero).")?><br><br></span></a>:
668                     </td><td>
669                         <input type="text" size="8" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
670                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
671                     </td>
672                 </tr>
673     <?php
674         break;
675         case "enum":
676         break;
677         case "custom":
678     ?>
679                 <tr>
680                     <td>
681                         <a href=# class="info"><?php echo _("Custom Dial String")?><span><?php echo _("Define the custom Dial String.  Include the token")?> $OUTNUM$ <?php echo _("wherever the number to dial should go.<br><br><b>examples:</b><br><br>CAPI/XXXXXXXX/")?>$OUTNUM$<?php echo _("/b<br>H323/")?>$OUTNUM$@XX.XX.XX.XX<br>OH323/$OUTNUM$@XX.XX.XX.XX:XXXX<br>vpb/1-1/$OUTNUM$</span></a>:
682                     </td><td>
683                         <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
684                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
685                     </td>
686                 </tr>   
687     <?php
688         break;
689         case "dundi":
690     ?>
691                 <tr>
692                     <td>
693                         <a href=# class="info"><?php echo _("DUNDi Mapping")?><span><?php echo _("This is the name of the DUNDi mapping as defined in the [mappings] section of remote dundi.conf peers. This corresponds to the 'include' section of the peer details in the local dundi.conf file. This requires manual configuration of DUNDi to use this trunk.")?></span></a>:
694                     </td><td>
695                         <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
696                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
697                     </td>
698                 </tr>   
699     <?php
700         break;
701         default:
702     ?>
703                 <tr>
704                     <td>
705                         <a href=# class="info"><?php echo _("Trunk Name")?><span><br><?php echo _("Give this trunk a unique name.  Example: myiaxtel")?><br><br></span></a>:
706                     </td><td>
707                         <input type="text" size="14" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
708                     </td>
709                 </tr>
710                 <tr>
711                     <td colspan="2">
712                     <a href=# class="info"><?php echo _("PEER Details")?><span><br><?php echo _("Modify the default PEER connection parameters for your VoIP provider.<br><br>You may need to add to the default lines listed below, depending on your provider.<br /><br />WARNING: Oreder is important as it will be retained. For example, if you use the \"allow/deny\" directives make sure deny comes first.")?><br><br></span></a>:
713                     </td>
714                 </tr>
715                 <tr>
716                     <td colspan="2">
717                         <textarea rows="10" cols="40" name="peerdetails" tabindex="<?php echo ++$tabindex;?>"><?php echo htmlspecialchars($peerdetails) ?></textarea>
718                     </td>
719                 </tr>
720                 <tr>
721                     <td colspan="2">
722                         <h4><?php echo _("Incoming Settings")?></h4>
723                     </td>
724                 </tr>
725                 <tr>
726                     <td>
727                         <a href=# class="info"><?php echo _("USER Context")?><span><br><?php echo _("This is most often the account name or number your provider expects.<br><br>This USER Context will be used to define the below user details.")?></span></a>:
728                     </td><td>
729                         <input type="text" size="14" name="usercontext" value="<?php echo htmlspecialchars($usercontext?>" tabindex="<?php echo ++$tabindex;?>"/>
730                     </td>
731                 </tr>
732                 <tr>
733                     <td colspan="2">
734                     <a href=# class="info"><?php echo _("USER Details")?><span><br><?php echo _("Modify the default USER connection parameters for your VoIP provider.")?><br><br><?php echo _("You may need to add to the default lines listed below, depending on your provider..<br /><br />WARNING: Oreder is important as it will be retained. For example, if you use the \"allow/deny\" directives make sure deny
735                 comes first.")?><br><br></span></a>:
736                     </td>
737                 </tr>
738                 <tr>
739                     <td colspan="2">
740                         <textarea rows="10" cols="40" name="userconfig" tabindex="<?php echo ++$tabindex;?>"><?php echo htmlspecialchars($userconfig); ?></textarea>
741                     </td>
742                 </tr>
743                 <tr>
744                     <td colspan="2">
745                         <h4><?php echo _("Registration")?></h4>
746                     </td>
747                 </tr>
748                 <tr>
749                     <td colspan="2">
750                         <a href=# class="info"><?php echo _("Register String")?><span><br><?php echo _("Most VoIP providers require your system to REGISTER with theirs. Enter the registration line here.<br><br>example:<br><br>username:password@switch.voipprovider.com.<br><br>Many providers will require you to provide a DID number, ex: username:password@switch.voipprovider.com/didnumber in order for any DID matching to work.")?><br><br></span></a>:
751                     </td>
752                 </tr>
753                 <tr>
754                     <td colspan="2">
755                         <input type="text" size="40" name="register" value="<?php echo htmlspecialchars($register) ?>" tabindex="<?php echo ++$tabindex;?>" />
756                     </td>
757                 </tr>
758     <?php
759         break;
760     }
761     ?>
762                
763             <tr>
764                 <td colspan="2">
765                     <h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>" tabindex="<?php echo ++$tabindex;?>"></h6>
766                 </td>
767             </tr>
768             </table>
769
770 <script language="javascript">
771 <!--
772
773 var theForm = document.trunkEdit;
774
775 theForm.outcid.focus();
776
777 function trunkEdit_onsubmit(act) {
778     var msgInvalidOutboundCID = "<?php echo _('Invalid Outbound Caller ID'); ?>";
779     var msgInvalidMaxChans = "<?php echo _('Invalid Maximum Channels'); ?>";
780     var msgInvalidDialRules = "<?php echo _('Invalid Dial Rules'); ?>";
781     var msgInvalidOutboundDialPrefix = "<?php echo _('Invalid Outbound Dial Prefix'); ?>";
782     var msgInvalidTrunkName = "<?php echo _('Invalid Trunk Name entered'); ?>";
783     var msgInvalidChannelName = "<?php echo _('Invalid Custom Dial String entered'); ?>";
784     var msgInvalidTrunkAndUserSame = "<?php echo _('Trunk Name and User Context cannot be set to the same value'); ?>";
785     var msgConfirmBlankContext = "<?php echo _('User Context was left blank and User Details will not be saved!'); ?>";
786     var msgNeverOverrideCIDValue = "<?php echo _('You must define an Outbound Caller ID when Choosing Never Override CallerID'); ?>";
787
788     defaultEmptyOK = true;
789
790     if (theForm.keepcid.checked && isEmpty($.trim(theForm.outcid.value)))
791         return warnInvalid(theForm.outcid, msgNeverOverrideCIDValue);
792
793     if (!isCallerID(theForm.outcid.value))
794         return warnInvalid(theForm.outcid, msgInvalidOutboundCID);
795    
796     if (!isInteger(theForm.maxchans.value))
797         return warnInvalid(theForm.maxchans, msgInvalidMaxChans);
798    
799     if (!isDialrule(theForm.dialrules.value))
800         return warnInvalid(theForm.dialrules, msgInvalidDialRules);
801    
802     if (!isDialIdentifierSpecial(theForm.dialoutprefix.value))
803         return warnInvalid(theForm.dialoutprefix, msgInvalidOutboundDialPrefix);
804    
805     <?php if ($tech != "enum" && $tech != "custom" && $tech != "dundi") { ?>
806     defaultEmptyOK = true;
807     if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
808         return warnInvalid(theForm.channelid, msgInvalidTrunkName);
809    
810     if (theForm.channelid.value == theForm.usercontext.value)
811         return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
812     <?php } else if ($tech == "custom" || $tech == "dundi") { ?>
813     if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
814         return warnInvalid(theForm.channelid, msgInvalidChannelName);
815
816     if (theForm.channelid.value == theForm.usercontext.value)
817         return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
818     <?php } ?>
819
820     <?php if ($tech == "sip" || substr($tech,0,3) == "iax") { ?>
821     if ((isEmpty(theForm.usercontext.value) || isWhitespace(theForm.usercontext.value)) &&
822         (!isEmpty(theForm.userconfig.value) && !isWhitespace(theForm.userconfig.value)) &&
823             (theForm.userconfig.value != "secret=***password***\ntype=user\ncontext=from-trunk")) {
824                 if (confirm(msgConfirmBlankContext) == false)
825                 return false;
826             }
827     <?php } ?>
828
829     theForm.action.value = act;
830     return true;
831 }
832
833 function isDialIdentifierSpecial(s) { // special chars allowed in dial prefix (e.g. fwdOUT)
834     var i;
835
836     if (isEmpty(s))
837        if (isDialIdentifierSpecial.arguments.length == 1) return defaultEmptyOK;
838        else return (isDialIdentifierSpecial.arguments[1] == true);
839
840     for (i = 0; i < s.length; i++)
841     {   
842         var c = s.charAt(i);
843
844         if ( !isDialDigitChar(c) && (c != "w") && (c != "W") && (c != "q") && (c != "Q") && (c != "+") ) return false;
845     }
846
847     return true;
848 }
849 //-->
850 </script>
851
852         </form>
853 <?php 
854 }
855 ?>
856
857
858
Note: See TracBrowser for help on using the browser.