#!/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`"
rootpath="/cgi-bin/Pppoe"
MOD_TAB_LIST="#/cgi-bin/Pppoe/pppoesvr_config б#/cgi-bin/Pppoe/pppoesvr_list"
afm_load_page 30 "${myself}"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function onAddServer()
{
	window.location.href = \"${rootpath}/pppoesvr_add\";
}
function onDeleteServer(name)
{
	if (confirm(\"ɾͨӵûǿߣȷҪɾ?\"))
		window.location.href = \"${myself}?action=delete&name=\" + name; 
}
function showServer(name)
{
	var url = \"/cgi-bin/Monitor/proxy_show?proxyname=\" + name;
	ShowWindow(url, \"\", 350, 380);
}
function editServer(name)
{
	window.location.href = \"${rootpath}/pppoesvr_edit?name=\" + name;
}
function showIf(ifname)
{
	var url = \"/cgi-bin/Monitor/ifview?ifname=\" + ifname + \"&title=ӿ->\" + ifname;
	ShowWindow(url, \"\", 840, 800);
}
function ajxs(settings)
{
	var http;
	if (typeof XMLHttpRequest != 'undefined') 
		http = new XMLHttpRequest();
	else {
		try {
			http = new ActiveXObject(\"Msxml2.XMLHTTP\");    
		}catch (e) {
			try {
				http = new ActiveXObject(\"Microsoft.XMLHTTP\");
			} catch (e) {return ;}
		}
	}
	http.open(settings.type, settings.url, true);
	http.setRequestHeader(\"Accept\", \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\");
	http.setRequestHeader(\"Cache-Control\", \"no-cache\");
	http.setRequestHeader(\"Accept-Language\", \"zh-CN,zh;q=0.8\");
	http.setRequestHeader(\"Content-Type\", \"text/html; charset=GB2312\");
	http.onreadystatechange = function() { 
		if (http.readyState == 4) {
			if (http.status == 200)
				settings.success(http.responseText);
			else
				settings.error(http.status);
		}
	}
	http.send(null);
}
function getstatus()
{
	var table = document.getElementsByTagName(\"table\")[1].rows;
	var items = new Array();
	var i;
	
	for(i = 1; i < table.length; i++)
		items.push(table[i].getAttribute(\"name\"));
	if(items.length <= 0)
		return;
	ajxs({type: 'POST', 
				 url: '/cgi-bin/common/plan_action?action=remark&items=' + items.join(' '), 
				 error: function(status){setTimeout(getstatus, 3000);},
				 success: function(data){ 
		// var d = JSON.parse(data);
		var d;
		try {
			d = eval('('+data+')');
		}catch(e) {
			setTimeout(getstatus, 1000);
			return;
		}
		if(table.length == d.data.length) {
			for(i=1; i < d.data.length; i++) {
				table[i].cells[13].childNodes[0].innerHTML = d.data[i].remark;
			}
		}
		else
			setTimeout(getstatus, 2000);
	}});
}
function onresize()
{
        if (document.body.clientWidth > 1280) 
                document.getElementById(\"mytbl1\").style.width=\"100%\";
        else 
                document.getElementById(\"mytbl1\").style.width=\"1280\";
}
function onloaddoc()
{
	getstatus();
	onresize();
}
function editIppool(id) 
{
	var url = \"/cgi-bin/Pppoe/ippool_edit?id=\" + id;
	ShowWindow(url, \"\", 680, 300);
}
</script>
";
if [ "${CGI_action}" = "delete" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} nat rmvproxy ${CGI_name}`
	[ "$?" != "0" ] && afm_dialog_msg "ʧ:${errmsg}"
fi

echo -n "
<body onload=\"onloaddoc();\">
"; cgi_show_title "PPPOE֤->б"
for nameval in `${FLOWEYE} pppoesvr stat`
do
	eval "CGI_${nameval}"
done

echo -n "
<table id=mytbl1 width=\"100%\" border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr>
	<td width=100 align=left>&nbsp;</td>
	<td width=50  align=right></td>
	<td width=80  align=right></td>
	<td width=80  align=right>صַ</td>
	<td width=140 align=right>DNS</td>
	<td width=50  align=right>VLAN</td>
	<td width=50  align=right>MTU</td>
	<td width=70  align=right>֤ʽ</td>
	<td width=70  align=right>ַ</td>
	<td width=80  align=right>RADIUS</td>
	<td width=95  align=right>û/</td>
	<td width=95  align=right></td>
	<td width=95  align=right></td>
	<td width=*   align=right>ע</td>
	<td width=80  align=right><a style=\"color:#0000ff;font-size:14px\" href=\"javascript:onAddServer()\">>>&nbsp;</a></td>
</tr>
";
natcount=0
idname="row1"
${FLOWEYE} nat listproxy type=posvrif | while read type id name linkup ifname addr vlan mtu service dns0 dns1 clntcnt \
lastinbytes lastoutbytes inbps outbps poolid poolname maxclnt auth disabled radsvrid radsvrname theothers
do 
	[ "${service}" = "NULL" ] && service=""
	[ "${vlan}" = "0" ] && vlan=""

echo -n "
    <tr id=${idname} name=\"${name}\">
    <td align=left><a style=\"color:#0000ff\" href=\"javascript:showServer('${name}')\">&nbsp;${name}</a></td>
    <td align=right><a style=\"color:#0000ff\" href=\"javascript:showIf('${ifname}')\">${ifname}&nbsp;</a></td>
    <td align=right>${service}</td>
    <td align=right>${addr}</td>
    <td align=right>${dns0},${dns1}</td>
    <td align=right>${vlan}</td>
    <td align=right>${mtu}</td>
";
	case "${auth}" in
		"local")
			echo "<td align=right>֤</td>"
			;;
		"radius")
			echo "<td align=right>RADIUS</td>"
			;;
		"localrad")
			echo "<td align=right>ȱغRADIUS</td>"
			;;
		"free")
			echo "<td align=right>֤</td>"
			;;
		*)
			echo "<td align=right>UNKNOWN</td>"
			;;
    esac

echo -n "
    <td align=right><a style=\"color:#0000ff\" href=\"javascript:editIppool('${poolid}')\">${poolname}</a></td>
"; if [ "${auth}" = "radius" -o "${auth}" = "localrad" ]; then 
echo -n "
    <td align=right>${radsvrname}&nbsp;</td>
"; else 
echo -n "
    <td align=right>&nbsp;</td>
"; fi 
echo -n "
    <td align=right>${clntcnt}/${maxclnt}&nbsp;</td>
    <td align=right>${inbps}</td> 
    <td align=right>${outbps}</td> 
    <td align=right><span style=\"width:180px;\"></span></td>
    <td align=right>
	<img style=\"margin-top:3px\" src=\"/img/edit.png\" title=\"޸Ĳ\" onclick=\"editServer('${name}')\" />&nbsp;
	<img style=\"margin-top:3px\" src=\"/img/delete.png\" title=\"ɾ\" onclick=\"onDeleteServer('${name}')\" />&nbsp;
    </td>
    </tr>
";
    if [ "${idname}" = "row1" ]; then
        idname="row2"
    else
        idname="row1"
    fi
done 

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