<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="stylemain.css" type="text/css">
<link rel="stylesheet" href="colors.css" type="text/css">
<meta http-equiv="Pragma" content="no-cache">
<title>OpenVPN</title>
<script language="javascript" src="util.js"></script>
<script language="javascript" src="openvpn_msg.js"></script>
<script language="javascript">
<!-- hide  
var sessionKey='<%ejGetOther(sessionKey)%>';

var mode = '<%ejGet(ovpnMajorMode)%>';

//setLanguage('<%ejGet(webUILanguage)%>'); 
//Butterlate.setTextDomain("advanced_5");

var brdId = '<%ejGet(boardID)%>';
var sessionKey='<%ejGetOther(sessionKey)%>';
var ovpnStatus = '<%ejGet(ovpnStatus)%>';
var ovpnRunning='<%ejGet(ovpnRunning)%>';
var ovpnNat = '<%ejGet(ovpnNat)%>';
var ovpnFullconeNat = '<%ejGet(ovpnFullconeNat)%>';
var ovpnConnName = '<%ejGet(ovpnConnName)%>';
var ovpnIndexName = '<%ejGet(ovpnIndexName)%>';
var ovpnMajorMode = '<%ejGet(ovpnMajorMode)%>';
var ovpnProtocol = '<%ejGet(ovpnProtocol)%>';
var ovpnPort = '<%ejGet(ovpnPort)%>';
var ovpnIpaddrAssign = '<%ejGet(ovpnIpaddrAssign)%>';
var ovpnIpaddrAssignNetmask = '<%ejGet(ovpnIpaddrAssignNetmask)%>';
var ovpnRemoteAddr = '<%ejGet(ovpnRemoteAddr)%>';
var ovpnDevice = '<%ejGet(ovpnDevice)%>';
var ovpnCompress = '<%ejGet(ovpnCompress)%>';
var ovpnPushRoute = '<%ejGet(ovpnPushRoute)%>';
var ovpnPushRouteIp = '<%ejGet(ovpnPushRouteIp)%>';
var ovpnPushRouteNetmask = '<%ejGet(ovpnPushRouteNetmask)%>';
var ovpnClientSubnet = '<%ejGet(ovpnClientSubnet)%>';
var ovpnCntName = '<%ejGet(ovpnCntName)%>';
var ovpnCntSubIp = '<%ejGet(ovpnCntSubIp)%>';
var ovpnCntSubNetmask = '<%ejGet(ovpnCntSubNetmask)%>';
var ovpnAuth= '<%ejGet(ovpnAuth)%>';
var ovpnCipher= '<%ejGet(ovpnCipher)%>';
var ovpnPersistKey= '<%ejGet(ovpnPersistKey)%>';
var ovpnPersistTun= '<%ejGet(ovpnPersistTun)%>';
var ovpnMuteReplay= '<%ejGet(ovpnMuteReplay)%>';
var ovpnNSCertType= '<%ejGet(ovpnNSCertType)%>';
var ovpnKeepAlive1= '<%ejGet(ovpnKeepAlive1)%>';
var ovpnKeepAlive2= '<%ejGet(ovpnKeepAlive2)%>';
var ovpnPKC12File= '<%ejGet(ovpnPKC12File)%>';

var ovpnTLS= '<%ejGet(ovpnTLS)%>';
var ovpnTLSFile= '<%ejGet(ovpnTLSFile)%>';
var ovpnDHFile= '<%ejGet(ovpnDHFile)%>';
var ovpnCAFile= '<%ejGet(ovpnCAFile)%>';
var ovpnCertFile= '<%ejGet(ovpnCertFile)%>';
var ovpnKeyFile= '<%ejGet(ovpnKeyFile)%>';

var ovpnebMtuTest= '<%ejGet(ovpnebMtuTest)%>';
var ovpnebTunMtu= '<%ejGet(ovpnebTunMtu)%>';
var ovpnTunMtu= '<%ejGet(ovpnTunMtu)%>';
var ovpnebMssfix= '<%ejGet(ovpnebMssfix)%>';
var ovpnMssfix= '<%ejGet(ovpnMssfix)%>';
var ovpnMute= '<%ejGet(ovpnMute)%>';
var ovpnVerb= '<%ejGet(ovpnVerb)%>';
var ovpnRemoteAddr= '<%ejGet(ovpnRemoteAddr)%>';

var ovpnpkcs12pwd= '<%ejGet(ovpnpkcs12pwd)%>';

var ovpnC2C= '<%ejGet(ovpnC2C)%>';
var ovpnMaxClients= '<%ejGet(ovpnMaxClients)%>';

var ovpnDupcn= '<%ejGet(ovpnDupcn)%>';
var ovpnTlsTime= '<%ejGet(ovpnTlsTime)%>';
var ovpnLocalAddr= '<%ejGet(ovpnLocalAddr)%>';

var m_server = "server";
var m_client = "client";
var m_port = 1194;

var TYPE_OVPNPK12FILE = "PK12File";
var TYPE_OVPNTLSFILE = "TLSFile";
var TYPE_OVPNDHFILE = "DHFile";
var TYPE_OVPNCAFILE = "CAFile";
var TYPE_OVPNCERTFILE = "CertFile";
var TYPE_OVPNKEYFILE = "KeyFile";

