Skip to content

Instantly share code, notes, and snippets.

@norfair00
Last active February 11, 2021 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norfair00/232ba1f08247dc50614a76fe882220e1 to your computer and use it in GitHub Desktop.
Save norfair00/232ba1f08247dc50614a76fe882220e1 to your computer and use it in GitHub Desktop.
local fs = require("filesystem")
local os = require("os")
local ser = require("serialization")
local term = require("term")
local shell = require("shell")
local event = require("event")
local component = require("component")
local internet = require("internet")
local computer = require("computer")
local thread = require("thread")
local bio_right_out = component.proxy("fe4c9db9-c4d9-4fda-9d96-2803157f53e0")
local bio_right_in = component.proxy("d43101a0-59d9-4d6b-8274-985b68b189e3")
local bio_left_out = component.proxy("5af17893-c331-4ef4-a790-a4a065e25bba")
local bio_left_in = component.proxy("c0dcc24c-15a3-4dd5-b996-72c7a3cc4c4e")
local door_right = component.proxy("26ada083-6551-4c96-b157-5bf5d5f9c458")
local door_left = component.proxy("5003bcf3-906b-4463-b086-a410521fcca6")
local light_right = component.proxy("c42399dd-6136-4d09-a87d-1b92e5960d85")
local light_left = component.proxy("a44b28ec-65a5-4877-8368-9799f6b3ee3f")
term.clear()
print("Security System")
print("---------------------------------------------------------------------------")
computer.beep()
light_right.setLampColor(4156)
light_left.setLampColor(4156)
os.sleep(0.1)
computer.beep()
os.sleep(0.1)
computer.beep()
os.sleep(0.1)
computer.beep()
os.sleep(0.1)
computer.beep()
os.sleep(0.1)
computer.beep()
local bio = {}
bio["fe4c9db9-c4d9-4fda-9d96-2803157f53e0"] = "[Right - Out]"
bio["d43101a0-59d9-4d6b-8274-985b68b189e3"] = "[Right - In]"
bio["5af17893-c331-4ef4-a790-a4a065e25bba"] = "[Left - Out]"
bio["c0dcc24c-15a3-4dd5-b996-72c7a3cc4c4e"] = "[Left - In]"
local auth = {}
auth["Y2UzMmQ2M2UtZjc5ZS00YzAwLTlmYWQtY2NhNTZhMWMzMjgz"] = "Norfair"
local function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
thread.create(function()
while true do
bioEvent, bioAddresss, uuid = event.pull("bioReader")
if (auth[uuid]) then
print(bio[bioAddresss] .. auth[uuid] .. " Access granted")
else
print(bio[bioAddresss] .. " Access denied")
end
if bioEvent then
if ((bioAddresss == bio_right_out.address or bioAddresss == bio_right_in.address) and auth[uuid]) then
print(bio[bioAddresss] .. " " .. "Door Open")
if not door_right.isOpen() then door_right.toggle() end
os.sleep(3)
print(bio[bioAddresss] .. " " .. "Door Close")
door_right.toggle()
end
end
end
end)
thread.create(function()
while true do
bioEvent, bioAddresss, uuid = event.pull("bioReader")
if (auth[uuid]) then
print(bio[bioAddresss] .. auth[uuid] .. " Access granted")
else
print(bio[bioAddresss] .. " Access denied")
end
if bioEvent then
if ((bioAddresss == bio_left_out.address or bioAddresss == bio_left_in.address) and auth[uuid]) then
print(bio[bioAddresss] .. " " .. "Door Open")
if not door_left.isOpen() then door_left.toggle() end
os.sleep(3)
print(bio[bioAddresss] .. " " .. "Door Close")
door_left.toggle()
end
end
end
end)
local fs = require("filesystem")
local os = require("os")
local shell = require("shell")
local event = require("event")
local component = require("component")
local internet = require("internet")
if not component.isAvailable("internet") then
io.stderr:write("This program requires an internet card to run.")
return
end
local function get(filename)
local f, reason = io.open(filename, "w")
if not f then
io.stderr:write("Failed opening file for writing: " .. reason)
return
end
io.write("Downloading from pastebin.com... ")
local url = "https://pastebin.com/raw/Zi1Z8rks"
local result, response = pcall(internet.request, url)
if result then
io.write("success.\n")
for chunk in response do
f:write(chunk)
end
f:close()
io.write("Saved data to " .. filename .. "\n")
else
io.write("failed.\n")
f:close()
fs.remove(filename)
io.stderr:write("HTTP request failed: " .. response .. "\n")
end
end
local path = shell.resolve("doorsecu.lua")
if fs.exists(path) then
os.remove(path)
end
get(path)
local success, reason = shell.execute(path, nil, ...)
if not success then
io.stderr:write(reason)
end
@norfair00
Copy link
Author

Test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment