Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cardDriveSide = "bottom" -- side where the card reader is connected
- local monitorSide = "right" -- side where the monitor is connected
- local doorSide = "left" -- side where the door is connected
- -- Wrap peripherals
- local cardDrive = peripheral.wrap(cardDriveSide)
- local monitor = peripheral.wrap(monitorSide)
- -- Lock status
- local deviceLocked = fs.exists("Block.txt")
- -- Function to display a message on the monitor
- local function displayMessage(line, message)
- monitor.setCursorPos(1, line)
- monitor.clearLine()
- monitor.write(message)
- end
- -- Function to display a detailed message about the access card status
- local function displayAccessCardMessage(status)
- monitor.clear()
- if status == "insert" then
- displayMessage(1, "Doggy OS Enterprise Security")
- displayMessage(2, "============================")
- displayMessage(4, "Welcome to Doggy OS Enterprise Security System.")
- displayMessage(6, "Please insert your access card to proceed.")
- elseif status == "valid" then
- displayMessage(1, "Access Granted")
- displayMessage(2, "============================")
- displayMessage(4, "Welcome, authorized user!")
- displayMessage(6, "Access has been granted.")
- sleep(3) -- Display message for 3 seconds
- elseif status == "invalid" then
- displayMessage(1, "Access Denied")
- displayMessage(2, "============================")
- displayMessage(4, "Invalid or unauthorized card.")
- displayMessage(6, "Access denied. Please contact")
- displayMessage(7, "security for assistance.")
- sleep(3) -- Display message for 3 seconds
- elseif status == "locked" then
- displayMessage(1, "Device Disabled")
- displayMessage(2, "============================")
- displayMessage(4, "Suspicious activity detected.")
- displayMessage(6, "Device is locked. Please")
- displayMessage(7, "contact security for assistance.")
- elseif status == "override" then
- displayMessage(1, "Override Disk Detected")
- displayMessage(2, "============================")
- displayMessage(4, "Admin access granted.")
- displayMessage(6, "Device will reset now.")
- sleep(3) -- Display message for 3 seconds
- end
- end
- -- Function to lock the device after suspicious activity
- local function lockDevice()
- deviceLocked = true
- displayAccessCardMessage("locked")
- -- Create a lock file to persist the lock state
- local file = fs.open("Block.txt", "w")
- file.write("Device is locked due to suspicious activity.")
- file.close()
- end
- -- Function to handle the override disk
- local function handleOverrideDisk()
- fs.delete("Block.txt")
- displayAccessCardMessage("override")
- sleep(2)
- os.reboot()
- end
- -- Function to show "Device Disabled" message and check for override disk
- local function showDeviceDisabledMessage()
- displayAccessCardMessage("locked")
- while deviceLocked do
- if cardDrive.isDiskPresent() then
- local diskID = cardDrive.getDiskID()
- local diskMountPath = "/disk"
- if fs.exists(diskMountPath .. "/Overide/" .. diskID .. ".ID") then
- handleOverrideDisk()
- break
- end
- end
- sleep(1) -- Wait briefly before checking again
- end
- end
- -- Function to check the inserted card and control the door
- function checkCard()
- if deviceLocked then
- showDeviceDisabledMessage() -- Show static lock message if locked
- return
- end
- displayAccessCardMessage("insert") -- Initial message to insert card
- while true do
- if cardDrive.isDiskPresent() then
- local diskID = cardDrive.getDiskID()
- local diskMountPath = "/disk"
- -- Check for startup files
- if fs.exists(diskMountPath .. "/startup") or fs.exists(diskMountPath .. "/startup.lua") then
- if not fs.exists("Block.txt") then
- -- Create Block.txt and reboot the device
- local file = fs.open("Block.txt", "w")
- file.write("Device is locked due to suspicious activity.")
- file.close()
- os.reboot()
- break
- end
- end
- if fs.exists(diskMountPath .. "/Overide/" .. diskID .. ".ID") then
- handleOverrideDisk()
- break
- elseif fs.exists(diskMountPath .. "/Cards/" .. diskID .. ".ID") then
- displayAccessCardMessage("valid")
- redstone.setOutput(doorSide, true) -- Open door
- sleep(1) -- Ensure door is fully open before ejecting
- -- Eject the card
- cardDrive.ejectDisk()
- sleep(2) -- Keep door open for 2 seconds after ejecting
- redstone.setOutput(doorSide, false) -- Close door
- break -- Exit loop after valid card action
- else
- displayAccessCardMessage("invalid")
- lockDevice()
- break -- Exit loop after invalid card action
- end
- else
- -- No card inserted, continue checking
- sleep(1) -- Wait briefly before checking again
- end
- end
- end
- -- Main loop to continuously check for the card
- while true do
- checkCard()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement