Compare commits
4
Commits
issue-1
...
a64c72d4fc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a64c72d4fc | ||
|
|
41cfa4c9c6 | ||
|
|
6d063ddf97 | ||
|
|
502065149b |
No files matched your search
+36
-25
@@ -15,18 +15,16 @@ local function establish_connection()
|
|||||||
for _, side in ipairs(peripherals) do
|
for _, side in ipairs(peripherals) do
|
||||||
if peripheral.getType(side) == "modem" then
|
if peripheral.getType(side) == "modem" then
|
||||||
rednet.open(side)
|
rednet.open(side)
|
||||||
print("Opened modem: "..side)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print("No modem found!")
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function validate_clearance(computer_id, clearance_level)
|
function validate_clearance(computer_id, clearance_level)
|
||||||
if establish_connection() then
|
if establish_connection() then
|
||||||
tg_server_id = rednet.lookup("tg", tg_server_name)
|
tg_server_id = rednet.lookup('tg', tg_server_name)
|
||||||
rednet.send(tg_server_id, "validate_clearance,"..computer_id..","..clearance_level)
|
rednet.send(tg_server_id, "validate_clearance,"..computer_id..","..clearance_level,"tg")
|
||||||
local id, msg, proto = rednet.receive("tg")
|
local id, msg, proto = rednet.receive("tg")
|
||||||
if msg == "granted" then
|
if msg == "granted" then
|
||||||
return true
|
return true
|
||||||
@@ -41,11 +39,11 @@ end
|
|||||||
function validate_key(minimum_clearance)
|
function validate_key(minimum_clearance)
|
||||||
if establish_connection() then
|
if establish_connection() then
|
||||||
if fs.exists("/disk/key") then
|
if fs.exists("/disk/key") then
|
||||||
key_file = fs.open("/disk/key","r")
|
local key_file = fs.open("/disk/key","r")
|
||||||
key = key_file.readLine()
|
local key = key_file.readLine()
|
||||||
tg_server_id = rednet.lookup('tg', tg_server_name)
|
tg_server_id = rednet.lookup('tg', tg_server_name)
|
||||||
rednet.send(tg_server_id, "validate_key,"..key..","..minimum_clearance, "tg")
|
rednet.send(tg_server_id, "validate_key,"..key..","..minimum_clearance, "tg")
|
||||||
id, msg, _ = rednet.receive("tg")
|
local id, msg, _ = rednet.receive("tg")
|
||||||
if msg == "authentication successful" then
|
if msg == "authentication successful" then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
@@ -59,27 +57,40 @@ function validate_key(minimum_clearance)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if fs.exists('/disk/key') then
|
function authenticate()
|
||||||
key_file = fs.open('/disk/key', 'r')
|
if fs.exists('/disk/key') then
|
||||||
key = key_file.readLine()
|
local key_file = fs.open('/disk/key', 'r')
|
||||||
if establish_connection() then
|
local key = key_file.readLine()
|
||||||
tg_server_id = rednet.lookup("tg", tg_server_name)
|
if establish_connection() then
|
||||||
rednet.send(tg_server_id, "authenticate,"..key,"tg")
|
tg_server_id = rednet.lookup("tg", tg_server_name)
|
||||||
local id, msg, proto = rednet.receive("tg")
|
rednet.send(tg_server_id, "authenticate,"..key,"tg")
|
||||||
|
local id, msg, proto = rednet.receive("tg")
|
||||||
|
|
||||||
if msg == "authentication successful" then
|
if msg == "authentication successful" then
|
||||||
key_parts = split(key,',')
|
local key_parts = split(key,',')
|
||||||
local card_holder = key_parts[1]
|
local card_holder = key_parts[1]
|
||||||
local card_clearance = key_parts[2]
|
local card_clearance = key_parts[2]
|
||||||
print("Authentication was successful.")
|
return true, _, card_holder, card_clearance
|
||||||
print("Hello "..card_holder..", you were granted clearance level "..card_clearance.." for this computer.")
|
else
|
||||||
|
print("Authentication failed.")
|
||||||
|
return false, "authentication failed"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
print("Authentication failed.")
|
return false, "modem not found"
|
||||||
end
|
end
|
||||||
|
key_file.close()
|
||||||
else
|
else
|
||||||
return false, "modem not found"
|
print("Key file not found. Aborting.")
|
||||||
|
return false, "key file not found"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if args[1] == "auth" or args[1] == "authenticate" then
|
||||||
|
local success, error, card_holder, card_clearance = authenticate()
|
||||||
|
if success then
|
||||||
|
print("Authentication was successful.")
|
||||||
|
print("Hello "..card_holder..", you were granted clearance level "..card_clearance.." for this computer.")
|
||||||
|
else
|
||||||
|
print("Authentication failed: "..error)
|
||||||
end
|
end
|
||||||
key_file.close()
|
|
||||||
else
|
|
||||||
print("Key file not found. Aborting.")
|
|
||||||
end
|
end
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local config = {
|
local config = {
|
||||||
name = "tg_server",
|
name = "tg_server",
|
||||||
modem_side = "top",
|
modem_side = "top",
|
||||||
clearance_expiry = 600, -- Minutes until clearance will expire
|
clearance_expiry = 600, -- Seconds until clearance will expire
|
||||||
key_file = "verified_keys.txt", -- Name of the key file, relative to tg_server.lua
|
key_file = "verified_keys.txt", -- Name of the key file, relative to tg_server.lua
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
@@ -3,7 +3,7 @@ local dir = fullPath:match("^(.*/)") or ""
|
|||||||
|
|
||||||
local config = dofile(dir..'taskguard.cfg')
|
local config = dofile(dir..'taskguard.cfg')
|
||||||
|
|
||||||
local clearances = { { computer_id = 1, clearance_level = 1, time_granted = os.clock() } }
|
local clearances = { } -- { computer_id = 1, clearance_level = 1, time_granted = os.clock() }
|
||||||
|
|
||||||
local function split(str, divider)
|
local function split(str, divider)
|
||||||
local t = {}
|
local t = {}
|
||||||
|
|||||||
Reference in new issue
Block a user