#!/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/Pppoe/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeCommit(frm)
{
	var rad_desc = document.getElementsByName(\"desc\")[0];
	var rad_ip = document.getElementsByName(\"ip\")[0];
	var rad_authport = document.getElementsByName(\"authport\")[0];
	var rad_acctport = document.getElementsByName(\"acctport\")[0];
	var rad_secret = document.getElementsByName(\"secret\")[0];
	rad_desc.value = TrimAll(rad_desc.value);
	if (rad_desc.value == \"\") {
		alert(\"ƲΪ!\");
		rad_desc.select();
		return false;
	}
	rad_ip.value = TrimAll(rad_ip.value);
	if (rad_ip.value == \"\" || rad_ip.value == \"0.0.0.0\") {
		alert(\"IPַΪ!\");
		rad_ip.select();
		return false;
	}
	rad_authport.value = TrimAll(rad_authport.value);
	if (rad_authport.value == \"\") {
		alert(\"֤˿ڲΪ!\");
		rad_authport.select();
		return false;
	}
	rad_acctport.value = TrimAll(rad_acctport.value);
	if (rad_acctport.value == \"\") {
		alert(\"ƷѶ˿ڲΪ!\");
		rad_acctport.select();
		return false;
	}
	rad_secret.value = TrimAll(rad_secret.value);
	if (rad_secret.value == \"\") {
		alert(\"ԿΪ!\");
		rad_secret.select();
	}
	return true;
}
function onCancel() 
{
	window.location.href = \"/cgi-bin/Pppoe/radsvr_list\";
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "${myself}"
	string_verify "${CGI_desc}"
	if [ "$?" = "0" ]; then
		afm_dialog_msg "аַ!"
		adm_load_page 0 "${myself}"
		exit 0
	fi
	[ "${CGI_authport}" = "" ] && CGI_authport=1812
	[ "${CGI_acctport}" = "" ] && CGI_acctport=1813
	[ "${CGI_discport}" = "" ] && CGI_discport=3799
	[ "${CGI_secret}" = "" ] && CGI_secret="panabit"
	[ "${CGI_proxy}" = "" ] && CGI_proxy="NULL"
	[ "${CGI_proxy2}" = "" ] && CGI_proxy2="NULL"
	cmdargs="ip=${CGI_ip} authport=${CGI_authport} acctport=${CGI_acctport}"
	cmdargs="${cmdargs} secret=${CGI_secret}"
	cmdargs="${cmdargs} proxy=${CGI_proxy}"
	cmdargs="${cmdargs} proxy2=${CGI_proxy2}"
	cmdargs="${cmdargs} desc=${CGI_desc}"
	errmsg=`${FLOWEYE} radsvr set id=${CGI_radid} ${cmdargs}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}"
	else
		afm_load_page 0 "/cgi-bin/Pppoe/radsvr_list"
		exit 0
	fi
else
	for nameval in `${FLOWEYE} radsvr get id=${CGI_radid}`
	do
		name=`echo ${nameval} | cut -d '=' -f1`
		val=`echo ${nameval} | cut -d '=' -f2-`
		eval "CGI_${name}=${val}"
	done
fi

echo -n "
<body>
"; cgi_show_title "RADIUS->޸ķ" 
echo -n "
<br>
<form method=post onsubmit=\"return beforeCommit(this)\" action=\"${myself}\">
<table width=650 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left></td>
	<td width=* align=left><input type=text name=desc style=\"width:100\" value=${CGI_desc}></input></td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>IP</td>
	<td width=* align=left><input type=text name=ip style=\"width:100\" value=${CGI_ip}></input></td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>֤˿</td>
	<td width=* align=left><input type=text name=authport style=\"width:100\" value=${CGI_authport}></input></td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>ƷѶ˿</td>
	<td width=* align=left><input type=text name=acctport style=\"width:100\" value=${CGI_acctport}></input></td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>Կ</td>
	<td width=* align=left><input type=text name=secret style=\"width:100\" value=${CGI_secret}></input>&nbsp;(󲻳30Ӣַ15ַ)</td>
</tr>
<tr id=row1>
	<td width=40></td>
        <td width=120 align=left>··</td>
        <td width=*>
		<select name=proxy value=\"${CGI_proxy}\" style=\"width:100\">
		";
			${FLOWEYE} nat listproxy type=proxy.pppoe.routerif | while read type id name theothers
			do
				if [ "${CGI_proxy}" = "${name}" ]; then
					echo "<option value=\"${name}\" selected>${name}</option>"
				else
					echo "<option value=\"${name}\">${name}</option>"
				fi
			done
			if [ "${CGI_proxy}" = "NULL" ]; then
				echo "<option value=\"NULL\" selected>·</option>"
			else
				echo "<option value=\"NULL\">·</option>"
			fi
		
echo -n "
		</select><a style=\"color:#0000ff\">&nbsp;(ͨ·RADIUSͨ)</a>
	</td>
</tr>
<tr id=row1>
	<td width=40></td>
        <td width=120 align=left>·</td>
        <td width=*>
		<select name=proxy2 value=\"${CGI_proxy2}\" style=\"width:100\">
		";
			${FLOWEYE} nat listproxy type=proxy.pppoe.routerif | while read type id name theothers
			do
				if [ "${CGI_proxy2}" = "${name}" ]; then
					echo "<option value=\"${name}\" selected>${name}</option>"
				else
					echo "<option value=\"${name}\">${name}</option>"
				fi
			done
			if [ "${CGI_proxy2}" = "NULL" ]; then
				echo "<option value=\"NULL\" selected>·</option>"
			else
				echo "<option value=\"NULL\">·</option>"
			fi
		
echo -n "
		</select><a style=\"color:#0000ff\">&nbsp;(·ͨʱͨ·RADIUSͨ)</a>
	</td>
</tr>
</table>
<table style=\"width:650; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:650\"> 
<tr>
	<td align=right>
		<input type=submit style=\"width:80\" value=\"ύ\" />
		<input type=button style=\"width:80\" value=\"ȡ\" onclick=\"onCancel()\"></input>
		<input type=hidden name=radid value=\"${CGI_radid}\" />
	</td>
</tr>
</table>
</form>
</body>
</html>
";