📄 functions.php
字号:
backendAddTrunk($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register); return $trunknum;}//obsoletefunction deleteTrunk($trunknum, $tech = null) { global $db; if ($tech === null) { // in EditTrunk, we get this info anyways $tech = getTrunkTech($trunknum); } //delete from globals table //$sql = "DELETE FROM globals WHERE variable LIKE '%OUT_$trunknum' OR variable LIKE '%OUTCID_$trunknum'"; $sql = "DELETE FROM globals WHERE variable LIKE '%OUT_$trunknum' OR variable IN ('OUTCID_$trunknum','OUTMAXCHANS_$trunknum','OUTPREFIX_$trunknum')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } //write outids writeoutids(); //delete from extensions table //delextensions('outbound-trunks','_${DIAL_OUT_'.$trunknum.'}.'); //DIALRULES deleteTrunkRules($trunknum); //and conditionally, 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'"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } break; case "sip": $sql = "DELETE FROM sip WHERE id = '9999$trunknum' OR id = '99999$trunknum' OR id = '9999999$trunknum'"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } break; }}//obsoletefunction editTrunk($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register) { //echo "editTrunk($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register)"; $tech = getTrunkTech($trunknum); deleteTrunk($trunknum, $tech); backendAddTrunk($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register);}//get and print peer details (prefixed with 4 9's)//obsoletefunction getTrunkPeerDetails($trunknum) { global $db; $tech = getTrunkTech($trunknum); if ($tech == "zap") return ""; // zap has no details $sql = "SELECT keyword,data FROM $tech WHERE id = '9999$trunknum' ORDER BY id"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } foreach ($results as $result) { if ($result[0] != 'account') { $confdetail .= $result[0] .'='. $result[1] . "\n"; } } return $confdetail;}//get and print user config (prefixed with 5 9's)//obsoletefunction getTrunkUserConfig($trunknum) { global $db; $tech = getTrunkTech($trunknum); if ($tech == "zap") return ""; // zap has no details $sql = "SELECT keyword,data FROM $tech WHERE id = '99999$trunknum' ORDER BY id"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } foreach ($results as $result) { if ($result[0] != 'account') { $confdetail .= $result[0] .'='. $result[1] . "\n"; } } return $confdetail;}//get trunk user context (prefixed with 5 9's)//obsoletefunction getTrunkUserContext($trunknum) { global $db; $tech = getTrunkTech($trunknum); if ($tech == "zap") return ""; // zap has no account $sql = "SELECT keyword,data FROM $tech WHERE id = '99999$trunknum' ORDER BY id"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } foreach ($results as $result) { if ($result[0] == 'account') { $account = $result[1]; } } return $account;}//obsoletefunction getTrunkTrunkName($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: $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 trunk account register string//obsoletefunction getTrunkRegister($trunknum) { global $db; $tech = getTrunkTech($trunknum); if ($tech == "zap") return ""; // zap has no register $sql = "SELECT keyword,data FROM $tech WHERE id = '9999999$trunknum'"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } foreach ($results as $result) { $register = $result[1]; } return $register;}//obsoletefunction addTrunkRegister($trunknum,$tech,$reg) { global $db; $sql = "INSERT INTO $tech (id, keyword, data) values ('9999999$trunknum','register','$reg')"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); }}//get unique outbound route names//obsoletefunction getroutenames() { global $db; $sql = "SELECT DISTINCT SUBSTRING(context,7) FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context "; // we SUBSTRING() to remove "outrt-" $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } if (count($results) == 0) { // see if they're still using the old dialprefix method $sql = "SELECT variable,value FROM globals WHERE variable LIKE 'DIAL\\\_OUT\\\_%'"; // we SUBSTRING() to remove "outrt-" $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } if (count($results) > 0) { // yes, they are using old method, let's update // get the default trunk $sql = "SELECT value FROM globals WHERE variable = 'OUT'"; $results_def = $db->getAll($sql); if(DB::IsError($results_def)) { die($results_def->getMessage()); } if (preg_match("/{OUT_(\d+)}/", $results_def[0][0], $matches)) { $def_trunk = $matches[1]; } else { $def_trunk = ""; } $default_patterns = array( // default patterns that used to be in extensions.conf "NXXXXXX", "NXXNXXXXXX", "1800NXXXXXX", "1888NXXXXXX", "1877NXXXXXX", "1866NXXXXXX", "1NXXNXXXXXX", "011.", "911", "411", "311", ); foreach ($results as $temp) { // temp[0] is "DIAL_OUT_1" // temp[1] is the dial prefix $trunknum = substr($temp[0],9); $name = "route".$trunknum; $trunks = array(1=>"OUT_".$trunknum); // only one trunk to use $patterns = array(); foreach ($default_patterns as $pattern) { $patterns[] = $temp[1]."|".$pattern; } if ($trunknum == $def_trunk) { // this is the default trunk, add the patterns with no prefix $patterns = array_merge($patterns, $default_patterns); } // add this as a new route addroute($name, $patterns, $trunks,"new"); } // delete old values $sql = "DELETE FROM globals WHERE (variable LIKE 'DIAL\\\_OUT\\\_%') OR (variable = 'OUT') "; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } // we need to re-generate extensions_additional.conf // i'm not sure how to do this from here // re-run our query $sql = "SELECT DISTINCT SUBSTRING(context,7) FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context "; // we SUBSTRING() to remove "outrt-" $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } } } // else, it just means they have no routes. return $results;}//get unique outbound route patterns for a given context//obsoletefunction getroutepatterns($route) { global $db; $sql = "SELECT extension, args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'dialout-trunk%' OR args LIKE'dialout-enum%') ORDER BY extension "; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } $patterns = array(); foreach ($results as $row) { if ($row[0][0] == "_") { // remove leading _ $pattern = substr($row[0],1); } else { $pattern = $row[0]; } if (preg_match("/{EXTEN:(\d+)}/", $row[1], $matches)) { // this has a digit offset, we need to insert a | $pattern = substr($pattern,0,$matches[1])."|".substr($pattern,$matches[1]); } $patterns[] = $pattern; } return array_unique($patterns);}//get unique outbound route trunks for a given context//obsoletefunction getroutetrunks($route) { global $db; $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%') 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]; } } else if (preg_match('/^dialout-enum,(\d+)/', $row[0], $matches)) { if (!in_array("OUT_".$matches[1], $trunks)) { $trunks[] = "OUT_".$matches[1]; } } } return $trunks;}//get password for this route//obsoletefunction getroutepassword($route) { global $db; $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%') ORDER BY priority "; $results = $db->getOne($sql); if(DB::IsError($results)) { die($results->getMessage()); } if (preg_match('/^.*,.*,.*,(\d+)/', $results, $matches)) { $password = $matches[1]; } else { $password = ""; } return $password; }//get outbound routes for a given trunk//obsoletefunction gettrunkroutes($trunknum) { global $db; $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 "; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } $routes = array(); foreach ($results as $row) { $routes[$row[0]] = $row[1]; } // array(routename=>priority) return $routes;}//obsoletefunction addroute($name, $patterns, $trunks, $method, $pass) { global $db; $trunktech=array(); //Retrieve each trunk tech for later lookup $sql="select * from globals WHERE variable LIKE 'OUT\\_%'"; $result = $db->getAll($sql); if(DB::IsError($result)) { die($result->getMessage()); } foreach($result as $tr) { $tech = strtok($tr[1], "/"); $trunktech[$tr[0]]=$tech; } if ($method=="new") { $sql="select DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context"; $routepriority = $db->getAll($sql); if(DB::IsError($result)) { die($result->getMessage());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -