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

📄 functions.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 5 页
字号:
            }            $order=setroutepriorityvalue(count($routepriority));	 	$name = sprintf ("%s-%s",$order,$name);	}	$trunks = array_values($trunks); // probably already done, but it's important for our dialplan		foreach ($patterns as $pattern) {				if (false !== ($pos = strpos($pattern,"|"))) {			// we have a | meaning to not pass the digits on			// (ie, 9|NXXXXXX should use the pattern _9NXXXXXX but only pass NXXXXXX, not the leading 9)						$pattern = str_replace("|","",$pattern); // remove all |'s			$exten = "EXTEN:".$pos; // chop off leading digit		} else {			// we pass the full dialed number as-is			$exten = "EXTEN"; 		}				if (!preg_match("/^[0-9*]+$/",$pattern)) { 			// note # is not here, as asterisk doesn't recoginize it as a normal digit, thus it requires _ pattern matching						// it's not strictly digits, so it must have patterns, so prepend a _			$pattern = "_".$pattern;		}				foreach ($trunks as $priority => $trunk) {			$priority += 1; // since arrays are 0-based, but we want priorities to start at 1						$sql = "INSERT INTO extensions (context, extension, priority, application, args) VALUES ";			$sql .= "('outrt-".$name."', ";			$sql .= "'".$pattern."', ";			$sql .= "'".$priority."', ";			$sql .= "'Macro', ";			if ($trunktech[$trunk] == "ENUM")				$sql .= "'dialout-enum,".substr($trunk,4).",\${".$exten."},".$pass."'"; // cut off OUT_ from $trunk			else				$sql .= "'dialout-trunk,".substr($trunk,4).",\${".$exten."},".$pass."'"; // cut off OUT_ from $trunk			$sql .= ")";						$result = $db->query($sql);			if(DB::IsError($result)) {				die($result->getMessage());			}			//blank pass so that it isn't added for additional trunks			$pass = "";		}				$priority += 1;		$sql = "INSERT INTO extensions (context, extension, priority, application, args, descr) VALUES ";		$sql .= "('outrt-".$name."', ";		$sql .= "'".$pattern."', ";		$sql .= "'".$priority."', ";		$sql .= "'Macro', ";		$sql .= "'outisbusy', ";		$sql .= "'No available circuits')";				$result = $db->query($sql);		if(DB::IsError($result)) {			die($result->getMessage());		}	}		// add an include=>outrt-$name  to [outbound-allroutes]:		// we have to find the first available priority.. priority doesn't really matter for the include, but	// there is a unique index on (context,extension,priority) so if we don't do this we can't put more than	// one route in the outbound-allroutes context.	$sql = "SELECT priority FROM extensions WHERE context = 'outbound-allroutes' AND extension = 'include'";	$results = $db->getAll($sql);	if(DB::IsError($results)) {		die($results->getMessage());	}	$priorities = array();	foreach ($results as $row) {		$priorities[] = $row[0];	}	for ($priority = 1; in_array($priority, $priorities); $priority++);		// $priority should now be the lowest available number		$sql = "INSERT INTO extensions (context, extension, priority, application, args, descr, flags) VALUES ";	$sql .= "('outbound-allroutes', ";	$sql .= "'include', ";	$sql .= "'".$priority."', ";	$sql .= "'outrt-".$name."', ";	$sql .= "'', ";	$sql .= "'', ";	$sql .= "'2')";		$result = $db->query($sql);	if(DB::IsError($result)) {		die($priority.$result->getMessage());	}	}//obsoletefunction deleteroute($name) {	global $db;	$sql = "DELETE FROM extensions WHERE context = 'outrt-".$name."'";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}		$sql = "DELETE FROM extensions WHERE context = 'outbound-allroutes' AND application = 'outrt-".$name."' ";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}		return $result;}//obsoletefunction renameRoute($oldname, $newname) {	global $db;	$route_prefix=substr($oldname,0,4);	$newname=$route_prefix.$newname;	$sql = "SELECT context FROM extensions WHERE context = 'outrt-".$newname."'";	$results = $db->getAll($sql);	if (count($results) > 0) {		// there's already a route with this name		return false;	}		$sql = "UPDATE extensions SET context = 'outrt-".$newname."' WHERE context = 'outrt-".$oldname."'";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}        $mypriority=sprintf("%d",$route_prefix);		$sql = "UPDATE extensions SET application = 'outrt-".$newname."', priority = '$mypriority' WHERE context = 'outbound-allroutes' AND application = 'outrt-".$oldname."' ";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}		return true;}//obsoletefunction editroute($name, $patterns, $trunks, $pass) {	deleteroute($name);	addroute($name, $patterns, $trunks,"edit", $pass);}function getroute($route) {	global $db; 	$sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND args LIKE 'dialout-trunk,%' ORDER BY priority "; 	$results = $db->getAll($sql); 	if(DB::IsError($results)) { 		die($results->getMessage()); 	} 	 	$trunks = array(); 	foreach ($results as $row) { 		if (preg_match('/^dialout-trunk,(\d+)/', $row[0], $matches)) { 			// check in_array -- even though we did distinct 			// we still might get ${EXTEN} and ${EXTEN:1} if they used | to split a pattern 			if (!in_array("OUT_".$matches[1], $trunks)) { 				$trunks[] = "OUT_".$matches[1]; 			} 		} 	} 	return $trunks;}function setroutepriorityvalue2($key){	$my_lookup=array();	$x=0;	for ($j=97;$j<100;$j++)	{		for ($i=97;$i<123;$i++)		{			$my_lookup[$x++] = sprintf("%c%c",$j,$i);		}	}echo "my key is $key $my_lookup[$key]";	return ($my_lookup[$key]);}//obsoletefunction setroutepriorityvalue($key){	$key=$key+1;	if ($key<10)		$prefix = sprintf("00%d",$key);	else if ((9<$key)&&($key<100))		$prefix = sprintf("0%d",$key);	else if ($key>100)		$prefix = sprintf("%d",$key);	return ($prefix);}//obsoletefunction setroutepriority($routepriority, $reporoutedirection, $reporoutekey){	global $db;	$counter=-1;	foreach ($routepriority as $tresult) 	{		$counter++;		if (($counter==($reporoutekey-1)) && ($reporoutedirection=="up")) {			// swap this one with the one before (move up)			$temproute = $routepriority[$counter];			$routepriority[ $counter ] = $routepriority[ $counter+1 ];			$routepriority[ $counter+1 ] = $temproute;					} else if (($counter==($reporoutekey)) && ($reporoutedirection=="down")) {			// swap this one with the one after (move down)			$temproute = $routepriority[ $counter+1 ];			$routepriority[ $counter+1 ] = $routepriority[ $counter ];			$routepriority[ $counter ] = $temproute;		}	}	unset($temptrunk);	$routepriority = array_values($routepriority); // resequence our numbers	$counter=0;	foreach ($routepriority as $tresult) 	{		$order=setroutepriorityvalue($counter++);		$sql = sprintf("Update extensions set context='outrt-%s-%s' WHERE context='outrt-%s'",$order,substr($tresult[0],4), $tresult[0]);		$result = $db->query($sql); 		if(DB::IsError($result)) {     			die($result->getMessage()); 		}	}	// Delete and readd the outbound-allroutes entries	$sql = "delete from  extensions WHERE context='outbound-allroutes'";	$result = $db->query($sql);	if(DB::IsError($result)) {        	die($result->getMessage().$sql);	}	$sql = "SELECT DISTINCT context FROM extensions WHERE context like 'outrt-%' ORDER BY context";	$results = $db->getAll($sql);	if(DB::IsError($results)) {		die($results->getMessage());	}	$priority_loops=1;		foreach ($results as $row) {		$sql = "INSERT INTO extensions (context, extension, priority, application, args, descr, flags) VALUES ";		$sql .= "('outbound-allroutes', ";		$sql .= "'include', ";		$sql .= "'".$priority_loops++."', ";		$sql .= "'".$row[0]."', ";		$sql .= "'', ";		$sql .= "'', ";		$sql .= "'2')";			//$sql = sprintf("Update extensions set application='outrt-%s-%s' WHERE context='outbound-allroutes' and  application='outrt-%s'",$order,substr($tresult[0],4), $tresult[0]);		$result = $db->query($sql); 		if(DB::IsError($result)) {     			die($result->getMessage(). $sql);  		}	}	$sql = "SELECT DISTINCT SUBSTRING(context,7) FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context ";        // we SUBSTRING() to remove "outrt-"        $routepriority = $db->getAll($sql);        if(DB::IsError($routepriority))        {                die($routepriority->getMessage());        }        return ($routepriority);		} //opsoletefunction 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];				}								parse_conf($filename, $conf, $section);			}		}	}}//obsoletefunction readDialRulesFile() {	global $localPrefixFile; // probably not the best way		parse_conf($localPrefixFile, &$conf, &$section);		return $conf;}//obsoletefunction getDialRules($trunknum) {	$conf = readDialRulesFile();	if (isset($conf["trunk-".$trunknum])) {		return $conf["trunk-".$trunknum];	}	return false;}//obsoletefunction 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);}//obsoletefunction addDialRules($trunknum, $dialrules) {	$values = array();	$i = 1;	foreach ($dialrules as $rule) {		$values["rule".$i++] = $rule;	}		$conf = readDialRulesFile();		// rewrite for this trunk	$conf["trunk-".$trunknum] = $values;		writeDialRulesFile($conf);}//obsoletefunction deleteDialRules($trunknum) {	$conf = readDialRulesFile();		// remove rules for this trunk	unset($conf["trunk-".$trunknum]);		writeDialRulesFile($conf);}//obsoletefunction addqueue($account,$name,$password,$prefix,$goto,$agentannounce,$members,$joinannounce) {	global $db;		//add to extensions table	if ($agentannounce != 'None')		$agentannounce="custom/$agentannounce";	else		$agentannounce="";	$addarray = array('ext-queues',$account,'1','Answer',''.'','','0');	addextensions($addarray);	$addarray = array('ext-queues',$account,'2','SetCIDName',$prefix.'${CALLERIDNAME}','','0');

⌨️ 快捷键说明

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