SHOW:
|
|
- or go back to the newest paste.
| 1 | os.pullEvent = os.pullEventRaw | |
| 2 | - | write("Loading Configs..."..'\n')
|
| 2 | + | function ReadFile(ReadPath) |
| 3 | - | UserConfig = fs.open("UserData.config","r")
|
| 3 | + | file = fs.open(ReadPath,'r') |
| 4 | - | UserConfigContent = UserConfig.readAll() |
| 4 | + | filedata = textutils.unserialize(file.readAll()) |
| 5 | - | UserCredentials = textutils.unserialize(UserConfigContent) |
| 5 | + | file.close() |
| 6 | - | UserConfig.close() |
| 6 | + | return filedata |
| 7 | - | UserRankConfig = fs.open("UserRank.config","r")
|
| 7 | + | |
| 8 | - | UserRankContent = UserRankConfig.readAll() |
| 8 | + | local function FileWrite(WritePath, DataKey, DataValue) |
| 9 | - | UserRanks = textutils.unserialize(UserRankContent) |
| 9 | + | local FileContents = ReadFile(WritePath) |
| 10 | - | UserRankConfig.close() |
| 10 | + | local file = fs.open(WritePath, 'w') |
| 11 | FileContents[DataKey] = DataValue | |
| 12 | file.write(textutils.serialize(FileContents)) | |
| 13 | file.close() | |
| 14 | end | |
| 15 | local function WaitForKey() | |
| 16 | write("Please press any key to continue"..'\n')
| |
| 17 | - | rank = nil |
| 17 | + | local event, WaitKey = os.pullEvent('key')
|
| 18 | end | |
| 19 | local UserDataPath = "UserData.config" | |
| 20 | local UserRankPath = "UserRank.config" | |
| 21 | local RankDefault = "User" | |
| 22 | - | for username,user_rank in pairs(UserRanks) do |
| 22 | + | local rank = nil |
| 23 | - | rank = user_rank |
| 23 | + | |
| 24 | local UserCredentials = ReadFile(UserDataPath) | |
| 25 | local UserRanks = ReadFile(UserRankPath) | |
| 26 | write("Config Loaded"..'\n')
| |
| 27 | write("Welcome to the Login Screen!"..'\n')
| |
| 28 | write("Username: ")
| |
| 29 | user = read() | |
| 30 | write("Password: ")
| |
| 31 | pass = read('*')
| |
| 32 | ||
| 33 | write("Validating Credentials..."..'\n')
| |
| 34 | for username,password in pairs(UserCredentials) do | |
| 35 | - | local event, key = os.pullEvent('key')
|
| 35 | + | |
| 36 | success = true | |
| 37 | rank = UserRanks[username] | |
| 38 | if rank == nil then | |
| 39 | rank = RankDefault | |
| 40 | write("No rank found for user: "..username.." in the database, assigning default rank"..'\n')
| |
| 41 | FileWrite(UserRankPath,username,RankDefault) | |
| 42 | end | |
| 43 | break | |
| 44 | else | |
| 45 | success = false | |
| 46 | end | |
| 47 | end | |
| 48 | ||
| 49 | if success == true then | |
| 50 | write("Your Credentials Were Valid, Welcome "..user.."."..'\n')
| |
| 51 | shell.run("clear")
| |
| 52 | write("Currently Logged in: "..user..'\n'.."System Rank: "..rank..'\n')
| |
| 53 | - | for username,password in pairs(UserCredentials) do |
| 53 | + | |
| 54 | WaitForKey() | |
| 55 | else | |
| 56 | - | write("Press any key to continue")
|
| 56 | + | |
| 57 | - | local event, key = os.pullEvent('key')
|
| 57 | + | |
| 58 | os.reboot() | |
| 59 | end | |
| 60 | if access == true and rank == "Admin" then | |
| 61 | while true do | |
| 62 | shell.run("clear")
| |
| 63 | - | GetUsers = fs.open("UserData.config","r")
|
| 63 | + | |
| 64 | - | UserFileData = GetUsers.readAll() |
| 64 | + | |
| 65 | - | AllUsers = textutils.unserialize(UserFileData) |
| 65 | + | |
| 66 | - | GetUsers.close() |
| 66 | + | |
| 67 | - | Addusers = fs.open("UserData.config","w")
|
| 67 | + | |
| 68 | - | AllUsers[NewUser] = NewPass |
| 68 | + | |
| 69 | - | Addusers.write(textutils.serialize(AllUsers)) |
| 69 | + | |
| 70 | - | Addusers.close() |
| 70 | + | |
| 71 | if key == keys.numPad1 then | |
| 72 | local UserList = ReadFile(UserDataPath) | |
| 73 | for username,password in pairs(UserList) do | |
| 74 | - | GetUsers = fs.open("UserData.config","r")
|
| 74 | + | |
| 75 | - | UserFileData = GetUsers.readAll() |
| 75 | + | |
| 76 | - | AllUsers = textutils.unserialize(UserFileData) |
| 76 | + | WaitForKey() |
| 77 | - | GetUsers.close() |
| 77 | + | |
| 78 | - | DelUsers = fs.open("UserData.config","w")
|
| 78 | + | |
| 79 | - | AllUsers[DelUser] = nil |
| 79 | + | |
| 80 | - | DelUsers.write(textutils.serialize(AllUsers)) |
| 80 | + | |
| 81 | - | DelUsers.close() |
| 81 | + | |
| 82 | - | write("Operation Complete, You might need to add rank.")
|
| 82 | + | write("Attempting to add user: "..NewUser.." with the password of: "..NewPass.."."..'\n'.."Are you sure?[Y/N]")
|
| 83 | local event, key = os.pullEvent('key')
| |
| 84 | if key == keys.y then | |
| 85 | FileWrite(UserDataPath,NewUser,NewPass) | |
| 86 | else | |
| 87 | write("Did not add user because the Y key was not pressed."..'\n')
| |
| 88 | - | GetRanks = fs.open("UserRank.config","r")
|
| 88 | + | end |
| 89 | - | RankFileData = GetRanks.readAll() |
| 89 | + | |
| 90 | - | AllRanks = textutils.unserialize(RankFileData) |
| 90 | + | |
| 91 | - | GetRanks.close() |
| 91 | + | |
| 92 | - | EditRanks = fs.open("UserRank.config","w")
|
| 92 | + | write("Attempting to delete user: "..DelUser..'\n'.."Are you sure?[Y/N]")
|
| 93 | - | AllRanks[RankUsername] = NewRank |
| 93 | + | local event, key = os.pullEvent('key')
|
| 94 | - | EditRanks.write(textutils.serialize(AllRanks)) |
| 94 | + | if key == keys.y then |
| 95 | - | EditRanks.close() |
| 95 | + | FileWrite(UserDataPath,DelUser,nil) |
| 96 | else | |
| 97 | write("Did not delete user because the Y key was not pressed."..'\n')
| |
| 98 | end | |
| 99 | elseif key == keys.numPad4 then | |
| 100 | write("What is their username: ")
| |
| 101 | RankUsername = read() | |
| 102 | write("What rank do you want to assign: ")
| |
| 103 | - | write("Press any key to continue")
|
| 103 | + | |
| 104 | - | local event, key = os.pullEvent('key')
|
| 104 | + | write("Attempting to add rank to user: "..RankUsername.." with rank: "..NewRank.."."..'\n'.."Are you sure?[Y/N]")
|
| 105 | local event, key = os.pullEvent('key')
| |
| 106 | if key == keys.y then | |
| 107 | FileWrite(UserRankPath,RankUsername,NewRank) | |
| 108 | else | |
| 109 | write("Did not change user rank because the Y key was not pressed."..'\n')
| |
| 110 | end | |
| 111 | elseif key == keys.numPad5 then | |
| 112 | for i=3,1,-1 do | |
| 113 | write("Rebooting the system in "..i.." seconds"..'\n')
| |
| 114 | sleep(1) | |
| 115 | end | |
| 116 | os.reboot() | |
| 117 | elseif key == keys.numPad6 then | |
| 118 | write("Current User: "..user..'\n')
| |
| 119 | WaitForKey() | |
| 120 | else | |
| 121 | write("There has seemed to be an issue with key"..'\n'.."processing, did you use numpad?")
| |
| 122 | end | |
| 123 | end | |
| 124 | elseif access == true and rank == "User" then | |
| 125 | while true do | |
| 126 | shell.run("clear")
| |
| 127 | - | UserCredentials[user] = NewPass |
| 127 | + | |
| 128 | write("1 - Change Password"..'\n')
| |
| 129 | write("2 - View Logged In User"..'\n')
| |
| 130 | write("3 - Reboot System"..'\n')
| |
| 131 | - | NewUserList = textutils.serialize(UserCredentials) |
| 131 | + | |
| 132 | - | NewUserCred = fs.open("UserData.config","w")
|
| 132 | + | |
| 133 | - | NewUserCred.write(NewUserList) |
| 133 | + | |
| 134 | - | NewUserCred.close() |
| 134 | + | |
| 135 | for username,password in pairs(UserCredentials) do | |
| 136 | if username == user and ConfPass == password then | |
| 137 | - | write("Press any key to continue")
|
| 137 | + | |
| 138 | NewPass = read('*')
| |
| 139 | write("Confirm New Password: ")
| |
| 140 | NewPassConf = read('*')
| |
| 141 | if NewPass == NewPassConf then | |
| 142 | FileWrite(UserDataPath,username,NewPass) | |
| 143 | end | |
| 144 | end | |
| 145 | end | |
| 146 | elseif key == keys.numPad2 then | |
| 147 | write("Current User: "..user)
| |
| 148 | WaitForKey() | |
| 149 | elseif key == keys.numPad3 then | |
| 150 | for i=3,1,-1 do | |
| 151 | - | write("Press any key to continue.")
|
| 151 | + | |
| 152 | - | local event, key = os.pullEvent('key')
|
| 152 | + | |
| 153 | end | |
| 154 | os.reboot() | |
| 155 | else | |
| 156 | write("there is something wrong with the key detector"..'\n'.."did you use NumPad?")
| |
| 157 | end | |
| 158 | end | |
| 159 | else | |
| 160 | write("You do not have a System Rank yet, contact System Admin")
| |
| 161 | WaitForKey() | |
| 162 | os.reboot() | |
| 163 | end |