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

📄 functions.inc.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 5 页
字号:
/* end page.users.php functions *//* begin page.trunks.php functions */// we're adding ,don't require a $trunknumfunction core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register) {	global $db;		// find the next available ID	$trunknum = 1;	foreach(core_trunks_list() as $trunk) {		if ($trunknum == ltrim($trunk[0],"OUT_")) { 			$trunknum++;		}	}		core_trunks_backendAdd($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register);		return $trunknum;}function core_trunks_del($trunknum, $tech = null) {	global $db;		if ($tech === null) { // in EditTrunk, we get this info anyways		$tech = core_trunks_getTrunkTech($trunknum);	}	//delete from globals table	sql("DELETE FROM globals WHERE variable LIKE '%OUT_$trunknum' OR variable IN ('OUTCID_$trunknum','OUTMAXCHANS_$trunknum','OUTPREFIX_$trunknum')");		//write outids	core_trunks_writeoutids();	// conditionally, delete from iax or sip	switch (strtolower($tech)) {		case "iax":		case "iax2":			sql("DELETE FROM iax WHERE id = '9999$trunknum' OR id = '99999$trunknum' OR id = '9999999$trunknum'");		break;		case "sip": 			sql("DELETE FROM sip WHERE id = '9999$trunknum' OR id = '99999$trunknum' OR id = '9999999$trunknum'");		break;	}}function core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register) {	//echo "editTrunk($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register)";	$tech = core_trunks_getTrunkTech($trunknum);	core_trunks_del($trunknum, $tech);	core_trunks_backendAdd($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register);}// just used internally by addTrunk() and editTrunk()//obsoletefunction core_trunks_backendAdd($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register) {	global $db;		if  (is_null($dialoutprefix)) $dialoutprefix = ""; // can't be NULL		//echo  "backendAddTrunk($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register)";		// change iax to "iax2" (only spot we actually store iax2, since its used by Dial()..)	$techtemp = ((strtolower($tech) == "iax") ? "iax2" : $tech);	$outval = (($techtemp == "custom") ? "AMP:".$channelid : strtoupper($techtemp).'/'.$channelid);		$glofields = array(			array('OUT_'.$trunknum, $outval),			array('OUTPREFIX_'.$trunknum, $dialoutprefix),			array('OUTMAXCHANS_'.$trunknum, $maxchans),			array('OUTCID_'.$trunknum, $outcid),			);				unset($techtemp); 		$compiled = $db->prepare('INSERT INTO globals (variable, value) values (?,?)');	$result = $db->executeMultiple($compiled,$glofields);	if(DB::IsError($result)) {		die($result->getMessage()."<br><br>".$sql);	}		core_trunks_writeoutids();		switch (strtolower($tech)) {		case "iax":		case "iax2":			core_trunks_addSipOrIax($peerdetails,'iax',$channelid,$trunknum);			if ($usercontext != ""){				core_trunks_addSipOrIax($userconfig,'iax',$usercontext,'9'.$trunknum);			}			if ($register != ""){				core_trunks_addRegister($trunknum,'iax',$register);			}		break;		case "sip":			core_trunks_addSipOrIax($peerdetails,'sip',$channelid,$trunknum);			if ($usercontext != ""){				core_trunks_addSipOrIax($userconfig,'sip',$usercontext,'9'.$trunknum);			}			if ($register != ""){				core_trunks_addRegister($trunknum,'sip',$register);			}		break;	}	}function core_trunks_getTrunkTech($trunknum) {	$results = sql("SELECT value FROM globals WHERE variable = 'OUT_".$trunknum."'","getAll");	if (!$results) {		return false;	}	if(strpos($results[0][0],"AMP:") === 0) {  //custom trunks begin with AMP:		$tech = "custom";	} else {		$tech = strtolower( strtok($results[0][0],'/') ); // the technology.  ie: ZAP/g0 is ZAP				if ($tech == "iax2") $tech = "iax"; // same thing, here	}	return $tech;}//add trunk info to sip or iax tablefunction core_trunks_addSipOrIax($config,$table,$channelid,$trunknum) {	global $db;		$confitem['account'] = $channelid;	$gimmieabreak = nl2br($config);	$lines = split('<br />',$gimmieabreak);	foreach ($lines as $line) {		$line = trim($line);		if (count(split('=',$line)) > 1) {			$tmp = split('=',$line);			$key=trim($tmp[0]);			$value=trim($tmp[1]);			if (isset($confitem[$key]) && !empty($confitem[$key]))				$confitem[$key].="&".$value;			else				$confitem[$key]=$value;		}	}	foreach($confitem as $k=>$v) {		$dbconfitem[]=array($k,$v);	}	$compiled = $db->prepare("INSERT INTO $table (id, keyword, data) values ('9999$trunknum',?,?)");	$result = $db->executeMultiple($compiled,$dbconfitem);	if(DB::IsError($result)) {		die($result->getMessage()."<br><br>INSERT INTO $table (id, keyword, data) values ('9999$trunknum',?,?)");		}}//get unique trunksfunction core_trunks_list() {	global $db;	global $amp_conf;		if ( $amp_conf["AMPDBENGINE"] == "sqlite")	{		// TODO: sqlite work arround - diego 		$unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll"); 	}	else	{		// we have to escape _ for mysql: normally a wildcard		$unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT\\\_%' ORDER BY RIGHT( variable, LENGTH( variable ) - 4 )+0","getAll"); 	}	//if no trunks have ever been defined, then create the proper variables with the default zap trunk	if (count($unique_trunks) == 0) 	{		//If all trunks have been deleted from admin, dialoutids might still exist		sql("DELETE FROM globals WHERE variable = 'DIALOUTIDS'");			$glofields = array(array('OUT_1','ZAP/g0'),							array('DIAL_OUT_1','9'),							array('DIALOUTIDS','1'));		$compiled = $db->prepare('INSERT INTO globals (variable, value) values (?,?)');		$result = $db->executeMultiple($compiled,$glofields);		if(DB::IsError($result))		{			die($result->getMessage()."<br><br>".$sql);			}		$unique_trunks[] = array('OUT_1','ZAP/g0');	}	// asort($unique_trunks);	return $unique_trunks;}//write the OUTIDS global variable (used in dialparties.agi)function core_trunks_writeoutids() {	// we have to escape _ for mysql: normally a wildcard	$unique_trunks = sql("SELECT variable FROM globals WHERE variable LIKE 'OUT\\\_%'","getAll"); 	foreach ($unique_trunks as $unique_trunk) {		$outid = strtok($unique_trunk[0],"_");		$outid = strtok("_");		$outids .= $outid ."/";	}		sql("UPDATE globals SET value = '$outids' WHERE variable = 'DIALOUTIDS'");}function core_trunks_addRegister($trunknum,$tech,$reg) {	sql("INSERT INTO $tech (id, keyword, data) values ('9999999$trunknum','register','$reg')");}function core_trunks_addDialRules($trunknum, $dialrules) {	$values = array();	$i = 1;	foreach ($dialrules as $rule) {		$values["rule".$i++] = $rule;	}		$conf = core_trunks_readDialRulesFile();		// rewrite for this trunk	$conf["trunk-".$trunknum] = $values;		core_trunks_writeDialRulesFile($conf);}function core_trunks_readDialRulesFile() {	global $localPrefixFile; // probably not the best way		core_trunks_parse_conf($localPrefixFile, $conf, $section);		return $conf;}function core_trunks_writeDialRulesFile($conf) {	global $localPrefixFile; // probably not the best way		$fd = fopen($localPrefixFile,"w");	foreach ($conf as $section=>$values) {		fwrite($fd, "[".$section."]\n");		foreach ($values as $key=>$value) {			fwrite($fd, $key."=".$value."\n");		}		fwrite($fd, "\n");	}	fclose($fd);}function core_trunks_parse_conf($filename, &$conf, &$section) {	if (is_null($conf)) {		$conf = array();	}	if (is_null($section)) {		$section = "general";	}		if (file_exists($filename)) {		$fd = fopen($filename, "r");		while ($line = fgets($fd, 1024)) {			if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=\s*(.*?)\s*([;#].*)?$/",$line,$matches)) {				// name = value				// option line				$conf[$section][ $matches[1] ] = $matches[2];			} else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) {				// section name				$section = strtolower($matches[1]);			} else if (preg_match("/^\s*#include\s+(.*)\s*([;#].*)?/",$line,$matches)) {				// include another file								if ($matches[1][0] == "/") {					// absolute path					$filename = $matches[1];				} else {					// relative path					$filename =  dirname($filename)."/".$matches[1];				}								core_trunks_parse_conf($filename, $conf, $section);			}		}	}}function core_trunks_getTrunkTrunkName($trunknum) {	$results = sql("SELECT value FROM globals WHERE variable = 'OUT_".$trunknum."'","getAll");	if (!$results) {		return false;	}		if(strpos($results[0][0],"AMP:") === 0) {  //custom trunks begin with AMP:		$tname = ltrim($results[0][0],"AMP:");	} else {	strtok($results[0][0],'/');		$tname = strtok('/'); // the text _after_ technology.  ie: ZAP/g0 is g0	}	return $tname;}//get and print peer details (prefixed with 4 9's)function core_trunks_getTrunkPeerDetails($trunknum) {	global $db;		$tech = core_trunks_getTrunkTech($trunknum);		if ($tech == "zap") return ""; // zap has no details		$results = sql("SELECT keyword,data FROM $tech WHERE id = '9999$trunknum' ORDER BY id","getAll");		foreach ($results as $result) {		if ($result[0] != 'account') {			if (isset($confdetail))				$confdetail .= $result[0] .'='. $result[1] . "\n";			else				$confdetail = $result[0] .'='. $result[1] . "\n";		}	}	return $confdetail;}//get trunk user context (prefixed with 5 9's)function core_trunks_getTrunkUserContext($trunknum) {	$tech = core_trunks_getTrunkTech($trunknum);	if ($tech == "zap") return ""; // zap has no account		$results = sql("SELECT keyword,data FROM $tech WHERE id = '99999$trunknum' ORDER BY id","getAll");	foreach ($results as $result) {		if ($result[0] == 'account') {			$account = $result[1];		}	}	return isset($account)?$account:null;}//get and print user config (prefixed with 5 9's)function core_trunks_getTrunkUserConfig($trunknum) {	global $db;		$tech = core_trunks_getTrunkTech($trunknum);		if ($tech == "zap") return ""; // zap has no details		$results = sql("SELECT keyword,data FROM $tech WHERE id = '99999$trunknum' ORDER BY id","getAll");	foreach ($results as $result) {		if ($result[0] != 'account') {			if (isset($confdetail))				$confdetail .= $result[0] .'='. $result[1] . "\n";			else				$confdetail = $result[0] .'='. $result[1] . "\n";		}	}	return isset($confdetail)?$confdetail:null;}//get trunk account register stringfunction core_trunks_getTrunkRegister($trunknum) {	$tech = core_trunks_getTrunkTech($trunknum);		if ($tech == "zap") return ""; // zap has no register		$results = sql("SELECT keyword,data FROM $tech WHERE id = '9999999$trunknum'","getAll");	foreach ($results as $result) {			$register = $result[1];	}	return $register;}function core_trunks_getDialRules($trunknum) {	$conf = core_trunks_readDialRulesFile();	if (isset($conf["trunk-".$trunknum])) {		return $conf["trunk-".$trunknum];	}	return false;}//get outbound routes for a given trunkfunction core_trunks_gettrunkroutes($trunknum) {	$results = sql("SELECT DISTINCT SUBSTRING(context,7), priority FROM extensions WHERE context LIKE 'outrt-%' AND (args LIKE 'dialout-trunk,".$trunknum.",%' OR args LIKE 'dialout-enum,".$trunknum.",%')ORDER BY context ","getAll");

⌨️ 快捷键说明

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