#!/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/Setup/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeAddBWO(frm)
{
	var pname = document.getElementsByName(\"pname\")[0];
	var prate = document.getElementsByName(\"prate\")[0];
	pname.value = TrimAll(pname.value);
	if (!IsName(pname.value)) {
		alert(\"ͨƲܳ&ַ!\");
		pname.select();
		return false;
	}
	prate.value = TrimAll(prate.value);
	if (prate.value == \"\") {
		alert(\"!\");
		prate.select();
		return false;
	}
	if (!IsDigitIn(prate.value, 1, 3000000)) {
		alert(\"1kb/s3000000kb/s֮!\");
		prate.select();
		return false;
	}
	return true;
}
function onTypeChanged(obj)
{
	if (obj.value == \"limit\") 
		document.getElementsByName(\"path\")[0].disabled = true;
	else
		document.getElementsByName(\"path\")[0].disabled = false;
}
function onCancel()
{
	window.location.href = \"/cgi-bin/Setup/pipe_list\";
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	if [ "${CGI_path}" = "" ]; then
		CGI_bridge=0
		CGI_dir="both"
	else
		CGI_bridge=`echo ${CGI_path} | cut -d'.' -f1`
		CGI_dir=`echo ${CGI_path} | cut -d'.' -f2`
	fi
	errmsg=`${FLOWEYE} policy addbwo name=${CGI_pname} type=${CGI_type} \
bridge=${CGI_bridge} dir=${CGI_dir} rate=${CGI_rate}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
		afm_load_page 0 "/cgi-bin/Setup/pipe_list"
		exit 0
	fi
fi

echo -n "
<body>
"; cgi_show_title "Զ->ͨ->ͨ" 
echo -n "
<br>
<form method=post onsubmit=\"return beforeAddBWO(this)\" action=\"${myself}\">
<table style=\"font:14px\" width=600 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=40></td>
        <td width=80 align=left>ͨ</td>
	<td width=400 align=left>
		<input type=text name=pname style=\"width:120px\" value=\"${CGI_pname}\"></input>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>ͨ</td>
        <td align=left>
		<input type=text name=rate style=\"width:120px\" value=\"${CGI_rate}\"></input> (λ:kbits/s Χ:1~3000000) 
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>ͨ</td>
        <td align=left>
		<select name=type style=\"width:120\" onchange=\"onTypeChanged(this)\">
			<option value=limit></option>
			<option value=reserved>Ԥ</option>
			<option value=gurantee>֤</option>
		</select>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>·</td>
        <td align=left><select name=path style=\"width:120\" disabled>
	";
		for bdg in `${FLOWEYE} bridge list`; do
			echo "<option value=\"${bdg}.out\">${bdg}</option>"
			echo "<option value=\"${bdg}.in\">${bdg}</option>"
		done
	
echo -n "</select>
	</td>
</tr>
</table>
<table style=\"width:600; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:600\"> 
<tr>
        <td align=right>
		<input type=submit style=\"width:80\" value=\"ύ\"></input>
		<input type=button style=\"width:80\" value=\"ȡ\" onclick=\"onCancel()\"></input>
	</td>
</tr>
</table>
</form>
</body>
</html>
";