-- Description: import users from old WinFTP to Wing FTP Server -- To execute this lua script, just type a command like "dofile('c:/importuser.lua')" on the Web Admin's Console. -- Author: Luke -- Date: 2010-05-05 require("LuaXML") function decryption(src) local strResult = "" local nLength = string.len(src) for i=1,nLength do local ch = string.char(string.byte(src,i) - nLength - i+1) strResult = strResult..ch end return UnScramble(strResult) end function UnScramble(src) local strResult = src local nEven = 1 local nOdd = 1 local nLength = string.len(strResult) local strEven = string.sub(strResult, 1, (nLength/2) ) local strOdd = string.sub(strResult, ((nLength+1)/2), nLength) strResult = "" for i=1,nLength do if (i % 2) == 1 then strResult = strResult..string.char(string.byte(strOdd,nOdd)) nOdd = nOdd + 1 else strResult = strResult..string.char(string.byte(strEven,nEven)) nEven = nEven + 1 end end return strResult end local domain = "DomainName" -- Your domain name local old_userfile = "c:/users.xml" -- Old user data filename local tab = xml.load(old_userfile) local unum = 1 while tab[unum] ~= nil do local dnum = 0 local username = (tab[unum][1][1]) --username local password = "" if tab[unum][2][1] ~= nil then password = (decryption(tab[unum][2][1])) end local enable_pass = tonumber(tab[unum][49][1]) --enable password? local enable_account = tonumber(tab[unum][15][1]) --enable account? if enable_account == 1 then enable_account = 0 else enable_account = 1 end c_AddUser(domain,username, md5(password), 63, enable_pass, enable_account) while tab[unum][53+dnum] ~= nil do local dirpath = (tab[unum][53+dnum][1][1]) --Dir Path if dirpath ~= nil then dirpath = string.gsub(dirpath,"\\","/") end local alias = (tab[unum][53+dnum][2][1]) --Alias if alias ~= nil then alias = string.gsub(alias,"\\","/") end local fread = (tab[unum][53+dnum][3][1]) --File_Read if fread == "1" then fread = true else fread = false end local fwrite = (tab[unum][53+dnum][4][1]) --File_Write if fwrite == "1" then fwrite = true else fwrite = false end local fappend = (tab[unum][53+dnum][5][1]) --File_Append if fappend == "1" then fappend = true else fappend = false end local fdelete = (tab[unum][53+dnum][6][1]) --File_Delete if fdelete == "1" then fdelete = true else fdelete = false end local frename = (tab[unum][53+dnum][7][1]) --Directory_Rename if frename == "1" then frename = true else frename = false end local ishome = (tab[unum][53+dnum][8][1]) --Home_Dir if ishome == "1" then ishome = true else ishome = false end local dlist = (tab[unum][53+dnum][9][1]) --Directory_List if dlist == "1" then dlist = true else dlist = false end local dmake = (tab[unum][53+dnum][10][1]) --Directory_Make if dmake == "1" then dmake = true else dmake = false end local ddelete = (tab[unum][53+dnum][11][1]) --Directory_Delete if ddelete == "1" then ddelete = true else ddelete = false end if ishome == true then alias = "/" end c_AddUserDirectory(domain, username, dirpath, alias, ishome, fread, fwrite, fappend, fdelete, dlist, dmake, ddelete, frename) dnum = dnum + 1 end unum = unum + 1 print("Import user '"..username.."' successfully\n") end