/*
function initTranslation() 
{
    var idArray = new Array("ovpn_title", "ovpn_btnNext", "ovpn_btnBack", "ovpn_btnUpload", "ovpn_btnRemove", 
		"ovpn_btnSave", "ovpn_btnDownload", "ovpn_remove", "ovpn_download", "ovpn_unloaded", 
		"ovpn_ebNat", "ovpn_ebFullconeNat", "ovpn_ebRunning", "ovpn_majorMode", "ovpn_device", 
		"ovpn_protocol", "ovpn_compress", "ovpn_persistKey", "ovpn_persistTun", "ovpn_muteReplay", 
		"ovpn_keepalive", "ovpn_mute", "ovpn_mtuTest", "ovpn_ebTunMtu", "ovpn_tunMtu", "ovpn_ebMssfix", 
		"ovpn_Mssfix", "ovpn_maxClient", "ovpn_c2c", "ovpn_dupcn", "ovpn_ebTLSClient", "ovpn_ebTLSServer", 
		"ovpn_uploadTLS", "ovpn_tlsKey", "ovpn_nsCertType", "ovpn_uploadPK12", "ovpn_pk12file", 
		"ovpn_uploadca", "ovpn_cafile", "ovpn_uploadCert", "ovpn_certfile", "ovpn_uploadkey", 
		"ovpn_keyfile", "ovpn_uploaddh", "ovpn_dhfile", "ovpn_pk12pwd", "ovpn_ipaddrAssign", 
		"ovpn_ipaddrAssignNetmask", "ovpn_port", "ovpn_pushRoute", "ovpn_pushRouteIp", 
		"ovpn_pushRouteNetmask", "ovpn_clientSubnet", "ovpn_cntName", "ovpn_cntSubIp", "ovpn_cipher",
		"ovpn_cntSubNetmask", "ovpn_remoteAddr", "ovpn_localAddr", "ovpn_tlsTime", "ovpn_authentication");
    
    setAllIdValue(idArray);
}
*/

function showhide(str, flag)
{
    var ctl;
    ctl = document.getElementById(str);

    if (flag==1)
    {
        ctl.style.display=''; 
    }
    else 
    {
        ctl.style.display='none'; 
    }
}

function checkBoxValue(ctl,value)
{
    if(value=='0')
    {
        ctl.checked=false;
    }
    else
    {
        ctl.checked=true;
    }
}

function formLoad()
{
    //initTranslation();
    with(document.forms[0])
    {

        var ovpnPushRouteIps = ovpnPushRouteIp.split("|"); 
        var ovpnPushRouteNetmasks =  ovpnPushRouteNetmask.split("|"); 
        
        var ovpnCntNames = ovpnCntName.split("|"); 
        var ovpnCntSubIps = ovpnCntSubIp.split("|"); 
        var ovpnCntSubNetmasks = ovpnCntSubNetmask.split("|"); 
        
        selMajorMode.value = ovpnMajorMode;
        selDevice.value = ovpnDevice;
        selProtocol.value = ovpnProtocol;
        selAuth.value=ovpnAuth;
        selCipher.value=ovpnCipher;
        selVerb.value=ovpnVerb;
        selNsCertType.value = ovpnNSCertType;       
        
        txtPort.value = ovpnPort;
        txtRemoteAddr.value=ovpnRemoteAddr;
        txtKeepAlive1.value = ovpnKeepAlive1;
        txtKeepAlive2.value = ovpnKeepAlive2;
        txtMute.value = ovpnMute;
        txtTunMtu.value = ovpnTunMtu;
        txtMssfix.value = ovpnMssfix;
        txtMaxClients.value = ovpnMaxClients;
        txtIpaddrAssign.value = ovpnIpaddrAssign;
        txtIpaddrAssignNetmask.value = ovpnIpaddrAssignNetmask;
        txtLocalAddr.value = ovpnLocalAddr;
        txtTlsTime.value = ovpnTlsTime;
        
        selPushRoute.value = ovpnPushRoute;
        selClientSubnet.value = ovpnClientSubnet;
                
        pushRouteChange(selPushRoute);
        ClientSubnetChange(selClientSubnet);       
        pwdPkcs12.value = ovpnpkcs12pwd;

        checkBoxValue(chbDupcn,ovpnDupcn);
        checkBoxValue(chbC2C,ovpnC2C);
        checkBoxValue(chbMssfix,ovpnebMssfix);
        checkBoxValue(chbCompress,ovpnCompress);
        checkBoxValue(chbPersistKey,ovpnPersistKey);
        checkBoxValue(chbPersistTun,ovpnPersistTun);
        checkBoxValue(chbMuteReplay,ovpnMuteReplay);
        checkBoxValue(chbMtuTest,ovpnebMtuTest);
        checkBoxValue(chbTunMtu,ovpnebTunMtu);
        checkBoxValue(chbTLS,ovpnTLS);
        checkBoxValue(chbRunning, ovpnRunning);
        checkBoxValue(chbNat, ovpnNat);
        checkBoxValue(chbFullconeNat, ovpnFullconeNat);
           
        showFileTable(ovpnPKC12File,TYPE_OVPNPK12FILE,"td_pkshow","td_pkremove","td_pkdownload","ovpn_filePK12file");
        showFileTable(ovpnDHFile,TYPE_OVPNDHFILE,"td_dhshow","td_dhremove","td_dhdownload","ovpn_fileDHfile");
        showFileTable(ovpnCAFile,TYPE_OVPNCAFILE,"td_cashow","td_caremove","td_cadownload","ovpn_fileCAfile");
        showFileTable(ovpnCertFile,TYPE_OVPNCERTFILE,"td_certshow","td_certremove","td_certdownload","ovpn_fileCertfile");
        showFileTable(ovpnKeyFile,TYPE_OVPNKEYFILE,"td_keyshow","td_keyremove","td_keydownload","ovpn_fileKeyfile");
        showFileTable(ovpnTLSFile,TYPE_OVPNTLSFILE,"td_tlsshow","td_tlsremove","td_tlsdownload","ovpn_fileTLSfile");
        
        showHideClick(chbMssfix);
        showHideClick(chbMtuTest);
        showHideClick(chbTLS);
        showHideClick(chbTunMtu);
        showHideClick(selMajorMode);
        checkBoxValue(chbTLS,ovpnTLS);
        showHideClick(chbNat);
        for(var i=0; i<selPushRoute.value; i++)
        {
            document.getElementById("txtpushRouteIp"+i).value = ovpnPushRouteIps[i];
            document.getElementById("txtpushRouteNetmask"+i).value = ovpnPushRouteNetmasks[i];
        }
        
        for(var i=0; i<selClientSubnet.value; i++)
        {
            document.getElementById("txtCntName"+i).value = ovpnCntNames[i];
            document.getElementById("txtCntSubIp"+i).value = ovpnCntSubIps[i];
            document.getElementById("txtCntSubNetmask"+i).value = ovpnCntSubNetmasks[i];
        }       
    }
}

