. // // Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca) // Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) // $display='trunks'; $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:''; $trunknum = ltrim($extdisplay,'OUT_'); $action = isset($_REQUEST['action'])?$_REQUEST['action']:''; $tech = strtolower(isset($_REQUEST['tech'])?htmlentities($_REQUEST['tech']):''); $outcid = isset($_REQUEST['outcid'])?$_REQUEST['outcid']:''; $maxchans = isset($_REQUEST['maxchans'])?$_REQUEST['maxchans']:''; $dialoutprefix= isset($_REQUEST['dialoutprefix'])?$_REQUEST['dialoutprefix']:''; $channelid = isset($_REQUEST['channelid'])?$_REQUEST['channelid']:''; $peerdetails = isset($_REQUEST['peerdetails'])?$_REQUEST['peerdetails']:''; $usercontext = isset($_REQUEST['usercontext'])?$_REQUEST['usercontext']:''; $userconfig = isset($_REQUEST['userconfig'])?$_REQUEST['userconfig']:''; $register = isset($_REQUEST['register'])?$_REQUEST['register']:''; $keepcid = isset($_REQUEST['keepcid'])?$_REQUEST['keepcid']:'off'; $disabletrunk = isset($_REQUEST['disabletrunk'])?$_REQUEST['disabletrunk']:'off'; $provider = isset($_REQUEST['provider'])?$_REQUEST['provider']:''; $trunk_name = isset($_REQUEST['trunk_name'])?$_REQUEST['trunk_name']:''; $failtrunk = isset($_REQUEST['failtrunk'])?$_REQUEST['failtrunk']:''; $failtrunk_enable = ($failtrunk == "")?'':'CHECKED'; if (isset($_REQUEST["dialrules"])) { $dialrules = explode("\n",$_REQUEST["dialrules"]); if (is_array($dialrules)) foreach (array_keys($dialrules) as $key) { //trim it $dialrules[$key] = trim($dialrules[$key]); // remove blanks if ($dialrules[$key] == "") unset($dialrules[$key]); // remove leading underscores (we do that on backend) if ($dialrules[$key][0] == "_") $dialrules[$key] = substr($dialrules[$key],1); } // check for duplicates, and re-sequence $dialrules = array_values(array_unique($dialrules)); } else { $dialrules = array(); } //if submitting form, update database switch ($action) { case "addtrunk": $trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider); core_trunks_addDialRules($trunknum, $dialrules); needreload(); redirect_standard(); break; case "edittrunk": core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider); // this can rewrite too, so edit is the same core_trunks_addDialRules($trunknum, $dialrules); needreload(); redirect_standard('extdisplay'); break; case "deltrunk": core_trunks_del($trunknum); core_trunks_deleteDialRules($trunknum); core_routing_trunk_del($trunknum); needreload(); redirect_standard(); break; case "populatenpanxx7": case "populatenpanxx10": if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) { // first thing we do is grab the exch: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)"); $str = curl_exec($ch); curl_close($ch); // quick 'n dirty - nabbed from PEAR require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php'); require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php'); $xml = new xml_unserializer; $xml->unserialize($str); $xmldata = $xml->getUnserializedData(); if (isset($xmldata['lca-data']['prefix'])) { if ($action == 'populatenpanxx10') { // 10 digit dialing // - add area code to 7 digits // - match local 10 digits // - add 1 to anything else $dialrules[] = $matches[1].'NXXXXXX'; // add NPA to 7-digits foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialrules[] = $prefix['npa'].'+'.$prefix['nxx'].'XXXX'; } foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialrules[] = $prefix['npa'].$prefix['nxx'].'XXXX'; } // if a number was not matched as local, dial it with '1' prefix $dialrules[] = '1+NXXNXXXXXX'; } else { // 7 digit dialing // - drop area code from local numbers // - match local 7 digit numbers // - add 1 to everything else foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialrules[] = $prefix['npa'].'|'.$prefix['nxx'].'XXXX'; } foreach ($xmldata['lca-data']['prefix'] as $prefix) { $dialrules[] = $prefix['nxx'].'XXXX'; } $dialrules[] = '1+NXXNXXXXXX'; $dialrules[] = '1'.$matches[1].'+NXXXXXX'; } // check for duplicates, and re-sequence $dialrules = array_values(array_unique($dialrules)); } else { $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"]; } } else { // what a horrible error message... :p $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)"); } if (isset($errormsg)) { echo ""; unset($errormsg); } break; } ?>

$baseURL.'tech=ZAP', 'tlabel' => _("Add Zap Trunk").(ast_with_dahdi()?" ("._("DAHDI compatibility mode").")":"" )), array('url'=> $baseURL.'tech=SIP', 'tlabel' => _("Add SIP Trunk")), array('url'=> $baseURL.'tech=IAX2', 'tlabel' => _("Add IAX2 Trunk")), array('url'=> $baseURL.'tech=ENUM', 'tlabel' => _("Add ENUM Trunk")), array('url'=> $baseURL.'tech=DUNDI', 'tlabel' => _("Add DUNDi Trunk")), array('url'=> $baseURL.'tech=CUSTOM', 'tlabel' => _("Add Custom Trunk")), ); foreach ($trunks as $trunk) { $label = ' '.$trunk['tlabel'].''; echo "".$label."

"; } } else { if ($extdisplay) { $trunk_details = core_trunks_getDetails($trunknum); $tech = htmlentities($trunk_details['tech']); $outcid = htmlentities($trunk_details['outcid']); $maxchans = htmlentities($trunk_details['maxchans']); $dialoutprefix = htmlentities($trunk_details['dialoutprefix']); $keepcid = htmlentities($trunk_details['keepcid']); $failtrunk = htmlentities($trunk_details['failscript']); $failtrunk_enable = ($failtrunk == "")?'':'CHECKED'; $disabletrunk = htmlentities($trunk_details['disabled']); $provider = $trunk_details['provider']; $trunk_name = htmlentities($trunk_details['name']); if ($tech!="enum") { $channelid = htmlentities($trunk_details['channelid']); if ($tech!="custom" && $tech!="dundi") { // custom trunks will not have user/peer details in database table // load from db if (empty($peerdetails)) { $peerdetails = core_trunks_getTrunkPeerDetails($trunknum); } if (empty($usercontext)) { $usercontext = htmlentities($trunk_details['usercontext']); } if (empty($userconfig)) { $userconfig = core_trunks_getTrunkUserConfig($trunknum); } if (empty($register)) { $register = core_trunks_getTrunkRegister($trunknum); } } } if (count($dialrules) == 0) { if ($temp = core_trunks_getDialRules($trunknum)) { foreach ($temp as $key=>$val) { // extract all ruleXX keys if (preg_match("/^rule\d+$/",$key)) { $dialrules[] = $val; } } } unset($temp); } $upper_tech = strtoupper($tech); echo "

".sprintf(_("Edit %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" ("._("DAHDI compatibility Mode").")":"")."

"; $tname = $trunk_name != '' ? $trunk_name : $channelid; $tlabel = sprintf(_("Delete Trunk %s"),substr($tname,0,20)); $label = ' '.$tlabel.''; ?>

0) { echo " "._("In use by")." ".$num_routes." ".($num_routes == 1 ? _("route") : _("routes")).""; foreach($routes as $route=>$priority) { echo _("Route")." ".$route.": "._("Sequence")." ".$priority."
"; } echo "
"; } else { echo " "._("WARNING:")." "._("This trunk is not used by any routes!").""; echo _("This trunk will not be able to be used for outbound calls until a route is setup that uses it. Click on Outbound Routes to setup routing."); echo ""; } } else { // set defaults $outcid = ""; $maxchans = ""; $dialoutprefix = ""; if ($tech == "zap") { $channelid = "g0"; } else { $channelid = ""; } // only for iax2/sip $peerdetails = "host=***provider ip address***\nusername=***userid***\nsecret=***password***\ntype=peer"; $usercontext = ""; $userconfig = "secret=***password***\ntype=user\ncontext=from-trunk"; $register = ""; $localpattern = "NXXXXXX"; $lddialprefix = "1"; $areacode = ""; $upper_tech = strtoupper($tech); echo "

".sprintf(_("Add %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" ("._("DAHDI compatibility mode").")":"")."

"; } switch ($tech) { case 'dundi': $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:

[mappings]
priv => dundi-extens,0,IAX2,priv:${SECRET}@218.23.42.26/${NUMBER},noparital

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.
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.'); break; case 'sip': break; default: $helptext = ''; } if ($helptext != '') { if ($extdisplay) { echo "

"; } echo $helptext; } ?>
');"> */?>




:


Format: <#######>. You can also use the format: \"hidden\" <#######> to hide the CallerID sent out over Digital lines if supported (E1/T1/J1/BRI/SIP/IAX).")?>

:



:
tabindex=""/>
: :
: OnClick='disable_verify(disabletrunk); return true;'>
: type="text" size="20" name="failtrunk" value=""/> OnClick='disable_field(failtrunk,failtrunk_enable); return true;'>




X   
Z   
N   
[1237-9] 
.   
|    +   

:

" tabindex=""/>



:
Dial rulesThe area code this trunk is in.:  
The dialing pattern to make a 'local' call."):
The prefix for dialing long-distance numbers. In north america, this should be \"1\".")?>:
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. ")?>:
This should be a list of local areacodes + prefixes to use for local dialing.")?>:  

Do a lookup from http://members.dandy.net/~czg/search.html to find all local-reachable area codes and phone numbers.")?>:


Most users should leave this option blank.")?>
:



The default setting is g0 (group zero).")?>

:
$OUTNUM$
examples:
")?>CAPI/XXXXXXXX/$OUTNUM$
H323/$OUTNUM$@XX.XX.XX.XX
OH323/$OUTNUM$@XX.XX.XX.XX:XXXX
vpb/1-1/$OUTNUM$
:
:



:


You may need to add to the default lines listed below, depending on your provider.

WARNING: Order is important as it will be retained. For example, if you use the \"allow/deny\" directives make sure deny comes first.")?>

:



This USER Context will be used to define the below user details.")?>
:




WARNING: Order is important as it will be retained. For example, if you use the \"allow/deny\" directives make sure deny comes first.")?>

:



example:

username:password@switch.voipprovider.com.

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.")?>

:
" tabindex="">