Posted 24 September 2014 - 08:42 PM
Hello everyone,
This is my first time I made a code this big, so I would really appreciate it if you would give me some advice on how to improve my code.
First off all you should install the doorlock via the pastebin link 2JNEmP5S (type in in the computercraft console "pastebin run 2JNEmP5S"). For the code to run properly you should have enabled pastebin access and HTTP-access. After the installation you will a couple of prompts asking about your first account name and the location of your door and disk drive (to disable the use of the disk drive and thus to disable usage of keycards, enter in "no").
After you entered your information, you can log in with your name and password you entered in earlier. To open the door, first select the option "Grant access rights" and then "Open door".
To create a keycard:
For a keycard to be registered you must have a disk drive next to your computer. First, log in and grant yourself access rights. Then put an empty floppy disk in the disk drive and select the option "Set up keycard". Your keycard will be ejected as soon as the process is completed.
To link a keycard:
If you want to use a keycard for multiple door locks, you should use the option "Link keycard" instead of "Set up keycard".
Usage of a keycard:
Keycards are linked to a username. If your access rights are revoked after the creation of your keycard to a certain door, you will not be able to enter anymore. To open a door with a keycard, just shift+right click on the disk drive. Your keycard will be ejected and the door will be opened.
Editing access rights and admin rights:
In server play, other players can create accounts too. These accounts do not have any rights. Admins can grant access or admin rights to these accounts. This is done by logging in, granting yourself access rights and then selecting "Grant admin rights". Then you either choose for "Configure access rights" or "Configure admin rights". First, you enter the name of the account to add or delete. After hitting enter you can choose to add or delete this user from the current list.
Automatic updating:
This program will update itself automatically via pastebin. When a new version is detected, it will ask you if you would like to install the new version. Note that new versions might be unstable.
Pastebin link to the code: http://pastebin.com/2JNEmP5S
Have fun!
This is my first time I made a code this big, so I would really appreciate it if you would give me some advice on how to improve my code.
First off all you should install the doorlock via the pastebin link 2JNEmP5S (type in in the computercraft console "pastebin run 2JNEmP5S"). For the code to run properly you should have enabled pastebin access and HTTP-access. After the installation you will a couple of prompts asking about your first account name and the location of your door and disk drive (to disable the use of the disk drive and thus to disable usage of keycards, enter in "no").
After you entered your information, you can log in with your name and password you entered in earlier. To open the door, first select the option "Grant access rights" and then "Open door".
To create a keycard:
For a keycard to be registered you must have a disk drive next to your computer. First, log in and grant yourself access rights. Then put an empty floppy disk in the disk drive and select the option "Set up keycard". Your keycard will be ejected as soon as the process is completed.
To link a keycard:
If you want to use a keycard for multiple door locks, you should use the option "Link keycard" instead of "Set up keycard".
Usage of a keycard:
Keycards are linked to a username. If your access rights are revoked after the creation of your keycard to a certain door, you will not be able to enter anymore. To open a door with a keycard, just shift+right click on the disk drive. Your keycard will be ejected and the door will be opened.
Editing access rights and admin rights:
In server play, other players can create accounts too. These accounts do not have any rights. Admins can grant access or admin rights to these accounts. This is done by logging in, granting yourself access rights and then selecting "Grant admin rights". Then you either choose for "Configure access rights" or "Configure admin rights". First, you enter the name of the account to add or delete. After hitting enter you can choose to add or delete this user from the current list.
Automatic updating:
This program will update itself automatically via pastebin. When a new version is detected, it will ask you if you would like to install the new version. Note that new versions might be unstable.
Pastebin link to the code: http://pastebin.com/2JNEmP5S
Have fun!
Code:
--This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
--License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
local version="ALPHA 0.1.3"
term.clear()
term.setCursorPos(1,1)
print("Welcome to the installer of SIGHT XIX LOCK version "..version.." . Please press a key to continue")
local param=0
local event=""
while event~="key" do
event,param=os.pullEvent("key")
end
print("Installing...")
a=fs.open("startup", "w")
a.write([[shell.run("pastebin", "run", "6hqCG9iX")]])
a.close()
a=fs.open("version", "w")
a.write(version)
a.close()
a=fs.open("bootup", "w")
a.write([[term.clear()
term.setCursorPos(1,1)
local username=""
local pass="-"
if not fs.exists("users/*") then
local passfill=""
fs.makeDir("users")
print("Please enter your desired username")
username=read()
while pass~=passfill do
term.clear()
term.setCursorPos(1,1)
print("Please enter your desired username")
print(username)
print("Please enter your password")
pass=read("*")
print("Please re-enter your password")
passfill=read("*")
if pass~=passfill then
print("Passwords do not match, please try again")
sleep(1)
end
end
local a=fs.open("users/"..username, "w")
a.write(pass)
a.close()
print("Saved")
sleep(1)
end
if not fs.exists("accesslist") then
local a = fs.open("accesslist", "w")
a.write(textutils.serialize({Key0 = username}))
a.close()
end
local side=""
local drive=""
function menuleft()
term.clear()
term.setCursorPos(1,1)
print("At which side is the redstone door located?")
print(" <---")
side="left"
end
function menuright()
term.clear()
term.setCursorPos(1,1)
print("At which side is the redstone door located?")
print(" --->")
side="right"
end
function driveleft()
term.clear()
term.setCursorPos(1,1)
print("At which side is the drive located?")
print("<---")
drive="left"
end
function drivenone()
term.clear()
term.setCursorPos(1,1)
print("At which side is the drive located?")
print(" NONE")
drive="no"
end
function driveright()
term.clear()
term.setCursorPos(1,1)
print("At which side is the drive located?")
print(" --->")
drive="right"
end
menuchoose=0
function menuchoosing()
if menuchoose==0 then
driveleft()
elseif menuchoose==1 then
drivenone()
elseif menuchoose==2 then
driveright()
end
end
if not fs.exists("options") then
local param=0
menuleft()
while param~=28 do
event, param=os.pullEvent("key")
if param==203 then
menuleft()
elseif param==205 then
menuright()
end
end
param=0
driveleft()
while param~=28 do
event, param=os.pullEvent("key")
if param==203 and menuchoose~=0 then
menuchoose=menuchoose-1
elseif param==205 and menuchoose~=2 then
menuchoose=menuchoose+1
end
menuchoosing()
end
local a={}
a["side"] = side
a["drive"] = drive
local handle=fs.open("options", "w")
handle.write(textutils.serialize(a))
handle.close()
end
if not fs.exists("identlist")then
local a={}
local handle=fs.open("identlist", "w")
handle.write(textutils.serialize(a))
handle.close()
end
if not fs.exists("adminlist") then
local a = fs.open("adminlist", "w")
a.write(textutils.serialize({Key0 = username}))
a.close()
end
shell.run("bootstrapper")]])
a.close()
a=fs.open("bootstrapper", "w")
a.write([[term.clear()
term.setCursorPos(18,5)
print("*---------------*")
term.setCursorPos(18,6)
print("| |")
term.setCursorPos(18,7)
print("| SIGHT19 |")
term.setCursorPos(18,8)
print("| LOCK |")
term.setCursorPos(18,9)
print("| ALPHA 0.1.3 |")
term.setCursorPos(18,10)
print("| |")
term.setCursorPos(18,11)
print("*---------------*")
sleep(0.5)
term.clear()
term.setCursorPos(1,1)
local menuchoose=0
local event=""
local param=0
function menucreate()
term.clear()
term.setCursorPos(1,1)
print("Please make a choice:")
print(" Login")
print("--> Create an account")
print(" Exit")
end
function menulogin()
term.clear()
term.setCursorPos(1,1)
print("Please make a choice:")
print("--> Login")
print(" Create an account")
print(" Exit")
end
function menuexit()
term.clear()
term.setCursorPos(1,1)
print("Please make a choice:")
print(" Login")
print(" Create an account")
print("--> Exit")
end
function menuchoosing()
if menuchoose==0 then
menulogin()
elseif menuchoose==1 then
menucreate()
elseif menuchoose==2 then
menuexit()
end
event, param=os.pullEvent()
end
menuchoosing()
diskchoose=false
while param~=28 do
if menuchoose~=2 and param==208 then
menuchoose=menuchoose+1
menuchoosing()
elseif menuchoose~=0 and param==200 then
menuchoose=menuchoose-1
menuchoosing()
elseif event=="disk" and diskchoose==false then
term.clear()
term.setCursorPos(1,1)
local handle=fs.open("options", "r")
local tableoptions=textutils.unserialize(handle.readAll())
local side=tableoptions["drive"]
local floppypath = disk.getMountPath(side)
if side=="no" then
print("Keycard system disabled")
diskchoose=true
elseif not fs.exists(floppypath.."/ident") then
print("No keycard detected, please do not use a blank floppy disk")
disk.eject(side)
sleep(1)
menuchoosing()
elseif side~="no" then
print("Checking keycard...")
local handle=fs.open(floppypath.."/ident", "r")
local ident=tonumber(handle.readAll())
handle.close()
local handle=fs.open("identlist", "r")
identlist=textutils.unserialize(handle.readAll())
handle.close()
local i=0
local succes=false
while true do
entry=identlist[i]
if entry==ident then
local handle=fs.open(floppypath.."/user", "r")
local userfloppy=handle.readAll()
handle.close()
local i=0
local l=""
local lastentry=""
local handle=fs.open("accesslist", "r")
local table=textutils.unserialize(handle.readAll())
handle.close()
local succesentry=true
while userfloppy~=lastentry do
l="Key"..tostring(i)
lastentry=table[l]
if lastentry==nil then
succesentry=false
break
end
i=i+1
end
if succesentry==true then
succes=true
print("congratz")
diskchoose=true
disk.eject(side)
break
else
succes=false
print("No registry found")
diskchoose=true
disk.eject(side)
break
end
elseif entry==nil then
succes=false
print("Bad luck ma nigga")
diskchoose=true
disk.eject(side)
break
else
i=i+1
end
end
if succes==true then
local handle=fs.open("options", "r")
tableoptions=textutils.unserialize(handle.readAll())
redstone.setOutput(tableoptions["side"], true)
sleep(3)
redstone.setOutput(tableoptions["side"], false)
handle.close()
os.reboot()
end
end
end
end
if menuchoose==2 then
print("Shutting down")
sleep(0.5)
os.shutdown()
elseif menuchoose==1 then
local passcre=""
local passrecre="0"
local failure=false
while passcre~=passrecre or failure==true do
term.clear()
term.setCursorPos(1,1)
print("Please fill in the following form:")
print("Username: ")
print("Password: ")
term.setCursorPos(11,2)
usercre=read()
if fs.exists(usercre) then
failure=true
term.setCursorPos(1,4)
print("There already exists an account with the username "..usercre)
sleep(2)
else
term.setCursorPos(11,3)
passcre=read("*")
term.setCursorPos(1,4)
print("Please confirm your password")
print("Confirm: ")
term.setCursorPos(10,5)
passrecre=read("*")
if passrecre==passcre then
print("Account created")
sleep(2)
break
else
print("Check back your password")
sleep(1)
end
end
end
local a=fs.open("users/"..usercre, "w")
a.writeLine(passcre)
a.close()
userfill=usercre
elseif menuchoose==0 then
local passfill=""
local pass=""
userfill=""
local failure=true
local tries=0
while failure==true and tries<4 do
term.clear()
term.setCursorPos(1,1)
print("Please enter your credentials:")
print("Username: ")
print("Password: ")
term.setCursorPos(11,2)
userfill=read()
if not fs.exists("users/"..userfill) then
term.setCursorPos(1,4)
print("Account doesn't exist")
sleep(2)
else
term.setCursorPos(11,3)
passfill=read("*")
local a=fs.open("users/"..userfill, "r")
if passfill==a.readLine() then
failure=false
print("Correct password, access granted")
sleep(1)
else
tries=tries+1
print("Wrong password, access denied")
sleep(2)
end
a.close()
end
end
if tries>3 then
print("Too many tries, account locked. Contact system administrator to unlock your account.")
sleep(2)
fs.delete("users/"..userfill)
local a = fs.open("users/"..userfill, "w")
a.writeLine("542293")
a.close()
os.shutdown()
end
end
local menuchoose=0
function menus1()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print("--> Log out")
print(" Grant access rights")
end
function menus2()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print(" Log out")
print("--> Grant access rights")
end
function menuchoosing()
if menuchoose==0 then
menus1()
elseif menuchoose==1 then
menus2()
end
end
menuchoosing()
param=0
while param~=28 do
event, param = os.pullEvent("key")
if param==200 and menuchoose~=0 then
menuchoose=menuchoose-1
menuchoosing()
elseif param==208 and menuchoose~=1 then
menuchoose=menuchoose+1
menuchoosing()
end
end
if menuchoose==0 then
print("Logging off...")
sleep(2)
os.shutdown()
elseif menuchoose==1 then
print("Looking for registration...")
local handle=fs.open("accesslist", "r")
local table=textutils.unserialize(handle.readAll())
handle.close()
local lastentry=""
local i=0
while lastentry~=nil do
local l="Key"..tostring(i)
lastentry=table[l]
if userfill==lastentry then
break
end
i=i+1
end
if lastentry==userfill then
print("Registry found: admission granted")
else
print("No registry entry found, system turning off")
sleep(1)
os.shutdown()
end
sleep(1)
end
menuchoose=0
function menua1()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print("--> Log out")
print(" Grant admin rights")
print(" Open door")
print(" Delete access")
print(" Set up keycard")
print(" Link keycard")
end
function menua2()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print(" Log out")
print("--> Grant admin rights")
print(" Open door")
print(" Delete access")
print(" Set up keycard")
print(" Link keycard")
end
function menua3()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print(" Log out")
print(" Grant admin rights")
print("--> Open door")
print(" Delete access")
print(" Set up keycard")
print(" Link keycard")
end
function menua4()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print(" Log out")
print(" Grant admin rights")
print(" Open door")
print("--> Delete access")
print(" Set up keycard")
print(" Link keycard")
end
function menua5()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print(" Log out")
print(" Grant admin rights")
print(" Open door")
print(" Delete access")
print("--> Set up keycard")
print(" Link keycard")
end
function menua6()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
term.setCursorPos(1,2)
print("-----------------------")
print(" Log out")
print(" Grant admin rights")
print(" Open door")
print(" Delete access")
print(" Set up keycard")
print("--> Link keycard")
end
function menuchoosing()
if menuchoose==0 then
menua1()
elseif menuchoose==1 then
menua2()
elseif menuchoose==2 then
menua3()
elseif menuchoose==3 then
menua4()
elseif menuchoose==4 then
menua5()
elseif menuchoose==5 then
menua6()
end
end
menuchoosing()
param=0
while param~=28 do
event,param=os.pullEvent("key")
if param==200 and menuchoose~=0 then
menuchoose=menuchoose-1
menuchoosing()
elseif param==208 and menuchoose~=5 then
menuchoose=menuchoose+1
menuchoosing()
end
end
if menuchoose==0 then
term.clear()
term.setCursorPos(1,1)
print("Logging off...")
sleep(1)
print("Goodbye")
sleep(1)
os.shutdown()
elseif menuchoose==2 then
term.clear()
term.setCursorPos(1,1)
local handle=fs.open("options", "r")
local tableoptions=textutils.unserialize(handle.readAll())
local side=tableoptions["side"]
handle.close()
if side~="left" and side~="right" then
print("Please contact an administrator to edit the location of the door in the settings")
sleep(1)
else
rs.setOutput(side, true)
print("Redstone signal sent to "..side.." side")
sleep(3)
rs.setOutput(side, false)
print("Redstone signal cut off")
sleep(2)
end
os.shutdown()
elseif menuchoose==3 then
term.clear()
term.setCursorPos(1,1)
if userfill=="system" then
print("It is not possible to delete the main system account as a regular user")
sleep(0.5)
print("Rebooting...")
sleep(1.5)
os.shutdown()
else
print("Are you sure that you want to delete your account?")
param=0
function lrno()
term.clear()
term.setCursorPos(1,1)
print("Are you sure that you want to delete your account?")
print("->NO<- YES")
end
function lryes()
term.clear()
term.setCursorPos(1,1)
print("Are you sure that you want to delete your account?")
print(" NO ->YES<-")
end
lrno()
while param~=28 do
event, param=os.pullEvent("key")
if param==203 then
lrno()
menuchoose=0
elseif param==205 then
lryes()
menuchoose=1
end
end
if menuchoose==0 then
os.shutdown()
elseif menuchoose==1 then
term.clear()
term.setCursorPos(1,1)
fs.delete(userfill)
local handle=fs.open("accesslist", "r")
local i=-1
local table=textutils.unserialize(handle.readAll())
handle.close()
local l="Key1"
while table[l]~=userfill do
i=i+1
l="Key"..tostring(i)
end
table[l]=false
local handle=fs.open("accesslist", "w")
handle.write(textutils.serialize(table))
handle.close()
fs.delete("users/"..userfill)
print("Deletion complete. Rebooting...")
sleep(2)
os.shutdown()
end
end
elseif menuchoose==1 then
print("Looking for admin registery")
local handle=fs.open("adminlist", "r")
local table=textutils.unserialize(handle.readAll())
local lastentry=""
local i=0
while lastentry~=nil do
local l="Key"..tostring(i)
lastentry=table[l]
if userfill==lastentry then
break
end
i=i+1
end
if lastentry==userfill then
print("Registry found: admin-level admission granted")
else
print("No registry entry found, system rebooting")
sleep(1)
os.shutdown()
end
handle.close()
sleep(1)
elseif menuchoose==4 then
term.clear()
term.setCursorPos(1,1)
local handle=fs.open("options", "r")
local tableoptions=textutils.unserialize(handle.readAll())
handle.close()
local side=tableoptions["drive"]
if side=="no" then
print("Keycards are not supported")
sleep(1)
os.shutdown()
end
local floppypath=disk.getMountPath(side)
if fs.exists(floppypath.."/user") then
print("Already user active")
sleep(1)
os.shutdown()
else
local handle = fs.open(floppypath.."/user", "w")
handle.write(userfill)
handle.close()
local handle = fs.open(floppypath.."/pass", "w")
handle.write(passfill)
handle.close()
local handle = fs.open(floppypath.."/ident", "w")
code= math.random(1000000,9999999)
handle.write(code)
handle.close()
local handle = fs.open("identlist", "r")
identlist=textutils.unserialize(handle.readAll())
handle.close()
local i=0
succes=false
while succes==false do
entry=identlist[i]
if entry==nil then
succes=true
end
i=i+1
end
i=i-1
identlist[i]=code
local handle = fs.open("identlist", "w")
handle.write(textutils.serialize(identlist))
handle.close()
print("Keycard registered")
disk.eject(side)
sleep(1)
os.shutdown()
end
elseif menuchoose==5 then
term.clear()
term.setCursorPos(1,1)
local handle=fs.open("options", "r")
local tableoptions=textutils.unserialize(handle.readAll())
handle.close()
local side=tableoptions["drive"]
if side=="no" then
print("Keycards are not supported")
sleep(1)
os.shutdown()
end
local floppypath = disk.getMountPath(side)
if not fs.exists(floppypath.."/user") then
print("No user active")
disk.eject(side)
sleep(1)
os.shudown()
else
local handle=fs.open(floppypath.."/ident", "r")
local code=tonumber(handle.readAll())
handle.close()
local handle=fs.open("identlist", "r")
local identlist=textutils.unserialize(handle.readAll())
handle.close()
local i=0
local succes=false
while succes==false do
local entry=identlist[i]
if entry==nil then
succes=true
end
i=i+1
end
i=i-1
local handle=fs.open("identlist", "w")
identlist[i]=code
handle.write(textutils.serialize(identlist))
handle.close()
print("written")
disk.eject(side)
sleep(1)
end
end
function menuo1()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("-----------------------")
print("--> Log out")
print(" Configure access rights")
print(" Configure administration rights")
print(" Delete account")
print(" Delete system account")
print(" Customize redstone door")
end
function menuo2()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("-----------------------")
print(" Log out")
print("--> Configure access rights")
print(" Configure administration rights")
print(" Delete account")
print(" Delete system account")
print(" Customize redstone door")
end
function menuo3()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("-----------------------")
print(" Log out")
print(" Configure access rights")
print("--> Configure administration rights")
print(" Delete account")
print(" Delete system account")
print(" Customize redstone door")
end
function menuo4()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("-----------------------")
print(" Log out")
print(" Configure access rights")
print(" Configure administration rights")
print("--> Delete account")
print(" Delete system account")
print(" Customize redstone door")
end
function menuo5()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("-----------------------")
print(" Log out")
print(" Configure access rights")
print(" Configure administration rights")
print(" Delete account")
print("--> Delete system account")
print(" Customize redstone door")
end
function menuo6()
term.clear()
term.setCursorPos(1,1)
print("Main Menu")
print("-----------------------")
print(" Log out")
print(" Configure access rights")
print(" Configure administration rights")
print(" Delete account")
print(" Delete system account")
print("--> Customize redstone door")
end
menuchoose=0
function menuchoosing()
if menuchoose==0 then
menuo1()
elseif menuchoose==1 then
menuo2()
elseif menuchoose==2 then
menuo3()
elseif menuchoose==3 then
menuo4()
elseif menuchoose==4 then
menuo5()
elseif menuchoose==5 then
menuo6()
end
end
menuchoosing()
param=0
while param~=28 do
event, param=os.pullEvent("key")
if param==208 and menuchoose~=5 then
menuchoose=menuchoose+1
menuchoosing()
elseif param==200 and menuchoose~=0 then
menuchoose=menuchoose-1
menuchoosing()
end
end
if menuchoose==0 then
term.clear()
term.setCursorPos(1,1)
print("Logging off...")
sleep(1)
print("Goodbye")
sleep(1)
os.shutdown()
elseif menuchoose==1 then
term.clear()
term.setCursorPos(1,1)
local username=""
menuchoose=0
function menuacc1()
term.clear()
term.setCursorPos(1,1)
print("Editing access list")
print("-----------------------")
print("Please enter a username:")
print(username)
print("->ADD<- delete check exit")
end
function menuacc2()
term.clear()
term.setCursorPos(1,1)
print("Editing access list")
print("-----------------------")
print("Please enter a username:")
print(username)
print(" add ->DELETE<- check exit")
end
function menuacc3()
term.clear()
term.setCursorPos(1,1)
print("Editing access list")
print("-----------------------")
print("Please enter a username:")
print(username)
print(" add delete ->CHECK<- exit")
end
function menuacc4()
term.clear()
term.setCursorPos(1,1)
print("Editing access list")
print("-----------------------")
print("Please enter a username:")
print(username)
print(" add delete check ->EXIT<-")
end
function menuchoosing()
if menuchoose==0 then
menuacc1()
elseif menuchoose==1 then
menuacc2()
elseif menuchoose==2 then
menuacc3()
elseif menuchoose==3 then
menuacc4()
end
end
while true do
print("Editing access list")
print("-----------------------")
print("Please enter a username:")
term.setCursorPos(1,4)
username = read()
menuchoosing()
param=0
while param~=28 do
event, param=os.pullEvent("key")
if param==205 and menuchoose~=3 then
menuchoose=menuchoose+1
menuchoosing()
elseif param==203 and menuchoose~=0 then
menuchoose=menuchoose-1
menuchoosing()
end
end
if menuchoose==0 then
handle=fs.open("accesslist", "r")
seriacces=handle.readAll()
acces=textutils.unserialize(seriacces)
handle.close()
lastentry=""
i=-1
while lastentry~=nil do
i=i+1
l="Key"..tostring(i)
lastentry=acces[l]
if lastentry==false then
break
end
end
l="Key"..tostring(i)
handle=fs.open("accesslist", "w")
acces[l]=username
handle.write(textutils.serialize(acces))
handle.close()
elseif menuchoose==1 then
handle=fs.open("accesslist", "r")
table=textutils.unserialize(handle.readAll())
local userread=""
i=0
while username~=userread do
l="Key"..tostring(i)
userread=table[l]
if table[l]==nil then
userread=false
break
end
i=i+1
end
handle.close()
if userread==false then
print("Username not found")
sleep(1)
else
handle=fs.open("accesslist", "w")
table[l]=false
handle.write(textutils.serialize(table))
handle.close()
end
elseif menuchoose==2 then
handle = fs.open("accesslist", "r")
table=textutils.unserialize(handle.readAll())
if username=="" then
l="Key1"
i=0
while table[l]~=nil do
l="Key"..tostring(i)
if type(table[l])=="string" then
print(table[l])
end
i=i+1
end
sleep(1)
else
i=0
userread=""
while userread~=username do
l="Key"..tostring(i)
userread=table[l]
if userread==nil then
break
end
i=i+1
end
if userread==nil then
print("User not found in the access list")
else
print('User "'..username..'" is found in the acces list')
end
sleep(2)
end
elseif menuchoose==3 then
os.shutdown()
end
term.clear()
term.setCursorPos(1,1)
end
elseif menuchoose==2 then
term.clear()
term.setCursorPos(1,1)
local username=""
menuchoose=0
function menuacc1()
term.clear()
term.setCursorPos(1,1)
print("Editing admin list")
print("-----------------------")
print("Please enter a username:")
print(username)
print("->ADD<- delete check exit")
end
function menuacc2()
term.clear()
term.setCursorPos(1,1)
print("Editing admin list")
print("-----------------------")
print("Please enter a username:")
print(username)
print(" add ->DELETE<- check exit")
end
function menuacc3()
term.clear()
term.setCursorPos(1,1)
print("Editing admin list")
print("-----------------------")
print("Please enter a username:")
print(username)
print(" add delete ->CHECK<- exit")
end
function menuacc4()
term.clear()
term.setCursorPos(1,1)
print("Editing admin list")
print("-----------------------")
print("Please enter a username:")
print(username)
print(" add delete check ->EXIT<-")
end
function menuchoosing()
if menuchoose==0 then
menuacc1()
elseif menuchoose==1 then
menuacc2()
elseif menuchoose==2 then
menuacc3()
elseif menuchoose==3 then
menuacc4()
end
end
while true do
print("Editing admin list")
print("-----------------------")
print("Please enter a username:")
term.setCursorPos(1,4)
username = read()
menuchoosing()
param=0
while param~=28 do
event, param=os.pullEvent("key")
if param==205 and menuchoose~=3 then
menuchoose=menuchoose+1
menuchoosing()
elseif param==203 and menuchoose~=0 then
menuchoose=menuchoose-1
menuchoosing()
end
end
if menuchoose==0 then
handle=fs.open("adminlist", "r")
seriacces=handle.readAll()
acces=textutils.unserialize(seriacces)
handle.close()
lastentry=""
i=-1
while lastentry~=nil do
i=i+1
l="Key"..tostring(i)
lastentry=acces[l]
if lastentry==false then
break
end
end
l="Key"..tostring(i)
handle=fs.open("adminlist", "w")
acces[l]=username
handle.write(textutils.serialize(acces))
handle.close()
elseif menuchoose==1 then
handle=fs.open("adminlist", "r")
table=textutils.unserialize(handle.readAll())
local userread=""
i=0
while username~=userread do
l="Key"..tostring(i)
userread=table[l]
if table[l]==nil then
userread=false
break
end
i=i+1
end
handle.close()
if userread==false then
print("Username not found")
sleep(1)
else
handle=fs.open("adminlist", "w")
table[l]=false
handle.write(textutils.serialize(table))
handle.close()
end
elseif menuchoose==2 then
handle = fs.open("adminlist", "r")
table=textutils.unserialize(handle.readAll())
if username=="" then
l="Key1"
i=0
while table[l]~=nil do
l="Key"..tostring(i)
if type(table[l])=="string" then
print(table[l])
end
i=i+1
end
sleep(1)
else
i=0
userread=""
while userread~=username do
l="Key"..tostring(i)
userread=table[l]
if userread==nil then
break
end
i=i+1
end
if userread==nil then
print("User not found in the access list")
else
print('User "'..username..'" is found in the acces list')
end
sleep(2)
end
elseif menuchoose==3 then
os.shutdown()
end
term.clear()
term.setCursorPos(1,1)
end
elseif menuchoose==3 then
term.clear()
term.setCursorPos(1,1)
function menudel1()
term.clear()
term.setCursorPos(1,1)
print("User configuration")
print("-----------------------")
print("--> List all accounts")
print(" Delete an account")
print(" Delete all accounts")
print(" Exit")
end
function menudel2()
term.clear()
term.setCursorPos(1,1)
print("User configuration")
print("-----------------------")
print(" List all accounts")
print("--> Delete an account")
print(" Delete all accounts")
print(" Exit")
end
function menudel3()
term.clear()
term.setCursorPos(1,1)
print("User configuration")
print("-----------------------")
print(" List all accounts")
print(" Delete an account")
print("--> Delete all accounts")
print(" Exit")
end
function menudel4()
term.clear()
term.setCursorPos(1,1)
print("User configuration")
print("-----------------------")
print(" List all accounts")
print(" Delete an account")
print(" Delete all accounts")
print("--> Exit")
end
menuchoose=0
function menuchoosing()
if menuchoose==0 then
menudel1()
elseif menuchoose==1 then
menudel2()
elseif menuchoose==2 then
menudel3()
elseif menuchoose==3 then
menudel4()
end
end
while true do
param=0
menuchoose=0
menuchoosing()
while param~=28 do
event, param=os.pullEvent("key")
if param==200 and menuchoose~=0 then
menuchoose=menuchoose-1
menuchoosing()
elseif param==208 and menuchoose~=3 then
menuchoose=menuchoose+1
menuchoosing()
end
end
if menuchoose==0 then
local handleacc=fs.open("accesslist", "r")
local handleadm=fs.open("adminlist", "r")
local acc=textutils.unserialize(handleacc.readAll())
local adm=textutils.unserialize(handleadm.readAll())
local acclist=fs.list("users/*")
usercheck=""
i=1
term.clear()
term.setCursorPos(1,1)
print("User list")
print("-----------------------")
local reg={}
while usercheck~=nil do
local term="lolz"
usercheck=acclist[i]
lastentry=""
i2=0
while usercheck~=lastentry do
l="Key"..tostring(i2)
lastentry=acc[l]
if lastentry==nil then
term="no access"
break
end
i2=i2+1
end
lastentry=""
i2=0
while usercheck~=lastentry do
l="Key"..tostring(i2)
lastentry=adm[l]
if lastentry==nil and term~="no access" then
term="regular user"
break
elseif term=="no access" then
break
end
i2=i2+1
end
if term=="lolz" then
term="admin"
end
reg["u"..tostring(i)]=usercheck
reg["t"..tostring(i)]=term
i=i+1
end
reg["u"..tostring(i-1)]=false
reg["t"..tostring(i-1)]=false
handleacc.close()
handleadm.close()
i=1
while reg["u"..tostring(i)]~=false do
term.setCursorPos(1,i+2)
print(reg["u"..tostring(i)])
term.setCursorPos(24,i+2)
print(reg["t"..tostring(i)])
i=i+1
end
param=0
while param~=28 do
event,param=os.pullEvent("key")
end
elseif menuchoose==1 then
term.clear()
term.setCursorPos(1,1)
print("Please enter a username")
term.setCursorPos(1,2)
local usercheck=read()
local accounts=fs.list("users/*")
local i=1
local lastentry=""
while usercheck~=lastentry do
lastentry=accounts[i]
if lastentry==nil then
print("No account with that name found")
sleep(2)
break
end
i=i+1
end
if usercheck==lastentry then
fs.delete("users/"..usercheck)
local handleacc=fs.open("accesslist", "r")
local handleadm=fs.open("adminlist", "r")
local i2=0
local l=""
acclist=textutils.unserialize(handleacc.readAll())
admlist=textutils.unserialize(handleadm.readAll())
handleacc.close()
handleadm.close()
local lastentry2=""
while usercheck~=lastentry2 do
l="Key"..tostring(i2)
lastentry2=acclist[l]
if lastentry2==nil then
break
end
i2=i2+1
end
if usercheck==lastentry2 then
acclist[l]=false
end
handleacc=fs.open("accesslist", "w")
handleacc.write(textutils.serialize(acclist))
handleacc.close()
i2=0
l=""
lastentry2=""
while usercheck~=lastentry2 do
l="Key"..tostring(i2)
lastentry2=admlist[l]
if lastentry2==nil then
break
end
i2=i2+1
end
if usercheck==lastentry2 then
admlist[l]=false
end
handleadm=fs.open("adminlist", "w")
handleadm.write(textutils.serialize(admlist))
handleadm.close()
end
elseif menuchoose==2 then
term.clear()
term.setCursorPos(1,1)
print("Please enter your master key")
local master=read("*")
if master=="542293" then
fs.delete("users")
fs.makeDir("users")
fs.delete("accesslist")
fs.delete("adminlist")
print("Completed, shutting down")
sleep(2)
os.shutdown()
else
print("Wrong master key! Logging out...")
sleep(1)
os.shutdown()
end
elseif menuchoose==3 then
os.shutdown()
end
end
elseif menuchoose==4 then
while true do
term.clear()
term.setCursorPos(1,1)
print("You are obliged to have at least one account with admin privileges and you have to fill in the master key")
term.setCursorPos(1,4)
local master=read("*")
local succes2=false
if master=="542293" then
succes2=true
else
succes2=false
end
local i=0
local handle=fs.open("adminlist", "r")
local l=""
local table=textutils.unserialize(handle.readAll())
handle.close()
lastentry=""
local succes1=false
while true do
l="Key"..tostring(i)
lastentry=table[l]
if lastentry~="system" and lastentry~=false and lastentry~=nil then
succes1=true
break
elseif lastentry==nil then
succes1=false
break
end
i=i+1
end
if succes1==true and succes2==true then
print("User with admin accessibility: "..lastentry)
sleep(1)
fs.delete("users/system")
handle=fs.open("accesslist", "r")
tableacc=textutils.unserialize(handle.readAll())
handle.close()
handle=fs.open("adminlist", "r")
tableadm=textutils.unserialize(handle.readAll())
handle.close()
i=0
l=""
lastentry=""
while lastentry~="system" do
l="Key"..tostring(i)
lastentry=tableacc[l]
if lastentry==nil then
break
end
i=i+1
end
tableacc[l]=false
handle=fs.open("accesslist", "w")
handle.write(textutils.serialize(tableacc))
handle.close()
i=0
l=""
lastentry=""
while lastentry~="system" do
l="Key"..tostring(i)
lastentry=tableadm[l]
if lastentry==nil then
break
end
i=i+1
end
tableadm[l]=false
handle=fs.open("adminlist", "w")
handle.write(textutils.serialize(tableadm))
handle.close()
sleep(2)
os.shutdown()
elseif succes1==false and succes2==true then
term.setCursorPos(1,5)
print("Please make another account with system priveleges")
elseif succes1==true and succes2==false then
term.setCursorPos(1,5)
print("Please check your master key")
elseif succes1==false and succes2==false then
term.setCursorPos(1,5)
print("Please make another account with system priveleges and check your master key")
end
sleep(2)
end
elseif menuchoose==5 then
term.clear()
term.setCursorPos(1,1)
print("Please enter the location of the redstone door")
while true do
local side=read()
local handle=fs.open("options", "r")
tableoption=textutils.unserialize(handle.readAll())
handle.close()
local handle=fs.open("options", "w")
if side=="left" or side=="right" then
tableoption["side"]=side
handle.write(textutils.serialize(tableoption))
handle.close()
print("Location "..side.." saved")
sleep(1)
break
elseif side=="lefg" or side=="righd" or side=="lddt" or side=="rifht" then
print("Your spelling kinda sucks. Please try again.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Please enter the location of the redstone door")
else
print("Please choose left or right")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Please enter the location of the redstone door")
end
end
term.clear()
term.setCursorPos(1,1)
print("Please enter the side of the floppy drive, or disable it by entering no")
while true do
local side=read()
local handle=fs.open("options", "r")
tableoption=textutils.unserialize(handle.readAll())
handle.close()
local handle=fs.open("options", "w")
if side=="no" then
print("Keycard access disabled.")
tableoption["drive"]="no"
handle.write(textutils.serialize(tableoption))
handle.close()
sleep(1)
break
elseif side=="left" then
tableoption["drive"]="left"
handle.write(textutils.serialize(tableoption))
handle.close()
print("Floppy drive wrapped on the "..side.." side")
sleep(1)
break
elseif side=="right" then
tableoption["drive"]="right"
handle.write(textutils.serialize(tableoption))
handle.close()
print("Floppy drive wrapped on the "..side.." side")
sleep(1)
break
elseif side=="lefg" or side=="righd" or side=="lddt" or side=="rifht" or side=="mo" or side=="np" then
print("Your spelling kinda sucks. Please try again.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Please enter the side of the floppy drive, or disable it by entering no")
end
end
os.shutdown()
end]])
a.close()
print("Finished")
sleep(2)
os.reboot()
Edited by