#!/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`" 
[ "${CGI_server}" = "" ] && CGI_server=0
[ "${CGI_sort}" = "" ] && CGI_sort="birth"
[ "${CGI_vlan}" = "" ] && CGI_vlan=0
sortargs="server=${CGI_server}&vlan=${CGI_vlan}"
[ "${CGI_account}" != "" ] && sortargs="${sortargs}&account=${CGI_account}" 
MOD_TAB_LIST="û#/cgi-bin/Pppoe/pppoe_online ڲ#/cgi-bin/Pppoe/pppoe_dialing"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function importAcct()
{
	window.location.href = \"/cgi-bin/Setup/l2bypass_import\";
}
function exportAcct()
{
	window.location.href = \"/cgi-bin/Setup/l2bypass_export\";
}
function addAcct()
{
	window.location.href = \"/cgi-bin/Pppoe/pppoe_addacct\";
}
function modifyAcct(acct)
{
	var url = \"/cgi-bin/Pppoe/pppoe_editacct?where=online&account=\" + acct;
	ShowWindow(url, \"\", 750, 400);
}
function onSelectItem(obj)
{
	var count0, count1;
	var accounts = document.getElementsByName(\"accts\");
	var delacct;
	count0 = count1 = 0;
	if (obj.value == \"_NULL_\") {
        	for(i = 1;i < accounts.length; i++) {
			accounts[i].checked = obj.checked;
			if (accounts[i].checked) count1++;
			else count0++;
		}
	}
	else {
       		for(i = 1;i < accounts.length; i++) {
			if (accounts[i].checked)
				count1++;
			else 
				count0++;
       		}
		if (count0 == 0 && count1 > 0)
			accounts[0].checked = true;
		else
			accounts[0].checked = false;
	}
	delacct = document.getElementById(\"delacct\");
	bindmac = document.getElementById(\"bindmac\");
	if (count1 > 0) {
		bindmac.style.color = \"#0000ff\";
		delacct.style.color = \"#0000ff\";
	}
	else {
		bindmac.style.color = \"#545454\";
		delacct.style.color = \"#545454\";
	}
}
function showServer(name)
{
	var url = \"/cgi-bin/Monitor/proxyr_show?proxyname=\" + name;
        ShowWindow(url, \"\", 350, 380);
}
function editIppool(id) 
{
	var url = \"/cgi-bin/Pppoe/ippool_edit?id=\" + id;
	ShowWindow(url, \"\", 680, 300);
}
</script>
<body>
"; cgi_show_title "PPPOE->û" 
echo -n "
<br>
";
if [ "${CGI_action}" = "kickoff" ]; then
	cmdargs=""
	for mac in ${CGI_maclist}
	do
		cmdargs="${cmdargs} mac=${mac}"
	done
	errmsg=`${FLOWEYE} pppoesvr rmvclnt ${cmdargs}`
	[ "$?" != "0" ] && afm_dialog_msg "${errmsg}"
elif [ "${CGI_action}" = "bindmac" ]; then
	cmdargs=""
	for name in ${CGI_namelist}
	do
		cmdargs="${cmdargs} bindmac=${name}"
	done
	errmsg=`${FLOWEYE} pppoeacct config ${cmdargs}`
	[ "$?" != "0" ] && afm_dialog_msg "${errmsg}"
fi

echo -n "
"; cgi_print_mod_header "ڲ" 1180 
echo -n "
<table width=1180 border=0 cellspacing=1 cellpadding=1> 
<form method=post action=\"${myself}\">
<tr id=tblhdr height=22>
	<td width=530 align=left>ѡ
	<select name=server value=\"${CGI_server}\" style=\"width:105;height:21\">
	";
		if [ "${CGI_server}" = "0" ]; then
			echo "<option value=0 selected></option>"
		else
			echo "<option value=0></option>"
		fi
		${FLOWEYE} nat listproxy type=posvrif | while read type id name theothers
		do
			if [ "${CGI_server}" = "${name}" ]; then
				echo "<option value=\"${name}\" selected>${name}</option>"
			else
				echo "<option value=\"${name}\">${name}</option>"
			fi
		done
	
echo -n "
	</select>VLAN
		<input type=text style=\"width:80;height:21\" name=vlan value=\"${CGI_vlan}\"></input>˺
		<input type=text style=\"width:150;height:21\" name=account value=\"${CGI_account}\"></input>
		<input type=submit value=\"ѯ\" style=\"width:50;height:22\"></input>
	</td>
	<td width=* align=right></td>
</tr>
</form>
</table>
<table width=1180 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
	<td width=25  align=center><input type=checkbox name=accts style=\"color:#0000ff\" value='_NULL_' onclick=\"onSelectItem(this)\"/></td>
	<td width=40  align=left></td>
	<td width=150 align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=mac&${sortargs}\">MACַ</a></td>
	<td width=150 align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=account&${sortargs}\">˺</a></td>
	<td width=103 align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=state&${sortargs}\">״̬</a></td>
	<td width=80  align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=vlan&${sortargs}\">VLAN</a></td>
	<td width=80  align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=mtu&${sortargs}\">MTU</a></td>
	<td width=150 align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=server&${sortargs}\"></a></td>
	<td width=*   align=left><a style=\"color:#0000ff\" href=\"${myself}?sort=birth&${sortargs}\">ʼʱ</a></td>
</tr>
";
case "${CGI_sort}" in
"pool")
	sortargs="-k4"
	;;
"account")
	sortargs="-k2"
	;;
"state")
	sortargs="-k12"
	;;
"mac")
	sortargs="-k7"
	;;
"mtu")
	sortargs="-k10"
	;;
"server")
	sortargs="-k5"
	;;