function DownloadClick(name)
{
    if(name!='')
    {
        var loc = 'openvpnexport.cgi?';
        loc += 'filename=' + name;
        loc += '&sessionKey=' + sessionKey;
        var code = 'location="' + loc + '"';
       eval(code);
    }
}


function showFileTable(obj,type,tipshow,tipremove,tipdownload,ctlfile) 
{
    if(obj=='')
    {
        document.getElementById(tipshow).innerHTML="<font color='red' id='ovpn_unloaded'>Not Loaded</font></td>";
        document.getElementById(tipremove).innerHTML="<input type='button' id='ovpn_btnRemoveClick' value='Remove' disabled>";          
        document.getElementById(tipdownload).innerHTML="<input type='button'  id='ovpn_btnDownload' value='Download' disabled>";
        document.getElementById(ctlfile).disabled=0;
    }
    else
    {
        document.getElementById(tipshow).innerHTML="<font color='green'>"+obj+"</font>";
        document.getElementById(tipremove).innerHTML="<input type='button' onClick='removeClick(\""+ type +"\")' id='ovpn_btnRemoveClick' value='Remove'>";         
        document.getElementById(tipdownload).innerHTML="<input type='button' onClick='DownloadClick(\""+ type +"\")' id='ovpn_btnDownload' value='Download'>";
        document.getElementById(ctlfile).disabled=1;
    }
}


function removeClick(val) 
{
    if(val==TYPE_OVPNTLSFILE)
    {
        ovpnTLSFile ='';
        showFileTable(ovpnTLSFile,TYPE_OVPNTLSFILE,"td_tlsshow","td_tlsremove","td_tlsdownload","ovpn_fileTLSfile");
    }
    else if(val==TYPE_OVPNPK12FILE)
    {
        ovpnPKC12File ='';
        showFileTable(ovpnPKC12File,TYPE_OVPNPK12FILE,"td_pkshow","td_pkremove","td_pkdownload","ovpn_filePK12file");
    }
    else if(val==TYPE_OVPNDHFILE)
    {
        ovpnDHFile ='';
        showFileTable(ovpnDHFile,TYPE_OVPNDHFILE,"td_dhshow","td_dhremove","td_dhdownload","ovpn_fileDHfile");
    }
    else if(val==TYPE_OVPNCAFILE)
    {
        ovpnCAFile ='';
        showFileTable(ovpnCAFile,TYPE_OVPNCAFILE,"td_cashow","td_caremove","td_cadownload","ovpn_fileCAfile");
    }
    else if(val==TYPE_OVPNCERTFILE)
    {
        ovpnCertFile ='';
        showFileTable(ovpnCertFile,TYPE_OVPNCERTFILE,"td_certshow","td_certremove","td_certdownload","ovpn_fileCertfile");
    }
    else if(val==TYPE_OVPNKEYFILE)
    {
        ovpnKeyFile ='';
        showFileTable(ovpnKeyFile,TYPE_OVPNKEYFILE,"td_keyshow","td_keyremove","td_keydownload","ovpn_fileKeyfile");
    }
    else
    {
        alert("Error");
    }
}
function checkFile(file, type, alt) 
{
    if(!checkFileType(file, type))
    {
        alert(_(alt));  
        return false;
    }
    return true;
}
function saveClick() 
{
    var tmp;
    with(document.forms[0])
    {
        if(selMajorMode.value == m_client)
        {
            if ( isValidIpAddress(txtRemoteAddr.value) == false ) 
            {
                alert(_("ovpn_alertIPAddr") + txtRemoteAddr.value + _("ovpn_alertInvalid"));
                return;
            }
            if(ovpnPKC12File=='')
            {
                if(!checkFile(filePK12file.value, ".p12" , "ovpn_alertFilePK12"))
                {
                    return;
                }
            }

        }
        else if(selMajorMode.value == m_server)
        {
             if ( isValidIpAddress(txtIpaddrAssign.value) == false ) 
             {
                alert(_("ovpn_alertIPAddr") + txtIpaddrAssign.value + _("ovpn_alertInvalid"));
                return;
             }
             if(  isValidMaskAddress(txtIpaddrAssignNetmask.value) == false ) 
             {
                alert(_("ovpn_alertSubMask")+ txtIpaddrAssignNetmask.value + _("ovpn_alertInvalid"));
                return;
             }
             if(txtLocalAddr.value!='')
             {
                 if(  isValidIpAddress(txtLocalAddr.value) == false ) 
                 {
                    alert(_("ovpn_alertLocalIPAddr")+ txtLocalAddr.value + _("ovpn_alertInvalid"));
                    return;
                 }
             }
			 		
            if(ovpnCAFile=='')
            {
                if(!checkFile(fileCAfile.value, ".crt" , "ovpn_alertFileCA"))
                {
                    return;
                }
            }
            
            if(ovpnCertFile=='')
            {
		  if(!checkFile(fileCertfile.value, ".crt" , "ovpn_alertFileCert"))
                {
                    return;
                }
            }
            if(ovpnKeyFile=='')
            {            
		  if(!checkFile(fileKeyfile.value, ".key" , "ovpn_alertFileKey"))
                {
                    return;
                }
            }
            
            if(ovpnDHFile=='')
            {
		  if(!checkFile(fileDHfile.value, ".pem" , "ovpn_alertFileDH"))
                {
                    return;
                }
            }
            
            if(selPushRoute.value > 0)
            {
                for(var i=0; i<selPushRoute.value; i++)
                {
                    if ( isValidIpAddress(document.getElementById("txtpushRouteIp"+i).value) == false ) 
                    {
                        alert(_("ovpn_alertIPAddr") + document.getElementById("txtpushRouteIp"+i).value + _("ovpn_alertInvalid"));
                        return;
                    }
                    if(  isValidMaskAddress(document.getElementById("txtpushRouteNetmask"+i).value) == false ) 
                    {
                        alert(_("ovpn_alertSubMask")+ document.getElementById("txtpushRouteNetmask"+i).value + _("ovpn_alertInvalid"));
                        return;
                    }
                }
            }
            if(selClientSubnet.value > 0)
            {
                for(var i=0; i<selClientSubnet.value; i++)
                {
                    if ( isValidNameWSpace(document.getElementById("txtCntName"+i).value) == false ) 
                    {
                        alert(_("ovpn_alertClientName") + document.getElementById("txtCntName"+i).value +'".');
                        return;
                    }

                    if ( isValidIpAddress(document.getElementById("txtCntSubIp"+i).value) == false ) 
                    {
                        alert(_("ovpn_alertIPAddr") + document.getElementById("txtCntSubIp"+i).value + _("ovpn_alertInvalid"));
                        return;
                    }
                    if(  isValidMaskAddress(document.getElementById("txtCntSubNetmask"+i).value) == false ) 
                    {
                        alert(_("ovpn_alertSubMask")+ document.getElementById("txtCntSubNetmask"+i).value + _("ovpn_alertInvalid"));
                        return;
                    }
                }
            }
        }
        tmp = parseInt(txtPort.value);
        if (tmp < 0 || tmp > 65535 || isNaN(tmp)==true)
        {
            alert(_("ovpn_port") + '"' + txtPort.value + '" ' + _("ovpn_alertInvalid"));
            return;
        }    
        if(chbTLS.checked == true)
        {
            if(txtTlsTime.value!='')
            {
                tmp = parseInt(txtTlsTime.value);
                if (tmp < 0 || tmp > 65535 || isNaN(tmp)==true)
                {
                    alert(_("ovpn_tlsTime") + '"' + txtTlsTime.value + '" ' + _("ovpn_alertInvalid"));
                    return;
                }    
            }		
            if(ovpnTLSFile=='')
            {
		  if(!checkFile(fileTLSfile.value, ".key" , "ovpn_alertFileTLS"))
                {
                    return;
                }
            }
        }
		
        if(document.getElementById("tr_tunmtu").style.display == "none")  
        {
            tmp = parseInt(txtTunMtu.value);
            if (tmp < 100 || tmp > 65535 || isNaN(tmp)==true)
            {
                alert(_("ovpn_tunMtu") + '"' + txtTunMtu.value + '" ' + _("ovpn_alertInvalid"));
                return;
            }    
        }
        if(document.getElementById("tr_mssfix").style.display == "none")  
        {
            tmp = parseInt(txtMssfix.value);
            if (tmp < 100 || tmp > 65535 || isNaN(tmp)==true)
            {
                alert(_("ovpn_ebMssfix") + '"' + txtMssfix.value + '" ' + _("ovpn_alertInvalid"));
                return;
            }    
        }
        tmp = parseInt(txtKeepAlive1.value);
        if (tmp < 0 || tmp > 65535 || isNaN(tmp)==true)
        {
            alert(_("ovpn_keepalive") + '"' + txtKeepAlive1.value + '" ' + _("ovpn_alertInvalid"));
            return;
        }    
        tmp = parseInt(txtKeepAlive2.value);
        if (tmp < 0 || tmp > 65535 || isNaN(tmp)==true)
        {
            alert(_("ovpn_keepalive") + '"' + txtKeepAlive2.value + '" ' + _("ovpn_alertInvalid"));
            return;
        }    
        tmp = parseInt(txtMute.value);
        if (tmp < 0 || tmp > 65535 || isNaN(tmp)==true)
        {
            alert(_("ovpn_mute") + '"' + txtMute.value + '" ' + _("ovpn_alertInvalid"));
            return;
        }    
    
        
    }
    document.importForm.submit();
}

function backClick() 
{
    var loc;
    var code;
    if(ovpnStatus==2)
    {
        code = 'location="openvpnview.html"';
    }
    else
    {
        loc = 'openvpnchoice.cgi?ovpnStatus=1';
        loc += '&sessionKey=' + sessionKey;
        code = 'location="' + loc + '"';
    }
    eval(code);
}

