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

📄 functions.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		}		if (count($thisExten) > 0) {			$thisExten[] = array('$extdisplay','tech','iax2','info');  //add this to the array - as it doesn't exist in the table		} else {			$sql = "SELECT * FROM zap WHERE id = '$extdisplay'";			$thisExten = $db->getAll($sql);			if(DB::IsError($thisExten)) {				die($thisExten->getMessage());			}			if (count($thisExten) > 0) {				$thisExten[] = array('$extdisplay','tech','zap','info');			}		}	}	//get var containing external cid	$sql = "SELECT * FROM globals WHERE variable = 'ECID$extdisplay'";	$ecid = $db->getAll($sql);	if(DB::IsError($ecid)) {	   die($ecid->getMessage());	}	$thisExten[] = array('$extdisplay','1outcid',$ecid[0][1],'info');	sort($thisExten);		return $thisExten;}//Delete an extension (extensions.php)function delExten($extdisplay) {	global $db;    $sql = "DELETE FROM sip WHERE id = '$extdisplay'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);    }    $sql = "DELETE FROM iax WHERE id = '$extdisplay'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);    }    $sql = "DELETE FROM zap WHERE id = '$extdisplay'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);    }    $sql = "DELETE FROM globals WHERE variable = 'E$extdisplay'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);    }    $sql = "DELETE FROM globals WHERE variable = 'ECID$extdisplay'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);    }	$sql = "DELETE FROM globals WHERE variable = 'ZAPCHAN_$extdisplay'";    $result = $db->query($sql);    if(DB::IsError($result)) {        die($result->getMessage().$sql);    }}*///add trunk to outbound-trunks context//obsoletefunction addOutTrunk($trunknum) {	extensionsexists();	global $db;	$sql = "INSERT INTO extensions (context, extension, priority, application, args, descr, flags) VALUES ('outbound-trunks', '_\${DIAL_OUT_".$trunknum."}.', '1', 'Macro', 'dialout,".$trunknum.",\${EXTEN}', NULL , '0')";	$result = $db->query($sql);	if(DB::IsError($result)) {        die($result->getMessage()."<br><br>".$sql);    }    return $result;}//write the OUTIDS global variable (used in dialparties.agi)//obsoletefunction writeoutids() {	global $db;	$sql = "SELECT variable FROM globals WHERE variable LIKE 'OUT\\\_%'"; // we have to escape _ for mysql: normally a wildcard	$unique_trunks = $db->getAll($sql);	if(DB::IsError($unique_trunks)) {	   die('unique: '.$unique_trunks->getMessage());	}	foreach ($unique_trunks as $unique_trunk) {		$outid = strtok($unique_trunk[0],"_");		$outid = strtok("_");		$outids .= $outid ."/";	}	$sql = "UPDATE globals SET value = '$outids' WHERE variable = 'DIALOUTIDS'";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}}//get unique trunks//obsoletefunction gettrunks() {	global $db;	$sql = "SELECT * FROM globals WHERE variable LIKE 'OUT\\\_%' ORDER BY RIGHT( variable, LENGTH( variable ) - 4 )+0"; // we have to escape _ for mysql: normally a wildcard	$unique_trunks = $db->getAll($sql);	if(DB::IsError($unique_trunks)) {	   die('unique: '.$unique_trunks->getMessage());	}	//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'";		$result = $db->query($sql);		if(DB::IsError($result)) {			die($result->getMessage());		}		$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');		addOutTrunk("1");	}	// asort($unique_trunks);	return $unique_trunks;}//add trunk info to sip or iax table//obsoletefunction addSipOrIaxTrunk($config,$table,$channelid,$trunknum) {	global $db;		//echo "addSipOrIaxTrunk($config,$table,$channelid,$trunknum)";		$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',?,?)");		}}//obsoletefunction getTrunkTech($trunknum) {	global $db;		$sql = "SELECT value FROM globals WHERE variable = 'OUT_".$trunknum."'";	if (!$results = $db->getAll($sql)) {		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;}function addTrunkDialRules($trunknum, $rules) {	global $db;		foreach ($rules as $rule) {		$values = array();				if (false !== ($pos = strpos($rule,"|"))) {			// we have a | meaning to not dial the numbers before it			// (ie, 1613|NXXXXXX should use the pattern _1613NXXXXXX but only pass NXXXXXX, not the leading 1613)						$exten = "EXTEN:".$pos; // chop off leading digit			$prefix = "";						$rule = str_replace("|","",$rule); // remove all |'s					} else if (false !== ($pos = strpos($rule,"+"))) {			// we have a + meaning to add the numbers before it			// (ie, 1613+NXXXXXX should use the pattern _NXXXXXX but pass it as 1613NXXXXXX)						$prefix = substr($rule,0,$pos); // get the prefixed digits			$exten = "EXTEN"; // pass as is						$rule = substr($rule, $pos+1); // only match pattern after the +		} else {			// we pass the full dialed number as-is			$exten = "EXTEN"; 			$prefix = "";		}				if (!preg_match("/^[0-9*]+$/",$rule)) { 			// 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 _			$rule = "_".$rule;		}				$values[] = array('1', 'Dial', '${OUT_'.$trunknum.'}/${OUTPREFIX_'.$trunknum.'}'.$prefix.'${'.$exten.'}');		$values[] = array('2', 'Congestion', '');		$values[] = array('102', 'NoOp', 'outdial-'.$trunknum.' dial failed');				$sql = "INSERT INTO extensions (context, extension, priority, application, args) VALUES ";		$sql .= "('outdial-".$trunknum."', ";		$sql .= "'".$rule."', ";		// priority, application, args:		$sql .= "?, ?, ?)";				$compiled = $db->prepare($sql);		$result = $db->executeMultiple($compiled,$values);		if(DB::IsError($result)) {			//var_dump($result);			die($result->getMessage());		}			}		// catch-all extension	$sql = "INSERT INTO extensions (context, extension, priority, application, args) VALUES ";	$sql .= "('outdial-".$trunknum."-catchall', ";	$sql .= "'_.', ";	// priority, application, args:	$sql .= "'1', ";	$sql .= "'Dial', ";	$sql .= "'\${OUT_".$trunknum."}/\${OUTPREFIX_".$trunknum."}\${EXTEN}');";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}	// include catch-all in main context	$sql = "INSERT INTO extensions (context, extension, priority, application, flags) VALUES ";	$sql .= "('outdial-".$trunknum."', ";	$sql .= "'include', ";	$sql .= "'1', ";	$sql .= "'outdial-".$trunknum."-catchall', ";	$sql .= "'2');";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}}function deleteTrunkDialRules($trunknum) {	global $db;		$sql = "DELETE FROM extensions WHERE context = 'outdial-".$trunknum."'";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}	// the "catch-all" extension	$sql = "DELETE FROM extensions WHERE context = 'outdial-".$trunknum."-catchall'";	$result = $db->query($sql);	if(DB::IsError($result)) {		die($result->getMessage());	}}function getTrunkDialRules($trunknum) {	global $db;	$sql = "SELECT extension, args FROM extensions WHERE context = 'outdial-".$trunknum."' AND application = 'Dial' ORDER BY extension ";	$results = $db->getAll($sql);	if(DB::IsError($results)) {		die($results->getMessage());	}		$rules = array();	foreach ($results as $row) {		if ($row[0][0] == "_") {			// remove leading _			$rule = substr($row[0],1);		} else {			$rule = $row[0];		}				if (preg_match("/(\d*){EXTEN:(\d+)}/", $row[1], $matches)) {			// this has a digit offset, we need to insert a |			$rule = substr($rule,0,$matches[2])."|".substr($rule,$matches[2]);		} else if (preg_match("/(\d){EXTEN}/", $row[1], $matches)) {			// this has a prefix, insert a +			$rule = substr($rule,0,strlen($matches[1]))."+".substr($rule,strlen($matches[1]));		}				$rules[] = $rule;	}	return array_unique($rules);	}// just used internally by addTrunk() and editTrunk()//obsoletefunction backendAddTrunk($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);	}		writeoutids();		//addOutTrunk($trunknum); don't need to add to outbound-routes anymore		switch (strtolower($tech)) {		case "iax":		case "iax2":			addSipOrIaxTrunk($peerdetails,'iax',$channelid,$trunknum);			if ($usercontext != ""){				addSipOrIaxTrunk($userconfig,'iax',$usercontext,'9'.$trunknum);			}			if ($register != ""){				addTrunkRegister($trunknum,'iax',$register);			}		break;		case "sip":			addSipOrIaxTrunk($peerdetails,'sip',$channelid,$trunknum);			if ($usercontext != ""){				addSipOrIaxTrunk($userconfig,'sip',$usercontext,'9'.$trunknum);			}			if ($register != ""){				addTrunkRegister($trunknum,'sip',$register);			}		break;	}	}// we're adding ,don't require a $trunknum//obsoletefunction addTrunk($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register) {	global $db;		// find the next available ID	$trunknum = 1;	foreach(gettrunks() as $trunk) {		if ($trunknum == ltrim($trunk[0],"OUT_")) { 			$trunknum++;		}	}	

⌨️ 快捷键说明

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