Posted 01 August 2012 - 02:46 AM
First post – thought I’d share a script I wrote a while ago. The script’s goal is to make complex security systems more robust and scalable.
Let’s say that you have a single room that you want to secure. Of course, the most obvious solution is to simply put a password on the machine. The problem with this, however, is that anybody with the password can get in (it’s easily shared), and that if the password needs to be changed, the admin would have to change the password on the terminal’s hard drive. Of course this is no problem on a small install.
But let’s say you have five doors that you want to secure, and a number of users, each needing access to different doors. I came up with a solution that I think is ideal in this situation.
It works in three parts: the first is the disk which each user holds in their inventory containing a password unique to that user, the second is the client (installed on the terminal near to the door) which reads a code off of the user’s disk and verifies it remotely, and the server which provides the verification.
In normal operation, the system will work as follows: the user’s code is read from their disk, this code is sent from the client to the server via rednet, the server checks for the user’s code on a list corresponding to the ID of the client terminal, the server responds with either a yes or no, the client then either spits back an error or allows the user through the door.
Client
Server
Any comments or criticisms are welcome!
Let’s say that you have a single room that you want to secure. Of course, the most obvious solution is to simply put a password on the machine. The problem with this, however, is that anybody with the password can get in (it’s easily shared), and that if the password needs to be changed, the admin would have to change the password on the terminal’s hard drive. Of course this is no problem on a small install.
But let’s say you have five doors that you want to secure, and a number of users, each needing access to different doors. I came up with a solution that I think is ideal in this situation.
It works in three parts: the first is the disk which each user holds in their inventory containing a password unique to that user, the second is the client (installed on the terminal near to the door) which reads a code off of the user’s disk and verifies it remotely, and the server which provides the verification.
In normal operation, the system will work as follows: the user’s code is read from their disk, this code is sent from the client to the server via rednet, the server checks for the user’s code on a list corresponding to the ID of the client terminal, the server responds with either a yes or no, the client then either spits back an error or allows the user through the door.
Client
local server = 41
local opentime = 2
local output = "bottom"
local diskside = "left"
local rednetside = "top"
rednet.open(rednetside)
while true do
os.pullEvent("disk")
print("Disk found")
file = fs.open("/disk/user", "r")
print("File opened")
if file then
local text = file.readAll()
file.close()
print(text)
rednet.send(server, text)
print("Reqeust sent")
senderID, message, distance = rednet.receive()
print(message)
if senderID == server then
if text == message then
print("User verified")
rs.setOutput(output, true)
disk.eject(diskside)
os.sleep(opentime)
rs.setOutput(output, false)
else
print("User is forbidden")
end
else
print("The transmissed was hijacked")
end
else
print("User ID cannot be found")
end
end
Server
rednet.open("right")
while true do
sender, message, distance = rednet.receive()
print("Message received")
recordpath = table.concat({"/disk/records", sender}, "/")
print(recordpath)
file = fs.open(recordpath, "r")
if file then
local text = file.readAll()
file.close()
if string.find(text, message) then
print("User found")
rednet.send(sender, message)
else
print("User not found")
rednet.send(sender, "denied")
end
else
print("Records not found")
rednet.send("denied")
end
end
Any comments or criticisms are welcome!