function showHideClick(ctl)
{
    with(document.forms[0])
    {
        if(ctl == chbMtuTest)
        {
            /*启动mtutest时，隐藏mssfix，tunmtu*/
            if(ctl.checked==true)
            {
                showhide("tr_ebtunmtu",0);
                showhide("tr_tunmtu",0);				
				
                showhide("tr_ebmssfix",0);				
                showhide("tr_mssfix",0);				
            }
            else
            {
                showhide("tr_ebtunmtu",1);
                showhide("tr_ebmssfix",1);		
                if(chbTunMtu.checked == true)
                {
                     showhide("tr_tunmtu",1);
                }
                else
                {
                     showhide("tr_tunmtu",0);
                }
                
                if(chbMssfix.checked == true)
                {
                     showhide("tr_mssfix",1);	
                }
                else
                {
                     showhide("tr_mssfix",0);	
                }
            }
        }
        else if(ctl == chbMssfix)
        {
            /*启动mssfix,tunmtu时，隐藏mtutest*/
            if(ctl.checked==true)
            {
                showhide("tr_mtuTest",0);
                showhide("tr_mssfix",1);
            }
            else
            {
                if(chbTunMtu.checked == false && selProtocol[selProtocol.selectedIndex].value == 'udp')
                {
                     showhide("tr_mtuTest",1);
		  }
		  
                showhide("tr_mssfix",0);
            }
        }
        else if(ctl == chbTunMtu)
        {
            if(ctl.checked==true)
            {
                showhide("tr_mtuTest",0);
                showhide("tr_tunmtu",1);
            }
            else
            {
                if(chbMssfix.checked == false && selProtocol[selProtocol.selectedIndex].value == 'udp')
                {
                     showhide("tr_mtuTest",1);
		  }
			
                showhide("tr_tunmtu",0);
            }
        }
	else if(ctl == chbNat)
        {
            if(ctl.checked==true)
            {
                showhide("tr_fullcone",1);
            }
            else
            {
                showhide("tr_fullcone",0);
            }
        }   
        else if(ctl == chbTLS)
        {
            if(ctl.checked==true)
            {
                showhide("divTls",1);
            }
            else
            {
                showhide("divTls",0);
            }
        }
        else if(ctl == selMajorMode)
        {
            var mode = ctl[ctl.selectedIndex].value;
            if(mode == m_server)
            {
                showhide("divserver", 1);
                showhide("divserver1", 1);
                showhide("divclient", 0);
                showhide("divclient1", 0);
                document.getElementById('ovpn_ebTLS').innerHTML="<input type='checkbox' name='chbTLS' onClick='showHideClick(this)'><span id='ovpn_ebTLSServer'>Enable TLS-Server</span>";
                
            }
            else if(mode == m_client)
            {
                showhide("divserver", 0);
                showhide("divserver1", 0);
                showhide("divclient", 1);
                showhide("divclient1", 1);
                document.getElementById('ovpn_ebTLS').innerHTML="<input type='checkbox' name='chbTLS' onClick='showHideClick(this)'><span id='ovpn_ebTLSClient'>Enable TLS-Client</span>";
            }		
        }
        else if(ctl == selProtocol)
        {
           /*tcp时，隐藏mtutest*/
           var proto = ctl[ctl.selectedIndex].value;
            if(proto != 'udp')
            {
                showhide("tr_mtuTest", 0);

                showhide("tr_ebtunmtu",1);
                showhide("tr_ebmssfix",1);		
                if(chbTunMtu.checked == true)
                {
                     showhide("tr_tunmtu",1);
                }
                else
                {
                     showhide("tr_tunmtu",0);
                }
                
                if(chbMssfix.checked == true)
                {
                     showhide("tr_mssfix",1);	
                }
                else
                {
                     showhide("tr_mssfix",0);	
                }
				
            }
	     else
	     {
                if(chbTunMtu.checked == false && chbMssfix.checked == false)
                {
                    showhide("tr_mtuTest", 1);

                    if(chbMtuTest.checked==true)
                    {
                        showhide("tr_ebtunmtu",0);
                        showhide("tr_tunmtu",0);                
                        
                        showhide("tr_ebmssfix",0);              
                        showhide("tr_mssfix",0);                
                    }
                    else
                    {
                        showhide("tr_ebtunmtu",1);
                        showhide("tr_ebmssfix",1);      
                        if(chbTunMtu.checked == true)
                        {
                             showhide("tr_tunmtu",1);
                        }
                        else
                        {
                             showhide("tr_tunmtu",0);
                        }
                        
                        if(chbMssfix.checked == true)
                        {
                             showhide("tr_mssfix",1);   
                        }
                        else
                        {
                             showhide("tr_mssfix",0);   
                        }
                    }					
                }
	     }
        }
    }
}

function pushRouteChange(txtctr)
{
    var rowCount = txtctr.value;
    if(rowCount < '0' || rowCount > '5'  || txtctr.value.length >1)
    {
        txtctr.value ='';
        return;
    }
    
    var t = document.getElementById('tbRouteIP');
    var j = t.rows.length;
    while(j>0)
    {
        j--;
        t.deleteRow(j);
    }
    for(var i=0; i<rowCount; i++)
    {
        var tr0 = t.insertRow(-1);
        var td0_1 = document.createElement("td");  
        var td0_2 = document.createElement("td");  
        var tr1 = t.insertRow(-1);
        var td1_1 = document.createElement("td");  
        var td1_2 = document.createElement("td");  
		
        td0_1.width = '40%';
        td0_1.id = 'ovpn_pushRouteIp';

        td1_1.width = '40%';
        td1_1.id = 'ovpn_pushRouteNetmask';
    
        td0_1.innerHTML="Server Subnet";
        td1_1.innerHTML="Server Subnet Netmask";

        td0_2.innerHTML="<input name='txtpushRouteIp"+ i +"' id='txtpushRouteIp"+ i +"' size='20' maxlength='60' type='text'>";
        td1_2.innerHTML="<input name='txtpushRouteNetmask"+ i +"' id='txtpushRouteNetmask"+ i +"' size='20' maxlength='60' type='text'>";
            
        tr0.appendChild(td0_1);
        tr0.appendChild(td0_2);
            
        tr1.appendChild(td1_1);
        tr1.appendChild(td1_2);
    } 
}

