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

📄 functions.inc.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	return sql($sql,"getAll",DB_FETCHMODE_ASSOC);}function core_did_get($extension="",$cidnum="",$channel=""){	$sql = "SELECT * FROM incoming WHERE cidnum = \"$cidnum\" AND extension = \"$extension\" AND channel = \"$channel\"";	return sql($sql,"getRow",DB_FETCHMODE_ASSOC);}function core_did_del($extension,$cidnum, $channel){	$sql="DELETE FROM incoming WHERE cidnum = \"$cidnum\" AND extension = \"$extension\" AND channel = \"$channel\"";	sql($sql);}function core_did_add($incoming){	extract($incoming); // create variables from request	$existing=core_did_get($extension,$cidnum,$channel);	if (empty($existing)) {		$destination=${$goto_indicate0.'0'};		$sql="INSERT INTO incoming (cidnum,extension,destination,faxexten,faxemail,answer,wait,privacyman,alertinfo, channel) values (\"$cidnum\",\"$extension\",\"$destination\",\"$faxexten\",\"$faxemail\",\"$answer\",\"$wait\",\"$privacyman\",\"$alertinfo\", \"$channel\")";		sql($sql);	} else {		echo "<script>javascript:alert('"._("A route for this DID/CID already exists!")."')</script>";	}}/* end page.did.php functions *//* begin page.devices.php functions *///get the existing devicesfunction core_devices_list() {	$sql = "SELECT id,description FROM devices";	$results = sql($sql,"getAll");	foreach($results as $result){		if (checkRange($result[0])){			$extens[] = array($result[0],$result[1]);		}	}	if (isset($extens)) {		sort($extens);		return $extens;	} else { 		return null;	}}function core_devices_add($id,$tech,$dial,$devicetype,$user,$description,$emergency_cid=null){	global $amp_conf;	global $currentFile;		//ensure this id is not already in use	$devices = core_devices_list();	if (is_array($devices)) {		foreach($devices as $device) {			if ($device[0] === $id) {				echo "<script>javascript:alert('"._("This device id is already in use")."');</script>";				return false;			}		}	}	//unless defined, $dial is TECH/id	//zap is an exception	if (empty($dial) && strtolower($tech) == "zap")		$dial = "ZAP/".$_REQUEST['channel'];	if (empty($dial))		$dial = strtoupper($tech)."/".$id;		//check to see if we are requesting a new user	if ($user == "new") {		$user = $id;		$jump = true;	}		if(!get_magic_quotes_gpc()) {		if(!empty($emergency_cid))			$emergency_cid = addslashes($emergency_cid);		if(!empty($description))			$description = addslashes($description);	}		//insert into devices table	$sql="INSERT INTO devices (id,tech,dial,devicetype,user,description,emergency_cid) values (\"$id\",\"$tech\",\"$dial\",\"$devicetype\",\"$user\",\"$description\",\"$emergency_cid\")";	sql($sql);		//add details to astdb	$astman = new AGI_AsteriskManager();	if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {		$astman->database_put("DEVICE",$id."/dial",$dial);		$astman->database_put("DEVICE",$id."/type",$devicetype);		$astman->database_put("DEVICE",$id."/user",$user);		if(!empty($emergency_cid))			$astman->database_put("DEVICE",$id."/emergency_cid","\"".$emergency_cid."\"");		if($user != "none") {			$existingdevices = $astman->database_get("AMPUSER",$user."/device");			if (empty($existingdevices)) {				$astman->database_put("AMPUSER",$user."/device",$id);			} else {				$existingdevices .= "&";				//only append device value if this id doesn't exist in it already				if(strpos($existingdevices,$id."&") === false) // if not containing $id 					$astman->database_put("AMPUSER",$user."/device",$existingdevices.$id);			}		}		$astman->disconnect();	} else {		fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);	}		// create a voicemail symlink if needed	$thisUser = core_users_get($user);	if(isset($thisUser['voicemail']) && ($thisUser['voicemail'] != "disabled")) {		if(empty($thisUser['voicemail']))			$vmcontext = "default";		else 			$vmcontext = $thisUser['voicemail'];		//voicemail symlink		exec("rm -f /var/spool/asterisk/voicemail/device/".$id);		exec("/bin/ln -s /var/spool/asterisk/voicemail/".$vmcontext."/".$user."/ /var/spool/asterisk/voicemail/device/".$id);	}			//take care of sip/iax/zap config	$funct = "core_devices_add".strtolower($tech);	if(function_exists($funct)){		$funct($id);	}	/*	if($user != "none") {		core_hint_add($user);	}*/		//if we are requesting a new user, let's jump to users.php	if (isset($jump)) {		echo("<script language=\"JavaScript\">window.location=\"config.php?display=users&extdisplay={$id}&name={$description}\";</script>");	}}function core_devices_del($account){	global $amp_conf;	global $currentFile;		//get all info about device	$devinfo = core_devices_get($account);		//delete details to astdb	$astman = new AGI_AsteriskManager();	if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {		// If a user was selected, remove this device from the user		$deviceuser = $astman->database_get("DEVICE",$account."/user");		if (isset($deviceuser) && $deviceuser != "none") {				// Remove the device record from the user's device list				$userdevices = $astman->database_get("AMPUSER",$deviceuser."/device");				/*$userdevices = str_replace($account."&", "", $userdevices."&");				// If there was more than one device, remove the extra "&" at the end.				if (substr($userdevices, -1, 1) == "&") {					$userdevices = substr($userdevices, 0, -1);				}*/                                $userdevicesarr = explode("&", $userdevices);                                array_splice($userdevicesarr, array_search($account, $userdevicesarr), 1);                                $userdevices = implode("&", $userdevicesarr);				if (empty($userdevices)) {						$astman->database_del("AMPUSER",$deviceuser."/device");				} else {						$astman->database_put("AMPUSER",$deviceuser."/device",$userdevices);				}		}		$astman->database_del("DEVICE",$account."/dial");		$astman->database_del("DEVICE",$account."/type");		$astman->database_del("DEVICE",$account."/user");		$astman->database_del("DEVICE",$account."/emergency_cid");		$astman->disconnect();		//delete from devices table		$sql="DELETE FROM devices WHERE id = \"$account\"";		sql($sql);		//voicemail symlink		exec("rm -f /var/spool/asterisk/voicemail/device/".$account);	} else {		fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);	}		//take care of sip/iax/zap config	$funct = "core_devices_del".strtolower($devinfo['tech']);	if(function_exists($funct)){		$funct($account);	}}function core_devices_get($account){	//get all the variables for the meetme	$sql = "SELECT * FROM devices WHERE id = '$account'";	$results = sql($sql,"getRow",DB_FETCHMODE_ASSOC);		//take care of sip/iax/zap config	$funct = "core_devices_get".strtolower($results['tech']);	if(function_exists($funct)){		$devtech = $funct($account);		if (is_array($devtech)){			$results = array_merge($results,$devtech);		}	}		return $results;}// this function rebuilds the astdb based on device table contents// used on devices.php if action=resetallfunction core_devices2astdb(){	require_once('common/php-asmanager.php');	checkAstMan();	global $amp_conf;	$sql = "SELECT * FROM devices";	$devresults = sql($sql,"getAll",DB_FETCHMODE_ASSOC);	//add details to astdb	$astman = new AGI_AsteriskManager();	if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {			$astman->database_deltree("DEVICE");		foreach($devresults as $dev) {			extract($dev);				$astman->database_put("DEVICE",$id."/dial",$dial);			$astman->database_put("DEVICE",$id."/type",$devicetype);			$astman->database_put("DEVICE",$id."/user",$user);					// If a user is selected, add this device to the user			if($user != "none") {					$existingdevices = $astman->database_get("AMPUSER",$user."/device");					if (!empty($existingdevices)) {							$existingdevices .= "&";					}					$astman->database_put("AMPUSER",$user."/device",$existingdevices.$id);			}						// create a voicemail symlink if needed			$thisUser = core_users_get($user);			if(isset($thisUser['voicemail']) && ($thisUser['voicemail'] != "disabled")) {				if(empty($thisUser['voicemail']))					$vmcontext = "default";				else 					$vmcontext = $thisUser['voicemail'];				//voicemail symlink				exec("rm -f /var/spool/asterisk/voicemail/device/".$id);				exec("/bin/ln -s /var/spool/asterisk/voicemail/".$vmcontext."/".$user."/ /var/spool/asterisk/voicemail/device/".$id);			}		}	} else {		echo _("Cannot connect to Asterisk Manager with ").$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"];	}	return $astman->disconnect();}// this function rebuilds the astdb based on users table contents// used on devices.php if action=resetallfunction core_users2astdb(){	require_once('common/php-asmanager.php');	checkAstMan();	global $amp_conf;	$sql = "SELECT * FROM users";	$userresults = sql($sql,"getAll",DB_FETCHMODE_ASSOC);		//add details to astdb	$astman = new AGI_AsteriskManager();	if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {		$astman->database_deltree("AMPUSER");		foreach($userresults as $usr) {			extract($usr);			$astman->database_put("AMPUSER",$extension."/password",$password);			$astman->database_put("AMPUSER",$extension."/ringtimer",$ringtimer);			$astman->database_put("AMPUSER",$extension."/noanswer",$noasnwer);			$astman->database_put("AMPUSER",$extension."/recording",$recording);			$astman->database_put("AMPUSER",$extension."/outboundcid","\"".addslashes($outboundcid)."\"");			$astman->database_put("AMPUSER",$extension."/cidname","\"".addslashes($name)."\"");			$astman->database_put("AMPUSER",$extension."/voicemail","\"".$voicemail."\"");		}		} else {		echo _("Cannot connect to Asterisk Manager with ").$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"];	}	return $astman->disconnect();}//add to sip tablefunction core_devices_addsip($account) {	global $db;	global $currentFile;	$sipfields = array(array($account,'account',$account),	array($account,'accountcode',(isset($_REQUEST['accountcode']))?$_REQUEST['accountcode']:''),	array($account,'secret',(isset($_REQUEST['secret']))?$_REQUEST['secret']:''),	array($account,'canreinvite',(isset($_REQUEST['canreinvite']))?$_REQUEST['canreinvite']:'no'),	array($account,'context',(isset($_REQUEST['context']))?$_REQUEST['context']:'from-internal'),	array($account,'dtmfmode',(isset($_REQUEST['dtmfmode']))?$_REQUEST['dtmfmode']:''),	array($account,'host',(isset($_REQUEST['host']))?$_REQUEST['host']:'dynamic'),	array($account,'type',(isset($_REQUEST['type']))?$_REQUEST['type']:'friend'),	array($account,'mailbox',(isset($_REQUEST['mailbox']) && !empty($_REQUEST['mailbox']))?$_REQUEST['mailbox']:$account.'@device'),	array($account,'username',(isset($_REQUEST['username']))?$_REQUEST['username']:$account),	array($account,'nat',(isset($_REQUEST['nat']))?$_REQUEST['nat']:'never'),	array($account,'port',(isset($_REQUEST['port']))?$_REQUEST['port']:'5060'),	array($account,'qualify',(isset($_REQUEST['qualify']))?$_REQUEST['qualify']:'no'),	array($account,'callgroup',(isset($_REQUEST['callgroup']))?$_REQUEST['callgroup']:''),	array($account,'pickupgroup',(isset($_REQUEST['pickupgroup']))?$_REQUEST['pickupgroup']:''),	array($account,'disallow',(isset($_REQUEST['disallow']))?$_REQUEST['disallow']:''),	array($account,'allow',(isset($_REQUEST['allow']))?$_REQUEST['allow']:''),	array($account,'record_in',(isset($_REQUEST['record_in']))?$_REQUEST['record_in']:'On-Demand'),	array($account,'record_out',(isset($_REQUEST['record_out']))?$_REQUEST['record_out']:'On-Demand'),	array($account,'callerid',(isset($_REQUEST['description']))?$_REQUEST['description']." <".$account.'>':'device'." <".$account.'>'));	$compiled = $db->prepare('INSERT INTO sip (id, keyword, data) values (?,?,?)');	$result = $db->executeMultiple($compiled,$sipfields);	if(DB::IsError($result)) {		die($result->getDebugInfo()."<br><br>".'error adding to SIP table');		}		   	//script to write sip conf file from mysql	//$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_sip_conf_from_mysql.pl';	//exec($wScript);}function core_devices_delsip($account) {	global $db;	global $currentFile;    $sql = "DELETE FROM sip WHERE id = '$account'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);	}	//script to write sip conf file from mysql	//$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_sip_conf_from_mysql.pl';	//exec($wScript);	//script to write op_server.cfg file from mysql 	//$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl';	//exec($wOpScript);}function core_devices_getsip($account) {	global $db;	$sql = "SELECT keyword,data FROM sip WHERE id = '$account'";	$results = $db->getAssoc($sql);	if(DB::IsError($results)) {		$results = null;	}	return $results;}//add to iax tablefunction core_devices_addiax2($account) {	global $db;	global $currentFile;	$iaxfields = array(array($account,'account',$account),	array($account,'secret',($_REQUEST['secret'])?$_REQUEST['secret']:''),	array($account,'notransfer',($_REQUEST['notransfer'])?$_REQUEST['notransfer']:'yes'),	array($account,'context',($_REQUEST['context'])?$_REQUEST['context']:'from-internal'),	array($account,'host',($_REQUEST['host'])?$_REQUEST['host']:'dynamic'),	array($account,'type',($_REQUEST['type'])?$_REQUEST['type']:'friend'),	array($account,'mailbox',($_REQUEST['mailbox'])?$_REQUEST['mailbox']:$account.'@device'),	array($account,'username',($_REQUEST['username'])?$_REQUEST['username']:$account),	array($account,'port',($_REQUEST['port'])?$_REQUEST['port']:'4569'),	array($account,'qualify',($_REQUEST['qualify'])?$_REQUEST['qualify']:'no'),	array($account,'disallow',($_REQUEST['disallow'])?$_REQUEST['disallow']:''),	array($account,'allow',($_REQUEST['allow'])?$_REQUEST['allow']:''),	array($account,'accountcode',($_REQUEST['accountcode'])?$_REQUEST['accountcode']:''),	array($account,'record_in',($_REQUEST['record_in'])?$_REQUEST['record_in']:'On-Demand'),	array($account,'record_out',($_REQUEST['record_out'])?$_REQUEST['record_out']:'On-Demand'),	array($account,'callerid',($_REQUEST['description'])?$_REQUEST['description']." <".$account.'>':'device'." <".$account.'>'));	$compiled = $db->prepare('INSERT INTO iax (id, keyword, data) values (?,?,?)');	$result = $db->executeMultiple($compiled,$iaxfields);	if(DB::IsError($result)) {		die($result->getMessage()."<br><br>error adding to IAX table");		}	

⌨️ 快捷键说明

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