Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1.1.4
- version = "1.1.4"
- print("V. "..version)
- if peripheral.getType("back") ~= "modem" then
- term.setTextColour(colours.red)
- print("A mondem or wireless modem on the back side is required by this program.")
- os.sleep(3)
- os.reboot()
- end
- if not fs.exists("/CB/%NAS%/admin/.ignore") then
- term.setTextColour(colours.white)
- write("choose the admin password : ")
- term.setTextColour(colours.yellow)
- pass = read("*")
- if pass == nil then
- term.setTextColour(colours.red)
- print("you need to type something")
- os.sleep(2)
- os.reboot()
- end
- term.setTextColour(colours.white)
- write("confirm your password : ")
- term.setTextColour(colours.yellow)
- cpass = read("*")
- if pass == cpass then
- naccount = fs.open("/CB/%NAS%/admin/.ignore", "w")
- naccount.writeLine(pass)
- naccount.close()
- end
- end
- term.setTextColour(colours.white)
- while true do
- local Mots = {}
- function letn (content)
- logfile = fs.open("/CB/%NAS%/admin/log", "a")
- logfile.writeLine(content)
- logfile.close()
- print(content)
- end
- local modem = peripheral.wrap("back")
- shell.run("mkdir /CB/%NAS%/shared")
- ing = fs.open("/CB/%NAS%/shared/.ignore", "w")
- ing.close()
- modem.open(1)
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- for i in string.gmatch(message, "%S+") do
- table.insert(Mots, i)
- end
- if Mots[4] == "@p" then
- Mots[4] = replyChannel-1
- end
- if Mots[1] == "version" then
- if Mots[2] ~= version then
- maj = fs.open("/CB/Prog/MAJ", "w")
- maj.writeLine('fs.delete("/CB/NAS")')
- maj.writeLine('shell.run("pastebin get 5WgxqxCv /CB/NAS")')
- maj.writeLine('os.reboot()')
- maj.close()
- shell.run("/CB/Prog/MAJ")
- end
- end
- if Mots[1] == "delete" then
- if fs.exists("/CB/%NAS%/"..Mots[3].."/"..Mots[2]) and Mots[2] ~= ".ignore" then
- fs.delete("/CB/%NAS%/"..Mots[3].."/"..Mots[2])
- letn("File /CB/%NAS%/"..Mots[3].."/"..Mots[2].."was deleted from #"..replyChannel-1)
- end
- end
- if Mots[1] == "account" then
- if fs.exists("/CB/%NAS%/"..Mots[2].."/") then
- modem.transmit(replyChannel, 1, "already exists")
- else
- modem.transmit(replyChannel, 1, "not exists")
- end
- letn("account status of "..Mots[2].." has been send to #"..replyChannel-1)
- end
- if Mots[1] == "login" then
- login = fs.open("/CB/%NAS%/"..Mots[2].."/.ignore", "r")
- pass = login.readLine()
- login.close()
- if pass == Mots[3] then
- modem.transmit(replyChannel, 1, "logged")
- letn(Mots[2].." logged in from #"..replyChannel-1)
- else
- modem.transmit(replyChannel, 1, "wrong")
- letn(Mots[2].." tried to log in from #"..replyChannel-1)
- end
- end
- if Mots[1] == "mkaccount" then
- shell.run("mkdir /CB/%NAS%/"..Mots[2])
- ing = fs.open("/CB/%NAS%/"..Mots[2].."/.ignore", "w")
- ing.write(Mots[3])
- ing.close()
- letn("Account "..Mots[2].." has been created from #"..replyChannel-1)
- end
- if Mots[1] == "lfiles" then
- local Files = fs.list("/CB/%NAS%/"..Mots[2])
- send = Files[1]
- for i=2,#Files do
- send = send.." "..Files[i]
- end
- letn("listfile from "..Mots[2].." send to #"..replyChannel-1)
- modem.transmit(replyChannel, 1, send)
- end
- if Mots[1] == "sfile" then
- if fs.exists("/CB/%NAS%/"..Mots[4].."/"..Mots[3]) then
- letn("write file failed "..Mots[4].."/"..Mots[3].." from #"..replyChannel-1)
- modem.transmit(replyChannel, 1, "failed : file already exists")
- else
- vfile = fs.open("/CB/%NAS%/"..Mots[4].."/"..Mots[3], "w")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- vfile.write(message)
- vfile.close()
- letn("write file "..Mots[4].."/"..Mots[3].." from #"..replyChannel-1)
- modem.transmit(replyChannel, 1, "succes")
- end
- end
- if Mots[1] == "rfile" then
- if not fs.exists("/CB/%NAS%/"..Mots[4].."/"..Mots[2]) then
- letn("send file failed "..Mots[4].."/"..Mots[2].." for #"..replyChannel-1)
- modem.transmit(replyChannel, 1, "failed : file not exists on server")
- else
- pfile = fs.open("/CB/%NAS%/"..Mots[4].."/"..Mots[2], "r")
- sendfile = pfile.readAll()
- pfile.close()
- letn("send file "..Mots[4].."/"..Mots[2].." for #"..replyChannel-1)
- modem.transmit(replyChannel, 1, sendfile)
- end
- end
- end
Add Comment
Please, Sign In to add comment