📄 astman.js
字号:
/* * Asterisk -- An open source telephony toolkit. * * Javascript routines or accessing manager routines over HTTP. * * Copyright (C) 1999 - 2006, Digium, Inc. * * Mark Spencer <markster@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. * */var sc_displaytime = 1000;var asterisk_guipingerror = "Message: Authentication Required";var asterisk_guiappname = "Asterisk GUI";var asterisk_guitools = "asterisk_guitools";var asterisk_guitoolsversion = "0.7";var asterisk_guiversion = "Version set on Install"var asterisk_guifbt = 3000; // Feedback msg timevar asterisk_scriptsFolder = "/var/lib/asterisk/scripts/" ; /* Directory for gui scripts (listfiles, for example) */var asterisk_guiNetworkSettings = "sh " + asterisk_scriptsFolder + "networking.sh";var asterisk_ConfigBkpPath = "/var/lib/asterisk/gui_configbackups/" ;var asterisk_Sounds_path = "/var/lib/asterisk/sounds/";var asterisk_menusRecord_path = asterisk_Sounds_path + "record/";var asterisk_guiSysInfo = "sh " + asterisk_scriptsFolder + "gui_sysinfo" ;var asterisk_guiSysInfo_output = "./sysinfo_output.html";var asterisk_guiZtscan = "ztscan > /etc/asterisk/ztscan.conf";var asterisk_guiMisdn = "misdn-init";var asterisk_guiMisdn_scan = "misdn-init scan > /var/lib/asterisk/static-http/config/scan.html";var asterisk_guiEditZap = "sh " + asterisk_scriptsFolder + "editzap.sh";var asterisk_rawmanPath = "../../rawman" ;var asterisk_guirPath = false;var asterisk_guiANOW = false;var asterisk_guiConfigFile = "guipreferences.conf"; // will be created in asterisk_configfolder, if the file does not exist var asterisk_configfolder = "/etc/asterisk/";var asterisk_guiListFiles = "sh " + asterisk_scriptsFolder + "listfiles" ;var asterisk_zaptelConfig = "/etc/zaptel.conf";var asterisk_guiTDPrefix = "DID_";var TIMERULES_CATEGORY = 'timebasedrules';var isIE = false;if(document.attachEvent){ isIE= true; }var listOfActions = function(){ this.current_batch = 1 ; this.current_batch_actionnumber = 0; this.actions = {};};listOfActions.prototype.filename= function(fn){ this.filename = fn;}; listOfActions.prototype.getacn = function(nc){ return this.current_batch_actionnumber;};listOfActions.prototype.addNewChange = function(nc){ var t = 'act_' + this.current_batch; if(!this.current_batch_actionnumber){ this.actions[t] = nc; }else{ this.actions[t] = this.actions[t] + nc; } if( this.current_batch_actionnumber == 5 ){ this.current_batch++; this.current_batch_actionnumber = 0; }else{ this.current_batch_actionnumber++; }};listOfActions.prototype.build_action = function(a,x,b,c,d,e){ var z = this.getacn(); var nc = e?build_action(a, z, b, c, d, e):build_action(a, z, b, c, d) ; this.addNewChange(nc);};listOfActions.prototype.callActions= function(callback){ var pre_uri = "action=updateconfig&srcfilename=" + encodeURIComponent(this.filename) + "&dstfilename=" + encodeURIComponent(this.filename); var treq = this.actions; var start_sqreqs = function(st){ var f = treq[ 'act_' + st ]; if(f){ setTimeout( function(){ makerequest("","",pre_uri + f, start_sqreqs(st+1) ); }, 500 ); }else{ setTimeout( callback , 600 ) ; } }; start_sqreqs(1);};/* Some useful functions */function isset(obj) { if (typeof obj != "object") return (typeof obj != "undefined"); for (var i in obj) return true; return false;}function trim(str) { return str.replace(/^[\s]+/, "").replace(/[\s]+$/, "");}Array.prototype.firstAvailable = function(start) { if(!start){ start = 1; }else{ start = Number( start ); } i=0; while( i < 1 ){ if( this.contains(start) ){ start++; }else{ return start; } }}Array.prototype.contains = function(str) { for(var i=0; i < this.length; i++ ){ if( this[i] === str )return true; } return false;}function ast_true(str) { return [ "yes", "true", "y", "t", "1", "on" ].contains(trim(str.toLowerCase()));}function ast_false(str) { return [ "no", "false", "n", "f", "0", "off" ].contains(trim(str.toLowerCase()));}String.prototype.beginsWith = function(a){ //return this.length>=a.length && this.substring(0,a.length)==a return this.indexOf(a)==0;};String.prototype.endsWith=function(a){ return this.length>=a.length&&this.substring(this.length-a.length)==a};String.prototype.contains=function(a){ return this.indexOf(a)!=-1;};var ASTGUI = { // the idea is to eventually move all the global variables and functions into this one object so that the global name space is not as cluttered as it is now. checkType: { isNull: function(a){ return a===null }, isString: function(a){ return typeof a=="string"; }, isNumber: function(a){ return typeof a=="number"; }, isBoolean: function(a){ return typeof a=="boolean"; }, isDefined: function(a){ return typeof a!="undefined" }, isArray: function(a){ return a instanceof Array ; }, isObject: function(a){ return (typeof a=="object") && a!=null }, isFunction: function(a){ return typeof a=="function"; } }, dialog : { load_iframe : function(msg){ top.alertframename = "alertiframe"; top.alertmsg = msg ; var h,_hs; if( !top.document.getElementById(top.alertframename)){ h= top.document.createElement("IFRAME"); h.setAttribute("id", top.alertframename ); h.setAttribute("ALLOWTRANSPARENCY", "true"); _hs = h.style ; _hs.position="absolute"; _hs.left= 0; _hs.top= 0; _hs.width= '100%'; _hs.height= '100%'; _hs.zIndex = 9999 ; h.src = "guialert.html" ; h.frameBorder="0"; h.scrolling="no"; _hs.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=90)'; //h.style.MozOpacity = .90; top.document.body.appendChild(h); }else{ top.document.getElementById( top.alertframename ).contentWindow.update( ); top.document.getElementById( top.alertframename ).style.display = ""; } }, waitWhile : function(msg){ top.alertmsgtype = 2 ; this.load_iframe(msg); }, alertmsg : function(msg){ top.alertmsgtype = 1 ; this.load_iframe(msg); }, hide : function(){ try{top.document.getElementById( top.alertframename ).style.display = "none";}catch(err){} } }, startDrag : function(event, movethis ){ var initialcursorX, initialcursorY, initialwindowleft, initialwindowtop, maxleft, maxtop ; var stopDrag = function(){ ASTGUI.events.remove( document , "mousemove" , movewindow ) ; ASTGUI.events.remove( document , "mouseup" , stopDrag ) ; }; var movewindow = function(event){ var x,y; if(typeof window.scrollX != "undefined"){ x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; }else{ x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } var tmp_top = initialwindowtop + y - initialcursorY ; var tmp_left = initialwindowleft + x - initialcursorX; if( tmp_left > 0 && tmp_left < maxleft ){ _$(movethis).style.left = tmp_left; } if( tmp_top > 0 && tmp_top < maxtop ){ _$(movethis).style.top = tmp_top; } }; if(typeof window.scrollX != "undefined"){ initialcursorX = event.clientX + window.scrollX; initialcursorY = event.clientY + window.scrollY; }else{ initialcursorX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; initialcursorY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } initialwindowleft = parseInt( _$(movethis).style.left ,10 ) ; initialwindowtop = parseInt(_$(movethis).style.top ,10) ; if(typeof window.innerWidth != "undefined"){ maxleft = window.innerWidth - parseInt(_$(movethis).style.width , 10) ; maxtop = window.innerHeight - parseInt(_$(movethis).style.height , 10) ; }else{ maxleft = document.body.offsetWidth - parseInt(_$(movethis).style.width , 10) ; maxtop = document.body.offsetWidth- parseInt(_$(movethis).style.height , 10) ; } ASTGUI.events.add( document , "mousemove" , movewindow ) ; ASTGUI.events.add( document , "mouseup" , stopDrag ) ; }, events: { getTarget: function(x){ x = x || window.event; return x.target || x.srcElement; }, add: function(a,b,c){ // a is element , b is event (string) , c is the function if(isIE) { a.attachEvent('on'+b, c); }else{ a.addEventListener(b, c, false); } }, remove: function(a,b,c){ if(isIE) { a.detachEvent('on'+b, c); }else{ a.removeEventListener(b, c, false); } } }, domActions: { removeAllChilds: function(x){ while(x.firstChild){ x.removeChild(x.firstChild); } }, clear_table: function(h){ for( var i=0; i < h.rows.length; ){ h.deleteRow(i); } } }, displayHeight: function(){ if(isIE){return document.body.clientHeight;}else{return window.innerHeight;} }, alignBbelowA: function(a,b){ var tmp_left = a.offsetLeft; var tmp_top = a.offsetTop + a.offsetHeight; var tmp_parent = a; while(tmp_parent.offsetParent != document.body){ tmp_parent = tmp_parent.offsetParent; tmp_left += tmp_parent.offsetLeft; tmp_top += tmp_parent.offsetTop; } b.style.left = tmp_left; b.style.top = tmp_top + 1; }, parseContextLine: { read: function(q){ var v = q.indexOf("="); return [q.substring(0,v), q.substr(v+1)]; }, getExten: function(q){ if( q.match('exten=') ){ return q.split('exten=')[1].split(',')[0]; }else{ return q.split(',')[0]; } }, getPriority: function(q){ if( q.match('exten=') ){ return q.split('exten=')[1].split(',')[1]; }else{ return q.split(',')[1]; } }, getApp: function(q){ var y = ASTGUI.parseContextLine.getAction(q); return y.split('(')[0]; }, getArgs: function(q){ var y = ASTGUI.parseContextLine.getAction(q); if( y.charAt(y.length-1) ==')' ){ y = y.substr(0, (y.length-1) ); } var t = y.split('('); t.splice(0,1); return t.join('('); }, getAction: function(q){ // q can be the the whole contextLine or just 'parseContextLine.read(contextline)[1]' var t = q.split(','); t.splice(0,2); return t.join(','); } }, selectbox: { insert_before: function(el,txt, val, i){ if(isIE){ el.add(new Option (txt,val), i ); }else{ el.add(new Option (txt,val), el.options[i] ); } }, insertOption_before: function(el,opt, i){ if(isIE){ el.add(opt, i ); }else{ el.add(opt, el.options[i] ); } }, append: function(el,txt, val){ el.options[el.options.length] = new Option (txt,val); }, append_option: function(el,opt){ if(isIE){ el.add(opt); } else{ el.add(opt,null); } }, remove_i: function(el, i){ el.options[i] = null; }, clear: function(el){ el.options.length = 0; }, selectOption: function(el, opt){ el.selectedIndex = -1; for (var x=0; x < el.options.length; x++) { if (el.options[x].value == opt){ el.selectedIndex = x; } } } }, COMBOBOX: function (a,w){ // Usage - ASTGUI.COMBOBOX.call( element , OptionsArray, width(Optional) ); // this.comboDiv - the div element created // this.comboOptions - the array of options var k = document.createElement('DIV'); var BoldBinA = function(a,b){ if(b==''){return a;} var position = a.toLowerCase().indexOf( b.toLowerCase() ) ; if (position == -1){ return a; } var c = a.substr( position , b.length ); return a.replace( c , "<B>" + c + "</B>" , "" ); }; var creatediv = function(){ ASTGUI.events.add( this, 'blur' , cleanupDiv ) ; var u = this; var q = k.cloneNode(false); q.className = "comboMainDiv"; if(w){q.style.width = w; } u.comboDiv = q; var selectOption = function(event){ var f = ASTGUI.events.getTarget(event); u.value = f.getAttribute( 'actualvalue' ); q.style.display = "none"; q.parentNode.removeChild(q); delete u.comboDiv; u.blur(); }; ASTGUI.events.add( q , 'click' , selectOption ) ; q.style.display = "none"; document.body.appendChild(q); ASTGUI.alignBbelowA(u,q); updateDivAndShow.call(this); }; var updateDivAndShow = function(){ var t = this.comboDiv; var srchStng = this.value.toLowerCase(); var z = this.comboOptions; var y; var matched =0; ASTGUI.domActions.removeAllChilds(t); for (var r =0; r < z.length; r++){ if( z[r].toLowerCase().contains(srchStng) || srchStng == '' ){ y = k.cloneNode(false); y.innerHTML = BoldBinA( z[r] , srchStng) ; y.setAttribute( 'actualvalue', z[r] );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -