<html>
   <head>
      <meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>
	<title>·þÎñ·ÃÎÊ¿ØÖÆ </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"><%ejGetOther(forbidHTMLCode)%></script>
            <script language="javascript">
<!-- hide 


var obj0Items = '<%ejGetObject(MDMOID_DEV2_NAT_PORT_MAPPING)%>';

var obj0Rows = numOfRow(obj0Items);
/* NOTICE: MDMOID_WAN_PPP_CONN_PORTMAPPING is Type1/Type2 object, follow variables are arrays */
var obj0_portMappingEnabledArray = getColFromList(obj0Items, "Enable");
var obj0_externalPortArray = getColFromList(obj0Items, "ExternalPort");
var obj0_ExternalPortEndArray = getColFromList(obj0Items, "ExternalPortEndRange");
var obj0_internalPortArray = getColFromList(obj0Items, "InternalPort");
var obj0_portMappingProtocolArray = getColFromList(obj0Items, "Protocol");
var obj0_portMappingDescriptionArray = getColFromList(obj0Items, "Description");



var obj2Items = '<%ejGetObject(MDMOID_SRV_CONTROL_CFG)%>';
var obj2Rows = numOfRow(obj2Items);
var obj2_srvNameArray = getColFromList(obj2Items, 0);
var obj2_srvProArray = getColFromList(obj2Items, 1);
var obj2_portArray = getColFromList(obj2Items, 3);
var obj2_lanAllowArray = getColFromList(obj2Items, 4);
var obj2_wanAllowArray = getColFromList(obj2Items, 5);
var srvNum = 0;

var eleObj = new Array( "id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8", "id9", "id10", "id11", "id12", "id13", "id14", "id15", "id16", "id17", "id18", "id19");
var elelength = eleObj.length;

function initTranslation() {
	var idArray = new Array("scsrvcntrTitle", "scsrvcntrTips", "scsrvcntrServices", "scsrvcntrPort","scsrvcntrenable", "scsrvcntrbtnApply");
	setAllIdValue(idArray);
}

function frmLoad() {
	initTranslation();
}

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].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(_("scsrvcntrAlert2"));
				return;
			}
		}
		
	 }
	 //end
var k,m,n;
        for(k=0;k < srvNum;k++)
        {
              for(m=0;m < obj0Rows;m++)
              {				 
                 if((parseInt(document.forms[0].portVal[k].value) >= parseInt(obj0_externalPortArray[m])) && 
				 	(parseInt(document.forms[0].portVal[k].value) <= parseInt(obj0_ExternalPortEndArray[m])) && (obj2_srvProArray[k] == obj0_portMappingProtocolArray[m]))
                 {
                     alert(_("scsrvcntrThePort") + document.forms[0].portVal[k].value + _("scsrvcntrThePortUsed"));
			return;
                 }
              }			  

        }
		
	 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 portnum = parseInt(document.forms[0].portVal[i].value);

		if( portnum < 0 || portnum > 65535)
		{
			alert(_("scsrvcntrAlert") + portnum + _("scsrvcntrAlert1"));
			return;
		}
		else
		{
			srvlst += document.forms[0].portVal[i].value;
		}

		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')
		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;
   
   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] + "'>" + _("scsrvcntrenable") + "</td>");
		else
	          document.writeln("<td align='center'><input type='checkbox' name='lanAllow' checked value='"+ obj2_srvNameArray[i] + "'>" + _("scsrvcntrenable") + "</td>");
	}
      else
          document.writeln("<td align='center'><input type='checkbox' name='lanAllow' value='" + obj2_srvNameArray[i] + "'>" + _("scsrvcntrenable") + "</td>");
	
      if (obj2_wanAllowArray[i] == '1')
          document.writeln("<td align='center'><input type='checkbox' name='wanAllow' checked value='" + obj2_srvNameArray[i] + "'>" + _("scsrvcntrenable") + "</td>");
      else	  
          document.writeln("<td align='center'><input type='checkbox' name='wanAllow' value='" + obj2_srvNameArray[i] + "'>" + _("scsrvcntrenable") + "</td>");

	document.writeln("<td>");
	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()'>
<form>
  <blockquote>
     <b class="tdTitle" id="scsrvcntrTitle">Access Control -- Services</b>
     <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'>WAN</td>
      	  <td class='hd' 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>
