function copy_list(){
$.ajax({
url:"ftp_useraccount.xml",
type: 'GET',
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var table = $("#t_user_list");
var tr_x = $("#t_user_list tr").length;
var list_l = $(xml).find("acclist_inx_v").length;
var list_str = "";
var enable_status = "";
ftp_acclist_inx_v = [];
ftp_accname_v = [];
ftp_accdir_v = [];
ftp_accpriv_v = [];
ftp_accen_v = [];
for(var q=tr_x-1;q>0;q--){
$("#t_user_list tr").eq(q).remove();
}
for(var a=0;a<list_l;a++){
ginx = $(xml).find("acclist_inx_v").eq(a).text();
gname_v = $(xml).find("accname_v").eq(a).text();
gaccdir_v = $(xml).find("accdir_v").eq(a).text();
gaccpriv_v = $(xml).find("accpriv_v").eq(a).text();
gaccen_v = $(xml).find("accen_v").eq(a).text();
ftp_acclist_inx_v.push(ginx);
ftp_accname_v.push(gname_v);
ftp_accdir_v.push(gaccdir_v);
ftp_accpriv_v.push(gaccpriv_v);
ftp_accen_v.push(gaccen_v);
}
for(var z=0;z<list_l;z++){
var cnt = parseInt(ftp_acclist_inx_v[z])-1;
if(cnt>= 0){
enable_status = (ftp_accen_v[cnt] == 1)?"checked":"";
str01 = (ftp_accpriv_v[cnt] == '1')?"Read/Write":"Read-Only";
list_str += "<tr align=center>";
list_str += "<td>"+(z+1)+"</td>";
list_str += "<td>"+ftp_accname_v[cnt]+"</td>";
list_str += "<td>****</td>";
list_str += "<td>"+ftp_accdir_v[cnt]+"</td>";
list_str += "<td>"+str01+"</td>";
list_str += "<td><input type='checkbox' "+enable_status+" disabled></td>";
list_str += "<td><input type='button' value='Edit' onclick='show_table(1,"+cnt+")'>"
list_str += "<input type='checkbox' name='user_del' value=\""+cnt+"\" style='margin-left:10px'><span>Select</span></td>";
list_str += "</tr>"
}
}
table.append(list_str);
}})
}
function show_table(type,index){
/* type:0 => add table ; typr:1 => edit table */
$("#t_storage_web_curdir").val("/");
$.ajax({
url:"ftp_useraccount.xml",
type: 'GET',
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var list_l = $(xml).find("acclist_inx_v").length;
ftp_acclist_inx_v = [];
ftp_accname_v = [];
ftp_accpw_v = [];
ftp_accdir_v = [];
ftp_accpriv_v = [];
ftp_accen_v = [];
for(var a=0;a<list_l;a++){
ginx = $(xml).find("acclist_inx_v").eq(a).text();
gname_v = $(xml).find("accname_v").eq(a).text();
gaccpw_v = $(xml).find("accpw_v").eq(a).text();
gaccdir_v = $(xml).find("accdir_v").eq(a).text();
gaccpriv_v = $(xml).find("accpriv_v").eq(a).text();
gaccen_v = $(xml).find("accen_v").eq(a).text();
ftp_acclist_inx_v.push(ginx);
ftp_accname_v.push(gname_v);
ftp_accpw_v.push(gaccpw_v);
ftp_accdir_v.push(gaccdir_v);
ftp_accpriv_v.push(gaccpriv_v);
ftp_accen_v.push(gaccen_v);
}
var user_enable = document.getElementById("t_user_enable");
var user_name = document.getElementById("t_user_name");
var user_dir = document.getElementById("s_file_name");
var user_dir_h = document.getElementById("t_usb_file_path");
var user_Perm = document.getElementById("s_user_permission");
var user_passsword = document.getElementById("t_user_password");
swids("t_user_table", true);
swids("b_add", type == 0);
swids("b_edit", type == 1);
if(type == 1){ // typr:1 => edit table
edit_index = index;
user_name.value = ftp_accname_v[index];
user_passsword.value = ftp_accpw_v[index];
user_dir_h.value = ftp_accdir_v[index];
user_dir.innerHTML = ftp_accdir_v[index];
user_Perm.value = ftp_accpriv_v[index];
user_enable.checked = (ftp_accen_v[index] == 1)?true:false;
}
else{ // type:0 => add table
edit_index = "";
user_name.value = "";
user_passsword.value = "";
user_dir.innerHTML = "";
user_Perm.value = 1;    //Read/Write
user_enable.checked = true;
}
}})
}
function user_add_save(){
$.ajax({
url:"ftp_useraccount.xml",
type: 'GET',
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var list_l = $(xml).find("acclist_inx_v").length;
var no0 = "X";
var no1 = "X";
ftp_acclist_inx_n = [];
ftp_accname_n = [];
ftp_accname_vall = [];
ftp_accpw_n = [];
ftp_accdir_n = [];
ftp_accpriv_n = [];
ftp_accen_n = [];
for(var a=0;a<list_l;a++){
ginx = $(xml).find("acclist_inx_v").eq(a).text();
gname_v = $(xml).find("accname_v").eq(a).text();
no0 = ((ginx=="")&&(no0=="X"))?a:no0;     // List 順序inx
no1 = ((gname_v=="")&&(no1=="X"))?a:no1;  // 功能CSID inx
if((no0!="X")&&(no1!="X")){
gacclist_inx_n = $(xml).find("acclist_inx_n").eq(no0).text();
gname_n = $(xml).find("accname_n").eq(no1).text();
gaccpw_n = $(xml).find("accpw_n").eq(no1).text();
gaccdir_n = $(xml).find("accdir_n").eq(no1).text();
gaccpriv_n = $(xml).find("accpriv_n").eq(no1).text();
gaccen_n = $(xml).find("accen_n").eq(no1).text();
ftp_acclist_inx_n.push(gacclist_inx_n+"="+(parseInt(no1)+1));
ftp_accname_n.push(gname_n);
ftp_accpw_n.push(gaccpw_n);
ftp_accdir_n.push(gaccdir_n);
ftp_accpriv_n.push(gaccpriv_n);
ftp_accen_n.push(gaccen_n);
}
ftp_accname_vall.push(gname_v);
}
var sent_str ="";
var add_name = document.getElementById("t_user_name").value;
var add_passsword = document.getElementById("t_user_password").value;
var add_user_dir = document.getElementById("t_usb_file_path").value;
var add_user_priv = document.getElementById("s_user_permission").value;
var add_enable = document.getElementById("t_user_enable").checked;
var add_en_value = (add_enable)?1:0;
var ck_L = ftp_accname_vall.length
if(ftp_accname_vall[(ck_L-1)] != ""){
alert(GetElmCont("_0","20 User is full!"))
return;
}
if(check1(add_name) == 0 || check2(add_passsword) == 0){
return;
}
for(a=0;a<ck_L;a++){
if(ftp_accname_vall[a] != "" && add_name == ftp_accname_vall[a]){
alert(GetElmCont("_1","UserName duplicated!"))
return;
}
}
if(add_user_dir == "") { add_user_dir = "/";
pw_encry = ftp_accpw_n[0];
pw_encry = pw_encry.replace(/S/ig,"P");
add_passsword = pwd_trans(document.getElementById("t_user_password").id);
var sent_str = "hide.htm?"+ftp_accname_n[0]+"="+add_name+"&"+pw_encry+"="+add_passsword+"&"
+ftp_accdir_n[0]+"="+add_user_dir+"&"+ftp_accpriv_n[0]+"="+add_user_priv+"&"
+ftp_accen_n[0]+"="+add_en_value+"&"+ftp_acclist_inx_n[0]+"&"
+"N801F0311=1"
sent_str +="&csrftok="+get_csrf_token();
$("#iframeH").attr("src",sent_str);
document.getElementById('show_pw').checked = false;
document.getElementById('t_user_password').type = "password";
setTimeout("copy_list()",2000);
close_table();
}}
})
}
function user_edit_save(){
$.ajax({
url:"ftp_useraccount.xml",
type: 'GET',
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var list_l = $(xml).find("acclist_inx_v").length;
var no1 = edit_index;
ftp_accname_n = [];
ftp_accname_vall = [];
ftp_accpw_n = [];
ftp_accdir_n = [];
ftp_accpriv_n = [];
ftp_accen_n = [];
for(var a=0;a<list_l;a++){
gname_v = $(xml).find("accname_v").eq(a).text();
if(a == no1){
gname_n = $(xml).find("accname_n").eq(no1).text();
gaccpw_n = $(xml).find("accpw_n").eq(no1).text();
gaccdir_n = $(xml).find("accdir_n").eq(no1).text();
gaccpriv_n = $(xml).find("accpriv_n").eq(no1).text();
gaccen_n = $(xml).find("accen_n").eq(no1).text();
ftp_accname_n.push(gname_n);
ftp_accpw_n.push(gaccpw_n);
ftp_accdir_n.push(gaccdir_n);
ftp_accpriv_n.push(gaccpriv_n);
ftp_accen_n.push(gaccen_n);
}
ftp_accname_vall.push(gname_v);
}
var sent_str ="";
var edit_name = document.getElementById("t_user_name").value;
var edit_passsword = document.getElementById("t_user_password").value;
var add_user_dir = document.getElementById("t_usb_file_path").value;
var add_user_priv = document.getElementById("s_user_permission").value;
var edit_enable = document.getElementById("t_user_enable").checked;
var edit_en_value = (edit_enable)?1:0;
if(check1(edit_name) == 0 || check2(edit_passsword) == 0){
return;
}
for(a=0;a<list_l;a++){
if(ftp_accname_vall[a] != "" && edit_name == ftp_accname_vall[a] && a != edit_index){
alert(GetElmCont("_1","UserName duplicated!"))
return;
}
}
if(add_user_dir == "") { add_user_dir = "/"; }
pw_encry = ftp_accpw_n[0];
pw_encry = pw_encry.replace(/S/ig,"P");
edit_passsword = pwd_trans(document.getElementById("t_user_password").id);
var sent_str = "hide.htm?"+ftp_accname_n[0]+"="+edit_name+"&"+pw_encry+"="+edit_passsword+"&"
+ftp_accdir_n[0]+"="+add_user_dir+"&"+ftp_accpriv_n[0]+"="+add_user_priv+"&"
+ftp_accen_n[0]+"="+edit_en_value+"&N801f0311=1" ;
sent_str +="&csrftok="+get_csrf_token();
$("#iframeH").attr("src",sent_str);
document.getElementById('show_pw').checked = false;
document.getElementById('t_user_password').type = "password";
setTimeout("copy_list()",2000);
close_table();
}})
}
function user_delect(){
$.ajax({
url:"ftp_useraccount.xml",
type: 'GET',
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var list_l = $(xml).find("acclist_inx_v").length;
ftp_acclist_inx_v = [];
ftp_acclist_inx_n = [];
ftp_accname_n = [];
ftp_accen_n = [];
for(var a=0;a<list_l;a++){
ginx = $(xml).find("acclist_inx_v").eq(a).text();
gacclist_inx_n = $(xml).find("acclist_inx_n").eq(a).text();
gname_n = $(xml).find("accname_n").eq(a).text();
gaccen_n = $(xml).find("accen_n").eq(a).text();
ftp_acclist_inx_v.push(ginx);
ftp_acclist_inx_n.push(gacclist_inx_n);
ftp_accname_n.push(gname_n);
ftp_accen_n.push(gaccen_n);
}
var tmp_del = document.getElementsByName("user_del");
var del_arr = new Array();
var index = 0;
var del_index =0;
var new_index = 0;
var sent_str ="hide.htm?";
var iframe = document.getElementById("iframeH");
var show_message = 0;
var show_message_str = "";
for(var t=0;t<tmp_del.length;t++)
{
if(tmp_del[t].checked)
{
del_arr[del_index] = parseInt(tmp_del[t].value)+1;  //del_arr[del_index] 要刪掉的item
del_index++;
}
}
if(del_arr.length == 0)
{
alert(GetElmCont("lb_0","Please choose one or more rule."));
return false;
}
for(var r=0;r<ftp_acclist_inx_v.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(ftp_acclist_inx_v[r] == del_arr[n])
{
ftp_acclist_inx_v[r] = "";
}
}
}
for(var a=0;a<ftp_acclist_inx_n.length;a++){
if(ftp_acclist_inx_v[a] != "")
{
sent_str += (sent_str == "hide.htm?")?ftp_acclist_inx_n[new_index]+"="+ftp_acclist_inx_v[a]:"&"+ftp_acclist_inx_n[new_index]+"="+ftp_acclist_inx_v[a];
new_index++;
}
}
for(var c=new_index;c<ftp_acclist_inx_n.length;c++){
sent_str += (sent_str == "hide.htm?")?ftp_acclist_inx_n[c]+"=":"&"+ftp_acclist_inx_n[c]+"=";
}
for(var x=0;x<del_arr.length;x++){
var xx = del_arr[x]-1;
sent_str += (sent_str == "hide.htm?")?ftp_accname_n[xx]+"=":"&"+ftp_accname_n[xx]+"=";
}
sent_str += "&N801F0311=1"
sent_str+='&csrftok='+get_csrf_token();
$("#iframeH").attr("src",sent_str);
setTimeout("copy_list()",2000);
}})
}
function close_table(){
swids("t_user_table", false);
}
function check1(string)
{
var add_name = document.getElementById("t_user_name");
var add_passsword = document.getElementById("t_user_password");
if((string.length>15) || (string.length<1))
{
alert(GetElmCont("_4","Please input string lentgh in range 1~15."));
add_name.value = "";
return 0;
}
if (chksafe(string)==0)
{
alert(GetElmCont("_5","Please don't input {'},{\\},{、},{,},{;},{/} ,{:},{|},{space},\n{~},{!},{@},{#},{$},{%},{^},{&},{*},{(},{)},\n{[},{]},{<},{>},{.},{?},{\"},{+},{=},{{},{}}...,special characters."));
add_name.value = "";
add_passsword.value = "";
return 0;
}
if(chkname(string)==0)
{
alert(GetElmCont("_6","Please don't input {root},{guest},{nobody},{ftp} to be username!"));
add_name.value = "";
add_passsword.value = "";
return 0;
}
flag = isNaN(string.charAt(0));
if (flag == false)
{
alert(GetElmCont("_7","The first character of username could not be digit number!"));
add_name.value = "";
add_passsword.value = "";
return 0;
}
return 1;
}
function check2(string)
{
var add_passsword = document.getElementById("t_user_passsword");
if((string.length>15) || (string.length == 0))
{
alert(GetElmCont("_4","Please input string lentgh in range 1~15."));
add_passsword.value = "";
return 0;
}
return 1;
}
function chksafe(a)
{
fibdn = new Array ("'" ,"\\", "、", ",", ";", "/" ,":" ,"|" ," ",
"~","!","@","#","$","%","^","&","*","(",")",
"{","}","[","]","<",">",".","?","\"","+","=" );
i=fibdn.length;
j=a.length;
for (ii=0;ii<i;ii++)
{
for (jj=0;jj<j;jj++)
{
temp1=a.charAt(jj);
temp2=fibdn[ii];
if (temp1==temp2)
{
return 0;
}
}
}
return 1;
}
function chkname(a)
{
a=a.toLowerCase();
if(a=="root")
{
return 0;
}
if(a=="guest")
{
return 0;
}
if(a=="nobody")
{
return 0;
}
if(a=="ftp")
{
return 0;
}
return 1;
}
function ftp_show_usb_list(){
var table = $("#t_usfb_list");
var table_count = $("#t_usfb_list tr").length;
var str = "<tr><td><img src=/folder0.gif><a href=javascript:ftp_up_folder();>Up folder"
+"</a></td></tr>";
var web_surdir = $("#t_storage_web_curdir").val();
usd_arr = [];
for(var a=table_count-1;a>=0;a--)
{
$("#t_usfb_list tr").eq(a).remove();
}
$.ajax({
url:"usb_fwug.xml?S801F0334="+web_surdir+'&csrftok='+get_csrf_token(),
type: 'GET',
dataType: 'xml',//資料型態可以不設定，且此型態不可是text或html
error: function(xml){
},
success: function(xml){
var data = $(xml).find("usb_data");
var data_length = $(xml).find("usb_data").length;
var data_content = "";
for(var a=0;a<data_length;a++)
{
data_content = data.eq(a).text();
if(data_content != "")
{
usd_arr.push(data_content);
}
}
for(var x=0;x<usd_arr.length;x++)
{
str += ftp_List(usd_arr[x]);
}
table.append(str);
}})
}
function ftp_List(v){
var str = "";
vsplt=v.split("|")
for(h=1;h<200;h++){
if(!eval("document.getElementById('ttr"+h+"')"))
break; //ttr? not exit
}
aa=h;
for(a=1;a<vsplt.length-1;a++){
df=vsplt[a].split(",");
if(df[0]=="D"){  //folder
str += "<tr id='ttr"+aa+"'><td><pre>&nbsp;&nbsp;<img src='/folder0.gif'>";
str += "<a href=javascript:ftp_select_tr("+aa+"); ondblclick=ftp_copyfd(1,"+aa+");>"+
"<font color=#695e4a><span id='show"+aa+"'>"+df[1]+"</span></font></a>";
str += "</pre></td></tr>"
aa++;
}
}
/*  -- file 不顯示 --
bb=aa;
for(b=1;b<vsplt.length-1;b++)
{
df=vsplt[b].split(",");
if(df[0]=="F")  //file
{
str += "<tr id='ttr"+bb+"'><td><pre>&nbsp;&nbsp;<img src='/item0.gif'>";
str += "<a href=javascript:ftp_select_tr("+bb+"); ondblclick=ftp_copyfd(2,"+bb+");><font color=#695e4a><span id='show"+bb+"'>"+
df[1]+"</span></font></a>";
str += "</pre></td></tr>";
bb++;
}
}
*/
return str;
}
function ftp_select_tr(ind){
ftp_init_color();
$("#ttr"+ind).css("backgroundColor","#D2DDFE");
ftp_copyfd(2,ind);
}
function ftp_copyfd(c,ind){
var current_dir = $("#t_storage_web_curdir");
var current_dir_val = $("#t_storage_web_curdir").val();
var usb_file_name = $("#s_file_name");
var usb_file_path = $("#t_usb_file_path");
var h_file_name = $("#h_file_name");
var chose_file = $("#show"+ind).html();
var default_path = current_dir_val + chose_file;
if(c==1){ //double click folder
current_dir.val(current_dir_val + chose_file +"/");
ftp_show_usb_list();
}
if(c==2){ //Selected the folder
h_file_name.val(chose_file);
usb_file_path.val(default_path)
}
if(c==3){ //Selected
usb_file_name.html(usb_file_path.val());
ftp_close_fancybox();
}
}
function ftp_init_color(){
for(c=1;c<200;c++){
if(!eval("document.getElementById('ttr"+c+"')")) break; //ttr? not exit
eval("document.getElementById('ttr"+c+"').style.backgroundColor='#FFFFFF'")
}
}
function ftp_up_folder(){
var current_dir = $("#t_storage_web_curdir");
var bac= $("#t_storage_web_curdir").val();
if(bac == "/") return; //already the top folder
bac = bac.substring(0,bac.length-1) //remove last "/"
current_dir.val(bac.substring(0,bac.lastIndexOf("/")+1));
ftp_show_usb_list();
}
function ftp_close_fancybox(){
$("#t_storage_web_curdir").val("/");
$.fancybox.close();
}