<html>
   <head>
      <meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>
      <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 language="javascript">
<!-- hide
var interfaceInfo = '<%ejGetOther(wanInterfaceInfo, forDnsPlusOne)%>';
var interfaces = interfaceInfo.split('|');
var enblDhcpClnt = '<%ejGet(enblDhcpClnt)%>';
var prtcl = '<%ejGetOther(memInfo, ntwkPrtcl)%>';
var dns1 = '<%ejGet(dnsPrimary)%>'; if ( dns1 == '&nbsp' || dns1 == '0.0.0.0') dns1 = '';
var dns2 = '<%ejGet(dnsSecondary)%>'; if ( dns2 == '&nbsp' || dns2 == '0.0.0.0' ) dns2 = '';
var dnsIfcs = '<%ejGetOther(sysInfo, dnsIfcs)%>'; if (dnsIfcs == '&nbsp') dnsIfcs= '';

var enblIpVer = '<%ejGet(enblIpVer)%>';
var intfInfo6 = '<%ejGetOther(wanInterfaceInfo, forDns6PlusOne)%>';
var intf6 = intfInfo6.split('|');
var wanAddr6Type = '<%ejGet(wanAddr6Type)%>';
var dns6type = '<%ejGetOther(sysInfo, dns6Type)%>'; if ( dns6type == '&nbsp' ) dns6type = '';
var dns6pri = '<%ejGetOther(sysInfo, dns6Pri)%>'; if ( dns6pri == '&nbsp' ) dns6pri = '';
var dns6sec = '<%ejGetOther(sysInfo, dns6Sec)%>'; if ( dns6sec == '&nbsp' ) dns6sec = '';
var dns6ifc = '<%ejGetOther(sysInfo, dns6Ifc)%>'; if ( dns6ifc == '&nbsp' ) dns6ifc = '';

function disableDnsIPInfo() {
   with ( document.forms[0] ) {
      dnsPrimary.disabled = 1;
      dnsPrimary.value = '';
      dnsSecondary.disabled = 1;
      dnsSecondary.value = '';

      selDnsIfcs.disabled = 0;
      availIfcs.disabled = 0;

   }
}

function enableDnsIPInfo() {
   with ( document.forms[0] ) {
      dnsPrimary.disabled = 0;
      dnsPrimary.value = dns1;
      dnsSecondary.disabled = 0;
      dnsSecondary.value = dns2;

      selDnsIfcs.disabled = 1;
      availIfcs.disabled = 1;
	  
   }
}

function dnsClick() {
   with ( document.forms[0] ) {
      if (dns[0].checked == true )
         disableDnsIPInfo();
      else
         enableDnsIPInfo();
   }
}

function disableDns6IPInfo() {
   with ( document.forms[0] ) {
      dns6Primary.disabled = 1;
      dns6Primary.value = '';
      dns6Secondary.disabled = 1;
      dns6Secondary.value = '';

      wanIf6.disabled = 0;
   }
}

function enableDns6IPInfo() {
   with ( document.forms[0] ) {
      dns6Primary.disabled = 0;
      dns6Primary.value = dns6pri;
      dns6Secondary.disabled = 0;
      dns6Secondary.value = dns6sec;

      wanIf6.disabled = 1;
   }
}

function dns6Click() {
   with ( document.forms[0] ) {
      if (dns6[0].checked == true )
         disableDns6IPInfo();
      else
         enableDns6IPInfo();
   }
}

function hideDns6Info(hide) {
   var status = 'block';

   if ( hide == 1 )
      status = 'none';
   if (document.getElementById)  // DOM3 = IE5, NS6
      document.getElementById('dns6Info').style.display = status;
   else {
      if (document.layers == false) // IE4
         document.all.dns6Info.style.display = status;
   }

   if (hide == 0) {
      dns6Click();
   }
}

