<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<05>")) {	//没有权限
		ob_clean();
		header("Location: accesserror.html");
		exit;
	}
?>

<?php
	$gpid=$_REQUEST["gpid"];
	$gpname=$_REQUEST["gpname"];
	if ($gpid=="" || $gpname=="") {
		echo("非法操作！");
		exit;
	}
	$bHaveAcl=$_REQUEST["haveacl"];
	$bMode=$_REQUEST["mode"];
	$bIcmp=$_REQUEST["icmp"];
	$bUdp=$_REQUEST["udp"];
	$bIgmp=$_REQUEST["igmp"];
	$bCheckPort=$_REQUEST["checkport"];
	if ($bIcmp!="y") {
		$bIcmp="n";
	}
	if ($bUdp!="y") {
		$bUdp="n";
	}
	if ($bIgmp!="y") {
		$bIgmp="n";
	}
	if ($bCheckPort!="y") {
		$bCheckPort="n";
	}
	if ($bMode!="0" && $bMode!="1" && $bMode!="2") {
		$bMode="0";
	}
	$ips=$_REQUEST["ips"];
	$ports=$_REQUEST["ports"];
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	mysql_query( "delete from useracl1 where userid='gp_".$gpid."'",$db );
	mysql_query( "delete from useracl2 where userid='gp_".$gpid."'",$db );
	mysql_query( "delete from useracl3 where userid='gp_".$gpid."'",$db );
	if ($bHaveAcl=="y") {
		mysql_query( "insert into useracl1 values('gp_".$gpid."','".$bMode."','".$bIcmp."','".$bUdp."','".$bIgmp."','".$bCheckPort."')",$db );
		$newline=chr(13).chr(10);	//回车换行符
		if ($bMode!="0" && $ips!="") {
			$m=1;
			$n=strpos($ips,$newline);
			while (!($n===FALSE)) {
				if ($n>0) {		//不是开头
					$str=trim(substr($ips,0,$n));
					if (strlen($str)>0 && strlen($str)<=50) {
						mysql_query( "insert into useracl2 values('gp_".$gpid."','".$str."',".strval($m).")",$db );
						$m=$m+1;
					}
				}
				$ips=substr($ips,$n+2);
				$n=strpos($ips,$newline);
			}
			if ($ips!="") {		//最后一项
				$str=trim($ips);
				if (strlen($str)>0 && strlen($str)<=50) {
					mysql_query( "insert into useracl2 values('gp_".$gpid."','".$str."',".strval($m).")",$db );
				}
			}
		}
		if ($bCheckPort=="y" && $ports!="") {
			$m=1;
			$n=strpos($ports,$newline);
			while (!($n===FALSE)) {
				if ($n>0) {
					$str=trim(substr($ports,0,$n));
					if (intval($str)>0 && intval($str)<65000) {
						mysql_query( "insert into useracl3 values('gp_".$gpid."',".$str.",".strval($m).")",$db );
						$m=$m+1;
					}
				}
				$ports=substr($ports,$n+2);
				$n=strpos($ports,$newline);
			}
			if ($ports!="") {		//最后一项
				$str=trim($ports);
				if (intval($str)>0 && intval($str)<65000) {
					mysql_query( "insert into useracl3 values('gp_".$gpid."',".$str.",".strval($m).")",$db );
				}
			}
		}
	}

	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','修改组上网范围，组ID：".$gpid."')",$db );
	mysql_close($db);
?>

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>组上网范围管理</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>组上网范围管理</b></font></p>
<hr color="#999966">

<p align="center">组别“<?php echo $gpname; ?>”的上网范围设置保存成功！</p>

<hr>
<p align="center">SIP企业上网管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>
</body>

</html>