"birth")
	sortargs="-k13"
	;;
*)
	sortargs="-k1"
	;;
esac
cmdargs=""
[ "${CGI_vlan}" != "0" -a "${CGI_vlan}" != "" ] && cmdargs="${cmdargs} vlan=${CGI_vlan}"
[ "${CGI_server}" != "0" -a "${CGI_server}" != "" ] && cmdargs="${cmdargs} server=${CGI_server}"
idname="row1"
count=0
${FLOWEYE} pppoesvr listclnt ${cmdargs} | sort  ${sortargs} | while read sid \
name poolid poolname svrname pctime clntmac svrmac ipaddr mtu vlan state birth expired auth theothers
do
	[ "${name}" = "" -o "${poolid}" = "" ] && continue
	[ "${state}" = "CONNECTED" ] && continue
	if [ "${CGI_account}" != "" ]; then
		case "${name}" in
		*${CGI_account}*)
			match=1;
			;;
		*)
			match=0
			;;
		esac
		[ ${match} -eq 0 ] && continue
	fi
	count=$((${count} + 1))
	[ "${poolname}" = "NULL" ] && poolname=""
	[ "${name}" = "NULL" ] && name=""
	[ "${svrname}" = "NULL" ] && svrname=""
	if [ "${expired}" = "1" ]; then
		echo "<tr id=row3>"
	else
		echo "<tr id=${idname}>"
	fi

echo -n "
	<td align=center><input type=checkbox name=accts style=\"color:#0000ff\" value='${name}&${clntmac}' onclick=\"onSelectItem(this)\"></td>
	<td align=left>${count}&nbsp;</td>
	<td align=left>${clntmac}&nbsp;</td>
"; if [ "${name}" != "" -a "${auth}" = "local" ]; then 
echo -n "
	<td align=left><a style=\"color:#0000ff\" href=\"javascript:modifyAcct('${name}')\">${name}</a>&nbsp;</td>
"; else 
echo -n "
	<td align=left>${name}&nbsp;</td>
"; fi 
echo -n "
	<td align=left>${state}&nbsp;</td>
	<td align=left>${vlan}&nbsp;</td>
	<td align=left>${mtu}&nbsp;</td>
"; if [ "${svrname}" != "" ]; then 
echo -n "
	<td align=left><a style=\"color:#0000ff\" href=\"javascript:showServer('${svrname}')\">${svrname}</a></td>
"; else 
echo -n "
	<td align=left></td>
"; fi 
echo -n "
	<td align=left>${birth}</td>
	</tr>
"; 	if [ "${idname}" = "row1" ]; then
	        idname="row2"
	else
	        idname="row1"
        fi
done

echo -n "
</table>
</body>
</html>
";