function btnNext() {
   var loc = 'ntwksum2.cgi?';
  	
   with ( document.forms[0] ) {
      if (enblIpVer != '2') {
         if (dns[0].checked) {
            var tempList = '';
	   
            for (i = 0; i < selDnsIfcs.length; i++) {
    	   	   if (i > 0)
    		  	tempList += ',';
              tempList += selDnsIfcs.options[i].value;
            }

            if (tempList == '') {
        	   alert('You have to choose a WAN interface as a DNS server OR enter static DNS IP addresses');
               return;
            } else {
               loc = loc + 'dnsIfcsList=' + tempList;
               loc +=  '&dnsPrimary=' + '0.0.0.0';
               loc +=  '&dnsSecondary=' + '0.0.0.0';
               loc += '&dnsRefresh=0';
            }
         }
         else {
            if(dnsPrimary.value == '<%ejGet(ethIpAddress)%>')
            {
               alert('Primary DNS Address "' + dnsPrimary.value + '" is same with the  LAN IP address.');
               return;
            }
		 
            if ( isValidUnicastIpAddress(dnsPrimary.value) == false ) {
               alert('Primary DNS "' + dnsPrimary.value + '" has invalid IP address.');
               return;
            }
            loc += 'dnsPrimary=' + dnsPrimary.value;
            if (dnsSecondary.value != '') {
               if(dnsSecondary.value == '<%ejGet(ethIpAddress)%>')
               {
                  alert('Secondary DNS address "' + dnsSecondary.value + '" is same with the  LAN IP address.');
                  return;
               }
			   
               if ( isValidUnicastIpAddress(dnsSecondary.value) == false ) {
                  alert('Secondary DNS "' + dnsSecondary.value + '" has invalid IP address.');
                  return;
               }
               loc += '&dnsSecondary=' + dnsSecondary.value;
            }
            else
               loc +=  '&dnsSecondary=' + '0.0.0.0';	  	
               loc += '&dnsIfcsList=' + '';
               loc += '&dnsRefresh=1';
         }
      }
      else
         loc = loc + 'dnsIfcsList=';

      if ( enblIpVer != '0' ) {
         if (dns6[0].checked == true) {
            loc += '&dns6Type=DHCP';

            var idx = wanIf6.selectedIndex;
            var ifc = wanIf6.options[idx].value;
            loc += '&dns6Ifc=' + ifc;
         }
         else {
            loc += '&dns6Type=Static';
            if ( isValidIpAddress6(dns6Primary.value) == false ) {
               alert('IPv6 Primary DNS Server "' + dns6Primary.value + '" is invalid address.');
               return;
            }
            loc += '&dns6Pri=' + dns6Primary.value;
            if (dns6Secondary.value != '' && isValidIpAddress6(dns6Secondary.value) == false ) {
               alert('IPv6 Secondary DNS Server "' + dns6Secondary.value + '" is invalid address.');
               return;
            }
            if (dns6Secondary.value != '') {
               loc += '&dns6Sec=' + dns6Secondary.value;
            }
         }
      }
    }

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

function btnBack() {
   var loc = 'ifcgateway.html';

   var code = 'location="' + loc + '"';
   eval(code);
}

function frmLoad() {
   with ( document.forms[0] ) {
      dns[0].checked  = false;
      dns[1].checked  = false;
      dns6[0].checked = false;
      dns6[1].checked = false;

      if (dns1 == '' && prtcl != 'IPoA') {
         dns[0].checked = true;
         dnsPrimary.value = '';
         dnsSecondary.value = '';	  	
      } else {
         dns[1].checked = true;
         dnsPrimary.value = dns1;
         if (dns2 == '0.0.0.0')
            dnsSecondary.value = '';
         else				 
            dnsSecondary.value = dns2;
      }

      if ( enblIpVer != '2' ) {
         if (enblDhcpClnt == 0 && interfaces.length <= 1) {
         }
      }
      else {
         dns[0].disabled = 1;
         dns[1].disabled = 1;
         dnsPrimary.disabled = 1;
         dnsSecondary.disabled = 1;
         selDnsIfcs.disabled = 1;
      }

      if ( enblIpVer != '0' ) {
         if (wanAddr6Type == 'Static' && intf6.length <= 1) {
            dns6[0].disabled = 1;
            dns6[0].checked  = false;
            dns6[1].checked  = true;
         }
         else
         {
            dns6[0].checked  = true;
            dns6[1].checked  = false;
         }

         hideDns6Info(0);
      } else {
         hideDns6Info(1);
      }
   }
}


function btnRemove() {
   with ( document.forms[0] ) {
      var arrSelected = new Array();
      var count = 0;
      for ( i = 0; i < selDnsIfcs.options.length; i++ ) {
         if ( selDnsIfcs.options[i].selected == true ) {
            arrSelected[count] = selDnsIfcs.options[i].value;
         }
         count++;
      }
      var x = 0;
      for (i = 0; i < selDnsIfcs.options.length; i++) {
         for (x = 0; x < arrSelected.length; x++) {
            if (selDnsIfcs.options[i].value == arrSelected[x]) {
               varOpt = new Option(selDnsIfcs.options[i].text, selDnsIfcs.options[i].value);
               availIfcs.options[availIfcs.length] = varOpt;
               selDnsIfcs.options[i] = null;
            }
         }
      }
   }
}

function btnAdd() {
   with ( document.forms[0] ) {
      var arrSelected = new Array();
      var count = 0;
      for ( i = 0; i < availIfcs.options.length; i++ ) {
         if ( availIfcs.options[i].selected == true ) {
            arrSelected[count] = availIfcs.options[i].value;
         }
         count++;
      }
      var x = 0;
      for (i = 0; i < availIfcs.options.length; i++) {
         for (x = 0; x < arrSelected.length; x++) {
            if (availIfcs.options[i].value == arrSelected[x]) {
               varOpt = new Option(availIfcs.options[i].text, availIfcs.options[i].value);
               selDnsIfcs.options[selDnsIfcs.length] = varOpt;
               availIfcs.options[i] = null;
            }
         }
      }
   }
}



// done hiding -->
</script>
   </head>
   <body onLoad='frmLoad()'>
      <blockquote>
         <form>
            <P>
               <b>DNS Server Configuration</b><br><br>
      			
     			Select DNS Server Interface from available WAN interfaces OR enter static DNS server IP addresses for the system.  If only a 
     			single WAN with static IPoE protocol is configured, Static DNS server IP addresses must be entered.<br>
                <b>DNS Server Interfaces</b> can have multiple WAN interfaces served as system dns servers but only one will be used according to
                the priority with the first being the higest and the last one the lowest priority if the WAN interface is connected.  Priority order can be changed
                by removing all and adding them back in again.               
            </P>
     		<br>
     		<table>
	          <tr>
                <td colspan="2"><input type="radio" name="dns" onClick='dnsClick()'><b>&nbsp;&nbsp;Select DNS Server Interface from available WAN interfaces:</b>
                </td>
              </tr>
              
              <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="150">Selected DNS Server Interfaces</td>
                  <td width="100"></td>
                  <td width="150">Available WAN Interfaces</td>
                </tr>
                <tr><td colspan="3">&nbsp;</td></tr>
                <tr>
                  <td>
                    <select multiple name="selDnsIfcs" size="10" style="width: 100">
                      
<script language="javascript">
<!-- hide
{
   	var i = 0;
	var dnsIfcsList;
	
   	if (dnsIfcs == '' && dns1 == '') {
      var names = interfaces[0].split('/');
	  dnsIfcs= names[1];
	  dnsIfcsList = dnsIfcs.split(',');
   	}
	dnsIfcsList = dnsIfcs.split(',');

	for (i = 0; i < dnsIfcsList.length; i++) 
 	   document.writeln("  <option value='" +dnsIfcsList[i] + "'>"+ dnsIfcsList[i]);
}
// done hiding -->
</script>
                      </select>
                   </td>
                  <td>
                     <table border="0" cellpadding="0" cellspacing="5">
                        <tr><td>
                           <input type="button" value="->" onClick="btnRemove()" style="width: 30; height: 30">
                        </td></tr>
                        <tr><td>
                           <input type="button" value="<-" onClick="btnAdd()" style="width: 30; height: 30">
                        </td></tr>
                     </table>
                  </td>
                  <td>
                      <select multiple name="availIfcs" size="10" style="width: 100">

<script language="javascript">
<!-- hide
{
   var i;

   {
      for (i = 0; i < interfaces.length; i++) {
         var names = interfaces[i].split('/');
   	  if (dnsIfcs.search(names[1]) == -1)
           document.writeln("  <option value='" + names[1] + "'>" + names[1]);
      }
   }
}
// done hiding -->
</script>
                        </select></td>
                     </tr>
                     </table>
                  <br>
                  <table>                                                    		   
	               <tr>
	                  <td colspan="2"><input type="radio" name="dns" onClick='dnsClick()'><b>&nbsp;&nbsp;Use the following Static DNS IP address:</b></td>
	               </tr>
                  
                  <tr>
                     <td>Primary DNS server:
                     </td>
                     <td><input type='text' name='dnsPrimary'></td>
                  </tr>
                  <tr>
                     <td>Secondary DNS server:
                     </td>
                     <td><input type='text' name='dnsSecondary'></td>
                  </tr>
                 </table>
                 
               </table>
               
               <br>
            <br>
            
            <div id='dns6Info'>
            <P>
               IPv6:  Select the configured WAN interface for IPv6 DNS server information OR enter the static IPv6 DNS server Addresses.<br>
			   Note that selecting a WAN interface for IPv6 DNS server will enable DHCPv6 Client on that interface.<br><br>
            </P>
               <table>
	              <tr>
	                 <td colspan="2"><input type="radio" name="dns6" onClick='dns6Click()'>&nbsp;&nbsp;Obtain IPv6 DNS info from a WAN interface:</td>
	              </tr>
                  <tr>
	                 <td>WAN Interface selected:</td>
	                 <td><select name='wanIf6'><script language="javascript">
<!-- hide
{
   var i = 0;

   if (wanAddr6Type == 'Static') {
      i = 1;
      if (intf6.length <= 1) {
         document.write("  <option value='&nbsp' selected>NO DHCP6C ENABLED INTERFACE");
         alert('No DHCPv6 Client enabled interface. Choose static ip address for DNS server');
      }
   }
   for ( ; i < intf6.length; i++ ) {
      var names = intf6[i].split('/');

      if ( names[1] == dns6ifc )
         document.write("  <option value='" + names[1] + "' selected>");
      else
         document.write("  <option value='" + names[1] + "'>");
      document.writeln(intf6[i]);
   }
}
// done hiding -->
</script>
                     </select></td>
                  </tr>
                  <tr></tr>
                  <tr></tr>
                  <tr></tr>
	              <tr>
	                 <td colspan="2"><input type="radio" name="dns6" onClick='dns6Click()'>&nbsp;&nbsp;Use the following Static IPv6 DNS address:</td>
	              </tr>
                  <tr>
                     <td>Primary IPv6 DNS server:</td>
                     <td><input type='text' name='dns6Primary'></td>
                  </tr>
                  <tr>
                     <td>Secondary IPv6 DNS server:</td>
                     <td><input type='text' name='dns6Secondary'></td>
                  </tr>
               </table><br><br>
            </div>
            <center>
               <input type='button' onClick='btnBack()' value='Back'><input type='button' onClick='btnNext()' value='Next'>
            </center>
         </form>
      </blockquote>
   </body>
</html>
