<html>
   <head>
      <meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>
	<title>Access Control</title>
      <link rel="stylesheet" href='stylemain.css' type='text/css'>
         <link rel="stylesheet" href='colors.css' type='text/css'>
            <script language="javascript" src="util.js"></script>
            <script type="text/javascript" src="lang/b28n.js"></script>
            <script language="javascript">
<!-- hide 
var DeviceProject = '<%ejGetOther(sysInfo, DeviceProject)%>';
var isUserAccount = '<%ejGetOther(sysInfo, isUserAccount)%>';
var obj2Items = '<%ejGetObject(MDMOID_SRV_CONTROL_CFG)%>';
var obj2Rows = numOfRow(obj2Items);
var obj2_srvNameArray = getColFromList(obj2Items, "SrvName");
var obj2_srvProArray = getColFromList(obj2Items, "Protocol");
var obj2_lanportArray = getColFromList(obj2Items, "LANPort");
var obj2_portArray = getColFromList(obj2Items, "Port");
var obj2_lanAllowArray = getColFromList(obj2Items, "LanAllow");
var obj2_wanAllowArray = getColFromList(obj2Items, "WanAllow");

var srvNum = 0;

function frmLoad() {
	if(DeviceProject == '2')
		Array.prototype.forEach.call(document.querySelectorAll(".wanSer"),function(e){e.style.display="none"});
	document.querySelector("body").style.display="";
}

function btnApply()
{
    var loc;

    with ( document.forms[0] ) {

        loc = "scsrvcntr.cmd?action=apply&";
		
        var i,j;
   	 var srvlst = 'servicelist=';

	//different service must not use same port, all the service can't take effect,zhoupeng+
	 for (i = 0; i < srvNum-1; i++)
	 {
		for (j=i+1; j < srvNum; j++)
		{
			if ((document.forms[0].lanAllow[i].checked == document.forms[0].lanAllow[j].checked&&
				document.forms[0].lanAllow[i].checked == true)
				 && (document.forms[0].lanportVal[i].value==document.forms[0].lanportVal[j].value))
			{
				alert("Different service can't use the same port");
				return;
			}

			if ((document.forms[0].wanAllow[i].checked == document.forms[0].wanAllow[j].checked&&
				document.forms[0].wanAllow[i].checked == true)
				 && (document.forms[0].portVal[i].value==document.forms[0].portVal[j].value))
			{
				alert("Different service can't use the same port");
				return;
			}
		}
		
	 }
	 //end
		
	 for (i = 0; i < srvNum; i++) {
	 	srvlst += document.forms[0].lanAllow[i].value;
		srvlst += '=';
		if (document.forms[0].lanAllow[i].checked == true)
			srvlst += '1,';
		else
			srvlst += '0,';

		if (document.forms[0].wanAllow[i].checked == true)
              	srvlst += '1,';
		else
			srvlst += '0,';

		var lanportnum = parseInt(document.forms[0].lanportVal[i].value);

		if( lanportnum < 0 || lanportnum > 65535)
		{
			alert("The port '" + lanportnum + "' is out of range  [0-65535].");
			return;
		}
		else
		{
			srvlst += document.forms[0].lanportVal[i].value;
			srvlst += ',';
		}
				
		var portnum = parseInt(document.forms[0].portVal[i].value);

		if( portnum < 0 || portnum > 65535)
		{
			alert("The port '" + portnum + "' is out of range  [0-65535].");
			return;
		}
		else
		{
			srvlst += document.forms[0].portVal[i].value;
			srvlst += ',';         			
		}

		srvlst += ';';
      }
    loc += srvlst;
    }
	
    loc += '&sessionKey=<%ejGetOther(sessionKey)%>';
    var code = 'location="' + loc + '"';
    eval(code);
}

function getSrvSupport(srvName) {
	var srvEnable;

	if (srvName == 'HTTP')
		srvEnable = '<%ejGetOther(servicesupported, HTTP) %>';
	else if (srvName == 'HTTPS')
		srvEnable = '<%ejGetOther(servicesupported, HTTPS) %>';	
	else if (srvName == 'TELNET')
		srvEnable = '<%ejGetOther(servicesupported, TELNET) %>';
	else if (srvName == 'SSH')
	{
		if (DeviceProject == '2' && isUserAccount == '1')
			srvEnable = 'false';			
		else
			srvEnable = '<%ejGetOther(servicesupported, SSH) %>';		
	}
	else if (srvName == 'FTP')
		srvEnable = '<%ejGetOther(servicesupported, FTP) %>';
	else if (srvName == 'TFTP')
		srvEnable = '<%ejGetOther(servicesupported, TFTP) %>';
	else if (srvName == 'ICMP')
		srvEnable = '<%ejGetOther(servicesupported, ICMP) %>';
	else if (srvName == 'SNMP')
		srvEnable = '<%ejGetOther(servicesupported, SNMP) %>';	
	else if (srvName == 'SAMBA')
		srvEnable = '<%ejGetOther(servicesupported, SAMBA) %>';
	else
		srvEnable = 'false';
	
	return srvEnable;
}

function fillObj2Items(){
	var i;
	srvNum = 0;
	var j = 0;
   
	for(i=0; i < obj2Rows; i++)
	{
		if (getSrvSupport(obj2_srvNameArray[i]) == 'false')   	
			continue;

		srvNum = srvNum + 1;
	  
      document.writeln("<tr>");
      document.writeln("<td>&nbsp;"+ obj2_srvNameArray[i] +"</td>");
	  
		if (obj2_lanAllowArray[i] == '1'){
			if(obj2_srvNameArray[i] == 'ICMP')
				document.writeln("<td align='center'><input type='checkbox' name='lanAllow' checked disabled value='"+ obj2_srvNameArray[i] + "'>" + "enable" + "</td>");
			else
				document.writeln("<td align='center'><input type='checkbox' name='lanAllow' checked value='"+ obj2_srvNameArray[i] + "'>" + "enable" + "</td>");
		}
		else
			document.writeln("<td align='center'><input type='checkbox' name='lanAllow' value='" + obj2_srvNameArray[i] + "'>" + "enable" + "</td>");

		if(obj2_srvNameArray[i] == 'ICMP')
			document.writeln("<td align='center'><input type='text' name='lanportVal' size='4' disabled value='" + obj2_lanportArray[i] + "'></td>");
		else
			document.writeln("<td align='center'><input type='text' name='lanportVal' size='4' value='" + obj2_lanportArray[i] + "'></td>");

		if (obj2_wanAllowArray[i] == '1')
			document.writeln("<td class='wanSer' align='center'><input type='checkbox' name='wanAllow' checked value='" + obj2_srvNameArray[i] + "'>" + "enable" + "</td>");
		else	  
			document.writeln("<td class='wanSer' align='center'><input type='checkbox' name='wanAllow' value='" + obj2_srvNameArray[i] + "'>" + "enable" + "</td>");

		document.writeln("<td class='wanSer'>");
		if(obj2_srvNameArray[i] == 'ICMP')
			document.writeln("<input  type='text' name='portVal' size='4' disabled value='" + obj2_portArray[i] + "'>");
		else
			document.writeln("<input  type='text' name='portVal' size='4' value='" + obj2_portArray[i] + "'>");
		document.writeln("&nbsp;</td>");
		document.writeln("</tr>");
   }
}

// done hiding -->
</script>

</head>
<body onLoad='frmLoad()' style='dispaly:none'>
<form>
  <blockquote>
	 <b class="tdTitle" id="scsrvcntrTitle">Access Control -- Services</b>
	 <script>
		if( '<%ejGetOther(sysInfo, buildVDFWarning)%>' == "1")
		{
		  document.writeln("<br><br>");
		  document.writeln("<b style='color:red'>For security reasons, it is recommended that the services that has been deactivated by default should remain deactivated when not in use.</b>");
		}
	  </script>
     <p id="scsrvcntrTips">Services access control list (SCL) enable or disable the running services.</p>
       <table border='1' cellpadding='4' cellspacing='0' id='serviceList'>
   	    <tr>
	      <td class='hd' id="scsrvcntrServices">Services</td>
	      <td class='hd'>LAN</td>
	      <td class='hd' id="scsrvcntrLANPort">LAN Port</td>
			<td class='hd wanSer'>WAN</td>
			<td class='hd wanSer' id="scsrvcntrPort">Port</td>
	    </tr>
	    <script language='javascript'>
	      <!--hide
	        fillObj2Items();
	      //-->
	    </script>
	</table><br>
        <p align="center">
           <input type='button' onClick='btnApply()' value='Apply/Save' id="scsrvcntrbtnApply">
        </P>
  </blockquote>
</form>
</body>
</html>
