Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Extras
- fs.makeDir("Programs")
- fs.makeDir("User")
- fs.makeDir("Backup")
- -- Variablen
- modemPresent = false;
- editText = false;
- bColor = colors.white;
- btColor = colors.gray;
- htColor = colors.lightGray;
- hColor = colors.gray;
- language = "$GER";
- password = {}
- allowedPC = {}
- resetPC = 2
- os.pullEvent = os.pullEventRaw
- tekkitLite = {
- "top",
- "bottom",
- "left",
- "right",
- "front",
- "back"
- }
- -- Funktionen
- function bin(program)
- if fs.exists("Programs/"..program) and program ~= "" then
- fs.delete("Programs/"..program)
- file = fs.open("DateiListe","r")
- data = file.readAll()
- file.close()
- firstpart = string.sub(data, 1, string.find(data.."",program) -1)
- secondpart = string.sub(data, string.find(data.."",program..";") + string.len(program..";"), -1)
- file = fs.open("DateiListe","w")
- file.write(firstpart..secondpart)
- file.close()
- return translate("$DELETED", language)
- else
- return translate("$NOT_EXIST", language)
- end
- end
- function download(program, sender)
- if fs.exists("Programs/"..program) and program ~= "" then
- downloading = fs.open("Programs/"..program,"r")
- file = downloading.readAll()
- downloading.close()
- else
- rednet.send(sender,translate("$ERROR_EXIST", language))
- end
- return file
- end
- function upload(programname,programcode)
- if not fs.exists("Programs/"..programname) then
- uploading = fs.open("Programs/"..programname,"w")
- uploading.write(programcode)
- uploading.close()
- backup = fs.open("Backup/"..programname,"w")
- backup.write(programcode)
- backup.close()
- ergebnis = programname.." "..translate("$UPLOADED", language)
- else
- ergebnis = translate("$ALREADY_EXIST", language)
- end
- return ergebnis
- end
- function addlist(eintrag)
- if fs.exists("DateiListe") then
- list = fs.open("DateiListe","a")
- list.write(eintrag..";")
- list.close()
- else
- list = fs.open("DateiListe","w")
- list.write(eintrag..";")
- list.close()
- end
- end
- function readlist()
- if fs.exists("DateiListe") then
- list = fs.open("DateiListe","r")
- readedList = list.readAll()
- list.close()
- return readedList
- else
- return translate("$NO_LIST_YET", language)
- end
- end
- function savePasswords()
- file = fs.open("User/passwords","w")
- file.write(textutils.serialize(password))
- file.close()
- end
- function loadPasswords()
- if fs.exists("User/passwords") then
- file = fs.open("User/passwords","r")
- tempPassword = file.readAll()
- password = textutils.unserialize(tempPassword)
- file.close()
- end
- end
- function downloadUser(program, user)
- downloading = fs.open("User/"..user.."/"..program,"r")
- file = downloading.readAll()
- downloading.close()
- return file
- end
- function uploadUser(programname,programcode,user)
- if not fs.exists("User/"..user.."/"..programname) then
- uploading = fs.open("User/"..user.."/"..programname,"w")
- uploading.write(programcode)
- uploading.close()
- ergebnis = programname.." "..translate("$DOWNLOADED", language)
- else
- ergebnis = translate("$ALREADY_EXIST", language)
- end
- return ergebnis
- end
- function binUser(program, user)
- if fs.exists("User/"..user.."/"..program) and program ~= "" then
- fs.delete("User/"..user.."/"..program)
- return translate("$DELETED", language)
- else
- return translate("$NOT_EXIST", language)
- end
- end
- function readUserList(user)
- if fs.exists("User/"..user) then
- local list = fs.list("User/"..user.."/")
- local newProgs = ""
- for i,v in pairs(list) do
- newProgs = newProgs..v..";"
- end
- return newProgs
- end
- end
- function getUserFromID(cID)
- for i,v in pairs(allowedPC) do
- if tostring(cID) == string.sub(v, 1, string.find(v, ";") - 1) then
- return string.sub(v, string.find(v, ";") + 1, -1);
- end
- end
- end
- function checkID(cID)
- for i,v in pairs(allowedPC) do
- if tostring(cID) == string.sub(v, 1, string.find(v, ";") - 1) then
- return true;
- else
- return false;
- end
- end
- end
- function checkUser(pw, user)
- local check = false
- for i,v in pairs(password) do
- if user == string.sub(v, 1, string.find(v, ";") - 1) then
- if pw == string.sub(v, string.find(v, ";") + 1, - 1) then
- check = true
- end
- end
- end
- return check, user
- end
- function writeLog(logString)
- logFile = fs.open("log.txt", "a")
- logFile.writeLine(logString)
- logFile.close()
- end
- function translate(tString, lang)
- translateGER = {
- ["$DELETED"] = "Erfolgreich geloescht!",
- ["$NOT_EXIST"] = "Diese Datei existiert nicht!",
- ["$ERROR_EXIST"] = "Error: existiert nicht!",
- ["$DOWNLOADED"] = "erfolgreich gedownloaded!",
- ["$ALREADY_EXIST"] = "Datei existiert bereits!",
- ["$NO_LIST_YET"] = "Keine bestehende Liste",
- ["$ADD_USER"] = "User hinzufuegen",
- ["$DELETE_USER"] = "User loeschen",
- ["$LOG_FILE"] = "Log-Datei",
- ["$GUEST"] = "Gast",
- ["$HAVE"] = "hat",
- ["$LOADED"] = "heruntergeladen",
- ["$UPLOADED"] = "hochgeladen",
- ["$DELETE"] = "geloescht",
- ["$GUEST_GET_LIST"] = "hat die Liste abgerufen.",
- ["$USER_GET_LIST"] = "hat seine Liste abgerufen.",
- ["$GUEST_TRY_LOGIN"] = "hat versucht sich anzumelden.",
- ["$USER_TRY_LOGIN"] = "hat sich angemeldet.",
- ["$LOGOUT"] = "hat sich abgemeldet.",
- ["$USERNAME"] = "Username",
- ["$PASSWORD"] = "Passwort",
- ["$USER_EXIST"] = "Benutzer besteht bereits",
- ["$DELETE_USER_FOLDER"] = " Ordner leeren ",
- ["$FOLDER_NAME"] = "Ordner Name",
- }
- translateENG = {
- ["$DELETED"] = "Successfully deleted!",
- ["$NOT_EXIST"] = "File doesnt exist!",
- ["$ERROR_EXIST"] = "Error: doesn't exist!",
- ["$DOWNLOADED"] = "successfully downloaded!",
- ["$ALREADY_EXIST"] = "File already exists!",
- ["$NO_LIST_YET"] = "No list yet",
- ["$ADD_USER"] = " Add a User ",
- ["$DELETE_USER"] = "Delete a User",
- ["$LOG_FILE"] = " Log-File",
- ["$GUEST"] = "Guest",
- ["$HAVE"] = "has",
- ["$LOADED"] = "downloaded",
- ["$UPLOADED"] = "uploaded",
- ["$DELETE"] = "deleted",
- ["$GUEST_GET_LIST"] = "retrieved the list.",
- ["$USER_GET_LIST"] = "retrieved his list.",
- ["$GUEST_TRY_LOGIN"] = "tried to login.",
- ["$USER_TRY_LOGIN"] = "logged in.",
- ["$LOGOUT"] = "logged out.",
- ["$USERNAME"] = "Username",
- ["$PASSWORD"] = "Password",
- ["$USER_EXIST"] = "User already exist",
- ["$DELETE_USER_FOLDER"] = " Clear Folder ",
- ["$FOLDER_NAME"] = "Folder name",
- }
- if lang == "$GER" then
- return translateGER[tString]
- elseif lang == "$ENG" then
- return translateENG[tString]
- end
- end
- function clearScreen()
- term.setTextColor(btColor);
- term.setBackgroundColor(bColor);
- term.setCursorPos(1, 1);
- term.clear();
- term.setTextColor(htColor);
- term.setBackgroundColor(hColor);
- term.write(" ");
- term.setCursorPos(1, 1);
- term.write("ID: #" .. os.computerID());
- term.setCursorPos(37, 1);
- term.write("Status: ");
- term.setTextColor(colors.red);
- term.write("Offline");
- term.setTextColor(btColor)
- term.setBackgroundColor(bColor)
- term.setCursorPos(1,19)
- term.write("Filetransfer 3.0 | by CCExpert")
- term.setBackgroundColor(colors.lightBlue);
- term.setTextColor(btColor);
- term.setCursorPos(5,4);
- term.write(" ");
- term.setCursorPos(4,5);
- term.write(" ");
- term.setCursorPos(4,6);
- term.write(" ".. translate("$ADD_USER", language) .." ");
- term.setCursorPos(4,7);
- term.write(" ");
- term.setCursorPos(5,8);
- term.write(" ");
- term.setBackgroundColor(colors.red);
- term.setTextColor(btColor);
- term.setCursorPos(5,11);
- term.write(" ");
- term.setCursorPos(4,12);
- term.write(" ");
- term.setCursorPos(4,13);
- term.write(" ".. translate("$LOG_FILE", language) .." ");
- term.setCursorPos(4,14);
- term.write(" ");
- term.setCursorPos(5,15);
- term.write(" ");
- term.setBackgroundColor(colors.yellow);
- term.setTextColor(btColor);
- term.setCursorPos(32,4);
- term.write(" ");
- term.setCursorPos(31,5);
- term.write(" ");
- term.setCursorPos(31,6);
- term.write(" ".. translate("$DELETE_USER", language) .." ");
- term.setCursorPos(31,7);
- term.write(" ");
- term.setCursorPos(32,8);
- term.write(" ");
- term.setBackgroundColor(colors.orange);
- term.setTextColor(btColor);
- term.setCursorPos(32,11);
- term.write(" ");
- term.setCursorPos(31,12);
- term.write(" ");
- term.setCursorPos(31,13);
- term.write(" ".. translate("$DELETE_USER_FOLDER", language) .." ");
- term.setCursorPos(31,14);
- term.write(" ");
- term.setCursorPos(32,15);
- term.write(" ");
- end
- -- Hauptteil
- function main()
- loadPasswords()
- while true do
- clearScreen()
- a,b,c = rednet.receive()
- b = tostring(b)
- if string.sub(b,1,2) == "D;" then
- program = string.sub(b,string.find(b.."","D;")+2,string.len(b))
- if fs.exists("Programs/"..program) then
- downloadfile = download(program,a)
- sleep(0.25)
- rednet.send(a,downloadfile)
- writeLog(translate("$GUEST", language) .."(\'".. a .."\') ".. translate("$HAVE",language) .." "..program.." ".. translate("$LOADED", language) ..".")
- else
- rednet.send(a,translate("$ERROR_EXIST", language))
- end
- elseif string.sub(b,1,2) == "V;" then
- program = string.sub(b,string.find(b.."","V;")+2,string.len(b))
- if checkID(a) then
- if fs.exists("User/"..getUserFromID(a).."/"..program) then
- downloadfile = downloadUser(program, getUserFromID(a))
- sleep(0.25)
- rednet.send(a,downloadfile)
- writeLog(getUserFromID(a).."(\'".. a .."\') ".. translate("$HAVE", language) .." "..program.." ".. translate("$LOADED", language) ..".")
- else
- rednet.send(a,translate("$ERROR_EXIST", language))
- end
- else
- rednet.send(a, "Access denied")
- end
- elseif string.sub(b,1,2) == "L;" and b ~= "" then
- ListFile = readlist()
- rednet.send(a,ListFile)
- writeLog(translate("$GUEST", language) .."(\'".. a .."\') ".. translate("$GUEST_GET_LIST", language))
- elseif string.sub(b,1,2) == "J;" and b ~= "" then
- if checkID(a) then
- ListFile = readUserList(getUserFromID(a))
- rednet.send(a,ListFile)
- writeLog(getUserFromID(a).."(\'".. a .."\') ".. translate("$USER_GET_LIST", language))
- else
- rednet.send(a, "Access denied")
- end
- elseif string.sub(b,1,2) == "P;" and b ~= "" then
- local correct = false
- loadPasswords()
- correct, curUser = checkUser(string.sub(b, 3, string.find(b.."", "$", 1, true) - 1), string.sub(b, string.find(b.."", "$", 1, true) + 1, -1))
- if not correct then
- rednet.send(a, "DENIED")
- writeLog(translate("$GUEST", language) .."(\'".. a .."\') ".. translate("$GUEST_TRY_LOGIN", language))
- else
- table.insert(allowedPC, tostring(a)..";"..curUser)
- progs = fs.list("User/"..curUser.."/")
- local newProgs = ""
- for i,v in pairs(progs) do
- newProgs = v..";"
- end
- rednet.send(a, newProgs)
- writeLog(getUserFromID(a).."(\'".. a .."\') ".. translate("$USER_TRY_LOGIN", language))
- end
- elseif string.sub(b,1,2) == "B;" and b ~= "" then
- delete = bin(string.sub(b, 3, -1))
- rednet.send(a, delete)
- writeLog(translate("$GUEST", language) .."(\'".. a .."\') ".. translate("$HAVE", language) .." ".. string.sub(b, 3, -1) .. " ".. translate("$DELETE", language) ..".")
- elseif string.sub(b,1,2) == "W;" and b ~= "" then
- if checkID(a) then
- delete = binUser(string.sub(b, 3, -1), getUserFromID(a))
- rednet.send(a, delete)
- writeLog(getUserFromID(a).."(\'".. a .."\') ".. translate("$HAVE", language) .." ".. string.sub(b, 3, -1) .." ".. translate("$DELETE", language) ..".")
- else
- rednet.send(a, "Access denied")
- end
- elseif string.sub(b,1,2) == "U;" and b ~= "" then
- rawprogram = string.sub(b,string.find(b.."","U;")+2,string.len(b))
- programname = string.sub(rawprogram,1,string.find(rawprogram.."","$;")-1)
- program = string.sub(rawprogram,string.find(rawprogram.."","$;")+2,string.len(b))
- if fs.exists("Programs/"..programname) then
- rednet.send(a,translate("$ALREADY_EXIST", language))
- else
- print(programname)
- addlist(programname)
- endergebnis = upload(programname,program)
- rednet.send(a,endergebnis)
- writeLog(translate("$GUEST", language) .."(\'".. a .."\') ".. translate("$HAVE", language) .." ".. programname .." ".. translate("$UPLOADED", language) ..".")
- end
- elseif string.sub(b,1,2) == "R;" and b ~= "" then
- if checkID(a) then
- rawprogram = string.sub(b,string.find(b.."","R;")+2,string.len(b))
- programname = string.sub(rawprogram,1,string.find(rawprogram.."","$;")-1)
- program = string.sub(rawprogram,string.find(rawprogram.."","$;")+2,string.len(b))
- if fs.exists("User/"..getUserFromID(a).."/"..programname) then
- rednet.send(a,translate("$ALREADY_EXIST", language))
- else
- print(programname)
- endergebnis = uploadUser(programname,program,getUserFromID(a))
- rednet.send(a,endergebnis)
- writeLog(getUserFromID(a).."(\'".. a .."\') ".. translate("$HAVE", language) .." ".. programname .." ".. translate("$UPLOADED", language) ..".")
- end
- else
- rednet.send(a, "Access denied")
- end
- elseif string.sub(b,1,2) == "I;" and b ~= "" then
- if checkID(a) then
- local tempPCList = textutils.serialize(allowedPC)
- tempPCList = textutils.unserialize(tempPCList)
- for i,v in pairs(allowedPC) do
- if tostring(a) == string.sub(v, 1, string.find(v, ";") - 1) then
- table.remove(tempPCList, i)
- end
- end
- writeLog(getUserFromID(a).."(\'".. a .."\') ".. translate("$LOGOUT", language))
- allowedPC = tempPCList
- else
- rednet.send(a, "Access denied")
- end
- elseif a == resetPC then
- if b == "$RESET" then
- allowedPC = {};
- end
- elseif b == nil then
- rednet.send(a,"Error nil!")
- end
- end
- end
- function control()
- while true do
- event, side, x, y = os.pullEvent("mouse_click")
- if event ~= "mouse_click" then
- control()
- end
- if x >= 4 and x <= 21 and y >= 4 and y <= 8 then
- editText = true;
- term.setBackgroundColor(colors.lightGray);
- term.setTextColor(colors.white);
- term.setCursorPos(11,7);
- term.write(" ");
- term.setCursorPos(11,7);
- term.write(translate("$ADD_USER", language))
- term.setBackgroundColor(colors.gray);
- term.setCursorPos(11,8);
- term.write(" ");
- term.setCursorPos(11,9);
- term.write(" ");
- term.setCursorPos(11,10);
- term.write(" ".. translate("$USERNAME", language) ..": ");
- term.setCursorPos(11,11);
- term.write(" ".. translate("$PASSWORD", language) ..": ");
- term.setCursorPos(11,12);
- term.write(" ");
- term.setCursorPos(11,13);
- term.write(" ");
- term.setCursorPos(11,14);
- term.write(" ");
- term.setCursorPos(14 + string.len(translate("$USERNAME", language)), 10)
- newUser = read()
- term.setCursorPos(14 + string.len(translate("$PASSWORD", language)), 11)
- newPassword = read()
- newAcc = newUser..";"..newPassword
- local alreadyExist = false;
- for i,v in pairs(password) do
- if (newAcc == v) then
- alreadyExist = true;
- end
- end
- if not alreadyExist then
- table.insert(password, newAcc)
- fs.makeDir("User/"..newUser)
- savePasswords()
- clearScreen()
- else
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(11,7)
- term.write(translate("$USER_EXIST", language))
- sleep(1)
- clearScreen()
- end
- editText = false;
- elseif x >= 31 and x <= 48 and y >= 4 and y <= 8 then
- editText = true;
- term.setBackgroundColor(colors.lightGray);
- term.setTextColor(colors.white);
- term.setCursorPos(11,7);
- term.write(" ");
- term.setCursorPos(11,7);
- term.write(translate("$DELETE_USER", language))
- term.setBackgroundColor(colors.gray);
- term.setCursorPos(11,8);
- term.write(" ");
- term.setCursorPos(11,9);
- term.write(" ");
- term.setCursorPos(11,10);
- term.write(" ".. translate("$USERNAME", language) ..": ");
- term.setCursorPos(11,11);
- term.write(" ");
- term.setCursorPos(11,12);
- term.write(" ");
- term.setCursorPos(11,13);
- term.write(" ");
- term.setCursorPos(14 + string.len(translate("$USERNAME", language)), 10)
- delUser = read()
- local tempPassword = {}
- for i,v in pairs(password) do
- table.insert(tempPassword, v)
- end
- for i,v in pairs(password) do
- if delUser == string.sub(v, 1, string.find(v.."", ";") - 1) then
- table.remove(tempPassword, i)
- end
- end
- password = {}
- for i,v in pairs(tempPassword) do
- table.insert(password, v)
- end
- savePasswords()
- clearScreen()
- editText = false;
- elseif x >= 31 and x <= 48 and y >= 11 and y <= 15 then
- editText = true;
- term.setBackgroundColor(colors.lightGray);
- term.setTextColor(colors.white);
- term.setCursorPos(11,7);
- term.write(" ");
- term.setCursorPos(11,7);
- term.write(translate("$DELETE_USER_FOLDER", language))
- term.setBackgroundColor(colors.gray);
- term.setCursorPos(11,8);
- term.write(" ");
- term.setCursorPos(11,9);
- term.write(" ");
- term.setCursorPos(11,10);
- term.write(" ".. translate("$FOLDER_NAME", language) ..": ");
- term.setCursorPos(11,11);
- term.write(" Reason: ");
- term.setCursorPos(11,12);
- term.write(" ");
- term.setCursorPos(11,13);
- term.write(" ");
- term.setCursorPos(11,14);
- term.write(" ");
- term.setCursorPos(14 + string.len(translate("$FOLDER_NAME", language)), 10)
- delFolder = read()
- term.setCursorPos(20,11)
- reason = read()
- if delFolder == "" then
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(11,7)
- term.write("Error: No Path")
- sleep(2)
- else
- if fs.exists("User/".. delFolder) then
- progs = fs.list("User/"..delFolder)
- for i,v in pairs(progs) do
- fs.delete("User/"..delFolder.."/"..v);
- end
- end
- file = fs.open("User/".. delFolder .."/Folder was cleared","w")
- file.write(reason)
- file.close()
- end
- clearScreen()
- editText = false;
- elseif x >= 4 and x <= 21 and y >= 11 and y <= 15 then
- editText = true;
- shell.run("edit log.txt")
- clearScreen();
- editText = false;
- end
- end
- end
- function checkStatus()
- local checkStatus = false;
- while true do
- if (not editText) then
- for i, side in pairs(tekkitLite) do
- if (peripheral.getType(side) == "modem" and checkStatus == false) then
- rednet.open(side);
- modemPresent = true;
- checkStatus = true;
- end
- if (peripheral.getType(side) ~= "modem" and checkStatus == false) then
- modemPresent = false;
- end
- end
- if (modemPresent) then
- term.setBackgroundColor(hColor);
- term.setTextColor(colors.green);
- term.setCursorPos(45, 1);
- term.write("Online ");
- else
- term.setBackgroundColor(hColor);
- term.setTextColor(colors.red);
- term.setCursorPos(45, 1);
- term.write("Offline");
- end
- modemPresent = false;
- checkStatus = false;
- end
- sleep(2);
- end
- end
- parallel.waitForAny(main, control, checkStatus)
- main()
- -- Scripted by Streetboy_xD | CCExpert
- -- Please keep this text in the program.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement