Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- v 2.30
- --[[
- 2015.10.28
- add user delete permission change
- add string hash
- add security program broken
- ]]--
- local pullEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- local unlock = {}
- local index = 1
- local matrix1 = ""
- local matrix2 = ""
- local ujverzio
- local regiverzio
- local width, height = term.getSize()
- local selectedMenu = 1
- local selectedItem = 1
- local username = ""
- local adminjog = ""
- local doors = ""
- local windows = ""
- local delete = ""
- local running = true
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function updateStartup()
- clear()
- shell.run("pastebin","get","ANLXqv40","update")
- local file = fs.open("update", "r")
- lx = file.readLine()
- s1 = lx:find("v")
- ujverzio = tonumber(lx:sub(s1+2))
- file.close()
- clear()
- print("Uj verzio: ", ujverzio)
- sleep(1)
- local file = fs.open("startup", "r")
- lx = file.readLine()
- s1 = lx:find("v")
- regiverzio = tonumber(lx:sub(s1+2))
- file.close()
- print("regi verzio: ", regiverzio)
- sleep(1)
- if regiverzio < ujverzio or regiverzio > ujverzio then
- fs.delete("startup")
- fs.copy("update", "startup")
- fs.delete("update")
- shell.run("startup")
- else
- fs.delete("update")
- clear()
- print("nincs elerheto frissites")
- sleep(1)
- return false
- end
- end
- updateStartup()
- 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 login()
- print("The program created by Csaba")
- print("login")
- username = read()
- if username == "" then
- print("can not be empty")
- sleep(.4)
- elseif not fs.exists("database/"..username) then
- print("username does not exist")
- sleep(.4)
- elseif fs.exists("database/"..username) then
- file = fs.open("database/"..username, "r")
- loads()
- file.close()
- print("jelszo")
- passhash = read("*")
- pass = tostring(StringHash(passhash))
- if pass == "" then
- print("can not be empty")
- sleep(.4)
- elseif pass == goodpass then
- if adminjog == "true" then
- selectedMenu = 2
- elseif adminjog == "false" then
- selectedMenu = 3
- end
- print("access granted")
- sleep(1)
- if goodpass == "1504751979" then
- clear()
- print("change rootpass")
- changepassword()
- end
- else
- print("access denied")
- sleep(.4)
- end
- end
- end
- function changepassword()
- file = fs.open("database/"..username, "r")
- actualpass = file.readLine()
- file.close()
- clear()
- print("actual password:")
- requestpass = read()
- if actualpass == tostring(StringHash(requestpass)) then
- print("password access")
- sleep(2) clear()
- print("new password")
- pass1hash = read("*")
- pass1 = tostring(StringHash(pass1hash))
- print("confirm password")
- pass2hash = read("*")
- pass2 = tostring(StringHash(pass2hash))
- if pass1 == "" or pass2 == "" then
- print("jelszo ures")
- sleep(.4)
- return changepassword()
- elseif actualpass == pass2 then
- print("root password can't same than root") sleep(2)
- return changepassword()
- elseif pass1 == pass2 then
- file = fs.open("database/"..username, "r")
- file.readLine()
- file.readLine()
- doors = file.readLine()
- windows = file.readLine()
- file.readLine()
- delete = file.readLine()
- file.close()
- file = fs.open("database/"..username, "w")
- file.writeLine(pass1)
- file.writeLine(adminjog)
- file.writeLine(doors)
- file.writeLine(windows)
- file.writeLine(signing)
- file.writeLine(delete)
- file.close()
- end
- else
- print("incorrect password")
- sleep(1)
- return changepassword()
- end
- end
- function createuser()
- if delete == "true" then
- print("username")
- newuser = read()
- print("password")
- newpasshash = read("*")
- newpass = tostring(StringHash(newpasshash))
- print("admin access (i/n)")
- adminjog2 = read()
- if newuser == "" or newpass == "" or adminjog2 == "" then
- print("newuser or password or admin access empty")
- sleep(.4)
- else
- file = fs.open("database/"..newuser, "w")
- file.writeLine(newpass)
- if adminjog2 == "i" or adminjog2 == "I" then
- file.writeLine("true")
- file.writeLine("true")
- file.writeLine("true")
- file.writeLine("false")
- file.writeLine("true")
- elseif adminjog2 == "n" or adminjog2 == "N" then
- file.writeLine("false")
- file.writeLine("false")
- file.writeLine("false")
- file.writeLine("false")
- file.writeLine("false")
- else
- print("wrong character")
- sleep(1)
- end
- file.close()
- end
- else
- print("You don't have enough permission")
- sleep(1)
- end
- end
- function alluser()
- clear()
- print("-----> Osszes felhasznalo <-----")
- local filelist = fs.list("database/")
- for _, file in ipairs(filelist) do
- list = fs.open("database/"..file, "r")
- list.readLine()
- list.readLine()
- list.readLine()
- list.readLine()
- signing = list.readLine()
- list.close()
- if signing == "true" then
- print(file, ": ", "alairva")
- else
- print(file, ": ", "nincs alairva")
- end
- sleep(.4)
- end
- print("press button continue")
- read("")
- end
- function permissions()
- perms = {"adminjog2", "doors", "windows", "signing", "delete"}
- clear()
- print("permissions:\n 1: root perm \n 2: doors\n 3: windows \n 4: signing\n 5: delete")
- print("user")
- user = read()
- if not fs.exists("database/"..user) then
- print("user not fould")
- sleep(.4)
- elseif fs.exists("database/"..user) then
- print("permissions")
- perm = tonumber(read())
- if perm == nil then
- print("can not be empty")
- sleep(.4)
- return permissions()
- end
- for i = 1, perm do
- jog = perms[i]
- print("jog: ", jog)
- end
- file = fs.open("database/"..user, "r")
- actpass = file.readLine()
- adminjog2 = file.readLine()
- doors = file.readLine()
- windows = file.readLine()
- signing = file.readLine()
- delete = file.readLine()
- file.close()
- print("mire")
- which = read()
- permissionok(user, jog, doors, windows, delete, which)
- end
- end
- function permissionok()
- print("doorsx: ", doors)
- print("windowsx: ", windows)
- print("whichx: ", which)
- print("jogx: ", jog)
- print("whichx: ", which)
- if jog == "adminjog2" then
- adminjog2 = which
- end
- if jog == "doors" then
- doors = which
- end
- if jog == "windows" then
- windows = which
- end
- if jog == "signing" then
- signing = which
- end
- if jog == "delete" then
- delete = which
- end
- file = fs.open("database/"..user, "w")
- file.writeLine(actpass)
- file.writeLine(adminjog2)
- file.writeLine(doors)
- file.writeLine(windows)
- file.writeLine(signing)
- file.writeLine(delete)
- file.close()
- sleep(1)
- end
- function deleteuser()
- if delete == "true" then
- print("username")
- deleteuser = read()
- if deleteuser == "" then
- print("ures") sleep(1)
- elseif not fs.exists("database/"..deleteuser) then
- print("user not found")
- sleep(.4)
- elseif fs.exists("database/"..deleteuser) then
- if deleteuser == "root" then
- print("You don't have enough permission")
- elseif username == username then
- print("You can not delete yourself")
- sleep(1)
- end
- print("user found")
- print("confirm delete i/n")
- delete2 = read()
- if delete2 == "i" or delete2 == "I" then
- fs.delete("database/"..deleteuser)
- elseif delete2 == "n" or delete2 == "N" then
- print("delete canceled")
- end
- end
- else
- print("You don't have enough permission")
- sleep(1)
- end
- end
- function shutdown()
- os.shutdown()
- end
- function logout()
- selectedItem = 1
- selectedMenu = 1
- end
- function loads()
- file = fs.open("database/"..username, "r")
- goodpass = file.readLine()
- adminjog = file.readLine()
- doors = file.readLine()
- windows = file.readLine()
- file.readLine()
- delete = file.readLine()
- file.close()
- end
- function doorsopen()
- clear()
- if doors == "true" then
- print("ajtok nyitva")
- rs.setOutput("right", true)
- sleep(6)
- rs.setOutput("right", false)
- end
- if doors == "false" then
- print("You don't have enough permission")
- sleep(1)
- end
- end
- function windowsopen()
- clear()
- if windows == "true" then
- print("ablakok nyitva")
- sleep(1)
- end
- if windows == "false" then
- print("You don't have enough permission")
- sleep(1)
- end
- end
- function programstops()
- for i = 1, #unlock do
- tabla = unlock[i]
- matrix2 = matrix1..tabla
- matrix1 = matrix2
- end
- if matrix2 == "19870221" then
- print("sikeres") sleep(.4)
- running = false
- else
- print("sikertelen") sleep(.4)
- end
- for i = 1, #unlock do
- table.remove(unlock)
- end
- index = 1
- matrix1 = ""
- matrix2 = ""
- end
- local mainMenu1 = {
- [1] = { text = "Login", handler = login },
- [2] = { text = "Shutdown", handler = shutdown }
- }
- local mainMenu2 = {
- [1] = { text = "new password", handler = changepassword },
- [2] = { text = "create user", handler = createuser },
- [3] = { text = "all user", handler = alluser },
- [4] = { text = "user perm", handler = permissions },
- [5] = { text = "delete user", handler = deleteuser },
- [6] = { text = "logout", handler = logout },
- [7] = { text = "doors open", handler = doorsopen },
- [8] = { text = "windows open", handler = windowsopen },
- [9] = { text = "program stops", handler = programstops }
- }
- local mainMenu3 = {
- [1] = { text = "new password", handler = changepassword },
- [2] = { text = "doors open", handler = doorsopen },
- [3] = { text = "windows open", handler = windowsopen },
- [4] = { text = "logout", handler = logout }
- }
- function printMenu( menu )
- if #menu < 18 then
- for i=1,#menu do
- if i < height then
- if i == selectedItem then
- term.setCursorPos(17, (i))
- print(">> "..menu[i].text .. " <<")
- else
- term.setCursorPos(17, (i))
- print(" "..menu[i].text)
- end
- end
- end
- elseif # menu >= 18 then
- for i=1, #menu do
- if i < height then
- if i == selectedItem then
- term.setCursorPos(4, (i))
- print(">> "..menu[i].text .. " <<")
- else
- term.setCursorPos(1, (i))
- print(" "..menu[i].text)
- end
- elseif i > height - 1 then
- if i == selectedItem then
- term.setCursorPos(32, (i-17))
- print(">> "..menu[i].text .. " <<")
- else
- term.setCursorPos(32, (i-17))
- print(" "..menu[i].text)
- end
- end
- end
- end
- end
- function keypressprint()
- term.setCursorPos(49,17)
- print("*") sleep(.1) index = index + 1
- end
- function onKeyPressed( key, menu )
- if key == 28 then
- onItemSelected(menu)
- elseif key == 200 then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == 208 then
- if selectedItem < #menu then
- selectedItem = selectedItem + 1
- end
- elseif key == 203 then
- if selectedItem > 17 then
- selectedItem = selectedItem - 17
- end
- elseif key == 205 then
- vissza = selectedItem
- if selectedItem < #menu then
- selectedItem = selectedItem + 17
- if selectedItem > #menu then
- selectedItem = vissza
- end
- end
- elseif key == 82 then
- table.insert(unlock, index, 0)
- keypressprint()
- elseif key == 79 then
- table.insert(unlock, index, 1)
- keypressprint()
- elseif key == 80 then
- table.insert(unlock, index, 2)
- keypressprint()
- elseif key == 81 then
- table.insert(unlock, index, 3)
- keypressprint()
- elseif key == 75 then
- table.insert(unlock, index, 4)
- keypressprint()
- elseif key == 76 then
- table.insert(unlock, index, 5)
- keypressprint()
- elseif key == 77 then
- table.insert(unlock, index, 6)
- keypressprint()
- elseif key == 71 then
- table.insert(unlock, index, 7)
- keypressprint()
- elseif key == 72 then
- table.insert(unlock, index, 8)
- keypressprint()
- elseif key == 73 then
- table.insert(unlock, index, 9)
- keypressprint()
- end
- end
- function onItemSelected( menu )
- menu[selectedItem].handler()
- end
- function main()
- if not fs.exists("database") then
- print("hi")
- fs.makeDir("database")
- local file = fs.open("database/root", "w")
- root = tostring(StringHash("root"))
- file.writeLine(root)
- file.writeLine("true")
- file.writeLine("true")
- file.writeLine("true")
- file.writeLine("false")
- file.close()
- end
- while running do
- if selectedMenu == 1 then
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu1)
- event, key = os.pullEvent("key")
- onKeyPressed(key,mainMenu1)
- elseif selectedMenu == 2 then
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu2)
- event, key = os.pullEvent("key")
- onKeyPressed(key,mainMenu2)
- elseif selectedMenu == 3 then
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu3)
- event, key = os.pullEvent("key")
- onKeyPressed(key,mainMenu3)
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement