var pptp_server_record_next_index = 0;
var pptp_server_record_edit_index = 0;
var pptp_server_max_number = 10;
var pptp_server_count =0;
var pptp_client_record_next_index = 0;
var pptp_client_max_number = 8;
var pptp_client_count =0;
/*
Add/Delete/Edit pptp server account
pptp_account_next_index => �n���J C_WEBUI_VPNPPTPACC_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
pptp_server_record_next_index => �U�@�� account �� index  �� C_PPTPSERV_ACCOUNT_USER �Ĥ@�Ӫťժ�CSID
by kent
*/
var pptp_server_account_csid = new Array(
"N00202040",
"N00202041",
"N00202042",
"N00202043",
"N00202044",
"N00202045",
"N00202046",
"N00202047",
"N00202048",
"N00202049",
""
)
var pptp_server_account_index = new Array(
"1",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
)
var pptp_server_user_csid = new Array(
"S001A0100",
"S001A0101",
"S001A0102",
"S001A0103",
"S001A0104",
"S001A0105",
"S001A0106",
"S001A0107",
"S001A0108",
"S001A0109",
""
)
var pptp_server_password_csid = new Array(
"S001A0200",
"S001A0201",
"S001A0202",
"S001A0203",
"S001A0204",
"S001A0205",
"S001A0206",
"S001A0207",
"S001A0208",
"S001A0209",
""
)
var pptp_server_account_active_csid = new Array(
"N001A0300",
"N001A0301",
"N001A0302",
"N001A0303",
"N001A0304",
"N001A0305",
"N001A0306",
"N001A0307",
"N001A0308",
"N001A0309",
""
)
var pptp_account_next_index = 0;
for(a=0;a<pptp_server_account_index.length;a++)
{
if(pptp_server_account_index[a] == "")
{
pptp_account_next_index = a;
break;
}
}
function add_edit_pptp_server_account(type,edit_user_index)
{
var add_edit_table = document.getElementById("add_edit_account_table");
var add_button = document.getElementById("add_save_button");
var edit_button = document.getElementById("edit_save_button");
var user_name_contant = document.getElementById("pptp_ser_username_text");
var user_password_contant = document.getElementById("pptp_ser_password_text");
var user_active_checked = document.getElementById("pptp_ser_active_check");
var anchor = document.getElementById("_a_anchor");
if(type == 'add')
{
if(pptp_account_next_index == pptp_server_max_number)
{
alert(GetElmCont("pptps_0","Rule could not be added anymore."));
return false;
}
}
else
{
user_name_contant.value = document.getElementById("s_account_username_"+edit_user_index).innerHTML;
user_password_contant.value = document.getElementById("s_account_password_"+edit_user_index).innerHTML;
user_active_checked.checked = (document.getElementById("s_account_active_"+edit_user_index).checked)?"checked":"";
pptp_server_record_edit_index = edit_user_index;
}
add_edit_table.style.display = "";
add_button.style.display = (type == "add")?"":"none";
edit_button.style.display = (type == "add")?"none":"";
anchor.click();
}
function save_pptp_server_user_account(type,obj)
{
var add_user_name = document.getElementById("pptp_ser_username_text").value;
var add_user_password = document.getElementById("pptp_ser_password_text").value;
var add_user_avtive_check = document.getElementById("pptp_ser_active_check").checked;
var add_user_avtive = (add_user_avtive_check)?1:0;
var account_str = "pptps.htm?";
var add_index = pptp_server_record_next_index;
var div_obj =  document.getElementById("d_hidden_element");
var str_message = "";
if(add_user_name == "" || add_user_password == "")
{
str_message = (add_user_name == "")?GetElmCont("_0","Username can not be empty."):GetElmCont("_0","Password can not be empty.");
alert(str_message);
return false;
}
if(type == 'add')
{
account_str += "<input typt='text' name='"+pptp_server_account_csid[pptp_account_next_index]+"' value='"+(add_index+1)+"'>";
account_str += "<input typt='text' name='"+pptp_server_user_csid[add_index]+"' value='"+add_user_name+"'>";
/*  -- �H�U�OPassword�[�K�ɪ��t�@�ؤ��k[�A�Ω��n�[�K��CSID�S���X�{�bHTML�ɸ̡A�άO��CSID�H�}�C�B�r�굥�覡�p�X�e�X������] --  */
/*  -- Password�b�e�X�e�������i���[�K�A�Φr�����N���覡�⥻�ӭn�ǥX��"S?"�令"P?"�A�[�K�����e(function)�@�w�n�g�b�o�̡A�g�bHTML�̭��e���X�{BUG --  */
var encrypt_pw_v = pwd_trans("pptp_ser_password_text");  /*  -- 1.�ɤJ�[�K��function --  */
var encrypt_pw_n = pptp_server_password_csid[add_index];  /*  -- 2.���oCSID�����m --  */
encrypt_pw_n = "P"+encrypt_pw_n.substr(1 , encrypt_pw_n.length);  /*  -- 3.���NCSID��P?�t�C --  */
account_str += "<input typt='text' name='"+encrypt_pw_n+"' value='"+encrypt_pw_v+"'>";  /*  -- 4.�[�K����Password�|�b�o�̦s�J�r�ꤤ�A�b�᭱��submit�Τ@�ǰe�X�h[�����սЦb�����W��] --  */
account_str += "<input typt='text' name='"+pptp_server_account_active_csid[add_index]+"' value='"+add_user_avtive+"'>";
}
else if(type == 'edit')
{
account_str += "<input typt='text' name='"+pptp_server_user_csid[pptp_server_record_edit_index]+"' value='"+add_user_name+"'>";
var encrypt_pw_v = pwd_trans("pptp_ser_password_text");
var encrypt_pw_n = pptp_server_password_csid[pptp_server_record_edit_index];
encrypt_pw_n = "P"+encrypt_pw_n.substr(1 , encrypt_pw_n.length);
account_str += "<input typt='text' name='"+encrypt_pw_n+"' value='"+encrypt_pw_v+"'>";
account_str += "<input typt='text' name='"+pptp_server_account_active_csid[pptp_server_record_edit_index]+"' value='"+add_user_avtive+"'>";
}
div_obj.innerHTML = account_str;
obj.form.submit();
}
function del_pptp_server_user_account()
{
var tmp_del = document.getElementsByName("del_account");
var del_arr = new Array();
var index = 0;
var new_index = 0;
var sent_str ="pptps.htm?N801A0001=1";
for(var t=0;t<tmp_del.length;t++)
{
if(tmp_del[t].checked)
{
del_arr[index] = tmp_del[t].value;
index++;
}
}
if(del_arr.length == 0)
{
alert(GetElmCont("lb_0","Please choose one or more rule."));
return false;
}
for(var r=0;r<pptp_server_account_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(pptp_server_account_index[r] == del_arr[n])
{
pptp_server_account_index[r] = "";
}
}
}
for(var a=0;a<pptp_server_account_csid.length;a++)
{
if(pptp_server_account_index[a] != "")
{
sent_str += (sent_str == "pptps.htm?")?pptp_server_account_csid[new_index]+"="+pptp_server_account_index[a]:"&"+pptp_server_account_csid[new_index]+"="+pptp_server_account_index[a];
new_index++;
}
}
for(var c=new_index;c<pptp_server_account_csid.length-1;c++)
{
sent_str += (sent_str == "pptps.htm?")?pptp_server_account_csid[c]+"=":"&"+pptp_server_account_csid[c]+"=";
}
for(var x=0;x<del_arr.length;x++)
{
var xx = del_arr[x]-1;
sent_str += (sent_str == "pptps.htm?")?pptp_server_user_csid[xx]+"=":"&"+pptp_server_user_csid[xx]+"=";
}
GURL(sent_str);
}
function controlsmit(_b,_tag){
if((document.getElementById('_wary_99')!=null)&&(document.getElementById('_wary_99').value == "Save"))
{
if(smit_str0 == "") { smit_str0 = _tag }
else if((smit_str0 != "")&&(smit_str0 != _tag)&&(_tag != "clr")){
smit_str0 = _tag
}
else if(_tag == "clr"){
if(smit_str0 != ""){
document.getElementById('add_edit_account_table').style.display = 'none';
}
smit_str0 = "";
}
document.getElementById('_wary_99').disabled = _b;
}
}
/*
add pptp server account
*/
/*
Add/Delete/Edit pptp client account
pptp_client_record_length => �n���J C_WEBUI_VPNPPTPCLI_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
pptp_client_record_next_index => �U�@�� account �� index  �� C_PPTP_CLI_TUNLNAME �Ĥ@�Ӫťժ�CSID
by kent
*/
var pptp_client_record_csid = new Array(
"N00202080",
"N00202081",
"N00202082",
"N00202083",
"N00202084",
"N00202085",
"N00202086",
"N00202087",
""
)
var pptp_client_record_index = new Array(
"1",
"",
"",
"",
"",
"",
"",
"",
""
)
var pptp_client_tunlname_csid = new Array(
"S00051200",
"S00051201",
"S00051202",
"S00051203",
"S00051204",
"S00051205",
"S00051206",
"S00051207",
""
)
var pptp_client_tunlen_csid = new Array(
"N00051100",
"N00051101",
"N00051102",
"N00051103",
"N00051104",
"N00051105",
"N00051106",
"N00051107",
""
)
var pptp_client_record_length = 0;
for(var g=0;g<pptp_client_record_index.length;g++)
{
if(pptp_client_record_index[g] == "")
{
pptp_client_record_length = g;
break;
}
}
function add_pptp_client_account(obj)
{
if(pptp_client_record_length != pptp_client_max_number)
{
obj.form.action = "pptpcadd.htm";
obj.form.Ntid.value = (pptp_client_record_next_index+1);
obj.form.Npptpclen.value = pptp_client_record_length;
obj.form.Nrule.value = pptp_client_record_next_index;
obj.form.submit();
}
else
{
alert(GetElmCont("_0","Rule could not be added anymore."));
}
}
function del_pptp_client_user_account()
{
var tmp_del = document.getElementsByName("pptp_client_del");
var del_arr = new Array();
var index = 0;
var new_index = 0;
var sent_str ="pptps.htm?Nserver="+document.forms[0].Nserver.value;
for(var t=0;t<tmp_del.length;t++)
{
if(tmp_del[t].checked)
{
del_arr[index] = tmp_del[t].value;
index++;
}
}
if(del_arr.length == 0)
{
alert(GetElmCont("lb_0","Please choose one or more rule."));
return false;
}
for(var r=0;r<pptp_client_record_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(pptp_client_record_index[r] == del_arr[n])
{
pptp_client_record_index[r] = "";
}
}
}
for(var a=0;a<pptp_client_record_csid.length;a++)
{
if(pptp_client_record_index[a] != "")
{
sent_str += (sent_str == "pptps.htm?")?pptp_client_record_csid[new_index]+"="+pptp_client_record_index[a]:"&"+pptp_client_record_csid[new_index]+"="+pptp_client_record_index[a];
new_index++;
}
}
for(var c=new_index;c<pptp_client_record_csid.length-1;c++)
{
sent_str += (sent_str == "pptps.htm?")?pptp_client_record_csid[c]+"=":"&"+pptp_client_record_csid[c]+"=";
}
for(var r=0;r<del_arr.length;r++)
{
var tunlname_index = del_arr[r]-1;
sent_str += "&"+pptp_client_tunlname_csid[tunlname_index]+"=";
}
for(var r=0;r<del_arr.length;r++)
{
var tunlen_index = del_arr[r]-1;
sent_str += "&"+pptp_client_tunlen_csid[tunlen_index]+"=0";
}
GURL(sent_str);
}
function swInterfc2(obj){
gswan = document.getElementById("s_pptp_cli_wan");
gswan.disabled = ((typeof(obj) == 'object')&&(obj.value == 2))?true:false;
}
function Interfc_bfsmit(obj){
var disop_ix = "X"
for(a=0;a<obj.length;a++){
if(obj.options[a].value==''){ disop_ix = obj.options[a].value ;break; }
}
/*
alert("del ss1="+(!obj.disabled)
+" ,ss2="+(disop_ix != "X")
+" ,ss3="+(obj.value == disop_ix)
+" ,disop_ix='"+disop_ix+"'"
+" ,obj.value='"+obj.value+"'"
)
*/
if((!obj.disabled)&&(disop_ix != "X")&&(obj.value == disop_ix)){
alert(GetElmCont("_xx","Interface has expired, please confirm again.")) ;
return false
}
return true
}
function Interfc_W_sel(sel0 , sel1 , sel2){
/* (sel2 != null) == for edit page
sel0: Name ; sel1: id
*/
arrw=Interfc_info(1) //arrw[0] = Wan1 ; arrw[1] = Wan2 ;arrw[2] = Wan3
str0 ="<select name="+sel0+" id="+sel1+">"
for(o=0;o<arrw.length;o++){
if((sel2!= null)&&((o+1) == sel2)&&(arrw[o] != "0")) { str0+="<option value='' selected>WAN"+(o+1)+"</option>" }
else if((sel2!= null)&&((o+1) == sel2)) { str0+="<option value='"+(o+1)+"' selected>WAN"+(o+1)+"</option>" }
else if(arrw[o] == "0") { str0+="<option value='"+(o+1)+"'>WAN"+(o+1)+"</option>" }
}
str0+="</select>"
return str0
}
function chk_save(){
var id_arr = new Array("t_pptp_cli_tunlname_0","t_pptp_cli_user_0","t_pptp_cli_password_0","peerip");
var alert_message = new Array(GetElmCont("stavpn_0","Tunnel Name"),GetElmCont("wary_0","User Name"),GetElmCont("wary_0","Password"),GetElmCont("wizvpn20_0","Peer IP/Domain"));
var gpptp_c_wan = document.getElementById("s_pptp_cli_wan");
var peer_id = document.getElementById("peerip").value;
var str_message = "";
var tmp_str = "";
var obj_opmode = document.getElementById("opmode_failover")
for(var a=0;a<id_arr.length;a++)
{
tmp_str = document.getElementById(id_arr[a]).value;
if(tmp_str == "")
{
str_message += (str_message == "")?alert_message[a]:" , "+alert_message[a];
}
}
if(str_message != ""){
str_message += GetElmCont("vpn1_0"," can not be empty.");
alert(str_message);
return false;
}
else if(!Interfc_bfsmit(gpptp_c_wan)){ return false; }  // ck Interface
if(obj_opmode.value == 1){ // PPTP/L2TP client :tunnel�Q�אּfailover�A�hconnect type�ݳ]��manual
var cnecttp_obj =(document.getElementById('h_pptp_cli_connect_type_0') != null)?document.getElementById('h_pptp_cli_connect_type_0'):document.getElementById('h_l2tp_cli_connect_type_0') ;
cnecttp_obj.value = 2 ;
}
return true;
}
function chg_LCP(value){
document.getElementById("_t_pptp_cli_lcp_interval_0").disabled = (value == 1)?false:true;
document.getElementById("_t_pptp_cli_lcp_failure_0").disabled = (value == 1)?false:true;
}
function swtun_fover(obj1){ //#--  Operation Mode/FailOver
gopfoved = document.getElementById("opmode_foved")
gopfailover = document.getElementById("opmode_failover")
if((ary_ipsecTN == null)&&(ary_pptpTN == null)&&(ary_l2tpTN == null)&&(ary_greTN == null)) {
for(var t=0;t<gopfailover.length;t++) {
if((gopfailover.value == 1)&&(gopfailover.options[t].value == 0))
{ gopfailover.options[t].selected = true }
if(gopfailover.options[t].value == 1){ gopfailover.options[t].disabled = true }
}
}
if(obj1.value == 1){ create_Tunty(); }
else { gopfoved.innerHTML = ""; }
}