#!/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="Cache|Device"
	LANG_002="Cache|Group"
	LANG_003="Policy"
	LANG_004="Confirm to delete?"
	LANG_005="Confirm to delete?"
	LANG_006="Error"
	LANG_007="Num"
	LANG_008="Src Interface"
	LANG_009="Src IP"
	LANG_010="Dst IP"
	LANG_011="File Type"
	LANG_012="Pattern"
	LANG_013="Target"
	LANG_014="Match"
	LANG_015="Add"
	LANG_016="Mirror"
	LANG_017="Tow"
	LANG_018="Pass"
	LANG_019="Edit"
	LANG_020="Delete"
	LANG_021="Enable"
	LANG_022="Disable"
fi
CGI_browsertitle="iXCache"
. ../../common/common.sh
cfgroot="/cgi-bin/App/ixcache"
myself="${cfgroot}/`basename $0`"
MOD_TAB_LIST="${LANG_001:=豸}#${cfgroot}/ixcache_list ${LANG_002:=}#${cfgroot}/ixcgroup_list ${LANG_003:=ǣ}#${cfgroot}/webmain"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function onAddProxy()
{
	window.location.href = \"/cgi-bin/App/ixcache/ixcache_add\";
}
function showProxy(proxyname)
{
        var url;
	url = \"/cgi-bin/Monitor/proxy_show?proxyname=\" + proxyname;
        ShowWindow(url, \"\", 350, 400);
}
function editProxy(id)
{
	window.location.href = \"/cgi-bin/App/ixcache/ixcache_edit?id=\" + id;
}
function deleteCache(id)
{
	if (confirm(\"${LANG_004:=汻ɾ,صĲҲᱻɾ,ȷҪɾ?}\"))
		window.location.href = \"${myself}?action=rmvcache&id=\" + id;
}
function onAddRule()
{
	window.location.href = \"/cgi-bin/App/ixcache/ixcache_addrule\";
}
function modifyRule(id)
{
	window.location.href = \"/cgi-bin/App/ixcache/ixcache_setrule?polno=\" + id;
}
function deleteRule(id)
{
	if (confirm(\"${LANG_005:=ȷɾò?}\"))
		window.location.href = \"${myself}?action=rmvrule&id=\" + id;
}
function disableRule(id)
{
	window.location.href = \"${myself}?action=disable&id=\" + id;
}
function enableRule(id)
{
	window.location.href = \"${myself}?action=enable&id=\" + id;
}
function showDesc()
{
        var url = \"/cgi-bin/App/ixcache/ixcache_typedesc\";
        ShowWindow(url, \"\", 350, 400);
}
function showIPGrp(gname)
{
        var url = \"/cgi-bin/Protocol/ipgrp_list?ipgrp=\" + gname;
        ShowWindow(url, \"\", 860, 630);
}
function showCacheGroup(id)
{
        var url = \"/cgi-bin/App/ixcache/ixcgroup_edit?id=\" + id;
        ShowWindow(url, \"\", 340, 370);
}
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 getifstats()
{
        var i;
        var stateobj;
        var inbpsobj, outbpsobj;
        var inppsobj, outppsobj;
        ajxs({type: 'POST',
               url: '${cfgroot}/ajax_webmain',
             error: function(status){setTimeout(getifstats, 3000);},
           success: function(data) {
                var d;
                try {
                        d = eval('('+data+')');
                } catch(e) {
                        setTimeout(getifstats, 3000);
                        return;
                }
                for (i = 0; i < d.length; i++) {
                        pktsobj = document.getElementById(\"pkts_\" + d[i].id);
			if (pktsobj != null) pktsobj.innerText = d[i].pkts;
                }
                setTimeout(getifstats, 3000);
        }});
}
function onload()
{
	getifstats();
}
</script>
";
if [ "${CGI_action}" = "rmvcache" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} ixcache remove id=${CGI_id}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "${LANG_006:=ʧ}:${errmsg}"
	fi
elif [ "${CGI_action}" = "enable" ]; then
	operator_check "${myself}"
	
	errmsg=`${FLOWEYE} ixcpolicy set id=${CGI_id} disable=0`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "${LANG_006:=ʧ}:${errmsg}"
	fi
elif [ "${CGI_action}" = "disable" ]; then
	operator_check "${myself}"
	
	errmsg=`${FLOWEYE} ixcpolicy set id=${CGI_id} disable=1`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "${LANG_006:=ʧ}:${errmsg}"
	fi
elif [ "${CGI_action}" = "rmvrule" ]; then
	operator_check "${myself}"
	
	errmsg=`${FLOWEYE} ixcpolicy remove id=${CGI_id}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "${LANG_006:=ʧ}:${errmsg}"
	fi
fi

echo -n "
<body onload=\"onload()\">
"; cgi_print_mod_header "${LANG_003:=ǣ}" 1280 
echo -n "
<table width=1280 border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr>
	<td width=40  align=center>${LANG_007:=}</td>
        <td width=100 align=right>${LANG_008:=Դӿ}</td>
        <td width=80  align=right>VLAN</td>
	<td width=120 align=right>${LANG_009:=Դַ}</td>
	<td width=120 align=right>${LANG_010:=Ŀַ}</td>
	<td width=200 align=right><a style=\"color:#0000ff;\" href=\"javascript:showDesc()\">${LANG_011:=ļ}</a></td>
	<td width=100 align=right>${LANG_012:=ģʽ}</td>
	<td width=120 align=right>${LANG_013:=ĿĻ}</td>
	<td width=100 align=right>${LANG_014:=ƥ}</td>
	<td width=*   align=right><a style=\"color:#0000ff;font-size:14px\" href=\"javascript:onAddRule()\">${LANG_015:=Ӳ}>>&nbsp;</a></td>
</tr>
";
idname="row1"
${FLOWEYE} ixcpolicy list | \
while read polno inif vlan intype inip outtype outip ftype pkts state mirror cachestate cacheid cache type others 
do
	if [ "${state}" = "enable" ]; then
		echo "<tr id=${idname} height=22>"
	else
		echo "<tr id=row4 height=22>"
	fi
	echo "<td align=center>${polno}</td>"
	echo "<td align=right>${inif}</td>"
	[ "${vlan}" = "0" ] && vlan=""
	echo "<td align=right>${vlan}</td>"
        if [ "${intype}" = "table" ]; then
                echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${inip}')\">${inip}&nbsp;</a></td>"
        else
                echo "<td align=right>${inip}&nbsp;</td>"
        fi
        if [ "${outtype}" = "table" ]; then
                echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${outip}')\">${outip}&nbsp;</a></td>"
        else
                echo "<td align=right>${outip}&nbsp;</td>"
        fi
	echo "<td align=right>${ftype}&nbsp;</td>"
	if [ "${mirror}" = "1" ]; then
		echo "<td align=right>${LANG_016:=}</td>"
	else
		echo "<td align=right>${LANG_017:=ǣ}</td>"
	fi
	if [ "${type}" = "group" ]; then
		echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showCacheGroup('${cacheid}')\">${cache}</a></td>"
	elif [ "${cache}" != "NULL" ]; then
		echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showCache('${cacheid}')\">${cache}</a></td>"
	else
		echo "<td align=right>${LANG_018:=ǣ}</td>"
	fi

echo -n "
	<td align=right id=\"pkts_${polno}\">${pkts}</td>
       	<td align=right>
	<img style=\"margin-top:3px;\" src=\"/img/edit.png\" title=\"${LANG_019:=޸Ĳ}\" onclick=\"modifyRule('${polno}')\" />&nbsp;
	<img style=\"margin-top:3px;\" src=\"/img/delete.png\" title=\"${LANG_020:=ɾ}\" onclick=\"deleteRule('${polno}')\" />&nbsp;
	"; if [ "${state}" = "enable" ]; then 
echo -n "
		<img style=\"margin-top:3px;\" src=\"/img/disable.png\" title=\"${LANG_022:=ò}\" onclick=\"disableRule('${polno}')\" />&nbsp;
	"; else 
echo -n "
		<img style=\"margin-top:3px;\" src=\"/img/enable.png\" title=\"${LANG_021:=ò}\" onclick=\"enableRule('${polno}')\" />&nbsp;
	"; fi 
echo -n "
	</td></tr>
";
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

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