function ClientSubnetChange(txtctr)
{
    var rowCount = txtctr.value;
    if(rowCount < '0' || rowCount > '5'  || txtctr.value.length >1)
    {
        txtctr.value ='';
        return;
    }
    
    var t = document.getElementById('tbClientSubnet');
    var j = t.rows.length;
    while(j>0)
    {
        j--;
        t.deleteRow(j);
    }
    for(var i=0; i<rowCount; i++)
    {
        var tr0=t.insertRow(-1);
        var td0_1=document.createElement("td");  
        var td0_2=document.createElement("td");  
        
        var tr1=t.insertRow(-1);
        var td1_1=document.createElement("td");  
        var td1_2=document.createElement("td");  
        
        var tr2=t.insertRow(-1);
        var td2_1=document.createElement("td");  
        var td2_2=document.createElement("td");  
        
        td0_1.width = '40%';
        td0_1.id = 'ovpn_cntName';
        
        td1_1.width = '40%';
        td1_1.id = 'ovpn_cntSubIp';
        
        td2_1.width = '40%';
        td2_1.id = 'ovpn_cntSubNetmask';
        
        td0_1.innerHTML="Client Common Name";
        td1_1.innerHTML="Client Subnet";
        td2_1.innerHTML="Client Subnet Netmask";
        
        td0_2.innerHTML="<input name='txtCntName"+ i +"' id='txtCntName"+ i +"' size='20' maxlength='60' type='text'>";
        td1_2.innerHTML="<input name='txtCntSubIp"+ i +"' id='txtCntSubIp"+ i +"' size='20' maxlength='60' type='text'>";
        td2_2.innerHTML="<input name='txtCntSubNetmask"+ i +"' id='txtCntSubNetmask"+ i +"' size='20' maxlength='60' type='text'>";     
            
        tr0.appendChild(td0_1);
        tr0.appendChild(td0_2);
            
        tr1.appendChild(td1_1);
        tr1.appendChild(td1_2);
        
        tr2.appendChild(td2_1);
        tr2.appendChild(td2_2);
    } 
}
 
// done hiding -->
</script>

<style type="text/css">
/*IE 8*/
select
{
    width:147px;
 }

text
{
    width:150px;
}

.small
{
    width:71px;
}
/*Chrome*/
@media screen and (-webkit-min-device-pixel-ratio:0) 
{
    select
    {
        width:127px;
    }
    
    text
    {
        width:70px;
    }
    
    .small
    {
        width:62px;
    }
}
/*Firefox*/
@-moz-document url-prefix() 
{
    select
    {
        width:100px;
     }
    
    text
    {
        width:70px;
    }
    
    .small
    {
        width:49px;
    }
}


</style>

</head>
<body onLoad="formLoad()">
<blockquote> <b id="ovpn_title">OpenVPN Setting<br>
  </b> <br>
  <br>
  <form name="importForm" method="post" ENCTYPE="multipart/form-data" action="openvpnwebcfg.cgi">
  
  <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr> 
        <td width="40%" id="ovpn_majorMode">OpenVPN Mode</td>
        <td>
           <select name="selMajorMode" onChange="showHideClick(this)">
            <option value="server">server</option>
            <option value="client">client</option>
          </select>
        </td>
     </tr> 

     <tr> 
        <td width="40%" id="ovpn_device">Device</td>
        <td>
           <select name="selDevice">
            <option value="tun" selected>tun</option>
            <option value="tap">tap</option>
          </select>
        </td>
     </tr> 

    <tr> 
        <td width="40%" id="ovpn_protocol">Protocol</td>
        <td>
           <select name="selProtocol" onChange="showHideClick(this)">
            <option value="udp" selected>udp</option>
            <option value="tcp">tcp</option>
          </select>
        </td>
     </tr> 
     
    <tr> 
        <td width="40%" id="ovpn_authentication">Authentication</td>
        <td>
           <select name="selAuth">
            <option value="SHA1" selected>SHA1</option>
            <option value="MD5">MD5</option>
            <option value="none">none</option>
          </select>
        </td>
     </tr> 
     <tr> 
        <td width="40%" id="ovpn_cipher">Cipher</td>
        <td>
           <select name="selCipher">
            <option value="AES-128-CBC">AES-128-CBC</option>
            <option value="AES-256-CBC" selected>AES-256-CBC</option>
            <option value="DES-EDE3-CBC">DES-EDE3-CBC</option>          
            <option value="none">none</option>
          </select>
        </td>
     </tr> 

     <tr> 
      <td width="40%"><input type='checkbox' name='chbCompress'> <span id="ovpn_compress">Enable compression on the VPN link</span></td>
      <td>&nbsp; </td>
     </tr> 
     <tr>
      <td width="40%" id='ovpn_port'> Port </td>
      <td> <input name="txtPort" size="20" maxlength="60" type="text"> </td>
     </tr>
   </table>
