<!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_1");

var brdId = '<%ejGet(boardID)%>';
var sessionKey='<%ejGetOther(sessionKey)%>';
var ovpnIndexName='<%ejGet(ovpnIndexName)%>';
var ovpnStatus = '<%ejGet(ovpnStatus)%>';
var ovpnConfigFile= '<%ejGet(ovpnConfigFile)%>';
var ovpnRunning='<%ejGet(ovpnRunning)%>';
var ovpnNat = '<%ejGet(ovpnNat)%>';
var ovpnFullconeNat = '<%ejGet(ovpnFullconeNat)%>';
/*
function initTranslation() 
{
    var idArray = new Array("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_titleCustom", 
		"ovpn_tipsCustom", "ovpn_confile", "ovpn_upfile");

    setAllIdValue(idArray);
}
*/

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


function formLoad()
{
    //initTranslation();
    with(document.forms[0])
    {
        checkBoxValue(chbRunning, ovpnRunning);
        checkBoxValue(chbNat, ovpnNat);
        checkBoxValue(chbFullconeNat, ovpnFullconeNat);
        natClick(chbNat);
        if(ovpnStatus==0)
        {
            ovpnConfigFile='';
        }
        else if(ovpnStatus==2)
        {
            ovpn_btnBack.disabled=1;
        }
    }
}

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

function removeClick(val) 
{
    if(val == '')
    {
        return;
    }
    var loc = 'openvpn.cmd?action=remove&page=1&rmLst=' + val;
    loc += '&sessionKey=' + sessionKey;
    var code = 'location="' + loc + '"';
    eval(code);
}
function nextClick() 
{
    if(ovpnConfigFile == '')
    {
        if(!checkFileType(document.importForm.fileConfigfile.value, ".ovpn"))
        {
            alert(_("ovpn_alertconfigFile"));  
            return;
        }
        document.importForm.submit();
    }
    else
    {
        with(document.forms[0])
        {
            var loc = 'openvpnmanual2.cgi?ovpnStatus=1';
            loc += '&sessionKey=' + sessionKey;
            if(chbRunning.checked==true)
            {
                loc += '&ovpnRunning=1';
            }
            else
            {
                loc += '&ovpnRunning=0';
            }
            if(chbNat.checked==true)
            {
                loc += '&ovpnNat=1';
                if(chbFullconeNat.checked==true)
                {
                    loc += '&ovpnFullconeNat=1';
                }
                else
                {
                    loc += '&ovpnFullconeNat=0';
                }
            }
            else
            {
                loc += '&ovpnNat=0';
            }
            
            var code = 'location="' + loc + '"';
            eval(code);
        }
    }
}

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 natClick(ctl)
{
    if(ctl.checked==true)
    {
        showhide("tr_fullcone",1);
    }
    else
    {
        showhide("tr_fullcone",0);
    }
}

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

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

// done hiding -->
</script>
</head>
<body onLoad="formLoad()">
<blockquote> <b id="ovpn_titleCustom">OpenVPN Custom Setting  </b><br>
<script language='javascript'>
   document.writeln("<span id='ovpn_tipsCustom'>If the configuration include file path, please use this path</span><font color='red'> /var/openvpn_"+ovpnIndexName+"</font>  ");
</script>
 <br>
  <br>
  <form name="importForm" method="post" ENCTYPE="multipart/form-data" action="openvpnuploadcfg.cgi">
    <table border='1' cellpadding='4' cellspacing='0'>
      <tr>
        <td class='hd' id="ovpn_confile">Config File</td>
        <td class='hd' id="ovpn_remove">Remove</td>
        <td class='hd' id="ovpn_download">Download</td>
      </tr>
      <tr>
        <script language='javascript'>

        if(ovpnConfigFile=='')
        {
            document.writeln("<td align='center'><font color='red' id='ovpn_unloaded'>Not Loaded</font></td>");
            document.writeln("<td align='center'><input type='button' value='Remove'  id='ovpn_btnRemove' disabled></td>");
            document.writeln("<td align='center'><input type='button' onClick='DownloadClick()' id='ovpn_btnDownload' value='Download' disabled></td>");
        }
        else
        {
            document.writeln("<td align='center'><font color='green'>"+ovpnConfigFile+"</font></td>");
            document.writeln("<td align='center'><input type='button' onClick='removeClick(\""+ovpnConfigFile+"\")' value='Remove'  id='ovpn_btnRemove'></td>");
            document.writeln("<td align='center'><input type='button' onClick='DownloadClick()' id='ovpn_btnDownload' value='Download'></td>");
        }

        </script>
      </tr>
    </table>
    <span id='ovpn_upfile'>Upload the configuration file[*.ovpn]</span>
    <script language='javascript'>
        if(ovpnConfigFile=='')
        {
            document.writeln("<input type='file' name='fileConfigfile' id='ovpn_fileConfig'>");
        }
        else
        {
            document.writeln("<input type='file' name='fileConfigfile' id='ovpn_fileConfig' disabled>");
        }
    </script>
    <br>
    <table border="0" cellpadding="0" cellspacing="2" width="100%">
      <tr>
        <td width="40%"><input type='checkbox' name='chbNat' onclick='natClick(this)'><span id='ovpn_ebNat'> Enable NAT</span></td>
      </tr>
      <tr id='tr_fullcone'>
        <td width="40%"><input type='checkbox' name='chbFullconeNat'><span id='ovpn_ebFullconeNat'> Enable Fullcone NAT</span></td>
      </tr>
      <tr>
        <td width="40%"><input type='checkbox' name='chbRunning'><span id='ovpn_ebRunning'>Enable<span></td>
      </tr>
    </table>

      <input type='button' onClick='backClick()' value='Back' id='ovpn_btnBack' name='ovpn_btnBack'>
      &nbsp;
      <input type='button' onClick='nextClick()' value='Next' id='ovpn_btnNext'>

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