#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html;charset=gb2312
Cache-Control: no-cache

"
echo -n "";
. ../../common/common.sh
myself="/cgi-bin/App/pktrule/`basename $0`"
if [ "${PALANG}" = "en" ]; then 
	LANG_001="Policy ID"
	LANG_002="Valid time period"
	LANG_003="All"
	LANG_004="Note"
	LANG_005="Max. 60 English characters"
	LANG_006="Condition"
	LANG_007="Source Interface"
	LANG_008="PPPoE Servers"
	LANG_009="Any"
	LANG_0010="10 or 10-20, 0, 0-0 and empty means any VLAN."
	LANG_0011="10 or 10-20, 0, 0-0 and empty means any TTL"
	LANG_0012="Source IP"
	LANG_0013="IP Group"
	LANG_0014="Source Port"
	LANG_0015="80 or 8000-8100, 0 means any port"
	LANG_0016="Destination IP"
	LANG_0017="Destination Port"
	LANG_0018="Protocol"
	LANG_0019="Application"
	LANG_0020="Select"
	LANG_0021="Standard edition, doesnt support application routing"
	LANG_0022="UserType"
	LANG_0023="Ippxy"
	LANG_0024="Nonippxy"
	LANG_0025="Action"
	LANG_0026="Route"
	LANG_0027="Null"
	LANG_0028="Next-Hop"
	LANG_0029="If null, traffic will be routed to NAT interface configured in previous step"
	LANG_0030="Submit"
	LANG_0031="Cancel"
	LANG_0032="Policy->Route->Add"
	LANG_0033="IP Pool"
	LANG_0034="DNAT-IP"
	LANG_0035="NAT"
	LANG_0036="If configured, the destination IP will be changed to designated IP"
	LANG_0037="Rule ordinal must be an integer between 1 and 65535!"
	LANG_0038="Please enter the correct IP address in the format of x.x.x.x/n"
	LANG_0039="Intranet port input error"
	LANG_0040="Please enter the correct IP segment in the format of x.x.x.x-y.y.y.y"
	LANG_0041="Source port input error"
	LANG_0042="Please input 0 ~ 63!"
	LANG_0043="Please select the next hop line!"
	LANG_0044="Please enter the correct DNAT address"
	LANG_0044="Invalid return value"
	LANG_0045="If empty or 0.0.0.0, the gateway of the destination address or line is used"
	LANG_0046="Error"
	LANG_0047="Success"
	LANG_0048="Add routing policy"
	LANG_0049="The number range is 1-65535, and the rule with small number is prioritized"
fi

