📄 trunks.html
字号:
<!--
* Asterisk-GUI - an Asterisk configuration interface
*
* Create/Manage Service Providers (trunks)
*
* Copyright (C) 2006-2007, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
* Pari Nannapaneni <pari@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*
-->
<script src="scripts/prototype.js"></script>
<script src="scripts/rico.js"></script>
<script src="scripts/astman.js"></script>
<script src="scripts/tooltip.js"></script>
<link href="stylesheets/rico.css" media="all" rel="Stylesheet" type="text/css" />
<link href="stylesheets/schwing.css" media="all" rel="Stylesheet" type="text/css" />
<script>
var origwidth;
var widgets = {};
var provwidgets = {};
var callbacks = new Object;
var phonecallbacks = new Object;
var providercallbacks = new Object;
var globalvars = new Object;
var fieldnames =[ 'disallow','allow','callerid','cancel','contact','context','delete','dialformat','fromdomain','fromuser','group','hasexten','hasiax','hassip','host','insecure',
'name','new','port','provider','registeriax','registersip','save','secret','trunkname','trunkstyleanalog','trunkstylecustomvoip',
'trunkstylevoip','username','zapchan'];
var provfieldnames = ['providerdesc', 'providerlogo'];
var isnewtrunk;
var dids_array = [];
var old_trunkname;
function add_didcontext(trunk){
var didcontext = asterisk_guiTDPrefix + trunk ;
var uri = build_action('newcat', 0, didcontext ,"", "");
uri += build_action('append', 1, didcontext ,"include", "default");
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function(t) { },
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText + "<BR><BR>"+ "Failed to create a DID context for " + trunk );
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
function update_didcontext(old_trunk, new_trunk){
var old_didcontext = asterisk_guiTDPrefix + old_trunk ;
var new_didcontext = asterisk_guiTDPrefix + new_trunk ;
var uri = build_action('renamecat', 0, old_didcontext ,"", new_didcontext );
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function(t) { callbacks_savechanges_step2(); },
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText);
gui_alert("Failed to Rename the DID context for " + old_didcontext );
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
function delete_didcontext(trunk){
var didcontext = asterisk_guiTDPrefix + trunk ;
var uri = build_action('delcat', 0, didcontext ,"", "");
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function(t) { },
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText + "<BR> Failed to delete DID context for " + trunk);
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
providercallbacks.postselect = function() {
var _pl = _$('providerlink') ;
try{
var f = _$('provider');
var g = f.stored_config.catbyname[f.value].fieldbyname['regurl'] ;
_pl.href= ( g ) ? g :'#' ;
_pl.target = ( g ) ? '_blank' : '';
}catch(e){
_pl.href= "#";
_pl.target = "";
}
}
providercallbacks.format = function(t) {
return t.fieldbyname['providername'];
}
globalvars.format = function(t) {
if ( t.name.substring(0,asterisk_guiTDPrefix.length) == asterisk_guiTDPrefix ){
dids_array.push( t.name.substring( asterisk_guiTDPrefix.length ) );
}
if (t.name == "globals"){ return t.name ; }
return null;
}
globalvars.loaded = function() {
parent.astmanEngine.config2list("users.conf", _$('devices'), widgets, callbacks);
}
providercallbacks.loaded = function() {
var p = _$('provider');
p.altonchange = p.onchange;
p.onchange = null;
parent.astmanEngine.config2list("extensions.conf", _$('hiddenglobals'), new Array, globalvars);
}
callbacks.format = function(t) {
if( InArray(dids_array, t.name) ){ return t.fieldbyname['trunkname']; }
return null;
}
callbacks.cancelnewcategory = function(){
hideSPdetails();
}
callbacks.cancelchanges = function(){
hideSPdetails();
}
callbacks.loaded = function() {
var _devices = _$('devices');
_devices.contentEditable = 'true';
_devices.disabled = 0;
add_event( _$('new') , "click", showSPdetails ) ;
loadServiceProvidersintotable();
preparemenus();
parent.loadscreen(this);
}
callbacks.postselect = function(){
if( _$('trunkstylecustomvoip').checked ){
// Custom VOIP
var tmp = $('trunkname').value.split("Custom - ") ;
_$('customvoip_name').value = tmp[1];
_$('customvoip_username').value = _$('username').value;
_$('customvoip_secret').value = _$('secret').value;
_$('customvoip_protocol').selectedIndex = ( _$('hassip').value == "yes" ) ? 1 : 0;
_$('customvoip_host').value = _$('host').value;
_$('customvoip_register').checked = ( _$('registeriax').value == "yes" || _$('registersip').value == "yes") ? true : false ;
}else if ( _$('trunkstylevoip').checked ){
// VOIP
_$('customvoip_name').value = "";
_$('customvoip_username').value = _$('username').value;
_$('customvoip_secret').value = _$('secret').value;
_$('customvoip_protocol').selectedIndex = 0;
_$('customvoip_host').value ="";
}
}
callbacks.delchanges = function(box, value) {
deletesp_fromui(value);
delete_didcontext(value);
var _hglobals = _$('hiddenglobals');
var oldvalue = _hglobals.stored_config.catbyname['globals'].fieldbyname[value];
if (oldvalue) {
uri = build_action('delete', 0, 'globals', value, "");
apply_uri( _hglobals, uri);
_hglobals.stored_config.catbyname['globals'].fieldbyname[value] = null;
return true;
}
}
callbacks.beforeSaving = function(){
var _tsv = _$('trunkstylevoip');
var _tsa = _$('trunkstyleanalog');
var _tscv = _$('trunkstylecustomvoip');
var _cv_un = _$('customvoip_username');
var _name = _$('name') ;
var _dvcs_v = _$('devices').value ;
var _msg1 = "When using VoIP, the username must not be empty!" ;
var _msg2 = "No analog line hardware installed on the system";
var _msg3 = "When using Analog, at least one port must be selected.";
var _msg4 = "Please enter a Comment for this Service Provider";
if ( _tsv.checked && !_$('username').value.length ) { gui_alert(_msg1); return false; }
if ( _tsa.checked ) {
var _zapchan = _$('zapchan');
if( _zapchan.options.length == 0 ){ gui_alert(_msg2); return false; }
if (!_zapchan.value) { gui_alert( _msg3); return false; }
}
if ( _tscv.checked ) {
var _csv_n = _$('customvoip_name');
if( _csv_n.value.length == 0 ){ gui_alert( _msg4); _csv_n.focus(); return false; }
var _cv_h = _$('customvoip_host') ;
if ( !_cv_h.value ) { gui_alert("Please enter a host name"); _cv_h.focus(); return false; }
if ( !_cv_un.value ) { gui_alert("Please enter a Username"); _cv_un.focus(); return false; }
}
if( !_tsv.checked && !_tsa.checked && !_tscv.checked ){ gui_alert("A trunk must be Analog or VoIP or Custom VOIP"); return false; }
if(_dvcs_v.length ==0 ){
ifnewtrunk();
}else{
ifedit_existing();
}
if(isnewtrunk ==1){
try{
var _pvdr = _$('provider');
provider = _pvdr.stored_config.catbyname[_pvdr.value];
if( typeof provider.fieldbyname['trunk_username'] != "undefined" && _tsv.checked ){
_name.value = provider.fieldbyname['trunk_username'];
}
}catch(e){
}
dids_array.push( _name.value );
}else{
old_trunkname = _dvcs_v ;
if( _dvcs_v != _name.value ){ // if the trunk name is changed , change the name in dids_array
for( var i=0 ; i < dids_array.length; i ++){ if( dids_array[i] == _dvcs_v ) { dids_array[i] = _name.value ; break; } }
}
}
}
callbacks.savechanges = function() {
if(isnewtrunk == 1){ //New Trunk created , add [DID_trunk_x] in extensions.conf
add_didcontext(_$('name').value);
if (_$('trunkstylevoip').checked) {
_$('dialformat').value = (provider.fieldbyname['dialformat']) ? provider.fieldbyname['dialformat'] : '${EXTEN:1}';
_$('callerid').value = '';
_$('insecure').value = (provider.fieldbyname['insecure']) ? provider.fieldbyname['insecure'] : '' ;
_$('port').value = (provider.fieldbyname['port']) ? provider.fieldbyname['port'] : '' ;
_$('fromuser').value = (provider.fieldbyname['fromuser']) ? provider.fieldbyname['fromuser'] : '' ;
if (_$('fromuser').value == '<DID>') { _$('fromuser').value = _$('username').value; }
_$('fromdomain').value = (provider.fieldbyname['fromdomain']) ? provider.fieldbyname['fromdomain'] : '' ;
}
callbacks_savechanges_step2();
}else{
if(old_trunkname != _$('name').value ){ update_didcontext(old_trunkname, _$('name').value); } // rename DID if needed
}
return false;
}
function callbacks_savechanges_step2(){
saveSPdetails();
var uri;
var newvalue;
var _devices = _$('devices') ;
var tmp = _devices.value.split('_');
var _hiddenglobals = _$('hiddenglobals') ;
var oldvalue = _hiddenglobals.stored_config.catbyname['globals'].fieldbyname[_devices.value];
if (_$('trunkstylevoip').checked || _$('trunkstylecustomvoip').checked) {
if (_devices.stored_config.catbyname[_devices.value].fieldbyname['hasiax'] == 'yes')
newvalue = "IAX2/" + _devices.value;
else
newvalue = "SIP/" + _devices.value;
} else {
newvalue = "Zap/g"+tmp[1];
}
if (newvalue != oldvalue) {
var _name = _$('name') ;
if(old_trunkname == _name.value ){
uri = build_action('update', 0, 'globals', _devices.value, newvalue);
apply_uri(_hiddenglobals, uri);
_hiddenglobals.stored_config.catbyname['globals'].fieldbyname[_devices.value] = newvalue;
return true;
}else{
uri = "";
var u =0;
if(old_trunkname){ uri = build_action('delete', u, 'globals', old_trunkname, "","" ); u++; }
uri += build_action('update', u , 'globals', _name.value, newvalue); u++;
apply_uri(_hiddenglobals, uri);
_hiddenglobals.stored_config.catbyname['globals'].fieldbyname[ _name.value ] = newvalue;
return true;
}
}
}
function ifedit_existing(){
}
function ifnewtrunk(){
var needcomma = 0;
var provider;
var count = 0;
var _provider = _$('provider');
var _zapchan = _$('zapchan');
var _trunkname = _$('trunkname');
_$('hasexten').value = 'no';
_$('context').value = asterisk_guiTDPrefix + _$('name').value ;
if (_$('trunkstylevoip').checked) {
provider = _provider.stored_config.catbyname[_provider.value];
_trunkname.value = _provider.options[_provider.selectedIndex].innerHTML + " - " + _$('username').value;
_$('hassip').value = provider.fieldbyname['hassip'];
_$('hasiax').value = provider.fieldbyname['hasiax'];
_$('registeriax').value = provider.fieldbyname['registeriax'];
_$('registersip').value = provider.fieldbyname['registersip'];
_$('host').value = provider.fieldbyname['host'];
for (var x=0;x<_zapchan.options.length;x++){ _zapchan.options[x].selected = false; }
_zapchan.value = '';
_$('group').value = '';
} else if (_$('trunkstyleanalog').checked) {
// Analog
_provider.selectedIndex = -1;
count = 0;
_trunkname.value = "";
for (var x=0;x<_zapchan.options.length;x++) {
if (_zapchan.options[x].selected) {
if (needcomma){ _trunkname.value += "," }
needcomma = 1 ;
_trunkname.value += _zapchan.options[x].value;
count++;
}
}
_trunkname.value = ((count > 1) ? "Ports ":"Port ") + _trunkname.value;
_$('callerid').value = 'asreceived';
_$('hassip').value = 'no';
_$('hasiax').value = 'no';
_$('callerid').value = 'asreceived';
_$('group').value = _$('name').value.split('_')[1];
} else if( _$('trunkstylecustomvoip').checked ){
// Custom VOIP Provider
_trunkname.value = "Custom - " + _$('customvoip_name').value;
provider = _$('customvoip_name').value;
_provider.selectedIndex = -1;
_$('username').value = _$('customvoip_username').value;
_$('secret').value = _$('customvoip_secret').value;
var _cv_p = $('customvoip_protocol').value ;
_$('hassip').value = ( _cv_p == "iax" ) ? "no" : "yes" ;
_$('hasiax').value = ( _cv_p == "iax" ) ? "yes" : "no";
var _cv_r = _$('customvoip_register') ;
var _registeriax = _$('registeriax') ;
var _registersip = _$('registersip');
if( !_cv_r.checked ){
_registeriax.value = 'no';
_registersip.value = 'no';
}else{
_registeriax.value = ( _cv_p == "iax") ?'yes' : 'no';
_registersip.value = ( _cv_p == "sip") ?'yes' : 'no';
}
_$('host').value = _$('customvoip_host').value ;
_$('dialformat').value = '${EXTEN:1}';
_$('callerid').value = '';
_$('insecure').value = '';
_$('port').value = ( _cv_p == "iax" ) ? "4569" : "5060";
//$('context').value = 'default';
_$('fromuser').value = '';
_$('fromdomain').value = '';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -