Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Info
- Save this program as: "startup". The advanced computer this will be used on should be dedicated for this program only.
- This program is part of a two part keycard reading system. Instead of using a password stored on the floppy disk,
- the program uses the unique ID of each floppy disk. Since the computer running this program will be hooked up to a more exposed
- disk drive, it is not recommended to have this system hooked up to a door lock, disk drive server, or anything important due to
- the higher risk of the computer being hijacked (as the startup program on a floppy disk overrides the computer's startup).
- Note: The reader is designed to work with my validator, however you can use your own program if you know the way it communicates.
- ]]--
- -- Set this to the drive the system will use to read the keycard
- side = "bottom"
- -- Ejects disks on startup to unclog itself
- disk.eject(side)
- -- Prevents program termination (to prevent easy tampering)
- os.pullEvent = os.pullEventRaw
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.blue)
- -- Change brackets to the name of the area the reader is located (e.g. Example Town, Lobby, Workshop, etc.)
- print("Welcome to <Area Name Here>")
- print("Please make sure validator is activated!")
- print("Insert Keycard Now")
- -- Security Variable (Don't touch this)
- tk = 1
- -- Opens Rednet communications
- rednet.open("left")
- -- Main Program
- while true do
- -- Waits for a disk to be inserted before continuing
- event,side = os.pullEvent("disk")
- -- Security code - Quarantines and deletes startup programs on disks
- if fs.exists("disk/startup") then
- term.setTextColor(colors.red)
- print("WARNING: Hijacking attempt detected!")
- c = 0
- while tk == 1 do
- -- If a program called startup_#### doesn't exist then:
- if not fs.exists("startup_" .. c) then
- -- resets security variable
- tk = 0
- -- stores a copy of the startup program to the computer as "startup_####"
- shell.run("copy disk/startup", "startup_" .. c)
- else
- -- Increases the number by 1
- sleep(0.1)
- c = c + 1
- end
- -- Deletes the startup program on the floppy disk
- shell.run("delete disk/startup")
- print("Program logged and deleted!")
- sleep(3)
- -- Ejects disk then reboots the computer
- disk.eject(side)
- os.reboot()
- end
- end
- -- Checks if a data disk was inserted or if a random object was inserted instead
- if not disk.hasData(side) then
- term.setTextColor(colors.red)
- print("Warning: Invalid Object Detected!")
- sleep(3)
- disk.eject(side)
- os.reboot()
- end
- -- Program Communications
- -- Grabs disk's unique ID
- IDdata = disk.getID(side)
- term.setTextColor(colors.cyan)
- print("Transmitting Data...")
- print("Do not restart the system")
- print("ID #: " ..IDdata)
- sleep(2)
- rednet.broadcast(IDdata)
- print("Awaiting Response..")
- -- Waits 5 seconds for a response
- id,resp1 = rednet.receive(5)
- -- Checks response from validator
- if resp1 == "Break" then
- -- If the ID was a maintenance card (Exits to terminal)
- term.setTextColor(colors.orange)
- term.setCursorPos(1,7)
- print("Maintenance Card Detected!")
- print("Welcome Operator!")
- disk.eject(side)
- break;
- elseif resp1 == "Denied" then
- -- If the ID was rejected
- term.setTextColor(colors.red)
- sleep(2)
- term.setCursorPos(1,7)
- print("Access Denied! ")
- sleep(2)
- disk.eject(side)
- os.reboot()
- elseif resp1 == "Granted" then
- -- If the ID was accepted
- sleep(1)
- rednet.broadcast("resume")
- term.setCursorPos(1,7)
- print("Response Recieved ")
- else
- -- Timed out or invalid response
- term.setTextColor(colors.red)
- sleep(1)
- term.setCursorPos(1,7)
- print("Error: Invalid Response/Timed Out")
- print("Please try again later")
- sleep(3)
- disk.eject(side)
- os.reboot()
- end
- id,name = rednet.receive()
- term.setTextColor(colors.green)
- print("Access Granted! Welcome " ..name.. "!")
- sleep(2)
- disk.eject(side)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement