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

Revision 10462, 36.6 kB (checked in by p_lindheimer, 1 year ago)

Merged revisions 10461 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.5

................

r10461 | p_lindheimer | 2010-11-01 13:13:34 -0700 (Mon, 01 Nov 2010) | 46 lines


Merged revisions 10460 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.6


................

r10460 | p_lindheimer | 2010-11-01 13:02:25 -0700 (Mon, 01 Nov 2010) | 39 lines


Merged revisions 10399-10418,10420-10422,10424-10426,10428-10429,10432,10436-10458 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.7


................

r10399 | GameGamer?43 | 2010-10-14 10:05:48 -0700 (Thu, 14 Oct 2010) | 1 line


closes #4590 - fixes issues with phonebook import

................

r10457 | p_lindheimer | 2010-11-01 12:46:35 -0700 (Mon, 01 Nov 2010) | 24 lines


Merged revisions 10456 via svnmerge from
http://svn.freepbx.org/modules/branches/2.8


................

r10456 | p_lindheimer | 2010-11-01 12:39:25 -0700 (Mon, 01 Nov 2010) | 17 lines


Merged revisions 10444,10447,10449-10451,10453-10455 via svnmerge from
http://svn.freepbx.org/modules/branches/2.9


........

r10444 | mbrevda | 2010-10-25 05:43:18 -0700 (Mon, 25 Oct 2010) | 1 line


re #4604 - potential injection when uploading files. Can be closed by when published/backported

........

r10454 | p_lindheimer | 2010-11-01 10:51:02 -0700 (Mon, 01 Nov 2010) | 1 line


block xss re #4615

........

r10455 | p_lindheimer | 2010-11-01 12:12:39 -0700 (Mon, 01 Nov 2010) | 1 line


changes to some of the fixes re #4604

........

................

................

r10458 | p_lindheimer | 2010-11-01 12:49:10 -0700 (Mon, 01 Nov 2010) | 1 line


update xml re #4590

................

................

................

  • 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'])?htmlentities($_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     core_routing_trunk_del($trunknum);
98    
99     /* //DIALRULES
100     deleteTrunkRules($channelid);
101     */
102     core_trunks_deleteDialRules($trunknum);
103     needreload();
104     redirect_standard();
105   break;
106   case "populatenpanxx7":
107   case "populatenpanxx10":
108     if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) {
109       // first thing we do is grab the exch:
110       $ch = curl_init();
111       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
112       curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]);
113       curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)");
114       $str = curl_exec($ch);
115       curl_close($ch);
116
117       // quick 'n dirty - nabbed from PEAR
118       require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php');
119       require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php');
120
121       $xml = new xml_unserializer;
122       $xml->unserialize($str);
123       $xmldata = $xml->getUnserializedData();
124
125       if (isset($xmldata['lca-data']['prefix'])) {
126        
127         if ($action == 'populatenpanxx10') {
128           // 10 digit dialing
129           // - add area code to 7 digits
130           // - match local 10 digits
131           // - add 1 to anything else
132           $dialrules[] = $matches[1].'NXXXXXX';
133           // add NPA to 7-digits
134           foreach ($xmldata['lca-data']['prefix'] as $prefix) {
135             $dialrules[] = $prefix['npa'].'+'.$prefix['nxx'].'XXXX';
136           }
137           foreach ($xmldata['lca-data']['prefix'] as $prefix) {
138             $dialrules[] = $prefix['npa'].$prefix['nxx'].'XXXX';
139           }
140           // if a number was not matched as local, dial it with '1' prefix
141           $dialrules[] = '1+NXXNXXXXXX';
142         } else {
143           // 7 digit dialing
144           // - drop area code from local numbers
145           // - match local 7 digit numbers
146           // - add 1 to everything else
147           foreach ($xmldata['lca-data']['prefix'] as $prefix) {
148             $dialrules[] = $prefix['npa'].'|'.$prefix['nxx'].'XXXX';
149           }
150           foreach ($xmldata['lca-data']['prefix'] as $prefix) {
151             $dialrules[] = $prefix['nxx'].'XXXX';
152           }
153           $dialrules[] = '1+NXXNXXXXXX';
154           $dialrules[] = '1'.$matches[1].'+NXXXXXX';
155         }
156
157         // check for duplicates, and re-sequence
158         $dialrules = array_values(array_unique($dialrules));
159       } else {
160         $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"];
161       }
162
163     } else {
164       // what a horrible error message... :p
165       $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)");
166     }
167    
168     if (isset($errormsg)) {
169       echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>";
170       unset($errormsg);
171     }
172   break;
173 }
174  
175 //get all rows from globals
176 $sql = "SELECT * FROM globals";
177 $globals = $db->getAll($sql);
178 if(DB::IsError($globals)) {
179   die_freepbx($globals->getMessage());
180 }
181
182 //create a set of variables that match the items in global[0]
183 foreach ($globals as $global) {
184   ${trim($global[0])} = htmlentities($global[1]);
185 }
186
187 ?>
188 </div>
189
190 <div class="rnav">
191 <ul>
192   <li><a <?php  echo ($extdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Trunk")?></a></li>
193 <?php 
194 //get existing trunk info
195 $tresults = core_trunks_list();
196
197 foreach ($tresults as $tresult) {
198   $background = ($tresult[2] == 'on')?'#DDD':'';
199   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";
200 }
201
202 ?>
203 </ul>
204 </div>
205
206 <div class="content">
207
208 <?php 
209
210 if (!$tech && !$extdisplay) {
211 ?>
212   <h2><?php echo _("Add a Trunk")?></h2>
213   <a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&amp;tech=ZAP"><?php echo _("Add ZAP Trunk")?></a><br><br>
214   <a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&amp;tech=IAX2"><?php echo _("Add IAX2 Trunk")?></a><br><br>
215   <a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&amp;tech=SIP"><?php echo _("Add SIP Trunk")?></a><br><br>
216   <a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&amp;tech=ENUM"><?php echo _("Add ENUM Trunk")?></a><br><br>
217   <a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&amp;tech=CUSTOM"><?php echo _("Add Custom Trunk")?></a><br><br>
218   <a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&amp;tech=DUNDI"><?php echo _("Add DUNDi Trunk")?></a><br><br>
219 <?php 
220 } else {
221   if ($extdisplay) {
222     //list($trunk_tech, $trunk_name) = explode("/",$tname);
223     //if ($trunk_tech == "IAX2") $trunk_tech = "IAX"; // same thing
224     $tech = core_trunks_getTrunkTech($trunknum);
225
226     $outcid = ${"OUTCID_".$trunknum};
227     $maxchans = ${"OUTMAXCHANS_".$trunknum};
228     $dialoutprefix = ${"OUTPREFIX_".$trunknum};
229     $keepcid = isset(${"OUTKEEPCID_".$trunknum})?${"OUTKEEPCID_".$trunknum}:'';
230     $failtrunk = isset(${"OUTFAIL_".$trunknum})?${"OUTFAIL_".$trunknum}:'';
231     $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
232     $disabletrunk = isset(${"OUTDISABLE_".$trunknum})?${"OUTDISABLE_".$trunknum}:'';
233
234    
235     if ($tech!="enum") {
236  
237       if (!isset($channelid)) {
238         $channelid = core_trunks_getTrunkTrunkName($trunknum);
239       }
240
241       if ($tech!="custom" && $tech!="dundi") {  // custom trunks will not have user/peer details in database table
242         // load from db
243         if (!isset($peerdetails)) {
244           $peerdetails = core_trunks_getTrunkPeerDetails($trunknum);
245         }
246  
247         if (!isset($usercontext)) {
248           $usercontext = core_trunks_getTrunkUserContext($trunknum);
249         }
250  
251         if (!isset($userconfig)) { 
252           $userconfig = core_trunks_getTrunkUserConfig($trunknum);
253         }
254          
255         if (!isset($register)) { 
256           $register = core_trunks_getTrunkRegister($trunknum);
257         }
258       }
259     }
260    
261     if (count($dialrules) == 0) {
262       if ($temp = core_trunks_getDialRules($trunknum)) {
263         foreach ($temp as $key=>$val) {
264           // extract all ruleXX keys
265           if (preg_match("/^rule\d+$/",$key)) {
266             $dialrules[] = $val;
267           }
268         }
269       }
270       unset($temp);
271     }
272
273     echo "<h2>".sprintf(_("Edit %s Trunk"),strtoupper($tech))."</h2>";
274 ?>
275     <p><a title="<?php echo $channelid ?>" href="config.php?display=<?php echo urlencode($display) ?>&amp;extdisplay=<?php echo urlencode($extdisplay) ?>&amp;action=deltrunk"><?php echo _("Delete Trunk")?> <?php  echo substr($channelid,0,20); ?></a></p>
276 <?php 
277
278     // find which routes use this trunk
279     $routes = core_trunks_gettrunkroutes($trunknum);
280     $num_routes = count($routes);
281     if ($num_routes > 0) {
282       echo "<a href=# class=\"info\">"._("In use by")." ".$num_routes." ".($num_routes == 1 ? _("route") : _("routes"))."<span>";
283       foreach($routes as $route=>$priority) {
284         echo _("Route")." <b>".$route."</b>: "._("Sequence")." <b>".$priority."</b><br>";
285       }
286       echo "</span></a>";
287     } else {
288       echo "<b>"._("WARNING:")."</b> <a href=# class=\"info\">"._("This trunk is not used by any routes!")."<span>";
289       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.");
290       echo "</span></a>";
291     }
292
293   } else {
294     // set defaults
295     $outcid = "";
296     $maxchans = "";
297     $dialoutprefix = "";
298    
299     if ($tech == "zap") {
300       $channelid = "g0";
301     } else {
302       $channelid = "";
303     }
304    
305     // only for iax2/sip
306     $peerdetails = "host=***provider ip address***\nusername=***userid***\nsecret=***password***\ntype=peer";
307     $usercontext = "";
308     $userconfig = "secret=***password***\ntype=user\ncontext=from-trunk";
309     $register = "";
310    
311     $localpattern = "NXXXXXX";
312     $lddialprefix = "1";
313     $areacode = "";
314  
315     echo "<h2>".sprintf("Add %s Trunk",strtoupper($tech))."</h2>";
316
317   }
318 switch ($tech) {
319   case 'dundi':
320     $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.');
321     break;
322   default:
323     $helptext = '';
324 }
325 if ($helptext != '') {
326   if ($extdisplay) {
327     echo "<br /><br />";
328   }
329   echo $helptext;
330 }
331    
332 ?>
333  
334     <form name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');">
335       <input type="hidden" name="display" value="<?php echo $display?>"/>
336       <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>
337       <input type="hidden" name="action" value=""/>
338       <input type="hidden" name="tech" value="<?php echo $tech?>"/>
339       <table>
340       <tr>
341         <td colspan="2">
342           <h4><?php echo _("General Settings")?></h4>
343         </td>
344       </tr>
345       <tr>
346         <td>
347           <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>:
348         </td><td>
349           <input type="text" size="20" name="outcid" value="<?php echo $outcid;?>"/>
350         </td>
351       </tr>
352       <tr>
353         <td>
354           <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>:
355         </td><td>
356           <input type="checkbox" name="keepcid" <?php if ($keepcid=="on") {echo "checked";}?>/>
357         </td>
358       <tr>
359         <td>
360 <?php
361   if ($tech == "sip" || substr($tech,0,3) == "iax") {
362     $pr_tech = ($tech == "iax") ? "iax2":$tech;
363 ?>
364           <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>:
365 <?php
366   } else {
367 ?>
368           <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>:
369 <?php
370   }
371 ?>
372         </td><td>
373           <input type="text" size="3" name="maxchans" value="<?php echo htmlspecialchars($maxchans); ?>"/>
374         </td>
375       </tr>
376
377       <tr>
378           <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>:
379           </td>
380           <td>
381         <input type='checkbox' name='disabletrunk' id="disabletrunk" <?php if ($disabletrunk=="on") { echo 'CHECKED'; }?> OnClick='disable_verify(disabletrunk); return true;'><small><?php echo _("Disable")?></small>
382           </td>
383       </tr>
384
385       <tr>
386           <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>:
387           </td>
388           <td>
389         <input <?php if (!$failtrunk_enable) echo "disabled style='background: #DDD;'"?> type="text" size="20" name="failtrunk" value="<?php echo htmlspecialchars($failtrunk)?>"/>
390         <input type='checkbox' 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>
391           </td>
392       </tr>
393
394       <tr>
395         <td colspan="2">
396           <h4><?php echo _("Outgoing Dial Rules")?></h4>
397         </td>
398       </tr>
399       <tr>
400         <td valign="top">
401           <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 />
402   <strong>X</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br />
403   <strong>Z</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br />
404   <strong>N</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br />
405   <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 />
406   <strong>.</strong>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more characters (not allowed before a | or +)")?><br />
407   <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)")?>
408   <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 />
409   <?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."); ?>
410           </span></a>:
411         </td><td valign="top">
412           <textarea id="dialrules" cols="20" rows="<?php 
413             if (is_array($dialrules)) {
414               $rows = count($dialrules)+1;
415               echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) );
416             } else {
417               echo "5";
418             } ?>" name="dialrules"><?php if(is_array($dialrules)) { echo implode("\n",$dialrules); } ?></textarea><br>
419           
420           <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />
421         </td>
422       </tr>
423       <tr>
424         <td>
425           <a href=# class="info"><?php echo _("Dial Rules Wizards")?><span>
426           <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>
427           <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>
428           <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>
429           </span></a>:
430         </td><td valign="top"><select id="autopop" name="autopop" onChange="changeAutoPop(); ">
431             <option value="" SELECTED><?php echo _("(pick one)")?></option>
432             <option value="always"><?php echo _("Always dial with prefix")?></option>
433             <option value="remove"><?php echo _("Remove prefix from local numbers")?></option>
434             <option value="lookup7"><?php echo _("Lookup numbers for local trunk (7-digit dialing)")?></option>
435             <option value="lookup10"><?php echo _("Lookup numbers for local trunk (10-digit dialing)")?></option>
436           </select>
437         </td>
438       </tr>
439       <input id="npanxx" name="npanxx" type="hidden" />
440       <script language="javascript">
441       
442       function disable_field(field, field_enable) {
443           if (field_enable.checked) {
444         field.style.backgroundColor = '#FFF';
445         field.disabled = false;
446           }
447           else {
448         field.style.backgroundColor = '#DDD';
449         field.disabled = true;
450           }
451       }
452
453       function disable_verify(field) {
454           if (field.checked) {
455         var answer=confirm("Are you sure you want to disable this trunk in all routes it is used?");
456         if (!answer) {
457             field.checked = false;
458         }
459           }
460           else {
461         alert("You have enabled this trunk in all routes it is used");
462           }
463       }
464
465       function populateLookup(digits) {
466 <?php 
467   if (function_exists("curl_init")) { // curl is installed
468 ?>        
469         //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
470         do {
471           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.".'")')?>;
472           if (npanxx == null) return;
473         } 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\'").'")'?>);
474         
475         document.getElementById('npanxx').value = npanxx;
476         if (digits == 10) {
477           document.trunkEdit.action.value = "populatenpanxx10";
478         } else {
479           document.trunkEdit.action.value = "populatenpanxx7";
480         }
481         document.trunkEdit.submit();
482 <?php 
483   } else { // curl is not installed
484 ?>
485         <?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.").'")'?>;
486 <?php 
487   }
488 ?>
489       }
490       
491       function populateAlwaysAdd() {
492         do {
493           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");
494           if (localpattern == null) return;
495         } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
496         
497         do {
498           var localprefix = <?php echo 'prompt("'._("What prefix should be added to the dialing pattern?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')?").'")'?>;
499           if (localprefix == null) return;
500         } while (!localprefix.match('^[0-9#*]+$') && <?php echo '!alert("'._("Invalid prefix. Only dialable characters (0-9, #, and *) are allowed.").'")'?>);
501
502         dialrules = document.getElementById('dialrules');
503         if (dialrules.value[dialrules.value.length-1] != '\n') {
504           dialrules.value = dialrules.value + '\n';
505         }
506         dialrules.value = dialrules.value + localprefix + '+' + localpattern + '\n';
507       }
508       
509       function populateRemove() {
510         do {
511           var localprefix = <?php echo 'prompt("'._("What prefix should be removed from the number?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')").'")'?>;
512           if (localprefix == null) return;
513         } while (!localprefix.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._('Invalid prefix. Only 0-9, #, *, Z, N, and X are allowed.').'")'?>);
514         
515         do {
516           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");
517           if (localpattern == null) return;
518         } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
519         
520         dialrules = document.getElementById('dialrules');
521         if (dialrules.value[dialrules.value.length-1] != '\n') {
522           dialrules.value = dialrules.value + '\n';
523         }
524         dialrules.value = dialrules.value + localprefix + '|' + localpattern + '\n';
525       }
526       
527       function changeAutoPop() {
528         switch(document.getElementById('autopop').value) {
529           case "always":
530             populateAlwaysAdd();
531           break;
532           case "remove":
533             populateRemove();
534           break;
535           case "lookup7":
536             populateLookup(7);
537           break;
538           case "lookup10":
539             populateLookup(10);
540           break;
541         }
542         document.getElementById('autopop').value = '';
543       }
544       </script>
545 <?php /* //DIALRULES
546       <tr>
547         <td>
548           <a href=# class="info">Dial rules<span>The area code this trunk is in.</span></a>:
549         </td><td>&nbsp;
550           <select id="dialrulestype" name="dialrulestype" onChange="changeRulesType();">
551 <?php
552           $rules = array( "asis" => "Don't change number",
553               "always" => "Always dial prefix+areacode",
554               "local" => "Local 7-digit dialing",
555               "local10" => "Local 10-digit dialing");
556
557           foreach ($rules as $value=>$display) {
558             echo "<option value=\"".$value."\" ".(($value == $dialrulestype) ? "SELECTED" : "").">".$display."</option>";
559           }
560 ?>
561           </select>
562           
563         </td>
564       </tr>
565       <tr>
566         <td>
567           <a href=# class="info"><?php echo _("Local dialing pattern<span>The dialing pattern to make a 'local' call.</span>")</a>:
568         </td><td>
569           <input id="localpattern" type="text" size="10" maxlength="20" name="localpattern" value="<?php echo $localpattern ?>"/>
570           
571         </td>
572       </tr>
573       <tr>
574         <td>
575           <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>:
576         </td><td>
577           <input id="lddialprefix" type="text" size="3" maxlength="6" name="lddialprefix" value="<?php echo $lddialprefix ?>"/>
578           
579         </td>
580       </tr>
581       <tr>
582         <td>
583           <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>:
584         </td><td>
585           <input id="areacode" type="text" size="3" maxlength="6" name="areacode" value="<?php echo $areacode ?>"/>
586           
587         </td>
588       </tr>
589       <tr>
590         <td valign="top">
591           <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>:
592         </td><td valign="top">&nbsp;
593           <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>
594           
595           <input id="npanxx" name="npanxx" type="hidden" /><br>
596           <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();" />
597           <br><br>
598         </td>
599       </tr>
600       <script language="javascript">
601       
602       function checkPopulate() {
603         //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
604         var npanxx = <?php echo 'prompt("'._("What is your areacode + prefix (NPA-NXX)?").'")'?>;
605         
606         if (npanxx.match("^[2-9][0-9][0-9][-]?[2-9][0-9][0-9]$")) {
607           document.getElementById('npanxx').value = npanxx;
608           trunkEdit.action.value = "populatenpanxx";
609           trunkEdit.submit();
610         } else if (npanxx != null) {
611           <?php echo 'alert("'._("Invalid format for NPA-NXX code (must be format: NXXNXX)").'")'?>;
612         }
613       }
614       
615       function changeRulesType() {
616         switch(document.getElementById('dialrulestype').value) {
617           case "always":
618             document.getElementById('lddialprefix').disabled = false;
619             document.getElementById('areacode').disabled = false;
620             document.getElementById('localprefixes').disabled = true;
621           break;
622           case "local":
623           case "local10":
624             document.getElementById('lddialprefix').disabled = false;
625             document.getElementById('areacode').disabled = false;
626             document.getElementById('localprefixes').disabled = false;
627           break;
628           case "asis":
629           default:
630             document.getElementById('lddialprefix').disabled = true;
631             document.getElementById('areacode').disabled = true;
632             document.getElementById('localprefixes').disabled = true;
633           break;
634         }
635       }
636       changeRulesType();
637       </script>
638 */?>
639       <tr>
640         <td>
641           <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>:
642         </td><td>
643           <input type="text" size="8" name="dialoutprefix" value="<?php echo htmlspecialchars($dialoutprefix) ?>"/>
644         </td>
645       </tr>
646       <?php if ($tech != "enum") { ?>
647       <tr>
648         <td colspan="2">
649           <h4><?php echo _("Outgoing Settings")?></h4>
650         </td>
651       </tr>
652       <?php } ?>
653
654   <?php
655   switch ($tech) {
656     case "zap":
657   ?>
658         <tr>
659           <td>
660             <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>:
661           </td><td>
662             <input type="text" size="8" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>"/>
663             <input type="hidden" size="14" name="usercontext" value="notneeded"/>
664           </td>
665         </tr>
666   <?php
667     break;
668     case "enum":
669     break;
670     case "custom":
671   ?>
672         <tr>
673           <td>
674             <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>:
675           </td><td>
676             <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>"/>
677             <input type="hidden" size="14" name="usercontext" value="notneeded"/>
678           </td>
679         </tr>
680   <?php
681     break;
682     case "dundi":
683   ?>
684         <tr>
685           <td>
686             <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>:
687           </td><td>
688             <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>"/>
689             <input type="hidden" size="14" name="usercontext" value="notneeded"/>
690           </td>
691         </tr>
692   <?php
693     break;
694     default:
695   ?>
696         <tr>
697           <td>
698             <a href=# class="info"><?php echo _("Trunk Name")?><span><br><?php echo _("Give this trunk a unique name.  Example: myiaxtel")?><br><br></span></a>:
699           </td><td>
700             <input type="text" size="14" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>"/>
701           </td>
702         </tr>
703         <tr>
704           <td colspan="2">
705           <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>:
706           </td>
707         </tr>
708         <tr>
709           <td colspan="2">
710             <textarea rows="10" cols="40" name="peerdetails"><?php echo htmlspecialchars($peerdetails) ?></textarea>
711           </td>
712         </tr>
713         <tr>
714           <td colspan="2">
715             <h4><?php echo _("Incoming Settings")?></h4>
716           </td>
717         </tr>
718         <tr>
719           <td>
720             <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>:
721           </td><td>
722             <input type="text" size="14" name="usercontext" value="<?php echo htmlspecialchars($usercontext)  ?>"/>
723           </td>
724         </tr>
725         <tr>
726           <td colspan="2">
727           <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
728         comes first.")?><br><br></span></a>:
729           </td>
730         </tr>
731         <tr>
732           <td colspan="2">
733             <textarea rows="10" cols="40" name="userconfig"><?php echo htmlspecialchars($userconfig); ?></textarea>
734           </td>
735         </tr>
736         <tr>
737           <td colspan="2">
738             <h4><?php echo _("Registration")?></h4>
739           </td>
740         </tr>
741         <tr>
742           <td colspan="2">
743             <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>:
744           </td>
745         </tr>
746         <tr>
747           <td colspan="2">
748             <input type="text" size="40" name="register" value="<?php echo htmlspecialchars($register) ?>"/>
749           </td>
750         </tr>
751   <?php
752     break;
753   }
754   ?>
755         
756       <tr>
757         <td colspan="2">
758           <h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6>
759         </td>
760       </tr>
761       </table>
762
763 <script language="javascript">
764 <!--
765
766 var theForm = document.trunkEdit;
767
768 theForm.outcid.focus();
769
770 function trunkEdit_onsubmit(act) {
771   var msgInvalidOutboundCID = "<?php echo _('Invalid Outbound Caller ID'); ?>";
772   var msgInvalidMaxChans = "<?php echo _('Invalid Maximum Channels'); ?>";
773   var msgInvalidDialRules = "<?php echo _('Invalid Dial Rules'); ?>";
774   var msgInvalidOutboundDialPrefix = "<?php echo _('Invalid Outbound Dial Prefix'); ?>";
775   var msgInvalidTrunkName = "<?php echo _('Invalid Trunk Name entered'); ?>";
776   var msgInvalidChannelName = "<?php echo _('Invalid Custom Dial String entered'); ?>";
777   var msgInvalidTrunkAndUserSame = "<?php echo _('Trunk Name and User Context cannot be set to the same value'); ?>";
778   var msgConfirmBlankContext = "<?php echo _('User Context was left blank and User Details will not be saved!'); ?>";
779   var msgNeverOverrideCIDValue = "<?php echo _('You must define an Outbound Caller ID when Choosing Never Override CallerID'); ?>";
780
781   defaultEmptyOK = true;
782
783   if (theForm.keepcid.checked && isEmpty($.trim(theForm.outcid.value)))
784     return warnInvalid(theForm.outcid, msgNeverOverrideCIDValue);
785
786   if (!isCallerID(theForm.outcid.value))
787     return warnInvalid(theForm.outcid, msgInvalidOutboundCID);
788  
789   if (!isInteger(theForm.maxchans.value))
790     return warnInvalid(theForm.maxchans, msgInvalidMaxChans);
791  
792   if (!isDialrule(theForm.dialrules.value))
793     return warnInvalid(theForm.dialrules, msgInvalidDialRules);
794  
795   if (!isDialIdentifierSpecial(theForm.dialoutprefix.value))
796     return warnInvalid(theForm.dialoutprefix, msgInvalidOutboundDialPrefix);
797  
798   <?php if ($tech != "enum" && $tech != "custom" && $tech != "dundi") { ?>
799   defaultEmptyOK = true;
800   if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
801     return warnInvalid(theForm.channelid, msgInvalidTrunkName);
802  
803   if (theForm.channelid.value == theForm.usercontext.value)
804     return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
805   <?php } else if ($tech == "custom" || $tech == "dundi") { ?>
806   if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
807     return warnInvalid(theForm.channelid, msgInvalidChannelName);
808
809   if (theForm.channelid.value == theForm.usercontext.value)
810     return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
811   <?php } ?>
812
813   <?php if ($tech == "sip" || substr($tech,0,3) == "iax") { ?>
814   if ((isEmpty(theForm.usercontext.value) || isWhitespace(theForm.usercontext.value)) &&
815     (!isEmpty(theForm.userconfig.value) && !isWhitespace(theForm.userconfig.value)) &&
816       (theForm.userconfig.value != "secret=***password***\ntype=user\ncontext=from-trunk")) {
817         if (confirm(msgConfirmBlankContext) == false)
818         return false;
819       }
820   <?php } ?>
821
822   theForm.action.value = act;
823   return true;
824 }
825
826 function isDialIdentifierSpecial(s) { // special chars allowed in dial prefix (e.g. fwdOUT)
827     var i;
828
829     if (isEmpty(s))
830        if (isDialIdentifierSpecial.arguments.length == 1) return defaultEmptyOK;
831        else return (isDialIdentifierSpecial.arguments[1] == true);
832
833     for (i = 0; i < s.length; i++)
834     {   
835         var c = s.charAt(i);
836
837         if ( !isDialDigitChar(c) && (c != "w") && (c != "W") && (c != "q") && (c != "Q") && (c != "+") ) return false;
838     }
839
840     return true;
841 }
842 //-->
843 </script>
844
845     </form>
846 <?php 
847 }
848 ?>
Note: See TracBrowser for help on using the browser.