var xml="apn_profile.xml?Nwan3g=0"
var profile_account_index_a = [];
var profile_account_next_index_a = 0;
var profile_record_next_index_a = 0;
var profile_account_index_b = [];
var profile_account_next_index_b = 0;
var profile_record_next_index_b = 0;
var profile_max_number = 16;
var profile_count =0;
/*
Add/Delete/Edit external server
profile_account_next_index_a => 要填入 C_WEBUI_VPNPPTPACC_RECORD_RULE 的下一筆 index 用來記錄讀取CSID 得順序
profile_record_next_index_a=> 下一筆的 index  為 C_PPTPSERV_ACCOUNT_USER 第一個空白的CSID
*/
var profile_record_csid_a = [];
var profile_name_csid_a = [];
var profile_apn_csid_a = [];
var profile_account_csid_a = [];
var profile_password_csid_a = [];
var profile_priority_csid_a = [];
var profile_enable_csid_a = [];
var profile_record_csid_b = [];
var profile_name_csid_b = [];
var profile_apn_csid_b = [];
var profile_account_csid_b = [];
var profile_password_csid_b = [];
var profile_priority_csid_b = [];
var profile_enable_csid_b = [];
profile_record_csid_a.push("N00202780");
profile_name_csid_a.push("S001E6C00");
profile_priority_csid_a.push("N001E7600");
profile_enable_csid_a.push("N001E6000");
profile_record_csid_b.push("N002027A0");
profile_name_csid_b.push("S001E6D00");
profile_priority_csid_b.push("N001E7700");
profile_enable_csid_b.push("N001E6100");
profile_record_csid_a.push("N00202781");
profile_name_csid_a.push("S001E6C10");
profile_priority_csid_a.push("N001E7610");
profile_enable_csid_a.push("N001E6010");
profile_record_csid_b.push("N002027A1");
profile_name_csid_b.push("S001E6D10");
profile_priority_csid_b.push("N001E7710");
profile_enable_csid_b.push("N001E6110");
profile_record_csid_a.push("N00202782");
profile_name_csid_a.push("S001E6C20");
profile_priority_csid_a.push("N001E7620");
profile_enable_csid_a.push("N001E6020");
profile_record_csid_b.push("N002027A2");
profile_name_csid_b.push("S001E6D20");
profile_priority_csid_b.push("N001E7720");
profile_enable_csid_b.push("N001E6120");
profile_record_csid_a.push("N00202783");
profile_name_csid_a.push("S001E6C30");
profile_priority_csid_a.push("N001E7630");
profile_enable_csid_a.push("N001E6030");
profile_record_csid_b.push("N002027A3");
profile_name_csid_b.push("S001E6D30");
profile_priority_csid_b.push("N001E7730");
profile_enable_csid_b.push("N001E6130");
profile_record_csid_a.push("N00202784");
profile_name_csid_a.push("S001E6C40");
profile_priority_csid_a.push("N001E7640");
profile_enable_csid_a.push("N001E6040");
profile_record_csid_b.push("N002027A4");
profile_name_csid_b.push("S001E6D40");
profile_priority_csid_b.push("N001E7740");
profile_enable_csid_b.push("N001E6140");
profile_record_csid_a.push("N00202785");
profile_name_csid_a.push("S001E6C50");
profile_priority_csid_a.push("N001E7650");
profile_enable_csid_a.push("N001E6050");
profile_record_csid_b.push("N002027A5");
profile_name_csid_b.push("S001E6D50");
profile_priority_csid_b.push("N001E7750");
profile_enable_csid_b.push("N001E6150");
profile_record_csid_a.push("N00202786");
profile_name_csid_a.push("S001E6C60");
profile_priority_csid_a.push("N001E7660");
profile_enable_csid_a.push("N001E6060");
profile_record_csid_b.push("N002027A6");
profile_name_csid_b.push("S001E6D60");
profile_priority_csid_b.push("N001E7760");
profile_enable_csid_b.push("N001E6160");
profile_record_csid_a.push("N00202787");
profile_name_csid_a.push("S001E6C70");
profile_priority_csid_a.push("N001E7670");
profile_enable_csid_a.push("N001E6070");
profile_record_csid_b.push("N002027A7");
profile_name_csid_b.push("S001E6D70");
profile_priority_csid_b.push("N001E7770");
profile_enable_csid_b.push("N001E6170");
profile_record_csid_a.push("N00202788");
profile_name_csid_a.push("S001E6C80");
profile_priority_csid_a.push("N001E7680");
profile_enable_csid_a.push("N001E6080");
profile_record_csid_b.push("N002027A8");
profile_name_csid_b.push("S001E6D80");
profile_priority_csid_b.push("N001E7780");
profile_enable_csid_b.push("N001E6180");
profile_record_csid_a.push("N00202789");
profile_name_csid_a.push("S001E6C90");
profile_priority_csid_a.push("N001E7690");
profile_enable_csid_a.push("N001E6090");
profile_record_csid_b.push("N002027A9");
profile_name_csid_b.push("S001E6D90");
profile_priority_csid_b.push("N001E7790");
profile_enable_csid_b.push("N001E6190");
profile_record_csid_a.push("N0020278A");
profile_name_csid_a.push("S001E6CA0");
profile_priority_csid_a.push("N001E76A0");
profile_enable_csid_a.push("N001E60A0");
profile_record_csid_b.push("N002027AA");
profile_name_csid_b.push("S001E6DA0");
profile_priority_csid_b.push("N001E77A0");
profile_enable_csid_b.push("N001E61A0");
profile_record_csid_a.push("N0020278B");
profile_name_csid_a.push("S001E6CB0");
profile_priority_csid_a.push("N001E76B0");
profile_enable_csid_a.push("N001E60B0");
profile_record_csid_b.push("N002027AB");
profile_name_csid_b.push("S001E6DB0");
profile_priority_csid_b.push("N001E77B0");
profile_enable_csid_b.push("N001E61B0");
profile_record_csid_a.push("N0020278C");
profile_name_csid_a.push("S001E6CC0");
profile_priority_csid_a.push("N001E76C0");
profile_enable_csid_a.push("N001E60C0");
profile_record_csid_b.push("N002027AC");
profile_name_csid_b.push("S001E6DC0");
profile_priority_csid_b.push("N001E77C0");
profile_enable_csid_b.push("N001E61C0");
profile_record_csid_a.push("N0020278D");
profile_name_csid_a.push("S001E6CD0");
profile_priority_csid_a.push("N001E76D0");
profile_enable_csid_a.push("N001E60D0");
profile_record_csid_b.push("N002027AD");
profile_name_csid_b.push("S001E6DD0");
profile_priority_csid_b.push("N001E77D0");
profile_enable_csid_b.push("N001E61D0");
profile_record_csid_a.push("N0020278E");
profile_name_csid_a.push("S001E6CE0");
profile_priority_csid_a.push("N001E76E0");
profile_enable_csid_a.push("N001E60E0");
profile_record_csid_b.push("N002027AE");
profile_name_csid_b.push("S001E6DE0");
profile_priority_csid_b.push("N001E77E0");
profile_enable_csid_b.push("N001E61E0");
profile_record_csid_a.push("N0020278F");
profile_name_csid_a.push("S001E6CF0");
profile_priority_csid_a.push("N001E76F0");
profile_enable_csid_a.push("N001E60F0");
profile_record_csid_b.push("N002027AF");
profile_name_csid_b.push("S001E6DF0");
profile_priority_csid_b.push("N001E77F0");
profile_enable_csid_b.push("N001E61F0");
var auth_ary=[GetElmCont("wary_0","Auto"),"PAP","CHAP",GetElmCont("wary_0","None")]
function swAPNProfile_list()
{
var t=new Date()
xmlDoc=loadXMLDocs(xml+"&ZT="+t.getTime());
if(xmlDoc==null)return;
var iptype_item = ["IPv4","IPv6","IPv4/6"];
for(i=0;i< sim_arr.length;i++){
var type = sim_arr[i];
var profile_account_index = eval("profile_account_index_"+type)
profile_account_index.length=0;
var div = document.getElementById("d_apn_list_"+type);
var chk_add=0;
var table_str = "<table width=100% border=0 align=center cellpadding=0 cellspacing=0 class='staball'>"
table_str += "<tr class='staball_sum'>";
table_str += "<th width='3%'><span id='_0'>ID</span></th>";
table_str += "<th width='10%'><span id='_0'>Profile Name</span></th>";
table_str += "<th width='12%'><span id='_0'>APN</span></th>";
table_str += "<th width='12%'><span id='_0'>IP Type</span></th>";
table_str += "<th width='10%'><span id='_wary_0'>Username</span></th>";
table_str += "<th width='10%'><span id='_wary_0'>Password</span></th>";
table_str += "<th width='10%'><span id='_wiz30_0'>Authentication</span></th>";
table_str += "<th width='10%'><span id='_lb_0'>Priority</span></th>";
table_str += "<th width='8%'><span id='_wary_0'>Enable</span></th>";
table_str += "<th width='20%'><span id='_sta_0'>Actions</span></th>";
table_str += "</tr>";
var list_id=0;
for(var x=0;x<profile_max_number;x++)
{
profile_rule_index = xmlDoc.getElementsByTagName("profile_rule_index_"+type)[x].childNodes[0];
if(profile_rule_index != null)
{
index = parseInt(profile_rule_index.nodeValue);
xml_index = (index-1);
list_id=list_id+1;
profile_name = xml_getvalue(xmlDoc,"profile_name_"+type,xml_index);
profile_apn = xml_getvalue(xmlDoc,"profile_apn_"+type,xml_index);
profile_iptype = xml_getvalue(xmlDoc,"profile_iptype_"+type,xml_index);
profile_account = xml_getvalue(xmlDoc,"profile_account_"+type,xml_index);
profile_password = xml_getvalue(xmlDoc,"profile_password_"+type,xml_index);
profile_auth = xml_getvalue(xmlDoc,"profile_auth_"+type,xml_index);
profile_priority = xml_getvalue(xmlDoc,"profile_priority_"+type,xml_index);
profile_enable = xml_getvalue(xmlDoc,"profile_enable_"+type,xml_index);
var password_show = "";
password_show = (profile_password != "")?"*****":"";
var enable_check = "";
enable_check = (profile_enable == 1)?"checked":"";
table_str += "<tr align='center'>"
table_str += "<td>"+list_id+"</td>"
table_str += "<td>"+profile_name+"&nbsp;</td>"
table_str += "<td>"+profile_apn+"&nbsp;</td>"
table_str += "<td>"+iptype_item[profile_iptype]+"&nbsp;</td>"
table_str += "<td>"+profile_account+"&nbsp;</td>"
table_str += "<td>"+password_show+"&nbsp;</td>"
table_str += "<td>"+auth_ary[profile_auth]+"&nbsp;</td>"
table_str += "<td>"+profile_priority+"&nbsp;</td>"
table_str += "<td><input type='checkbox' "+enable_check+" disabled>&nbsp;</td>"
button = "<input type='button' id='_wary_0' value='Edit' onclick=\"edit_apn_account(this,'"+type+"',"+xml_index+")\">";
button += "<input type='checkbox' name='profile_del_"+type+"' value='"+(index)+"'><span id=_wary_0>Select</span>";
table_str += "<td align='center'>"+button+"</td>"
table_str += "</tr>"
profile_account_index.push(index);
}
else
{
profile_account_index.push("");
}
}
for(var x=0;x<profile_max_number;x++)
{
apn_priority = xml_getvalue(xmlDoc,"profile_priority_"+type,x);
if(apn_priority == "")
{
if(type=='a') profile_record_next_index_a = x;
if(type=='b') profile_record_next_index_b = x;
break;
}
}
for(a=0;a<profile_account_index.length;a++)
{
if(profile_account_index[a] == "")
{
if(type=='a') profile_account_next_index_a = a;
if(type=='b') profile_account_next_index_b = a;
chk_add=1;
break;
}
}
if(chk_add==0){
if(type=='a') profile_account_next_index_a = profile_max_number;
if(type=='b') profile_account_next_index_b = profile_max_number;
}
table_str += "</table>";
div.innerHTML = table_str;
}
}
function add_apn_account(obj,type)
{
/*
Napnmod:1=add
Napntype: 0=sima,1=simb
Napnlen:記錄C_WEBUI_PRO_SIMA_RECORD_RULE的位置，3G1是從0開始(0-15)，3G2是從16開始(16-32)
Nidx :記錄LIST的順序(+1是為了從1開始排序)
Nrule:記錄PROFILE的index, profile_idx*16+index_3g ,profile_idx 從0開始(0-15),index_3g:3G1是0,3G2是1
*/
var profile_account_next_index = eval("profile_account_next_index_"+type)
var profile_record_next_index = eval("profile_record_next_index_"+type)
if(profile_account_next_index != profile_max_number)
{
obj.form.action = "apn_profilerule.htm";
obj.form.Napnmod.value = 1; //add
obj.form.Napntype.value = (type == 'a')?0:1;
obj.form.Napnlen.value = profile_account_next_index;
obj.form.Nid.value = profile_account_next_index+1;
obj.form.Nidx.value = profile_record_next_index+1;
obj.form.Nrule.value = (profile_record_next_index*16)+0;
obj.form.Slocal.value = (location.pathname =='/primx.htm')?"primx.htm":"primx_sim.htm";
if(chkForm()&&setPW(obj.form)) {
document.getElementById("alter_wanset").disabled = true;
document.getElementById("alter_3g_pin").disabled = true;
document.getElementById("alter_multiwan").disabled = true;
obj.form.submit();
}
}
else
{
alert(GetElmCont("pptps_0","Rule could not be added anymore."));
}
}
function edit_apn_account(obj,type,idx)
{
obj.form.action = "apn_profilerule.htm";
obj.form.Napntype.value = (type == 'a')?0:1; //sima:0,simb:1
obj.form.Nrule.value = (idx*16)+0;
obj.form.Slocal.value = (location.pathname =='/primx.htm')?"primx.htm":"primx_sim.htm";
if(chkForm()&&setPW(obj.form)){
document.getElementById("alter_wanset").disabled = true;
document.getElementById("alter_3g_pin").disabled = true;
document.getElementById("alter_multiwan").disabled = true;
obj.form.submit();
}
}
function del_tunnel(type)
{
var tmp_del = document.getElementsByName("profile_del_"+type);
var record_index = eval("profile_account_index_"+type);
var record_csid = eval("profile_record_csid_"+type);
var del_arr = new Array();
var index = 0;
var new_index = 0;
var sent_str =(location.pathname =='/primx.htm')?"primx.htm?rc=":"primx_sim.htm?rc=";
var iframe = document.getElementById("i_apnlist");
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<record_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(record_index[r] == del_arr[n])
{
record_index[r] = "";
}
}
}
for(var a=0;a<record_index.length;a++)
{
if(record_index[a] != "")
{
sent_str += "&"+record_csid[new_index]+"="+record_index[a];
new_index++;
}
}
for(var c=new_index;c<record_csid.length;c++)
{
sent_str += "&"+record_csid[c]+"=";
}
for(var r=0;r<del_arr.length;r++)
{
var tunlname_index = del_arr[r]-1;
sent_str += "&"+eval("profile_name_csid_"+type+"["+tunlname_index+"]")+"=";
sent_str += "&"+eval("profile_priority_csid_"+type+"["+tunlname_index+"]")+"=";
sent_str += "&"+eval("profile_enable_csid_"+type+"["+tunlname_index+"]")+"=0";
}
iframe.src = sent_str+"&csrftok="+get_csrf_token();
setTimeout("swAPNProfile_list()",1000);
}
swAPNProfile_list()