Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Var init
- local RP_BOOL = true
- local NETWORK_LIST = {}
- --Log
- local function log(ID, oMSG, reason)
- local FILE = fs.open("/log", "a")
- if type(oMSG) == "string" then
- local toMSG = oMSG
- elseif type(oMSG) == "table" then
- local toMSG = textutils.serialise(oMSG)
- else
- toMSG = "nil"
- end
- toMSG = "nil"
- local TEMP = "[LOG] ID:"..ID.." toMSG: "..toMSG.." Reason: "..reason
- print(TEMP)
- FILE.writeLine(TEMP)
- FILE.close()
- return true
- end
- --Users management
- local USER_FILE = "/users"
- local DB_SCHEM = {Users = {}, Password = {}, Biolock = {}, AccessLevel = {}, Token= {}}
- local function USERS_CREATEDB()
- local USER_TEMP = fs.open(USER_FILE, "w")
- USER_TEMP.write(textutils.serialise(DB_SCHEM))
- USER_TEMP.close()
- end
- local function USERS_GET()
- local OBJECT_UF = fs.open(USER_FILE, "r")
- local USERS = textutils.unserialise(OBJECT_UF.readAll())
- if USERS == nil then
- USERS_CREATEDB()
- USERS = textutils.unserialise(OBJECT_UF.readAll())
- end
- OBJECT_UF.close()
- return USERS
- end
- local function USERS_ID(users, tofind)
- local ID = nil
- for i = 1,#users["Users"] do
- if tofind == nil then
- ID = i
- else
- if users["Users"][i] == tofind then
- ID = i
- end
- end
- end
- return ID
- end
- local function USERS_CREATE(name, pass, biolock, accesslevel)
- local oUSERS = USERS_GET()
- local fUSERS = oUSERS
- local lastID = USERS_ID(oUSERS)
- if lastID == nil then lastID = 1 else lastID = lastID + 1 end
- if name == nil or pass == nil or accesslevel == nil then
- return false
- end
- if biolock == nil then biolock = "unknown" end
- fUSERS["Users"][lastID] = name
- fUSERS["Password"][lastID] = pass
- fUSERS["Biolock"][lastID] = biolock
- fUSERS["Token"][lastID] = "unknown" --add token generator
- fUSERS["AccessLevel"][lastID] = accesslevel
- local TO_SAVE = fs.open(USER_FILE,"w")
- TO_SAVE.write(textutils.serialise(fUSERS))
- TO_SAVE.close()
- end
- --We need the famous Gitano Parser !
- local function gitanoParser(sTable,sID)
- print(type(sTable))
- print(sTable)
- if sTable.type == nil then
- log(sID, sTable, "bad type")
- return false
- elseif sTable.type == "token" then
- elseif sTable.type == "entry" then
- elseif sTable.type == "log" then
- elseif sTable.type == "ping" then
- rednet.send(sID, true)
- log(sID, sTable, "ping")
- elseif sTable.type == "WAS" then --Wow address system
- elseif sTable.type == "database" then
- if sTable.todo == "createUser" then
- if sTable.Username == nil or sTable["Password"] == nil or sTable["Biolock"] == nil or sTable["accesslevel"] == nil then
- else
- if USERS_CREATE(sTable.Username,sTable.Password,sTable.Biolock,sTable.accesslevel) then
- print("User Created")
- rednet.send(sID, true)
- else
- print("Failed to create")
- rednet.send(sID, true)
- end
- end
- elseif sTable.todo == "Userinfo" then
- elseif sTable.todo == "reset" then
- USERS_CREATEDB()
- end
- elseif sTable.type == "network" then
- end
- end
- --Database
- term.write("Rednet state: ")
- if rednet.isOpen() then print("true") else print("false") end
- if rednet.isOpen() ~= true then rednet.open("top") end
- rednet.host("HomePI", "main")
- print("Rednet opened\nID: ".. os.computerID())
- --USERS_CREATEDB()
- --print(USERS_CREATE("admin", "test", "unknown", 5))
- local function securityinit()
- term.clear() --To finish
- end
- local function receiveparse()
- while RP_BOOL do
- local sID, msg = rednet.receive()
- if type(msg) ~= "table" then rednet.send(sID, "Please use API") log(sID, msg, "Dont use a table") else
- gitanoParser(msg,sID) -- redirect to gitanoParser
- end
- end
- end
- parallel.waitForAll(receiveparse)
Add Comment
Please, Sign In to add comment