<div id="divserver"> 
  <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
      <td width="40%" id='ovpn_ipaddrAssign'> Client IP Address Assignment </td>
      <td> <input name="txtIpaddrAssign" size="20" maxlength="60" type="text"> </td>
   </tr>    
   <tr>
      <td width="40%" id='ovpn_ipaddrAssignNetmask'>Client Netmask Assigment </td>
      <td> <input name="txtIpaddrAssignNetmask" size="20" maxlength="60" type="text"> </td>
   </tr>

   <tr>
      <td width="40%" id='ovpn_localAddr'>Server IP Address </td>
      <td> <input name="txtLocalAddr" size="20" maxlength="60" type="text"> </td>
   </tr>
   

   <tr>
      <td width="40%" id='ovpn_pushRoute'>Push Routes</td>
      <td><select name="selPushRoute" onChange='pushRouteChange(this)'>
         <script language="javascript">
           for(var i=0;i<=5;i++)
           {
                  document.writeln("<option value='"+i+"'>"+i+"</option>");
	    }
           </script>
         </select>
      </td>
   </tr>
  </table>
  
    <table id="tbRouteIP" border="0" cellpadding="0" cellspacing="2" width="100%">
  </table>
  
  <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
      <td width="40%" id='ovpn_clientSubnet'>Routes to the specific client</td>
    <td><select name="selClientSubnet" onChange='ClientSubnetChange(this)'>
          <script language="javascript">
           for(var i=0;i<=5;i++)
           {
                  document.writeln("<option value='"+i+"'>"+i+"</option>");
	    }
           </script>
         </select>
    </td>
    </tr>
  </table>

  <table id="tbClientSubnet" border="0" cellpadding="0" cellspacing="2" width="100%">  
  </table>
  
   <table border="0" cellpadding="0" cellspacing="2" width="100%">
      <tr>
      <td width="40%" id='ovpn_maxClient'> Max Clients </td>
      <td> <input name="txtMaxClients" size="20" maxlength="60" type="text"> </td>
     </tr>
      <tr>
      <td width="40%" ><input type='checkbox' name='chbC2C' ><span id='ovpn_c2c'>Enable Client-To-Client</span> </td>
      <td>&nbsp;  </td>
     </tr>
     
     <tr>
      <td width="40%"><input type='checkbox' name='chbDupcn'><span  id='ovpn_dupcn'>Enable Duplicate-cn</span></td>
      <td>&nbsp;  </td>
     </tr>
     
   </table>
   
  </div>
  <div id="divclient">   
   <table border="0" cellpadding="0" cellspacing="2" width="100%">
      <tr>
      <td width="40%" id='ovpn_remoteAddr'>Server IP address </td>
      <td> <input name="txtRemoteAddr" size="20" maxlength="60" type="text"> </td>
     </tr>
   </table>
  </div>
      <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
      <td width="40%" ><input type='checkbox' name='chbPersistKey'> <span id='ovpn_persistKey'>Enable Persist Key </td>
      <td>&nbsp;</td>
     </tr>
    
     <tr>
      <td width="40%" ><input type='checkbox' name='chbPersistTun' > <span id='ovpn_persistTun'> Enable Persist Tun</span></td>
      <td>&nbsp;</td>
     </tr>
     
     <tr>
      <td width="40%" id='ovpn_keepalive'> Keep Alive </td>
      <td>
       <input name="txtKeepAlive1" maxlength="60" type="text" class="small">
       <input name="txtKeepAlive2" maxlength="60" type="text" class="small">
      </td>
     </tr>
    
      <tr id="tr_mtuTest">
      <td width="40%"><input type='checkbox' name='chbMtuTest' id="chbMtuTest" onClick="showHideClick(this)"><span id='ovpn_mtuTest'>Enable MTU test</span></td>
      <td>&nbsp;</td>
     </tr>
     
     <tr id="tr_ebtunmtu">
      <td width="40%" ><input type='checkbox' name='chbTunMtu' onClick="showHideClick(this)"><span id='ovpn_ebTunMtu'> Enable tun MTU </span></td>
      <td>&nbsp;</td>
     </tr>
     <tr id="tr_tunmtu">
      <td width="40%" id='ovpn_tunMtu'>Tun MTU</td>
      <td> <input name="txtTunMtu" maxlength="60" type="text" class="small"> </td>
     </tr>
     
     <tr id="tr_ebmssfix">
      <td width="40%"><input type='checkbox' name='chbMssfix' onClick="showHideClick(this)"><span  id='ovpn_ebMssfix'>Enable MSSFIX </span></td>
      <td>&nbsp; </td>
     </tr>
     <tr id="tr_mssfix">
      <td width="40%" id='ovpn_Mssfix'>MSSFIX</td>
      <td> <input name="txtMssfix" maxlength="60" type="text" class="small"> </td>
     </tr>
    
  </table>
    <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
      <td width="40%" id='ovpn_ebTLS'><input type='checkbox' name='chbTLS' onClick="showHideClick(this)"><span id='ovpn_ebTLSServer'>Enable TLS-Server</span></td>   
      <td>&nbsp;</td>
     </tr>
     
   </table>   
 <div id='divTls'>
  <table border="0" cellpadding="0" cellspacing="2" width="100%">
      <tr>
        <td width="40%" id='ovpn_tlsTime'>TLS Timeout</td>
        <td> <input name="txtTlsTime" maxlength="60" type="text" class="small"> </td>
      </tr>
    <tr>
        <td width="40%" id='ovpn_uploadTLS'>Upload TLS Key[ta.key]</td>
        <td>&nbsp; </td>
      </tr>
  </table>
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id='ovpn_tlsKey'>TLS Key</td>
        <td class='hd' id='ovpn_remove'>Remove</td>
        <td class='hd' id='ovpn_download'>Download</td>
      </tr>
      <tr>
        <td align='center' id='td_tlsshow'>&nbsp;</td>
        <td align='center' id='td_tlsremove'>&nbsp;</td>
        <td align='center' id='td_tlsdownload'>&nbsp;</td>
      </tr>
    </table>
     <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
       <td><input type='file' name='fileTLSfile' id='ovpn_fileTLSfile'></td>
     </tr>
    </table>
  </div>

