#!/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="Shared detection"
	LANG_002="Please input TTL"
	LANG_003="Please input the Weight"
	LANG_004="Success"
	LANG_005="Error"
	LANG_006="Shared object calculation method: number of shared objects = (ie object weight * ie object number + chrome object weight * chrome object number) / 100"
	LANG_007="enable"
	LANG_008="disable"
	LANG_009="Object ttl"
	LANG_010="(seconds, delete the object when it is not accessed after the specified time of this parameter)"
	LANG_011="IE object weight"
	LANG_012="Chrome object weight"
	LANG_013="Active detection interval"
	LANG_014="(seconds, 0 means turned off, and active detection will consume some system performance)"
	LANG_015="Submit"
fi
CGI_browsertitle="${LANG_001:=}"
. ../../common/common.sh 
myself="/cgi-bin/App/ipcookie/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeCommit(frm)
{
        var cookie_ttl = document.getElementsByName(\"ttl\")[0];
        var cookie_internal = document.getElementsByName(\"internal\")[0];
        var iecookie_weight = document.getElementsByName(\"iecookie_weight\")[0];
        var chromecookie_weight = document.getElementsByName(\"chromecookie_weight\")[0];
	cookie_ttl.value = TrimAll(cookie_ttl.value);
	if (!IsDigit(cookie_ttl.value)) {
		alert(\"${LANG_002:=}\");
		cookie_ttl.select();
		return false;
	}
	cookie_internal.value = TrimAll(cookie_internal.value);
	iecookie_weight.value = TrimAll(iecookie_weight.value);
	if (!IsDigitIn(iecookie_weight.value, 0, 100)) {
		alert(\"${LANG_003:=ȷȨֵ}\");
		iecookie_weight.select();
		return false;
	}
	chromecookie_weight.value = TrimAll(chromecookie_weight.value);
	if (!IsDigitIn(chromecookie_weight.value, 0, 100)) {
		alert(\"${LANG_003:=ȷȨֵ}\");
		chromecookie_weight.select();
		return false;
	}
	
        return true;
}
</script>
"; 
if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "${myself}"
	[ "${CGI_ttl}" = "" ] && CGI_ttl=600
	[ "${CGI_internal}" = "" ] && CGI_internal=0
	[ "${CGI_iecookie_weight}" = "" ] && CGI_iecookie_weight=80
	[ "${CGI_chromecookie_weight}" = "" ] && CGI_chromecookie_weight=80
	cmdargs="enable=${CGI_enable} internal=${CGI_internal} ttl=${CGI_ttl}"
	cmdargs="${cmdargs} iecookie_weight=${CGI_iecookie_weight}"
	cmdargs="${cmdargs} chromecookie_weight=${CGI_chromecookie_weight}"
	errmsg=`${FLOWEYE} ipcookie config ${cmdargs}`
	if [ "$?" != "0" ]; then 
		afm_dialog_msg "${LANG_005:=ִ}: ${errmsg}"
	else
		afm_dialog_msg "${LANG_004:=ɹ}"
	fi
else
	for nameval in `${FLOWEYE} ipcookie stat`
	do
		name=`echo ${nameval} | cut -d'=' -f1`
		val=`echo ${nameval} | cut -d'=' -f2-`
		export CGI_${name}="${val}"
	done
fi

echo -n "
<body>
<br>
<table width=800 border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<tr id=row1>
<td width=20></td>
<td align=left style=\"color:#0000ff;font:13px\">${LANG_006:=㷽:  = (IEȨֵ*IE + ChromeȨֵ*Chrome) / 100}</td>
</tr>
</table>
<br>
<form method=post onsubmit=\"return beforeCommit(this)\" action=\"${myself}\">
<table width=600 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=20></td>
	<td width=160 align=left>${LANG_001:=}</td>
	<td width=100 align=left>
		<select name=enable value=${CGI_enable} style=\"width:100\">
		"; if [ ${CGI_enable} -eq 0 ]; then 
echo -n "
			<option value=1>${LANG_007:=}</option>
			<option value=0 selected>${LANG_008:=}</option>
		"; else 
echo -n "
			<option value=1 selected>${LANG_007:=}</option>
			<option value=0>${LANG_008:=}</option>
		"; fi 
echo -n "
		</select>
	</td>
	<td width=*></td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>${LANG_009:=}</td>
	<td align=left><input type=text name=ttl style=\"width:100\" value=\"${CGI_ttl}\" /></td>
	<td>${LANG_010:=(,˲ָʱûʱɾ)}</td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>${LANG_011:=IEȨֵ}</td>
	<td align=left><input type=text name=iecookie_weight style=\"width:100\" value=\"${CGI_iecookie_weight}\" /></td>
	<td>(%,0~100)</td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>${LANG_012:=ChromeȨֵ}</td>
	<td align=left><input type=text name=chromecookie_weight style=\"width:100\" value=\"${CGI_chromecookie_weight}\" /></td>
	<td>(%,0~100)</td>
</tr>
<tr id=row1>
	<td></td>
	<td align=left>${LANG_013:=}</td>
	<td align=left><input type=text name=internal style=\"width:100\" value=\"${CGI_internal}\" /></td>
	<td>${LANG_014:=(,0ʾر,һЩϵͳ)}</td>
</tr>
</table>
<table style=\"width:800; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:800\">
<tr>
        <td align=right>
                <input type=submit style=\"width:80\" value=\"${LANG_015:=ύ}\"></input>
        </td>
</tr>
</table>
</form>
</body>
</html>
";