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

📄 page.trunks.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php /* $Id: page.trunks.php 2287 2006-09-07 08:52:14Z qldrob $ */// routing.php Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca)// Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)////This program is free software; you can redistribute it and/or//modify it under the terms of the GNU General Public License//as published by the Free Software Foundation; either version 2//of the License, or (at your option) any later version.////This program is distributed in the hope that it will be useful,//but WITHOUT ANY WARRANTY; without even the implied warranty of//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//GNU General Public License for more details.$localPrefixFile = "/etc/asterisk/localprefixes.conf";$display='trunks'; $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:'';$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';$tech = strtolower(isset($_REQUEST['tech'])?$_REQUEST['tech']:'');$trunknum = ltrim($extdisplay,'OUT_');// populate some global variables from the request string$set_globals = array("outcid","maxchans","dialoutprefix","channelid","peerdetails","usercontext","userconfig","register");foreach ($set_globals as $var) {	if (isset($_REQUEST[$var])) {		$$var = stripslashes( $_REQUEST[$var] );	}}$dialrules = array();if (isset($_REQUEST["dialrules"])) {	//$dialpattern = $_REQUEST["dialpattern"];	$dialrules = explode("\n",$_REQUEST["dialrules"]);	if (!$dialrules) {		$dialrules = array();	}		foreach (array_keys($dialrules) as $key) {		//trim it		$dialrules[$key] = trim($dialrules[$key]);				// remove blanks		if ($dialrules[$key] == "") unset($dialrules[$key]);				// remove leading underscores (we do that on backend)		if ($dialrules[$key][0] == "_") $dialrules[$key] = substr($dialrules[$key],1);	}		// check for duplicates, and re-sequence	$dialrules = array_values(array_unique($dialrules));}//if submitting form, update databaseswitch ($action) {	case "addtrunk":		$trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $dialrules);				core_trunks_addDialRules($trunknum, $dialrules);		needreload();				$extdisplay = "OUT_".$trunknum; // make sure we're now editing the right trunk	break;	case "edittrunk":		core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register);				/* //DIALRULES		deleteTrunkRules($channelid);		addTrunkRules($channelid, $dialrules);		*/				// this can rewrite too, so edit is the same		core_trunks_addDialRules($trunknum, $dialrules);		needreload();	break;	case "deltrunk":			core_trunks_del($trunknum);				/* //DIALRULES		deleteTrunkRules($channelid);		*/		core_trunks_deleteDialRules($trunknum);		needreload();				$extdisplay = ''; // resets back to main screen	break;	case "populatenpanxx": 		if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) {			// first thing we do is grab the exch:			$ch = curl_init();			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);			curl_setopt($ch, CURLOPT_URL, "http://members.dandy.net/~czg/lca_prefix.php?npa=".$matches[1]."&nxx=".$matches[2]."&ocn=&pastdays=0&nextdays=0");			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; Amportal Local Trunks Configuration)");			$str = curl_exec($ch);			curl_close($ch);						if (preg_match("/exch=(\d+)/",$str, $matches)) {				$ch = curl_init();				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);				curl_setopt($ch, CURLOPT_URL, "http://members.dandy.net/~czg/lprefix.php?exch=".$matches[1]);				curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; Amportal Local Trunks Configuration)");				$str = curl_exec($ch);				curl_close($ch);								foreach (explode("\n", $str) as $line) {					if (preg_match("/^(\d{3});(\d{3})/", $line, $matches)) {						$dialrules[] = "1".$matches[1]."|".$matches[2]."XXXX";						//$localprefixes[] = "1".$matches[1].$matches[2];					}				}								// check for duplicates, and re-sequence				$dialrules = array_values(array_unique($dialrules));			} else {				$errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"];			}					} else {			// what a horrible error message... :p			$errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)");		}				if (isset($errormsg)) {			echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>";			unset($errormsg);		}	break;}		//get all rows from globals$sql = "SELECT * FROM globals";$globals = $db->getAll($sql);if(DB::IsError($globals)) {	die($globals->getMessage());}//create a set of variables that match the items in global[0]foreach ($globals as $global) {	${trim($global[0])} = htmlentities($global[1]);}?></div><div class="rnav">    <li><a id="<?php  echo ($extdisplay=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Trunk")?></a></li><?php //get existing trunk info$tresults = core_trunks_list();foreach ($tresults as $tresult) {    echo "<li><a id=\"".($extdisplay==$tresult[0] ? 'current':'')."\" href=\"config.php?display=".urlencode($display)."&extdisplay=".urlencode($tresult[0])."\" title=\"".urlencode($tresult[1])."\">"._("Trunk")." ".substr(ltrim($tresult[1],"AMP:"),0,15)."</a></li>";}?></div><div class="content"><?php if (!$tech && !$extdisplay) {?>	<h2><?php echo _("Add a Trunk")?></h2>	<a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&tech=ZAP"><?php echo _("Add ZAP Trunk")?></a><br><br>	<a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&tech=IAX2"><?php echo _("Add IAX2 Trunk")?></a><br><br>	<a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&tech=SIP"><?php echo _("Add SIP Trunk")?></a><br><br>	<a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&tech=ENUM"><?php echo _("Add ENUM Trunk")?></a><br><br>	<a href="<?php echo $_SERVER['PHP_SELF'].'?display='.urlencode($display); ?>&tech=CUSTOM"><?php echo _("Add Custom Trunk")?></a><br><br><?php } else {	if ($extdisplay) {		//list($trunk_tech, $trunk_name) = explode("/",$tname);		//if ($trunk_tech == "IAX2") $trunk_tech = "IAX"; // same thing		$tech = core_trunks_getTrunkTech($trunknum);		$outcid = ${"OUTCID_".$trunknum};		$maxchans = ${"OUTMAXCHANS_".$trunknum};		$dialoutprefix = ${"OUTPREFIX_".$trunknum};				if ($tech!="enum") {				if (!isset($channelid)) {				$channelid = core_trunks_getTrunkTrunkName($trunknum); 			}			if ($tech!="custom") {  // custom trunks will not have user/peer details in database table				// load from db				if (!isset($peerdetails)) {						$peerdetails = core_trunks_getTrunkPeerDetails($trunknum);				}					if (!isset($usercontext)) {						$usercontext = core_trunks_getTrunkUserContext($trunknum); 				}					if (!isset($userconfig)) {						$userconfig = core_trunks_getTrunkUserConfig($trunknum);				}									if (!isset($register)) {						$register = core_trunks_getTrunkRegister($trunknum);				}			}		}				/* //DIALRULES		if (!isset($_REQUEST["dialrules"])) { // we check REQUEST because dialrules() is always an array			$dialrules = getTrunkDialRules($trunknum);		}		*/				if (count($dialrules) == 0) {			if ($temp = core_trunks_getDialRules($trunknum)) {				foreach ($temp as $key=>$val) {					// extract all ruleXX keys					if (preg_match("/^rule\d+$/",$key)) {						$dialrules[] = $val;					}				}			}			unset($temp);		}				echo "<h2>".sprintf(_("Edit %s Trunk"),strtoupper($tech))."</h2>";?>		<p><a title="<?php echo $channelid ?>" href="config.php?display=<?php echo urlencode($display) ?>&extdisplay=<?php echo urlencode($extdisplay) ?>&action=deltrunk"><?php echo _("Delete Trunk")?> <?php  echo substr($channelid,0,20); ?></a></p><?php 		// find which routes use this trunk		$routes = core_trunks_gettrunkroutes($trunknum);		$num_routes = count($routes);		if ($num_routes > 0) {			echo "<a href=# class=\"info\">"._("In use by")." ".$num_routes." ".($num_routes == 1 ? _("route") : _("routes"))."<span>";			foreach($routes as $route=>$priority) {				echo _("Route")." <b>".$route."</b>: "._("Sequence")." <b>".$priority."</b><br>";			}			echo "</span></a>";		} else {			echo "<b>"._("WARNING:")."</b> <a href=# class=\"info\">"._("This trunk is not used by any routes!")."<span>";			echo _("This trunk will not be able to be used for outbound calls until a route is setup that uses it. Click on <b>Outbound Routes</b> to setup routing.");			echo "</span></a>";		}		echo "<br><br>";	} else {		// set defaults		$outcid = "";		$maxchans = "";		$dialoutprefix = "";				if ($tech == "zap") {			$channelid = "g0";		} else {			$channelid = "";		}				// only for iax2/sip		$peerdetails = "host=***provider ip address***\nusername=***userid***\nsecret=***password***\ntype=peer";		$usercontext = "";		$userconfig = "secret=***password***\ntype=user\ncontext=from-trunk";		$register = "";				$localpattern = "NXXXXXX";		$lddialprefix = "1";		$areacode = "";			echo "<h2>".sprintf("Add %s Trunk",strtoupper($tech))."</h2>";	} ?>			<form name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');">			<input type="hidden" name="display" value="<?php echo $display?>"/>			<input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>			<input type="hidden" name="action" value=""/>			<input type="hidden" name="tech" value="<?php echo $tech?>"/>			<table>			<tr>				<td colspan="2">					<h4><?php echo _("General Settings")?></h4>				</td>			</tr>			<tr>				<td>					<a href=# class="info"><?php echo _("Outbound Caller ID")?><span><br><?php echo _("Caller ID for calls placed out on this trunk<br><br>Format: <b>\"caller name\" &lt;#######&gt;</b>. You can also use the magic string 'hidden' to hide the CallerID sent out over ISDN lines ONLY (E1/T1/J1/BRI)")?><br><br></span></a>: 				</td><td>					<input type="text" size="20" name="outcid" value="<?php echo $outcid;?>"/>				</td>			</tr>			<tr>				<td>					<a href=# class="info"><?php echo _("Maximum channels")?><span><?php echo _("Controls the maximum number of channels (simultaneous calls) that can be used on this trunk, including both incoming and outgoing calls. Leave blank to specify no maximum.")?></span></a>: 				</td><td>					<input type="text" size="3" name="maxchans" value="<?php echo htmlspecialchars($maxchans); ?>"/>				</td>			</tr>			<tr>				<td colspan="2">					<br><h4><?php echo _("Outgoing Dial Rules")?></h4>				</td>			</tr>			<tr>				<td valign="top">					<a href=# class="info"><?php echo _("Dial Rules")?><span><?php echo _("A Dial Rule controls how calls will be dialed on this trunk. It can be used to add or remove prefixes. Numbers that don't match any patterns defined here will be dialed as-is. Note that a pattern without a + or | (to add or remove a prefix) is useless.")?><br><br><b><?php echo _("Rules:")?></b><br>	<strong>X</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br>	<strong>Z</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br>	<strong>N</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br>	<strong>[1237-9]</strong>&nbsp;   <?php echo _("matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)")?><br>	<strong>.</strong>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more characters (not allowed before a | or +)")?><br>	<strong>|</strong>&nbsp;&nbsp;&nbsp; <?php echo _("removes a dialing prefix from the number (for example, 613|NXXXXXX would match when some dialed \"6135551234\" but would only pass \"5551234\" to the trunk)")?>	<strong>+</strong>&nbsp;&nbsp;&nbsp; <?php echo _("adds a dialing prefix from the number (for example, 1613+NXXXXXX would match when some dialed \"5551234\" and would pass \"16135551234\" to the trunk)")?>					</span></a>:				</td><td valign="top">&nbsp;					<textarea id="dialrules" cols="20" rows="<?php  $rows = count($dialrules)+1; echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) ); ?>" name="dialrules"><?php echo implode("\n",$dialrules);?></textarea><br>										<input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>" />				</td>			</tr>			<tr>				<td>					<a href=# class="info"><?php echo _("Dial rules wizards")?><span>					<strong><?php echo _("Always add prefix to local numbers")?></strong> <?php echo _("is useful for VoIP trunks, where if a number is dialed as \"5551234\", it can be converted to \"16135551234\".")?><br>					<strong><?php echo _("Remove prefix from local numbers")?></strong> <?php echo _("is useful for ZAP trunks, where if a local number is dialed as \"16135551234\", it can be converted to \"555-1234\".")?><br>					<strong><?php echo _("Lookup and remove local prefixes")?></strong> <?php echo _("is the same as Remove prefix from local numbers, but uses the database at http://members.dandy.net/~czg/search.html to find your local calling area (NA-only)")?><br>					</span></a>:				</td><td valign="top">&nbsp;&nbsp;<select id="autopop" name="autopop" onChange="changeAutoPop(); ">						<option value="" SELECTED><?php echo _("(pick one)")?></option>						<option value="always"><?php echo _("Always add prefix to local numbers")?></option>						<option value="remove"><?php echo _("Remove prefix from local numbers")?></option>						<option value="lookup"><?php echo _("Lookup and remove local prefixes")?></option>					</select>				</td>			</tr>			<input id="npanxx" name="npanxx" type="hidden" />			<script language="javascript">						function populateLookup() {<?php 	if (function_exists("curl_init")) { // curl is installed?>				

⌨️ 快捷键说明

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