.
//
// 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;
}
?>