<div id='divclient1'>
  <table border="0" cellpadding="0" cellspacing="2" width="100%">
   <tr>
        <td width="40%" id='ovpn_nsCertType'>NS-Cert-Type</td>
        <td> 
          <select name="selNsCertType">
            <option value="server" selected>server</option>
            <option value="client">client</option>
          </select>
         </td>
     </tr>
  
    <tr>
        <td width="40%" id='ovpn_pk12pwd'>PKCS12 password</td>  
        <td><input type='password' name='pwdPkcs12'></td>
   </tr>
  
    <tr>
        <td width="40%" id='ovpn_uploadPK12'>Upload PKCS12 certificate[*.p12]</td>  
   </tr>
  </table>
  
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id='ovpn_pk12file'>PKCS12 Certificate</td>
        <td class='hd' id='ovpn_remove'>Remove</td>
        <td class='hd' id='ovpn_download'>Download</td>
      </tr>
      <tr>
      <td align='center' id='td_pkshow'>&nbsp;</td>
      <td align='center' id='td_pkremove'>&nbsp;</td>
      <td align='center' id='td_pkdownload'>&nbsp;</td>
      </tr>
    </table>

     <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
        <td><input type='file' name='filePK12file' id='ovpn_filePK12file'></td>
     </tr>
    </table>

    
    </div>
    <div id="divserver1"> 
    <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
        <td width="40%" id='ovpn_uploadca'>Upload root CA certificate[ca.crt]</td>  
   </tr>
  </table>
  
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id='ovpn_cafile'>CA </td>
        <td class='hd' id='ovpn_remove'>Remove</td>
        <td class='hd' id='ovpn_download'>Download</td>
      </tr>
      <tr>
      <td align='center' id='td_cashow'>&nbsp;</td>
      <td align='center' id='td_caremove'>&nbsp;</td>
      <td align='center' id='td_cadownload'>&nbsp;</td>
      </tr>
    </table>

    <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
        <td><input type='file' name='fileCAfile' id='ovpn_fileCAfile'></td>
     </tr>
    </table>
    
    <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
        <td width="40%" id='ovpn_uploadcert'>Upload Local Certificate [*.crt]</td> 
   </tr>
  </table>
  
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id='ovpn_certfile'>Local Certificate </td>
        <td class='hd' id='ovpn_remove'>Remove</td>
        <td class='hd' id='ovpn_download'>Download</td>
      </tr>
      <tr>
      <td align='center' id='td_certshow'>&nbsp;</td>
      <td align='center' id='td_certremove'>&nbsp;</td>
      <td align='center' id='td_certdownload'>&nbsp;</td>
      </tr>
    </table>

    <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
        <td><input type='file' name='fileCertfile' id='ovpn_fileCertfile'></td>
     </tr>
    </table>
    
    <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
        <td width="40%" id='ovpn_uploadkey'>Upload Local Private Key [.key]</td>  
   </tr>
  </table>
  
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id='ovpn_keyfile'>Local Private Key </td>
        <td class='hd' id='ovpn_remove'>Remove</td>
        <td class='hd' id='ovpn_download'>Download</td>
      </tr>
      <tr>
      <td align='center' id='td_keyshow'>&nbsp;</td>
      <td align='center' id='td_keyremove'>&nbsp;</td>
      <td align='center' id='td_keydownload'>&nbsp;</td>
      </tr>
    </table>

   <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
        <td><input type='file' name='fileKeyfile' id='ovpn_fileKeyfile'></td>
     </tr>
    </table>
    
    <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
        <td width="40%" id='ovpn_uploaddh'>Upload Diffie-Hellman [dh1024.pem]</td>  
   </tr>
  </table>
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id='ovpn_dhfile'>Diffie-Hellman </td>
        <td class='hd' id='ovpn_remove'>Remove</td>
        <td class='hd' id='ovpn_download'>Download</td>
      </tr>
      <tr>
      <td align='center' id='td_dhshow'>&nbsp;</td>
      <td align='center' id='td_dhremove'>&nbsp;</td>
      <td align='center' id='td_dhdownload'>&nbsp;</td>
      </tr>
    </table>

   <table border="0" cellpadding="0" cellspacing="2" width="100%">
     <tr>
        <td><input type='file' name='fileDHfile' id='ovpn_fileDHfile'></td>
     </tr>
    </table>
    
    </div>

  <table border="0" cellpadding="0" cellspacing="2" width="100%">
    <tr>
        <td width="40%" ><input type='checkbox' name='chbNat' onclick='showHideClick(this)'><span id='ovpn_ebNat'>Enable NAT</span></td>
       <td>&nbsp; </td>
      </tr>
      <tr id='tr_fullcone'>
        <td width="40%" ><input type='checkbox' name='chbFullconeNat'><span id='ovpn_ebFullconeNat'>Enable Fullcone NAT</span></td>
       <td>&nbsp; </td>
      </tr>
     
     <tr>
       <td width="40%"><input type='checkbox' name='chbMuteReplay'><span id='ovpn_muteReplay'> Enable Mute Replay Warnings</span></td>
       <td>&nbsp; </td>
     </tr>
      
      <tr>
      <td width="40%" id='ovpn_mute'>Mute</td>
      <td><input name="txtMute" size="10" maxlength="60" type="text" class="small"> </td>
      </tr>
       <tr>
        <td width="40%" id='ovpn_loglevel'>Log Level</td>
        <td><select name="selVerb" class="small">     
        <script language='javascript'>
        for(var i=0;i<16;i++)
        {
            if(i==3)
            {
                document.writeln("<option value="+i+" selected>"+i+"</option>");
            }
            else
            {
                document.writeln("<option value="+i+">"+i+"</option>");
            }           
        }           
        </script>
          </select></td>
      </tr>
     <tr>
        <td width="40%"><input type='checkbox' name='chbRunning'><span id='ovpn_ebRunning'>Enable</span></td>
        <td>&nbsp;</td>
      </tr>  

      
    </table>

      <input type='button' onClick='backClick()' value='Back' id='ovpn_btnBack' name='ovpn_btnBack'>
      &nbsp;
      <input type='button' onClick='saveClick()' value='Save' id='ovpn_btnSave'>

    <br>
    <br>
  </form>
</blockquote>
</body>
</html>
