#!/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 "";
if [ "${PALANG}" = "en" ]; then
	LANG_001=""
fi
CGI_browsertitle="iXCache"
. ../../common/common.sh 
cfgroot="/cgi-bin/App/ixcache"
myself="${cfgroot}/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeAddProxy(frm)
{
	var name = document.getElementsByName(\"name\")[0];
	var ifaddr    = document.getElementsByName(\"ifaddr\")[0];
	var netmask   = document.getElementsByName(\"netmask\")[0];
	var ifname    = document.getElementsByName(\"ifname\")[0];
	var vlan      = document.getElementsByName(\"vlan\")[0];
	var mtu       = document.getElementsByName(\"mtu\")[0];
	ifname.value = TrimAll(ifname.value);
	if (!IsName(ifname.value)) {
		alert(\"в&ַ!\");
		ifname.select();
		return false;
	}
	ifaddr.value = TrimAll(ifaddr.value);
	if (!IsIPAddr(ifaddr.value)) {
		alert(\"ӿڵIPַ!\");
		ifaddr.select();
		return false;
	}
	netmask.value = TrimAll(netmask.value);
	if (!IsIPAddr(netmask.value)) {
		alert(\"!\");
		netmask.select();
		return false;
	}
	vlan.value = TrimAll(vlan.value);
	if (!IsDigitIn(vlan.value, 0, 65535)) {
		alert(\"VLAN TAG!\");
		vlan.select();
		return false;
	}
	mtu.value = TrimAll(mtu.value);
	if (mtu.value != \"\" && !IsDigitIn(mtu.value, 1000, 1500)) {
		alert(\"ȷMTU!\");
		mtu.select();
		return false;
	}
	if (ifname.value == \"\") {
		alert(\"ѡ!\");
		ifname.select();
		return false;
	}
	return true;
}
function onCancel() 
{
	window.location.href = \"${cfgroot}/ixcache_list\";
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "${myself}"
	[ "${CGI_nexthop}" = "" ] && CGI_nexthop="0.0.0.0"
	errmsg=`${FLOWEYE} ixcache set id=${CGI_id} name=${CGI_name} ip=${CGI_ip} proxy=${CGI_proxy} nexthop=${CGI_nexthop}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}"
	else
		afm_load_page 0 "${cfgroot}/ixcache_list"
		exit 0
	fi
fi
for nameval in `${FLOWEYE} ixcache get id=${CGI_id}`
do
	name=`echo ${nameval} | cut -d'=' -f1`
	val=`echo ${nameval} | cut -d'=' -f2-`
	export CGI_${name}="${val}"
done

echo -n "
<body>
"; cgi_show_title "ǣ->޸Ļ" 
echo -n "
<br>
<form method=post onsubmit=\"return beforeAddProxy(this)\" action=\"${myself}\">
<table style=\"font:14px\" width=600 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=20></td>
        <td width=80 align=left></td>
	<td width=400 align=left><input type=text name=name style=\"width:120px\" value=\"${CGI_name}\" />&nbsp;(Ҫ8ֻ15Ӣַ)</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>IPַ</td>
        <td align=left>
		<input type=text name=ip style=\"width:120px\" value=\"${CGI_ip}\" />&nbsp;(дIP)
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>··</td>
        <td align=left>
		<select name=proxy style=\"width:120\" value=\"${CGI_proxy}\">
		";
		for proxy in `${FLOWEYE} nat listproxy type=proxy.routerif | awk '{print $3}'`
		do
			if [ "${proxy}" = "${CGI_proxy}" ]; then
				echo "<option value=\"${proxy}\" selected>${proxy}</option>"
			else
				echo "<option value=\"${proxy}\">${proxy}</option>"
			fi
		done
		
echo -n "
		</select>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>һ</td>
        <td align=left><input type=text name=nexthop style=\"width:120px\" value=\"${CGI_nexthop}\" />&nbsp;(Ҫ·ﵽ,·IP,0.0.0.0)</td>
</tr>
</table>
<table style=\"width:600; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:600\"> 
<tr>
        <td align=right>
		<input type=hidden name=id value=\"${CGI_id}\" />
		<input type=submit id=newbtn value=\"ύ\" />
		<input type=button id=newbtn value=\"ȡ\" onclick=\"onCancel()\" />
	</td>
</tr>
</table>
</form>
</body>
</html>
";