#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html
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 keepalive = document.getElementsByName(\"keepalive\")[0];
	var rad_ip = document.getElementsByName(\"rad_ip\")[0];
	var rad_authport = document.getElementsByName(\"rad_authport\")[0];
	var rad_acctport = document.getElementsByName(\"rad_acctport\")[0];
	var rad_secret = document.getElementsByName(\"rad_secret\")[0];
	var rad_acctinternal = document.getElementsByName(\"rad_acctinternal\")[0];
	var rad_ttl = document.getElementsByName(\"rad_ttl\")[0];
	keepalive.value = TrimAll(keepalive.value);
	rad_ip.value = TrimAll(rad_ip.value);
	rad_authport.value = TrimAll(rad_authport.value);
	rad_acctport.value = TrimAll(rad_acctport.value);
	rad_secret.value = TrimAll(rad_secret.value);
	if (rad_secret.value == \"\") {
		alert(\"ԿΪ!\");
		rad_secret.select();
	}
	rad_acctinternal.value = TrimAll(rad_acctinternal.value);
	if (rad_acctinternal.value == \"\") {
		alert(\"ȷļƷѼʱ!\");
		rad_acctinternal.select();
	}
	rad_ttl.value = TrimAll(rad_ttl.value);
	if (rad_ttl.value == \"\") {
		alert(\"Ӧȴʱ!\");
		rad_ttl.select();
	}
	return true;
}
function onCancel() 
{
	window.location.href = \"${returl}\";
}
</script>
";
fail=0
if [ "${REQUEST_METHOD}" = "POST" ]; then
	cmdargs="${cmdargs} enable=${CGI_enable} keepalive=${CGI_keepalive}"
	errmsg=`${FLOWEYE} pppoesvr config ${cmdargs}`
	if [ "$?" != "0" ]; then 
		afm_dialog_msg "ʧ:${errmsg}"
	else
		[ "${CGI_rad_ip}" = "" ] && CGI_rad_ip="0.0.0.0"
		[ "${CGI_rad_authport}" = "" ] && CGI_rad_authport=1812
		[ "${CGI_rad_acctport}" = "" ] && CGI_rad_acctport=1813
		[ "${CGI_rad_acctinternal}" = "" ] && CGI_rad_acctinternal=300
		[ "${CGI_rad_secret}" = "" ] && CGI_rad_secret="panabit"
		[ "${CGI_rad_proxy}" = "" ] && CGI_rad_proxy="NULL"
		cmdargs="enable=${CGI_rad_enable} ip=${CGI_rad_ip}"
		cmdargs="${cmdargs} authport=${CGI_rad_authport}"
		cmdargs="${cmdargs} acctport=${CGI_rad_acctport}"
		cmdargs="${cmdargs} secret=${CGI_rad_secret}"
		cmdargs="${cmdargs} acctinternal=${CGI_rad_acctinternal}"
		cmdargs="${cmdargs} proxy=${CGI_rad_proxy}"
		cmdargs="${cmdargs} ttl=${CGI_rad_ttl}"
		errmsg=`${FLOWEYE} radius config ${cmdargs}`
		if [ "$?" != "0" ]; then
			afm_dialog_msg "ʧ:${errmsg}"
			fail=1
		fi
	fi
fi
if [ ${fail} -eq 0 ]; then 
	for nameval in `${FLOWEYE} pppoesvr stat`
	do
		eval "CGI_${nameval}"
	done
	for nameval in `${FLOWEYE} radius stat`
	do
		eval "CGI_rad_${nameval}"
	done
fi

echo -n "
<body>
"; cgi_show_title "PPPOE->" 
echo -n "
<br>
<table style=\"width:700; border-bottom:1px #787882 solid; font-bold:true;font-size:14px;\">
<tr>
	<td style=\"font:14px\"><b>ͳϢ</b></td>
	<td style=\"font:12px;\" align=right width=\"*\"></td>
</tr>
</table>
<br>
<table width=600 border=0 cellspacing=2 cellpadding=1 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>û</td>
	<td width=* align=left>${CGI_poolsz}</td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>ͳ</td>
	<td align=left>${CGI_rad_disconnect}</td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>Ʒͳ</td>
	<td align=left>${CGI_rad_acctreq}/${CGI_rad_acctres}/${CGI_rad_accttimeout}(/Ӧ/ʱ)</td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>֤ͳ</td>
	<td width=* align=left>${CGI_rad_authreq}/${CGI_rad_authack}/${CGI_rad_authrej}/${CGI_rad_authtimeout}(//ܾ/ʱ)</td>
</tr>
</table>
<br>
<form method=post onsubmit=\"return beforeCommit(this)\" action=\"${myself}\">
<table style=\"width:700; border-bottom:1px #787882 solid; color:#000000\">
<tr><td align=left style=\"font-size:11px\"><b></b></td></tr>
</table>
<br>
<table width=700 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>PPPOE</td>
	<td width=* align=left>
		<select name=enable value=${CGI_enable} style=\"width:100\">
		";
			if [ ${CGI_enable} -eq 0 ]; then
				echo "<option value=1></option>"
				echo "<option value=0 selected></option>" 
			else 
				echo "<option value=1 selected></option>"
				echo "<option value=0></option>" 
			fi
		
echo -n "
		</select>
	</td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>ͻ</td>
	<td width=* align=left><input type=text name=keepalive style=\"width:100\" value=${CGI_keepalive}></input>&nbsp;(,0ʾ)</td>
</tr>
</table>
<br>
<table style=\"width:650; border-bottom:1px #787882 solid; color:#000000\">
<tr><td align=left style=\"font-size:11px\"><b>RADIUS</b></td></tr>
</table>
<br>
<table width=700 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>RADIUS</td>
	<td width=* align=left>
		<select name=rad_enable value=${CGI_rad_enable} style=\"width:100\">
		";
			if [ ${CGI_rad_enable} -eq 0 ]; then
				echo "<option value=1></option>"
				echo "<option value=0 selected></option>" 
			else 
				echo "<option value=1 selected></option>"
				echo "<option value=0></option>" 
			fi
		
echo -n "
		</select>
	</td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>IP</td>
	<td width=* align=left><input type=text name=rad_ip style=\"width:100\" value=${CGI_rad_ip}></input>
"; if [ "${CGI_rad_rtentry_active}" = "1" ]; then 
echo -n "
	&nbsp;<b><a style=\"color:#0000ff\">ɴ</a></b>
"; else 
echo -n "
	&nbsp;<b><a style=\"color:#ff0000\">ɴ</a></b>
"; fi 
echo -n "
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>֤˿</td>
	<td width=* align=left><input type=text name=rad_authport style=\"width:100\" value=${CGI_rad_authport}></input>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>ƷѶ˿</td>
	<td width=* align=left><input type=text name=rad_acctport style=\"width:100\" value=${CGI_rad_acctport}></input>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>Կ</td>
	<td width=* align=left><input type=text name=rad_secret style=\"width:100\" value=${CGI_rad_secret}></input>&nbsp;(󲻳30Ӣַ15ַ)
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>Ʒѷͼ</td>
	<td width=* align=left><input type=text name=rad_acctinternal style=\"width:100\" value=${CGI_rad_acctinternal}></input>&nbsp;()
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>Ӧȴʱ</td>
	<td width=* align=left><input type=text name=rad_ttl style=\"width:100\" value=${CGI_rad_ttl}></input>&nbsp;(룬ʱRADIUSӦ𽫱)</td>
</tr>
<tr id=row1>
	<td width=40></td>
        <td width=120 align=left>··</td>
        <td width=*>
		<select name=rad_proxy value=\"${CGI_rad_proxy}\" style=\"width:100\">
		";
			${FLOWEYE} nat listproxy type=proxy.routerif | while read type id name theothers
			do
				if [ "${CGI_rad_proxy}" = "${name}" ]; then
					echo "<option value=\"${name}\" selected>${name}</option>"
				else
					echo "<option value=\"${name}\">${name}</option>"
				fi
			done
			if [ "${CGI_rad_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>
</table>
<table style=\"width:700; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:700\"> 
<tr><td align=right><input type=submit style=\"width:80\" value=\"ύ\" /></td></tr>
</table>
</form>
</body>
</html>
";