⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 astman.js

📁 asterisk 的图形管理界面
💻 JS
📖 第 1 页 / 共 4 页
字号:
/* * 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_guiappname =  "Asterisk GUI (Beta)";var asterisk_guitools = "asterisk_guitools";var asterisk_guitoolsversion = "0.7";var asterisk_guiversion = "$Revision$";var asterisk_guifbt = 3000; // Feedback msg timevar 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 /etc/asterisk/scripts/gui_sysinfo" ;var asterisk_guiSysInfo_output = "./sysinfo_output.html";var asterisk_guiZapscan = "/sbin/zapscan.bin" ;var asterisk_rawmanPath = "../../rawman" ;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 /etc/asterisk/scripts/listfiles" ;var sortbynames = false;var dragdata = new Object;var asterisk_guiTDPrefix = "DID_";function gui_feedback(a,b,c){ // a is msg, b is color (optional ), c is display time in milliseconds(optional, default to asterisk_guifbt)	if(!b || b=='default'){		var b = "#DA2804"; // dark reddish brown	}	if(b=='blue'){ 		b = "#303BCA"; // dark blue	}else if(b=='green'){		b = "#448156"; // dark green	}	if(!c){c = asterisk_guifbt;}	var _f = top._$('feedback_round');	var _g = top._$('feedback');	_g.style.color = b;	_g.innerHTML = a ;	_f.style.display = '';	top.window.setTimeout( function(){top._$('feedback_round').style.display = "none"; }, c );}function  gui_alert(msg){	gui_alertmsg( 1, msg );}function gui_alertmsg( msgtype, msg ){	// Alternative to javascript's alert box - the native alert boxes are stopping the background XHRs	//  usage - msgtype could be 1 or 2 or 3 , msg is the alert message	top.alertframename = "alertiframe";	top.alertmsg = msg ;	top.alertmsgtype = msgtype ;	if( !top.document.getElementById(top.alertframename)){		var h= top.document.createElement("IFRAME");		h.setAttribute("id", top.alertframename );		h.setAttribute("ALLOWTRANSPARENCY", "true");		var _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 = "";	}}// Douglas Crockford's purge function for IE Memory leaks// http://javascript.crockford.com/memory/leak.html// No details about copyrights or License mentioned - assumed to be in public domainfunction purge(d) {    var a = d.attributes, i, l, n;    if (a) {        l = a.length;        for (i = 0; i < l; i += 1) {            n = a[i].name;            if (typeof d[n] === 'function') {                d[n] = null;            }        }    }    a = d.childNodes;    if (a) {        l = a.length;        for (i = 0; i < l; i += 1) {            purge(d.childNodes[i]);        }    }}function add_event( a , b, c ){  	// cross browser function for adding events	// a is element , b is event (string) , c is the function 	if ( a.addEventListener){		a.addEventListener(b, c, false);	} else if (a.attachEvent){		a.attachEvent('on'+b, c);	}}function remove_event(a,b,c){ 	// cross browser function for removing events	// a is element , b is event (string) , c is the function 	if(a.removeEventListener){		a.removeEventListener( b, c , false);	}else if(a.detachEvent){		a.detachEvent("on"+b, c);	}}function config2json(a, b, c){		// a is filename (string) , b is 0 or 1 , c is callback function	var opt = { method: 'get', asynchronous: true,		onSuccess: function(originalRequest) {  var f = toJSON(originalRequest.responseText, b) ;  c(f) ; },		onFailure: function(t) { gui_alert("Config Error: " + t.status + ": " + t.statusText); },		parameters: "action=getconfig&filename="+a };	var tmp = new Ajax.Request(asterisk_rawmanPath , opt);}function toJSON(z, p){	// This function converts z,  the asterisk config file as read using 'action=getconfig' to a JSON string 	// where z is originalRequest.responseText of the getconfig on a asterisk format config file, 	// and p is 0 or 1, 	//	 0 for non unique subfields ( extensions.conf context where there are multiple subfields with same name - -  Ex: 'exten ='   )	//	 1 for unique subfields ( config files where there are no two subfields of a context have same name )	//  if not sure ,  use p = 0 	var a = [ ] ;	var  json_data = "";	var t = z.split("\n");	for(var r=0; r < t.length ; r++){		var f = t[r].split("-") ;		var h = f[0].toLowerCase();		var catno = parseInt( f[1] ,10 );		if( h == "category" ){			var g = t[r].indexOf(":") ; 			var catname = t[r].substr(g+1) ; // catogory 			catname = catname.replace(/^\s*|\s*$/g,'') ; // trim 			a[ catno ] = { };			a[ catno ].categoryname = catname  ;			if(!p)				a[ catno ].subfields = [] ;			else				a[ catno ].subfields = {} ;		}else if ( h == "line" ){			var j = t[r].indexOf(":") ;			var subfield = t[r].substr(j+1) ; // subfield			subfield = subfield.replace(/^\s*|\s*$/g,'') ; // trim 			if( !p){				a[ catno ].subfields.push( subfield ) ;			}else{				var v = subfield.indexOf("=");				var subfield_a = subfield.substring(0,v); // subfield variable				var subfield_b =  subfield.substr(v+1) ; // subfield variable value				a[ catno ].subfields[subfield_a] = subfield_b;			}		}	}	// start building the json string	json_data = "{" ;	if(!p){		for( var s=0; s < a.length; s++ ){			var b = a[s].subfields ;			json_data += '"' + a[s].categoryname + '" : [ ' ;			for ( var y = 0 ;  y < b.length ;  y++ ){				json_data += '"' + escape(b[y]) + '"' ;				if( y < b.length - 1 ){	json_data += ',' ;	}			}			if( s < a.length - 1 ){ json_data += ' ],' ; }else{ json_data += ' ]}' ; }		}	}else{		for( var s=0; s < a.length; s++ ){			var b = a[s].subfields ;			json_data += '"' + a[s].categoryname + '" :  {' ;			var hascomma = 0;			for ( var y in b ){ 				if ( b.hasOwnProperty(y) ){ 					if(hascomma){						json_data += ', "' + y + '":"' + escape(b[y]) + '"' ; 					}else{						json_data += '"' + y + '":"' + escape(b[y]) + '"' ; 						hascomma = 1;					}				} 			}			if( s < a.length - 1 ){ json_data += ' },' ; }else{ json_data += ' }}' ; }		}	}	if(json_data == "{"){ return '{}';}	// done building the json string	return json_data ;}function setWindowTitle(a){	top.document.title = asterisk_guiappname + " -- " + a ;}function startDrag(event, movethis ){	dragdata.movethis = movethis ;	if(typeof window.scrollX != "undefined"){		dragdata.initialcursorX = event.clientX + window.scrollX;		dragdata.initialcursorY = event.clientY + window.scrollY;	}else{		dragdata.initialcursorX =  window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;		dragdata.initialcursorY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;	}	dragdata.initialwindowleft = parseInt( $(dragdata.movethis).style.left) ;	dragdata.initialwindowtop = parseInt($(dragdata.movethis).style.top) ;	if(typeof window.innerWidth != "undefined"){		dragdata.maxleft = window.innerWidth - parseInt($(dragdata.movethis).style.width) ;		dragdata.maxtop = window.innerHeight - parseInt($(dragdata.movethis).style.height) ;	}else{		dragdata.maxleft = document.body.offsetWidth - parseInt($(dragdata.movethis).style.width) ;		dragdata.maxtop = document.body.offsetWidth- parseInt($(dragdata.movethis).style.height) ;	}	add_event( document , "mousemove" , movewindow ) ;	add_event( document , "mouseup" , stopDrag ) ;}function stopDrag(){	remove_event( document , "mousemove" , movewindow ) ;	remove_event( document , "mouseup" , stopDrag ) ;}function movewindow(event){	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 = dragdata.initialwindowtop  + y - dragdata.initialcursorY ; 	  var tmp_left = dragdata.initialwindowleft + x - dragdata.initialcursorX;	  if( tmp_left > 0 && tmp_left < dragdata.maxleft ){ $(dragdata.movethis).style.left = tmp_left  + "px"; }	  if( tmp_top > 0 && tmp_top < dragdata.maxtop ){ $(dragdata.movethis).style.top  = tmp_top + "px"; }}function check_patternonfields(fields){	// for checking validity of field contents before form submitting 	for (var i=0; i < fields.length; i++){		var x = document.getElementById(fields[i]);		if( x.getAttribute('pattern') && !check_pattern(x.getAttribute('pattern') , x.value)   ){			gui_alert("Invalid Characters in "+ fields[i]);			x.focus();			return false;		}	}	return true;}function showdiv_statusmessage(){        var h= document.createElement("div");	h.setAttribute("id","status_message");	var _hs = h.style;	_hs.display="none";	_hs.position="absolute";	_hs.left= 170;	_hs.top= 190;	_hs.width= 350;	_hs.height= 115;	_hs.backgroundColor= "#F4EFE5";	_hs.borderWidth= "1px";	_hs.borderColor= "#7E5538";	_hs.borderStyle= "solid";	h.innerHTML = "<BR><BR><TABLE border=0 cellpadding=0 cellspacing=3 align=\"center\"> <TR>	<TD><img src=\"images/loading.gif\"></TD> <TD valign=\"middle\" align=\"center\">&nbsp;&nbsp;<div id=\"message_text\"></div></TD> </TR> </TABLE> ";	document.body.appendChild(h);}function combo_box(a, b, c ){		var combo_text = document.getElementById(a);	var combo_selectdiv = document.getElementById(b);	var combo_selectbox = document.getElementById(c);	var TAB = 9;	var ENTER = 13;	var ESC = 27;	var KEYUP = 38;	var KEYDN = 40;	var BKSPACE = 8;	function xyz(event){		if( event.keyCode == ENTER || event.keyCode == ESC || event.keyCode == TAB){			combo_selectdiv.style.display = "none";			return false;		}else if( event.keyCode == KEYDN ||  event.keyCode == KEYUP ){			combo_selectbox.focus();			return false;		}else if( event.keyCode == BKSPACE && combo_text.value.length ==0 ){			combo_selectdiv.style.display = "none";			return false;		}else{			combo_selectdiv.style.display = "";			return true;		}	}		function abcd(event){		if( event.keyCode == ENTER || event.keyCode == ESC || event.keyCode == TAB){		return false;		}		for (var i=0; i < combo_selectbox.options.length; i++){			if(combo_selectbox.options[i].value.toLowerCase().match(combo_text.value.toLowerCase()) ){				combo_selectbox.selectedIndex = i;				return true;			}		}		combo_selectdiv.style.display = "none";					}	function efgh(event) {		if( event.keyCode == ENTER ){			combo_text.value = combo_selectbox.value;			combo_text.focus();			combo_selectdiv.style.display = "none";			return false;		}else if( event.keyCode == ESC ){			combo_text.focus();			combo_selectdiv.style.display = "none";		}else{			return true;		}	}	function ijkl(event) {		combo_text.value = combo_selectbox.value;		combo_text.focus();		combo_selectdiv.style.display = "none";	}	combo_selectdiv.style.position ="absolute";	combo_selectdiv.style.top = "0px";	combo_selectdiv.style.left = "0px";//	combo_selectdiv.style.z-index = 10000;	combo_selectdiv.style.display = "none";	add_event( combo_text , 'keychange' , combobox_activate ) ;	add_event( combo_text , 'focus' , combobox_activate ) ;	add_event( combo_text , 'focusout' , function(){ combo_selectdiv.style.display ='none'; } ) ;	add_event( combo_text , 'keypress' , xyz) ;	add_event( combo_text , 'keyup' , abcd ) ;	add_event( combo_selectbox, 'keypress' , efgh ) ;	add_event( combo_selectbox, 'click' , ijkl ) ;	function combobox_activate(){		var tmp_left = combo_text.offsetLeft;		var tmp_top = combo_text.offsetTop + combo_text.offsetHeight;		var tmp_parent = combo_text;		while(tmp_parent.offsetParent != document.body){			tmp_parent = tmp_parent.offsetParent;			tmp_left += tmp_parent.offsetLeft;			tmp_top += tmp_parent.offsetTop;		}		combo_selectdiv.style.left = tmp_left;		combo_selectdiv.style.top = tmp_top ;		combo_selectdiv.style.width = combo_text.offsetWidth;		combo_selectdiv.style.display = "";	}}function  InArray(search_array, searchstring ){	var i = search_array.length	if( i>0){		for(i=0; i < search_array.length; i++ ){			if( search_array[i] === searchstring )				return true;		}	}	return false;	}function objcopy(orig) {	var copy = new Object;	for (i in orig) {		if (typeof orig[i] == 'object') {			copy[i] = objcopy(orig[i]);		} else {			copy[i] = orig[i];		}	}	return copy;};function do_compare(box, a, b){	var ret;	if (box.callbacks.compare) {		return box.callbacks.compare(box, a,b);	} else if (a.innerHTML < b.innerHTML)		return true;	return false;}function insert_option(box, res, value, core_name){	var z;	if (res) {		var opt_new = box.ownerDocument.createElement('option');		opt_new.text = res  ;		opt_new.value = value ;		opt_new.core_name = core_name;		// Now decide where to add in box, and add it to box		var add = 0;		for ( var g=0; g < box.options.length  ; g++) {			if(	opt_new.text < box.options[g].text  ){ // add before this element in box				add = 1;				try{					box.add(opt_new, box.options[g] );					break;				}catch(err){					box.add(opt_new, g);					break;				}			}		}		if ( add ==0 ){ try{ box.add(opt_new, null); } catch(err){ box.add(opt_new); }}	}}function reformat_option(box, index){	var v, tmp, res;	var cfg = box.stored_config;	v = box.options[index].value;	tmp = v.split(']');	res = ( tmp.length > 1 ) ? box.callbacks.format(cfg.catbyname[tmp[0]], tmp[1]) : box.callbacks.format(cfg.catbyname[v]) ;	if (res){ box.options[index].innerHTML = res;}}function update_option(box, index){	var v, tmp;	var cfg = box.stored_config;	v = box.options[index].value;	tmp = v.split(']');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -