'',
'alaw' => '',
'gsm' => '',
'g726' => '',
'g722' => '',
'slin' => '',
'g729' => '',
'ilbc' => '',
'g723' => '',
'g726aal2' => '',
'adpcm' => '',
'lpc10' => '',
'speex' => '',
'siren7' => '',
'siren14' => '',
'speex16' => '',
'slin16' => '',
'g719' => '',
'speex32' => '',
'slin12' => '',
'slin24' => '',
'slin32' => '',
'slin44' => '',
'slin48' => '',
'slin96' => '',
'slin192' => '',
'opus' => '',
'silk8' => '',
'silk12' => '',
'silk16' => '',
'silk24' => '',
);
$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';
$continue = isset($_REQUEST['continue'])?$_REQUEST['continue']:'off';
$provider = isset($_REQUEST['provider'])?$_REQUEST['provider']:'';
$trunk_name = isset($_REQUEST['trunk_name'])?$_REQUEST['trunk_name']:'';
$pjsip_context = isset($_REQUEST['pjsip_context'])?$_REQUEST['pjsip_context']:'from-pstn';
$pjsip_inband_progress = isset($_REQUEST['pjsip_inband_progress'])?$_REQUEST['pjsip_inband_progress']:'no';
$pjsip_auth_rejection_permanent = isset($_REQUEST['pjsip_auth_rejection_permanent'])?$_REQUEST['pjsip_auth_rejection_permanent']:'no';
$pjsip_direct_media = isset($_REQUEST['pjsip_direct_media'])?$_REQUEST['pjsip_direct_media']:'no';
$pjsip_contact_user = isset($_REQUEST['pjsip_contact_user'])?$_REQUEST['pjsip_contact_user']:'';
$pjsip_qualify_frequency = isset($_REQUEST['pjsip_qualify_frequency'])?$_REQUEST['pjsip_qualify_frequency']:'60';
$pjsip_max_retries = isset($_REQUEST['pjsip_max_retries'])?$_REQUEST['pjsip_max_retries']:'10';
$pjsip_retry_interval = isset($_REQUEST['pjsip_retry_interval'])?$_REQUEST['pjsip_retry_interval']:'60';
$pjsip_expiration = isset($_REQUEST['pjsip_expiration'])?$_REQUEST['pjsip_expiration']:'3600';
$pjsip_transport = isset($_REQUEST['pjsip_transport'])?$_REQUEST['pjsip_transport']:'transport-udp';
$pjsip_rtp_symmetric = isset($_REQUEST['pjsip_rtp_symmetric'])?$_REQUEST['pjsip_rtp_symmetric']:'yes';
$pjsip_media_encryption = isset($_REQUEST['pjsip_media_encryption'])?$_REQUEST['pjsip_media_encryption']:'no';
$pjsip_rewrite_contact = isset($_REQUEST['pjsip_rewrite_contact'])?$_REQUEST['pjsip_rewrite_contact']:'yes';
$pjsip_dtmf_mode = isset($_REQUEST['pjsip_dtmf_mode'])?$_REQUEST['pjsip_dtmf_mode']:'auto';
$pjsip_trust_id_inbound = isset($_REQUEST['pjsip_trust_id_inbound'])?$_REQUEST['pjsip_trust_id_inbound']:'no';
$pjsip_fax_detect = isset($_REQUEST['pjsip_fax_detect'])?$_REQUEST['pjsip_fax_detect']:'no';
$pjsip_t38_udptl = isset($_REQUEST['pjsip_t38_udptl'])?$_REQUEST['pjsip_t38_udptl']:'no';
$pjsip_t38_udptl_nat = isset($_REQUEST['pjsip_t38_udptl_nat'])?$_REQUEST['pjsip_t38_udptl_nat']:'no';
$pjsip_t38_udptl_ec = isset($_REQUEST['pjsip_t38_udptl_ec'])?$_REQUEST['pjsip_t38_udptl_ec']:'none';
$pjsip_support_path = isset($_REQUEST['pjsip_support_path'])?$_REQUEST['pjsip_support_path']:'no';
$pjsip_outbound_proxy = isset($_REQUEST['pjsip_outbound_proxy'])?$_REQUEST['pjsip_outbound_proxy']:'';
$pjsip_user_eq_phone = isset($_REQUEST['pjsip_user_eq_phone'])?$_REQUEST['pjsip_user_eq_phone']:'no';
$pjsip_stir_shaken = isset($_REQUEST['pjsip_stir_shaken'])?$_REQUEST['pjsip_stir_shaken']:'';
$post_codec = isset($_REQUEST['codec']) ? $_REQUEST['codec'] : array();
if(count($post_codec)>0) {
$pri = 1;
foreach (array_keys($post_codec) as $codec) {
$codecs[$codec] = $pri++;
}
asort($codecs);
$sel_codec=array();
foreach($codecs as $key=>$val) {
if($val<>''){
$sel_codec[$val]=$key;
}
}
$pjsip_codecs=implode(",",$sel_codec);
}
if(isset($_REQUEST['pjsip_registration'])) { $register=$_REQUEST['pjsip_registration']; }
$failtrunk = isset($_REQUEST['failtrunk'])?$_REQUEST['failtrunk']:'';
$failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
$dialopts = isset($_REQUEST['dialopts'])?$_REQUEST['dialopts']:false;
$pjsipconfig='';
foreach($_REQUEST as $key=>$val) {
if(substr($key,0,5)=='pjsip') {
$newkey = substr($key,6);
$pjsipconfig .="$newkey=$val\n";
}
}
if($pjsipconfig<>'') {
$pjsipconfig.="codecs=$pjsip_codecs\n";
$userconfig=$pjsipconfig;
}
// Check if they uploaded a CSV file for their route patterns
//
if (isset($_FILES['pattern_file']) && $_FILES['pattern_file']['tmp_name'] != '') {
$fh = fopen($_FILES['pattern_file']['tmp_name'], 'r');
if ($fh !== false) {
$csv_file = array();
$index = array();
// Check first row, ingoring empty rows and get indices setup
//
while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) {
if (count($row) == 1 && $row[0] == '') {
continue;
} else {
$count = count($row) > 3 ? 3 : count($row);
for ($i=0;$i<$count;$i++) {
switch (strtolower($row[$i])) {
case 'prepend':
case 'prefix':
case 'match pattern':
$index[strtolower($row[$i])] = $i;
break;
default:
break;
}
}
// If no headers then assume standard order
if (count($index) == 0) {
$index['prepend'] = 0;
$index['prefix'] = 1;
$index['match pattern'] = 2;
if ($count == 3) {
$csv_file[] = $row;
}
}
break;
}
}
$row_count = count($index);
while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) {
if (count($row) == $row_count) {
$csv_file[] = $row;
}
}
}
}
//
// Use a hash of the value inserted to get rid of duplicates
$dialpattern_array = array();
$dialpattern_insert = array();
$p_idx = 0;
$n_idx = 0;
// If we have a CSV file it replaces any existing patterns
//
if (!empty($csv_file)) {
foreach ($csv_file as $row) {
$this_prepend = isset($index['prepend']) ? htmlspecialchars(trim($row[$index['prepend']])) : '';
$this_prefix = isset($index['prefix']) ? htmlspecialchars(trim($row[$index['prefix']])) : '';
$this_match_pattern = isset($index['match pattern']) ? htmlspecialchars(trim($row[$index['match pattern']])) : '';
if ($this_prepend != '' || $this_prefix != '' || $this_match_pattern != '') {
$dialpattern_insert[] = array(
'prepend_digits' => $this_prepend,
'match_pattern_prefix' => $this_prefix,
'match_pattern_pass' => $this_match_pattern,
);
}
}
} else if (isset($_POST["prepend_digit"])) {
$prepend_digit = $_POST["prepend_digit"];
$pattern_prefix = $_POST["pattern_prefix"];
$pattern_pass = $_POST["pattern_pass"];
foreach (array_keys($prepend_digit) as $key) {
if ($prepend_digit[$key]!='' || $pattern_prefix[$key]!='' || $pattern_pass[$key]!='') {
$dialpattern_insert[] = array(
'prepend_digits' => htmlspecialchars(trim($prepend_digit[$key])),
'match_pattern_prefix' => htmlspecialchars(trim($pattern_prefix[$key])),
'match_pattern_pass' => htmlspecialchars(trim($pattern_pass[$key])),
);
}
}
}
// TODO: remember old name, if new one is different the don't rename
//
//if submitting form, update database
switch ($action) {
case "copytrunk":
$sv_channelid = isset($_REQUEST['sv_channelid'])?$_REQUEST['sv_channelid']:'';
$sv_trunk_name = isset($_REQUEST['sv_trunk_name'])?$_REQUEST['sv_trunk_name']:'';
$sv_usercontext = isset($_REQUEST['sv_usercontext'])?$_REQUEST['sv_usercontext']:'';
if ($trunk_name == $sv_trunk_name) {
$trunk_name .= ($trunk_name == '' ? '' : '_') . "copy_$trunknum";
}
if ($channelid == $sv_channelid) {
$channelid .= '_copy_' . $trunknum;
}
if ($usercontext != '' && $usercontext == $sv_usercontext) {
$usercontext .= '_copy_' . $trunknum;
}
$disabletrunk = 'on';
$continue = 'on';
$trunknum = '';
$extdisplay='';
// Fallthrough to addtrunk now...
//
case "addtrunk":
$trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider, $continue, $dialopts);
core_trunks_update_dialrules($trunknum, $dialpattern_insert);
needreload();
$_SESSION['msg']=base64_encode(_dgettext('amp','Item has been added'));
$_SESSION['msgtype']='success';
$_SESSION['msgtstamp']=time();
redirect_standard();
break;
case "edittrunk":
core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider, $continue, $dialopts);
// this can rewrite too, so edit is the same
core_trunks_update_dialrules($trunknum, $dialpattern_insert, true);
needreload();
$_SESSION['msg']=base64_encode(_dgettext('amp','Item has been saved'));
$_SESSION['msgtype']='success';
$_SESSION['msgtstamp']=time();
redirect_standard('extdisplay');
break;
case "delete":
core_trunks_del($trunknum);
core_trunks_delete_dialrules($trunknum);
core_routing_trunk_delbyid($trunknum);
needreload();
$_SESSION['msg']=base64_encode(_dgettext('amp','Item has been deleted'));
$_SESSION['msgtype']='warning';
$_SESSION['msgtstamp']=time();
redirect_standard();
break;
case "populatenpanxx7":
case "populatenpanxx10":
$dialpattern_array = $dialpattern_insert;
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, "https://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; IssabelPBX Local Trunks Configuration)");
$str = curl_exec($ch);
curl_close($ch);
if($str=="") {
$errormsg = __("Error connecting to localcallinguide.com");
echo "";
unset($errormsg);
break;
}
// 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'])) {
$hash_filter = array(); //avoid duplicates
if ($action == 'populatenpanxx10') {
// 10 digit dialing
// - add area code to 7 digits
// - match local 10 digits
// - add 1 to anything else
$dialpattern_array[] = array(
'prepend_digits' => '',
'match_pattern_prefix' => '',
'match_pattern_pass' => htmlspecialchars($matches[1].'NXXXXXX'),
);
// add NPA to 7-digits
foreach ($xmldata['lca-data']['prefix'] as $prefix) {
if (isset($hash_filter[$prefix['npa'].'+'.$prefix['nxx']])) {
continue;
} else {
$hash_filter[$prefix['npa'].'+'.$prefix['nxx']] = true;
}
$dialpattern_array[] = array(
'prepend_digits' => htmlspecialchars($prefix['npa']),
'match_pattern_prefix' => '',
'match_pattern_pass' => htmlspecialchars($prefix['nxx'].'XXXX'),
);
}
foreach ($xmldata['lca-data']['prefix'] as $prefix) {
if (isset($hash_filter[$prefix['npa'].$prefix['nxx']])) {
continue;
} else {
$hash_filter[$prefix['npa'].$prefix['nxx']] = true;
}
$dialpattern_array[] = array(
'prepend_digits' => '',
'match_pattern_prefix' => '',
'match_pattern_pass' => htmlspecialchars($prefix['npa'].$prefix['nxx'].'XXXX'),
);
}
// if a number was not matched as local, dial it with '1' prefix
$dialpattern_array[] = array(
'prepend_digits' => '',
'match_pattern_prefix' => '',
'match_pattern_pass' => '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) {
if (isset($hash_filter[$prefix['npa'].'|'.$prefix['nxx']])) {
continue;
} else {
$hash_filter[$prefix['npa'].'|'.$prefix['nxx']] = true;
}
$dialpattern_array[] = array(
'prepend_digits' => '',
'match_pattern_prefix' => htmlspecialchars( $prefix['npa']),
'match_pattern_pass' => htmlspecialchars($prefix['nxx'].'XXXX'),
);
}
foreach ($xmldata['lca-data']['prefix'] as $prefix) {
if (isset($hash_filter[$prefix['nxx']])) {
continue;
} else {
$hash_filter[$prefix['nxx']] = true;
}
$dialpattern_array[] = array(
'prepend_digits' => '',
'match_pattern_prefix' => '',
'match_pattern_pass' => htmlspecialchars($prefix['nxx'].'XXXX'),
);
}
$dialpattern_array[] = array(
'prepend_digits' => '1',
'match_pattern_prefix' => '',
'match_pattern_pass' => 'NXXNXXXXXX',
);
$dialpattern_array[] = array(
'prepend_digits' => htmlspecialchars('1'.$matches[1]),
'match_pattern_prefix' => '',
'match_pattern_pass' => 'NXXXXXX',
);
}
// check for duplicates, and re-sequence
unset($hash_filter);
} 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;
}
?>
".$label." \n";
}
drawListMenu($alltrunks, $type, $display, $extdisplay);
?>
$baseURL.'tech=SIP', 'tlabel' => __("Add SIP Trunk"));
$trunks[] = array('url'=> $baseURL.'tech=PJSIP', 'tlabel' => __("Add PJSIP Trunk"));
$trunks[] = array('url'=> $baseURL.'tech=DAHDI', 'tlabel' => __("Add DAHDi Trunk"));
$trunks[] = array('url'=> $baseURL.'tech=IAX2', 'tlabel' => __("Add IAX2 Trunk"));
//--------------------------------------------------------------------------------------
// Added to enable the unsupported misdn module
if (function_exists('misdn_ports_list_trunks') && count(misdn_ports_list_trunks())) {
$trunks[] = array('url'=> $baseURL.'tech=MISDN', 'tlabel' => __("Add mISDN Trunk"));
}
//--------------------------------------------------------------------------------------
$trunks[] = array('url'=> $baseURL.'tech=ENUM', 'tlabel' => __("Add ENUM Trunk"));
$trunks[] = array('url'=> $baseURL.'tech=DUNDI', 'tlabel' => __("Add DUNDi Trunk"));
$trunks[] = array('url'=> $baseURL.'tech=CUSTOM', 'tlabel' => __("Add Custom Trunk"));
foreach ($trunks as $trunk) {
$label="
";
$label .='
'.$trunk['tlabel'].' ';
echo "
".$label." ";
}
echo "\n";
} 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']);
$continue = htmlentities($trunk_details['continue']);
$provider = $trunk_details['provider'];
$trunk_name = htmlentities($trunk_details['name']);
$dialopts = $trunk_details['dialopts'] === false ? false : htmlentities($trunk_details['dialopts']);
if ($tech!="enum") {
$channelid = htmlentities($trunk_details['channelid']);
if ($tech!="custom" && $tech!="dundi" && $tech!="pjsip") { // 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);
}
} else if ($tech=="pjsip") {
if (empty($register)) {
$register = core_trunks_getTrunkRegister($trunknum);
$userconfig = core_trunks_getTrunkUserConfig($trunknum);
// ok, this is ugly, but we need this done fast, not pretty
$lineas = explode("\n",$userconfig);
foreach($lineas as $linea) {
$partes = preg_split("/=/",$linea);
if($partes[0]=='codecs') {
$storedcodecs=explode(",",$partes[1]);
$pri=1;
foreach($storedcodecs as $codecname) {
$codecs[$codecname]=$pri++;
}
} else {
$varname = "pjsip_".$partes[0];
$$varname=$partes[1];
}
}
}
}
}
if (count($dialpattern_array) == 0) {
$dialpattern_array = core_trunks_get_dialrules($trunknum);
}
$upper_tech = strtoupper($tech);
if (trim($trunk_name) == '') {
$trunk_name = ($upper_tech == 'ZAP'|$upper_tech == 'DAHDI'?sprintf(__('%s Channel %s'),$upper_tech,$channelid):$channelid);
}
echo "
".sprintf(__("Edit %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" (".__("DAHDi compatibility Mode").")":"")." ";
// find which routes use this trunk
$routes = core_trunks_gettrunkroutes($trunknum);
$num_routes = count($routes);
if ($num_routes > 0) {
echo "
";
} else {
$warning_article = "
";
//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 " ";
}
$usage_list = framework_display_destination_usage(core_getdest(ltrim($extdisplay,'OUT_')));
if (!empty($usage_list)) {
echo ipbx_usage_info($usage_list['text'],$usage_list['tooltip']);
}
} else {
// set defaults
$outcid = "";
$maxchans = "";
$dialoutprefix = "";
if ($tech == 'zap' || $tech == 'dahdi') {
$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").")":"")." ";
}
if (!isset($dialpattern_array)) {
$dialpattern_array = array();
}
switch ($tech) {
case 'dundi':
$helptext = __('IssabelPBX 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},nopartial
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 IssabelPBX 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 IssabelPBX.');
break;
case 'sip':
break;
default:
$helptext = '';
}
if ($helptext != '') {
if ($extdisplay) {
echo "
";
}
echo $helptext;
}
?>