Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ----------> Beléptető rendszer <----------
- Beléptető rendszer. Előszőr root felhasználónévvel és root jelszóval tudtok belépni.
- Ezután tudtok felhasználókat, illetve admin jogokkal rendelkező felhasználókat létrehozni.
- Egyenlőre egy ajtó nyitási funkció van beprogramozva. Ezt bármire kicserélhetitek.
- Erre rákeresve: function Choice1()
- Itt találhatjátok az 1. menüpont funkcióhívását. A Choice1 re újra rákeresve a menüt tudjátok átírni.
- A script szabadon másólható, illetve módosítható, amennyiben az eredeti részt csak kommentezitek és az eredeti
- tulaját feltüntetitek. Jelen esetben Matteo Delfavero
- Használjátok sok sikerrel. Bármi kérdésetek van itt feltehetitek: matteo.delfaveroKUKACgmail.com
- A jelszavakat 32 bites hash eléssel menti, terminate-elni nem lehet a futó programot, csak újra indítani
- a ctrl+r el.
- ui.: A Script csak egy része van commentezve. Hamarosan kész lesz.
- 2013.07.18
- 2017.10.17
- -debug funkcio berakva /alapértelmezetten falsra van állítva
- -bugfix: ha adminként jelentkeztél be nem írta ki, hogy admin vagy. javítva-
- -Menü lista balra igazítva (jobb megjelenítés)
- ]]--
- inMainMenuA = false
- inMainMenuU = false
- DebugMode = false
- local termWidth, termHeight = term.getSize()
- local selectedItem = 1
- username = -1
- passworld = -1
- rsout1 = "left"
- rsout2 = "right"
- local pullEvent = os.pullEvent -- Anti terminate
- os.pullEvent = os.pullEventRaw -- Anti terminate
- function debug(...)
- if DebugMode then print("Debug: " .. tostring(...)) sleep(.25) end
- end
- function StringHash(text)
- local counter = 1
- local len = string.len(text)
- for i = 1, len, 3 do
- counter = math.fmod(counter*8161, 4294967279) +
- (string.byte(text,i)*16776193) +
- ((string.byte(text,i+1) or (len-i+256))*8372226) +
- ((string.byte(text,i+2) or (len-i+256))*3932164)
- end
- return math.fmod(counter, 4294967291)
- end
- function InstallDatabase() --Adatbázis mappa létrehozása
- if not fs.exists("Database") then --Ellenőrzi, hogy létezik-e a mappa
- fs.makeDir("Database") --Létrehozza a mappát
- local file = fs.open("Database/root.dat", "w") --Létrehoz egy root felhasználót tartalmazó file-t
- file.writeLine(tostring(StringHash("root"))) --Beleírja a root jelszavat
- file.writeLine(tostring(StringHash("true"))) --Adminra állítja
- file.close() --Bezárja a file-t
- return false --Igaz értékkel tér vissza a functio
- else
- return true --Már létre van hozva a mappa ezért false értékkel tér vissza, tehát nem volt telepítés
- end
- end
- function rootPass()
- local file = fs.open("Database/root.dat", "r")
- debug(file)
- local rootPass = file.readLine()
- debug(rootPass)
- local rootAdmin = file.readLine()
- debug(rootAdmin)
- file.close()
- if rootPass == tostring(StringHash("root")) then --Ha a root jelszava root akkor igaz értékkel tér vissza
- return true --Ez kérőbb lesz érdekes
- else
- return false
- end
- end
- function IsAdmin(username) --Ellenőrzi, hogy a felhasználónak vannak-e root azaz admin jogosúltságai
- local file = fs.open("Database/"..username..".dat", "r")
- debug(file)
- local ReadedPass = file.readLine()
- debug(ReadedPass)
- local ReadedAdmin = file.readLine()
- debug(ReadedAdmin)
- file.close()
- if ReadedAdmin == tostring(StringHash("true")) then
- return true
- else
- return false
- end
- end
- function rootChange()
- if rootPass() then
- centerText("-----> Root jelszo megvaltoztatasa <-----")
- print("")
- write("Uj root jelszo: ")
- local rootpass1 = read("x")
- write("Uj root jelszo megegyszer: ")
- local rootpass2 = read("x")
- if rootpass1 == "root" then
- cls()
- centerText("Nem lehet ujra root a jelszo")
- sleep(3)
- return rootChange()
- end
- if rootpass1 == rootpass2 then
- local file = fs.open("Database/root.dat", "w")
- file.writeLine(tostring(StringHash(rootpass2)))
- file.writeLine(tostring(StringHash("true")))
- file.close()
- print("Root jelszo frissitese....")
- sleep(2)
- return true
- else
- print("A ket jelszo nem egyezik")
- sleep(3)
- return rootChange()
- end
- end
- end
- function centerText(text)
- local x,y = term.getSize()
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- print(text)
- end
- function UserAdd()
- cls()
- centerText("-----> Regisztracio <-----")
- print("")
- write("Felhasznalonev: ")
- local username = read()
- print("")
- write("Jelszo: ")
- local passwd1 = read("x")
- write("Jelszo megerositese: ")
- local passwd2 = read("x")
- write("A felhasznalonak root jogai vannak? i/n: ")
- local Admin = read()
- if Admin == "i" or Admin == "I" then
- AdminJog = "true"
- elseif Admin == "n" or Admin == "N" then
- AdminJog = "false"
- else
- print("Helytelen válasz i/n !")
- sleep(3)
- return UserAdd()
- end
- if passwd1 ~= passwd2 then
- print("A ket jelszo nem egyezik")
- sleep(3)
- return UserAdd()
- end
- if not InstallDatabase() then
- cls()
- print("Nem lehetett létrehozni")
- read("")
- return main()
- end
- if fs.exists("Database/" .. username ..".dat") then
- cls()
- print("Van mar ilyen felhasznalo")
- read("")
- return main()
- end
- local file = fs.open("Database/" .. username ..".dat", "w")
- file.writeLine(tostring(StringHash(passwd1)))
- file.writeLine(tostring(StringHash(AdminJog)))
- file.close()
- return menu()
- end
- function cls()
- term.clear()
- term.setCursorPos(1,1)
- end
- function NoUser()
- cls()
- print("Nincs ilyen felhasznalo")
- read("")
- return main()
- end
- function Acces(user, pass)
- if fs.exists("Database/"..user..".dat") then
- local file = fs.open("Database/"..user..".dat", "r")
- debug(file)
- local ReadedPass = file.readLine()
- adminUser = file.readLine()
- debug(adminUser)
- file.close()
- if ReadedPass == tostring(StringHash(pass)) then
- return true
- else
- return false
- end
- else
- return NoUser()
- end
- end
- function AccessDenied()
- cls()
- print("Felhasznalonev/jelszo nem eggyezik")
- read("")
- return main()
- end
- function AccessEnable()
- rootChange()
- print("Debug mauin")
- return menu()
- end
- function main()
- InstallDatabase()
- cls()
- centerText("-----> Bejelentkezes <-----")
- print("")
- write("Felhasznalonev: ")
- username = read()
- print("")
- write("Jelszo: ")
- passworld = read("x")
- if Acces(username, passworld) then
- return AccessEnable()
- else
- return AccessDenied()
- end
- end
- function printMenu ( menu, admin )
- if admin then
- centerText("Udv admin: " .. username)
- else
- centerText("Udv user: " .. username)
- end
- for i = 1, #menu do
- if i == selectedItem then
- term.setCursorPos(15,(i+5))
- print(">> "..menu[i].text)
- else
- term.setCursorPos(15,(i+5))
- print(" "..menu[i].text)
- end
- end
- end
- function onKeyPressed( key, menu )
- -- if key == keys.enter then
- if key == 28 then
- onItemSelected(menu)
- elseif key == 200 then
- -- elseif key == keys.up then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- -- elseif key == keys.down then
- elseif key == 208 then
- if selectedItem < #menu then
- selectedItem = selectedItem +1
- end
- end
- end
- function onItemSelected(menu)
- menu[selectedItem].handler()
- end
- function timerAjto(sec)
- while sec ~= 0 do
- cls()
- centerText("Ajtok zarasa " .. sec .. "-mp mulva.")
- sec = sec-1
- debug("Counter down -1: ", sec)
- sleep(1)
- end
- end
- function timer(sec)
- while sec ~= 0 do
- write(sec)
- sec = sec-1
- sleep(1)
- end
- end
- function Choice1() --Ajtó nyitás
- cls()
- redstone.setOutput(rsout1, true)
- debug("redstone.setOutput(rsout1, true)")
- redstone.setOutput(rsout2, true)
- debug("redstone.setOutput(rsout2, true)")
- timerAjto(6)
- redstone.setOutput(rsout1, false)
- debug("redstone.setOutput(rsout1, false)")
- redstone.setOutput(rsout2, false)
- debug("redstone.setOutput(rsout2, false)")
- return menu()
- end
- function Choice2() --Új regisztráció
- UserAdd()
- end
- function Choice3()
- cls()
- centerText("-----> Jelszo csere <-----")
- print("")
- write("Felhasznalonev: ")
- local ExchangeUserPass = read()
- print("Felhasznalo keresese...")
- sleep(2)
- if fs.exists("Database/"..ExchangeUserPass..".dat") then
- print("Felhasznalo megtalalva: " .. ExchangeUserPass)
- local file = fs.open("Database/"..ExchangeUserPass..".dat", "r")
- local ReadedPass = file.readLine()
- local ReadedAdmin = file.readLine()
- file.close()
- write("Uj jelszo: ")
- local Passwd1 = read("x")
- write("Jelszo megegyszer: ")
- local Passwd2 = read("x")
- if Passwd1 == Passwd2 then
- local file = fs.open("Database/"..ExchangeUserPass..".dat", "w")
- file.writeLine(tostring(StringHash(Passwd1)))
- file.writeLine(tostring(StringHash(ReadedAdmin)))
- file.close()
- print("Jelszo frissitese...")
- sleep(1)
- print("Frissites sikeres a/az " .. ExchangeUserPass .. " felhasznalonal")
- sleep(3)
- return menuA()
- else
- print("A ket jelszo nem egyezik!!!")
- sleep(3)
- return Choice3()
- end
- else
- print("Nem talalhato ilyen felhasznalo: " .. ExchangeUserPass)
- end
- end
- function Choice4()
- cls()
- centerText("-----> Jelszo csere <-----")
- print("")
- write("Jelenlegi jelszavad: ")
- local NowPass = read("x")
- local file = fs.open("Database/"..username..".dat", "r")
- local NowReadedPass = file.readLine()
- file.close()
- if NowReadedPass == tostring(StringHash(NowPass)) then
- write("Uj jelszo megadasa: ")
- local NewPasswd1 = read("x")
- write("Jelszo megegyszer: ")
- local NewPasswd2 = read("x")
- if NewPasswd1 == NewPasswd2 then
- local file = fs.open("Database/"..username..".dat", "w")
- file.writeLine(tostring(StringHash(NewPasswd2)))
- file.writeLine(tostring(StringHash("false")))
- file.close()
- print("Jelszo frissitese....")
- sleep(2)
- print("Kesz!")
- sleep(.5)
- return menu()
- else
- print("A ket jelszo nem eggyezik!!")
- sleep(3)
- cls()
- return Choice4()
- end
- else
- print("A megadott jelszavad nem")
- print("eggyezik a tarolt jelszavaddal.")
- sleep(4)
- return menu()
- end
- end
- function Choise5()
- cls()
- centerText("-----> felhasznalo torlese <-----")
- print("")
- write("Felhasznalonev: ")
- local DeleteUser = read()
- print("Felhasznalo keresese...")
- sleep(2)
- if fs.exists("Database/"..DeleteUser..".dat") then
- print("Felhasznalo megtalalva.")
- print("Biztosan torolni szeretned a/az " .. DeleteUser .. " felhasznalot? i/n")
- local Delete = read()
- if Delete == "i" or Delete == "I" then
- fs.delete("Database/"..DeleteUser..".dat")
- print("Torles...")
- sleep(1)
- if not fs.exists("Database/"..DeleteUser..".dat") then
- print("Sikeresen torolted a/az " .. DeleteUser .. " felhasznalot.")
- sleep(3)
- return menu()
- else
- print("ERROR FELHASZNALO NEM TOROLHETO")
- sleep(3)
- return menu()
- end
- elseif Delete == "n" or Delete == "N" then
- return menu()
- else
- print("Igen vagy nem?! i/n")
- sleep(3)
- return Choise5()
- end
- else
- print("Felhasznalo nem talalhato")
- sleep(3)
- return menu()
- end
- end
- function Choise6()
- cls()
- centerText("-----> Osszes felhasznalo <-----")
- local FileList = fs.list("Database/")
- for _, file in ipairs(FileList) do
- print(file)
- end
- read("")
- return menu()
- end
- function Exit() --Kijelentkezés
- inMainMenuA = false
- inMainMenuU = false
- main()
- end
- mainMenuA = {
- [1] = { text = "Ajtok nyitasa", handler = Choice1 },
- [2] = { text = "Uj regisztracio", handler = Choice2 },
- [3] = { text = "Jelszo csere", handler = Choice3 },
- [4] = { text = "Felhasznalo torlese", handler = Choise5 },
- [5] = { text = "Osszes felhasznalo", handler = Choise6 },
- [6] = { text = "Log out", handler = Exit }
- }
- mainMenuU = {
- [1] = { text = "Ajtok nyitasa", handler = Choice1 },
- [2] = { text = "Sajat jelszo cere", handler = Choice4 },
- [3] = { text = "Log out", handler = Exit }
- }
- function menu()
- debug(username)
- if IsAdmin(username) then
- selectedItem = 1
- inMainMenuA = true
- inMainMenuU = false
- return menuA()
- else
- selectedItem = 1
- inMainMenuA = false
- inMainMenuU = true
- return menuU()
- end
- end
- function menuA()
- while inMainMenuA do
- cls()
- printMenu(mainMenuA, true)
- event, key = os.pullEvent("key")
- onKeyPressed(key, mainMenuA)
- end
- end
- function menuU()
- while inMainMenuU do
- cls()
- printMenu(mainMenuU, false)
- event, key = os.pullEvent("key")
- onKeyPressed(key, mainMenuU)
- end
- end
- main()
Add Comment
Please, Sign In to add comment