echo -n "
<link href=\"/img/select2.min.css\" rel=\"stylesheet\" />
<script type=\"text/javascript\" src=\"/img/select2.min.js\"></script>
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeAddRule(frm)
{
	var rngs;
	var polno   = document.getElementsByName(\"polno\")[0];
	var srctype  = document.getElementsByName(\"srctype\")[0];
	var dsttype = document.getElementsByName(\"dsttype\")[0];
	var srcipnet = document.getElementsByName(\"srcipnet\")[0];
	var srciprng = document.getElementsByName(\"srciprng\")[0];
	var dstipnet= document.getElementsByName(\"dstipnet\")[0];
	var dstiprng= document.getElementsByName(\"dstiprng\")[0];
	var srcport  = document.getElementsByName(\"srcport\")[0];
	var dstport = document.getElementsByName(\"dstport\")[0];
	var apid    = document.getElementsByName(\"appid\")[0];
	var dscp    = document.getElementsByName(\"dscp\")[0];
	var nexthop = document.getElementsByName(\"nat_nexthop\")[0];
	var vlan    = document.getElementsByName(\"vlan\")[0];
	var ttl     = document.getElementsByName(\"ttl\")[0];
	var desc    = document.getElementsByName(\"desc\")[0];
	
	var en_desc = document.getElementsByName(\"en_desc\")[0];
	var newdstip = document.getElementsByName(\"newdstip\")[0];
	polno.value = TrimAll(polno.value);
	if (!IsDigitIn(polno.value, 1, 65535)) {
		alert(\"${LANG_0037:=űǽ165535֮һ!}\");
		polno.select();
		return false;
	}
	vlan.value = TrimAll(vlan.value);
	srcipnet.value = TrimAll(srcipnet.value);
	srciprng.value = TrimAll(srciprng.value);
	if (srctype.value == \"net\") {
		if (!IsIPAddr(srcipnet.value)) {
			alert(\"${LANG_0038:=ȷIPַʽΪx.x.x.x/n}\");
			srcipnet.select();
			return false;
		}
	}
	else
	if (srctype.value == \"range\") {
		rngs = srciprng.value.split(\"-\");
		if (rngs.length != 2 || !IsIPAddr(rngs[0]) || !IsIPAddr(rngs[1])) {
			alert(\"${LANG_0040:=ȷIPΣʽΪx.x.x.x-y.y.y.y}\");
			srciprng.select();
			return false;
		}
	}
	srcport.value = TrimAll(srcport.value);
	if (srcport.value == \"\") srcport.value = \"0\";
	rngs = srcport.value.split(\"-\");
	if (rngs.length == 2) {
		if (!IsDigitIn(rngs[0], 0, 65535) || !IsDigitIn(rngs[1], 0, 65535)) {
			alert(\"${LANG_0039:=˿!}\");
			srcport.select();
			return false;
		}
	}
	else {
		if (!IsDigitIn(srcport.value, 0, 65535)) {
			alert(\"${LANG_0039:=˿!}\");
			srcport.select();
			return false;
		}
	}
	dstipnet.value = TrimAll(dstipnet.value);
	dstiprng.value = TrimAll(dstiprng.value);
	if (dsttype.value == \"net\") {
		if (!IsIPAddr(dstipnet.value)) {
			alert(\"${LANG_0038:=ȷIPַʽΪx.x.x.x/n}\");
			dstipnet.select();
			return false;
		}
	}
	else
	if (dsttype.value == \"range\") {
		rngs = dstiprng.value.split(\"-\");
		if (rngs.length != 2 || !IsIPAddr(rngs[0]) || !IsIPAddr(rngs[1])) {
			alert(\"${LANG_0040:=ȷIPΣʽΪx.x.x.x-y.y.y.y}\");
			dstiprng.select();
			return false;
		}
	}
	dstport.value = TrimAll(dstport.value);
	if (dstport.value == \"\") dstport.value = \"0\";
	rngs = dstport.value.split(\"-\");
	if (rngs.length == 2) {
		if (!IsDigitIn(rngs[0], 0, 65535) || !IsDigitIn(rngs[1], 0, 65535)) {
			alert(\"${LANG_0041:=˿!}\");
			dstport.select();
			return false;
		}
	}
	else {
		if (!IsDigitIn(dstport.value, 0, 65535)) {
			alert(\"${LANG_0041:=˿!}\");
			dstport.select();
			return false;
		}
	}
		
	dscp.value = TrimAll(dscp.value);
	if (dscp.value == \"\") dscp.value = \"0\";
	if (!IsDigitIn(dscp.value, 0, 63)) {
		alert(\"${LANG_0042:=0~63!}\");
		dscp.select();
		return false;
	}
	ttl.value = TrimAll(ttl.value);
	newdstip.value = TrimAll(newdstip.value);
	if (newdstip.value != \"\" && !IsIPAddr(newdstip.value)) {
		alert(\"${LANG_0044:=ȷDNATַ!}\");
		newdstip.select();
		return false;
	}
	
	"; if [ "${PALANG}" = "en" ]; then 
echo -n "
		en_desc.value = encodeURIComponent(desc.value);
	"; else 
echo -n "
		desc.value = TrimAll(desc.value);
	"; fi 
echo -n "
	
	return true;
}
function onCancel()
{
	window.location.href = \"/cgi-bin/App/pktrule/webmain\";
}
function onSrctypeChanged(obj) 
{
	var net = document.getElementsByName(\"srcipnet\")[0];
	var rng = document.getElementsByName(\"srciprng\")[0];
	var tbl = document.getElementsByName(\"srciptbl\")[0];
	if (obj.value == \"any\") {
		net.style.display = \"none\";
		rng.style.display = \"none\";
		tbl.style.display = \"none\";
		\$(\".select2_srciptbl\").next().css(\"display\", \"none\");
	}
	else
	if (obj.value == \"net\") {
		net.style.display = \"block\";
		rng.style.display = \"none\";
		tbl.style.display = \"none\";
		\$(\".select2_srciptbl\").next().css(\"display\", \"none\");
	}
	else
	if (obj.value == \"range\") {
		net.style.display = \"none\";
		rng.style.display = \"block\";
		tbl.style.display = \"none\";
		\$(\".select2_srciptbl\").next().css(\"display\", \"none\");
	}
	else
	if (obj.value == \"table\") {
		net.style.display = \"none\";
		rng.style.display = \"none\";
		tbl.style.display = \"block\";
		\$(\".select2_srciptbl\").next().css(\"display\", \"block\");
	}
}
function onDsttypeChanged(obj) 
{
	var net = document.getElementsByName(\"dstipnet\")[0];
	var rng = document.getElementsByName(\"dstiprng\")[0];
	var tbl = document.getElementsByName(\"dstiptbl\")[0];
	if (obj.value == \"any\") {
		net.style.display = \"none\";
		rng.style.display = \"none\";
		tbl.style.display = \"none\";
		\$(\".select2_dstiptbl\").next().css(\"display\", \"none\");
	}
	else
	if (obj.value == \"net\") {
		net.style.display = \"block\";
		rng.style.display = \"none\";
		tbl.style.display = \"none\";
		\$(\".select2_dstiptbl\").next().css(\"display\", \"none\");
	}
	else
	if (obj.value == \"range\") {
		net.style.display = \"none\";
		rng.style.display = \"block\";
		tbl.style.display = \"none\";
		\$(\".select2_dstiptbl\").next().css(\"display\", \"none\");
	}
	else
	if (obj.value == \"table\") {
		net.style.display = \"none\";
		rng.style.display = \"none\";
		tbl.style.display = \"block\";
		\$(\".select2_dstiptbl\").next().css(\"display\", \"block\");
	}
}
function onActionChanged(obj)
{
	var nattbl = document.getElementById(\"row_route\");
	var routetbl = document.getElementById(\"row_iwan\");
	if (obj.value == \"route\") {
		nattbl.style.display = \"block\";
		routetbl.style.display = \"none\";
	}
	else {
		nattbl.style.display = \"none\";
		routetbl.style.display = \"block\";
	}
}
function onLoad()
{
	var action = document.getElementsByName(\"action\")[0];
	onActionChanged(action);
	\$(\".select2_srciptbl\").select2();
	\$(\".select2_dstiptbl\").select2();
	\$(\".select2_srciptbl\").next().css(\"display\", \"none\");
	\$(\".select2_dstiptbl\").next().css(\"display\", \"none\");
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "/cgi-bin/App/pktrule/webmain"
	cmdargs="id=${CGI_polno}"
	
	[ "${CGI_inifname}" != "any" ] && cmdargs="${cmdargs} inif=${CGI_inifname}"
	case "${CGI_srctype}" in
	"any")
		CGI_srcip="any"
		;;
	"net")
		CGI_srcip="${CGI_srcipnet}"
		;;
	"range")
		CGI_srcip="${CGI_srciprng}"
		;;
	"table")
		CGI_srcip="${CGI_srciptbl}"
		;;
	esac
	if [ "${CGI_srcport}" != "" -a "${CGI_srcport}" != "0" ]; then
		CGI_srcip="${CGI_srcip}:${CGI_srcport}"
	fi
	cmdargs="${cmdargs} src=${CGI_srcip}"
	case "${CGI_dsttype}" in
	"any")
		CGI_dstip="any"
		;;
	"net")
		CGI_dstip="${CGI_dstipnet}"
		;;
	"range")
		CGI_dstip="${CGI_dstiprng}"
		;;
	"table")
		CGI_dstip="${CGI_dstiptbl}"
		;;
	esac
	if [ "${CGI_dstport}" != "" -a "${CGI_dstport}" != "0" ]; then
		CGI_dstip="${CGI_dstip}:${CGI_dstport}"
	fi
	cmdargs="${cmdargs} dst=${CGI_dstip}"
	if [ "${CGI_dscp}" != "" -a "${CGI_dscp}" != "0" ]; then
		cmdargs="${cmdargs} dscp=${CGI_dscp}"
	fi
	[ "${CGI_proto}" != "any" ] && cmdargs="${cmdargs} proto=${CGI_proto}"
	cmdargs="${cmdargs} app=${CGI_appid}"
	if [ "${CGI_action}" = "route" ]; then
		cmdargs="${cmdargs} action=${CGI_action}-${CGI_proxy}"
	else
		cmdargs="${cmdargs} action=${CGI_action}-${CGI_sriwan}"
	fi
	[ "${CGI_nat_nexthop}" != "" ] && cmdargs="${cmdargs} nexthop=${CGI_nat_nexthop}"
	if [ "${CGI_vlan}" != "" -a "${CGI_vlan}" != "0" -a "${CGI_vlan}" != "0-0" ]; then
		cmdargs="${cmdargs} vlan=${CGI_vlan}"
	fi
	if [ "${CGI_schtime}" != "" -a "${CGI_schtime}" != "0" ]; then
		cmdargs="${cmdargs} schtime=${CGI_schtime}"
	fi
	[ "${CGI_ttl}" != "" ] && cmdargs="${cmdargs} ttl=${CGI_ttl}"
	[ "${CGI_usrtype}" != "any" -a "${CGI_usrtype}" != "" ] && cmdargs="${cmdargs} usrtype=${CGI_usrtype}"
	[ "${CGI_pool}" != "0" -a "${CGI_pool}" != "" ] && cmdargs="${cmdargs} pool=${CGI_pool}"
	
	if [ "${CGI_desc}" = "" ]; then
		cmdargs="${cmdargs} desc=NULL"
	else
		[ "${PALANG}" = "en" ] && CGI_desc="${CGI_en_desc}"
		cmdargs="${cmdargs} desc=${CGI_desc}"
	fi
	[ "${CGI_newdstip}" != "" ] && cmdargs="${cmdargs} newdstip=${CGI_newdstip}"
	errmsg=`${FLOWEYE} route add ${cmdargs} group=pkt`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "${LANG_0046:=ִ}:${errmsg}"
	else
		afm_dialog_msg "${LANG_0047:=ɹ!}"
		afm_load_page 0 "/cgi-bin/App/pktrule/webmain"
		WEB_LOGGER "${LANG_0048:=·ɲ}" "id=${CGI_polno}"
		sleep .500
		exit 0
	fi
else
	[ "${CGI_dscp}" = "" ] && CGI_dscp=0
	[ "${CGI_srcport}" = "" ] && CGI_srcport=0
	[ "${CGI_dstport}" = "" ] && CGI_dstport=0
	[ "${CGI_nat_nexthop}" = "" ] && CGI_nat_nexthop="_NULL_"
	[ "${CGI_route_nexthop}" = "" ] && CGI_route_nexthop="0.0.0.0"
	[ "${CGI_vlan}" = "0-0" -o "${CGI_vlan}" = "0" ] && CGI_vlan=""
	[ "${CGI_ttl}" = "0-255" ] && CGI_ttl=""
	[ "${CGI_schtime}" = "" ] && CGI_schtime=0
	[ "${CGI_action}" = "" ] && CGI_action="nat"
	[ "${CGI_pool}" = "" ] && CGI_pool=0
	if [ "${PALANG}" = "en" ]; then
		CGI_desc=`echo ${CGI_desc} | sed -r 's/\%20/ /g'`
	fi
fi

echo -n "
<body onload=\"onLoad()\">
<script type=\"text/javascript\" src=\"/img/wz_tooltip.js\"></script>
<span id=\"hlpno\" style=\"display:none\">${LANG_0049:=ŷΧΪ1~65535,СĹƥ}</span>
";
cgi_show_title "${LANG_0032:=->ת->Ӳ}"
tblexists=`${FLOWEYE} table list`

echo -n "
<br>
<form method=post onsubmit=\"return beforeAddRule(this)\" action=\"${myself}\">
<table width=950 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=80></td>
        <td width=120 align=left>${LANG_001:=Աʶ}</td>
	<td width=* align=left>
		<input align=right type=text name=polno style=\"width:160\" value=\"${CGI_polno}\" />&nbsp;
		<a style=\"color:#0000ff\" onmouseover=\"TagToTip('hlpno')\" onmouseout=\"UnTip()\">(1~65535)</a>
	</td>
</tr>
"; if [ "${CGI_from}" != "" ]; then 
echo -n "
<tr id=row1>
	<td></td>
        <td align=left>${LANG_002:=Чʱ}</td>
	<td align=left>
		<select name=schtime style=\"width:160\" value=\"${CGI_schtime}\">
		";
			if [ "${CGI_schtime}" = "0" ]; then
				echo "<option value=0 selected>${LANG_003:=ʱ}</option>"
			else
				echo "<option value=0>${LANG_003:=ʱ}</option>"
			fi
			${FLOWEYE} rtptime list | while read id name theothers
			do
				if [ "${CGI_schtime}" = "${id}" ]; then
					echo "<option value=${id} selected>${name}</option>"
				else
					echo "<option value=${id}>${name}</option>"
				fi
			done
		
echo -n "
		</select>
	</td>
</tr>
"; fi 
echo -n "
<tr id=row1>
	<td width=80></td>
        <td width=120 align=left>${LANG_004:=Աע}</td>
	<td width=* align=left>
		<input align=right type=text name=desc style=\"width:240\" value=\"${CGI_desc}\" />&nbsp;
		<input align=right type=hidden name=en_desc style=\"width:240\" value=\"${CGI_desc}\" />&nbsp;
		(${LANG_005:=30ֻ60Ӣַ})
	</td>
</tr>
</table>
<br>
<table style=\"width:950; border-bottom:1px #787882 solid; color:#000000\">
<tr><td align=left style=\"font-size:11px\"><b>${LANG_006:=ƥ}</b></td></tr>
</table>
<br>
<table width=950 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=80></td>
        <td width=120 align=left>${LANG_007:=Դӿ}</td>
	<td width=160 align=left>
		<select name=inifname style=\"width:160\" value=\"${CGI_iniftype}.${CGI_inif}\" class=\"select2_ifname\">
		";
			if [ "${CGI_inif}" = "any" ]; then
				echo "<option value=any selected>${LANG_009:=}</option>"
			else
				echo "<option value=any>${LANG_009:=}</option>"
			fi
			${FLOWEYE} nat listproxy type=lan | while read type id name theothers
			do
				if [ "${CGI_iniftype}" = "proxy" -a "${CGI_inif}" = "${name}" ]; then
					echo "<option value=\"proxy.${name}\" selected>${name}</option>"
				else
					echo "<option value=\"proxy.${name}\">${name}</option>"
				fi
			done
			${FLOWEYE} nat listproxy type=wan | while read type id name theothers
			do
				if [ "${CGI_iniftype}" = "proxy" -a "${CGI_inif}" = "${name}" ]; then
					echo "<option value=\"proxy.${name}\" selected>${name}</option>"
				else
					echo "<option value=\"proxy.${name}\">${name}</option>"
				fi
			done
			${FLOWEYE} if list | while read ifname ifmode ifzone theothers
			do
				[ "${ifzone}" != "inside" ] && continue
				if [ "${CGI_inif}" = "${ifname}"  -a "${CGI_iniftype}" = "if" ]; then
					echo "<option value=\"if.${ifname}\" selected>${ifname}</option>"
				else
					echo "<option value=\"if.${ifname}\">${ifname}</option>"
				fi
			done
			if [ "${CGI_iniftype}" = "posvr" -a "${CGI_inif}" = "all" ]; then
				echo "<option value=allposvr selected>${LANG_008:=PPPOE}</option>"
			else
				echo "<option value=allposvr>${LANG_008:=PPPOE}</option>"
			fi
		
echo -n "
		</select>
	</td>
	<td width=* align=left></td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0033:=û/ַ}</td>
        <td align=left>
		<select name=pool style=\"width:160\" value=\"${CGI_pool}\">
		";
		if [ "${CGI_pool}" = "0" ]; then
			echo "<option value=0 selected>${LANG_009:=}</option>"
		else
			echo "<option value=0>${LANG_009:=}</option>"
		fi
			
		${FLOWEYE} pppoeippool list | while read pid pname start end theothers
		do
			if [ "${CGI_pool}" = "${pid}" ]; then
				echo "<option value=\"${pid}\" selected>${pname}</option>"
			else
				echo "<option value=\"${pid}\">${pname}</option>"
			fi
		done
		
echo -n "
		</select>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>VLAN</td>
        <td align=left><input type=text name=vlan value=\"${CGI_vlan}\" style=\"width:160\"></input></td>
	<td width=* align=left><a style=\"color:#0000ff\">(${LANG_0010:=1010-2010-20/10-20,00-0ʾVLAN})</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>TTL</td>
        <td align=left><input type=text name=ttl value=\"${CGI_ttl}\" style=\"width:160\"></input></td>
	<td width=* align=left><a style=\"color:#0000ff\">(${LANG_0011:=1010-20,ʾTTL})</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0012:=Դַ}</td>
        <td align=left>
		<select name=srctype style=\"width:160\" value=\"any\" onchange=\"onSrctypeChanged(this)\">
			<option value=\"any\" selected>${LANG_009:=ַ}</option>
			<option value=\"net\">xxx.xxx.xxx.xxx/nn</option>
			<option value=\"range\">n.n.n.n-m.m.m.m</option>
		";
			if [ "${tblexists}" != "" ]; then
				echo "<option value=\"table\">${LANG_0013:=IPȺ}</option>"
			fi
		
echo -n "
		</select>
	</td>
	<td width=* align=left>
		<input type=text name=srcipnet style=\"width:210px;display:none\"></input>
		<input type=text name=srciprng style=\"width:210px;display:none\"></input>
		<select name=srciptbl style=\"width:210px;display:none\" class=\"select2_srciptbl\">
		";
			${FLOWEYE} table list | while read tblid tblname
			do
				echo "<option value=\"${tblid}\">${tblname}</option>"
			done
		
echo -n "
		</select>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0014:=Դ˿}</td>
        <td><input type=text name=srcport value=\"${CGI_srcport}\" style=\"width:160\"></input></td>
	<td width=* align=left><a style=\"color:#0000ff\">(${LANG_0015:=808000-81000ʾ˿})</a></td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0016:=Ŀַ}</td>
        <td align=left>
		<select name=dsttype style=\"width:160\" value=\"any\" onchange=\"onDsttypeChanged(this)\">
			<option value=\"any\" selected>${LANG_009:=}</option>
			<option value=\"net\">xxx.xxx.xxx.xxx/nn</option>
			<option value=\"range\">n.n.n.n-m.m.m.m</option>
		";
			if [ "${tblexists}" != "" ]; then
				echo "<option value=\"table\">${LANG_0013:=IPȺ}</option>"
			fi
		
echo -n "
		</select>
	</td>
	<td width=* align=left>
		<input type=text name=dstipnet style=\"width:210px;display:none\"></input>
		<input type=text name=dstiprng style=\"width:210px;display:none\"></input>
		<select name=dstiptbl style=\"width:210px;display:none\" class=\"select2_dstiptbl\">
		";
			${FLOWEYE} table list | while read tblid tblname
			do
				echo "<option value=\"${tblid}\">${tblname}</option>"
			done
		
echo -n "
		</select>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0017:=˿}</td>
        <td align=left><input type=text name=dstport value=\"${CGI_dstport}\" style=\"width:160\"></input></td>
	<td width=* align=left><a style=\"color:#0000ff\">(${LANG_0015:=808000-81000ʾ˿})</a></td>
</tr>
";
[ "${CGI_appid}" = "" ] && CGI_appid="any"
if [ "${PALANG}" = "en" ]; then
	appname="any"
else
	appname=`${FLOWEYE} app name ${CGI_appid}`
fi

echo -n "
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0018:=Э}</td>
        <td><select name=proto value=\"${CGI_proto}\" style=\"width:160\">
		";
			case "${CGI_proto}" in
			"tcp|TCP")
				echo "<option value=any>${LANG_009:=}</option>"
				echo "<option value=TCP selected>TCP</option>"
				echo "<option value=UDP>UDP</option>"
				echo "<option value=ICMP>ICMP</option>"
				;;
			"udp|UDP")
				echo "<option value=any>${LANG_009:=}</option>"
				echo "<option value=TCP>TCP</option>"
				echo "<option value=UDP selected>UDP</option>"
				echo "<option value=ICMP>ICMP</option>"
				;;
			"icmp|ICMP")
				echo "<option value=any>${LANG_009:=}</option>"
				echo "<option value=TCP>TCP</option>"
				echo "<option value=UDP>UDP</option>"
				echo "<option value=ICMP selected>ICMP</option>"
				;;
			*)
				echo "<option value=any selected>${LANG_009:=}</option>"
				echo "<option value=TCP>TCP</option>"
				echo "<option value=UDP>UDP</option>"
				echo "<option value=ICMP>ICMP</option>"
				;;
			esac
		
echo -n "
		</select>
	</td>
        <td width=* align=left></td>
</tr>
"; if [ ${JOS_RELEASE} -ne 0 ]; then 
echo -n "
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0019:=ӦЭ}</td>
        <td align=left>
		<input type=hidden name=appid value=\"${CGI_appid}\"></input>
		<input type=text name=appname value=\"${appname}\" disabled style=\"width:160\">
	</td>
	<td width=* class=cssTDArial align=left>
	  <input type=button name=tmp value=\"${LANG_0020:=ѡӦ}...\" style=\"width:80px\" onclick=\"selectApp('${CGI_appid}')\"></input>
	</td>
</tr>
"; else 
echo -n "
<tr id=row1>
	<td></td>
        <td align=left>${LANG_0019:=ӦЭ}</td>
        <td align=left>
		<input type=hidden name=appid value=\"any\"></input>
		<input type=text name=appname value=\"${LANG_009:=}\" disabled style=\"width:160\">
	</td>
	<td width=* class=cssTDArial style=\"color:#ff0000\" align=left>${LANG_0021:=Ǳ׼棬֧Ӧ·}</td>
</tr>
"; fi 
echo -n "
<tr id=row1>
	<td></td>
        <td align=left>DSCP</td>
        <td align=left><input type=text name=dscp value=\"${CGI_dscp}\" style=\"width:160\"></input></td>
	<td width=* align=left></td>
</tr>
</table>
<br>
<table style=\"width:950; border-bottom:1px #787882 solid; color:#000000\">
<tr><td align=left style=\"font-size:11px\"><b>${LANG_0025:=ִж}</b></td></tr>
</table>
<br>
<table width=950 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=80></td>
        <td width=120 align=left>${LANG_0025:=ִж}</td>
        <td width=160>
		<select name=action value=\"${CGI_action}\" style=\"width:160px\" onchange=\"onActionChanged(this)\">
		";
			if [ "${CGI_action}" = "nat" ]; then
				echo "<option value=\"route\" selected>ת</option>"
				echo "<option value=\"iwansr\">iWANSR</option>"
			else
				echo "<option value=\"route\">ת</option>"
				echo "<option value=\"iwansr\" selected>iWANSR</option>"
			fi
		
echo -n "
		</select>
	</td>
        <td width=* align=left></td>
</tr>
</table>
<table id=\"row_route\" style=\"font:14px;width:950px\" border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=80></td>
        <td width=120 align=left>${LANG_0035:=ת·}</td>
        <td width=160>
		<select name=proxy value=\"${CGI_nat_proxy}\" style=\"width:160px\" class=\"select2_ifname\">
		";
			${FLOWEYE} nat listproxy type=wan | while read type id name theothers
			do
				if [ "${CGI_nat_proxy}" = "${name}" ]; then
					echo "<option value=\"${name}\" selected>${name}</option>"
				else
					echo "<option value=\"${name}\">${name}</option>"
				fi
			done
		
echo -n "
		</select>
	</td>
	<td width=* align=left></td>
</tr>
</table>
<table id=\"row_iwan\" style=\"font:14px;width:950px;display:none;\" border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=80></td>
        <td width=120 align=left>iWAN·</td>
        <td width=160>
		<select name=sriwan value=\"${CGI_nat_proxy}\" style=\"width:160px\" class=\"select2_ifname\">
		";
			${FLOWEYE} nat listproxy type=iwan | while read type id name theothers
			do
				if [ "${CGI_nat_proxy}" = "${name}" ]; then
					echo "<option value=\"${name}\" selected>${name}</option>"
				else
					echo "<option value=\"${name}\">${name}</option>"
				fi
			done
		
echo -n "
		</select>
	</td>
        <td width=* align=left></td>
</tr>
</table>
<table style=\"font:14px;width:950px\" border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=80></td>
	<td width=120 align=left>${LANG_0028:=һ}</td>
	<td width=160>
		<input name=nat_nexthop style=\"width:160px\">
	</td>
	<td width=* align=left></td>
</tr>
</table>
<table style=\"width:950; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:950\"> 
<tr>
        <td align=right>
		<input type=submit style=\"width:80\" class=\"btns\"  value=\"${LANG_0030:=ύ}\"></input>
		<input type=button style=\"width:80\" value=\"${LANG_0031:=ȡ}\" class=\"btns\"  onclick=\"onCancel()\"></input>
		<input type=hidden name=from value=\"${CGI_from}\" />
	</td>
</tr>
</table>
</form>
</body>
</html>
";