Advertisement
Vincent38190

DataSystem

May 21st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. if not fs.exists("/Fsociety/data/side") then
  2. print("ERROR NO SIDE FILE")
  3. os.reboot()
  4. end
  5. sideFile = fs.open("/Fsociety/data/side","r")
  6. modemSide = sideFile.readLine()
  7. sideFile.close()
  8. --------------------------------------------
  9. --                                        --
  10. --            Data System from            --
  11. --            Security System V0.1        --
  12. --            By Fsociety                 --
  13. --                                        --
  14. --------------------------------------------
  15. local m = peripheral.wrap(modemSide)
  16. m.open(102)
  17. if fs.exists("/Fsociety/data/whitelist") then
  18.   whitelistFile = fs.open("/Fsociety/data/whitelist","r")
  19. else
  20.   print("EDIT WHITELIST IN /Fsociety/data/whitelist")
  21.   fs.makeDir("/Fsociety")
  22.   fs.makeDir("/Fsociety/data")
  23.   create = fs.open("/Fsociety/data/whitelist","w")
  24.   create.write("Put withelisted user ( only one per line )")
  25.   create.close()
  26.   whitelistFile = fs.open("/Fsociety/data/whitelisted","r")
  27. end
  28. local nbLine = 0
  29. local whitelist = {}
  30. whitelistFile.readLine()
  31. while whitelistFile.readLine() ~= nil do
  32.   nbLine = nbLine + 1
  33. end
  34. whitelistFile.close()
  35. whitelistFile = fs.open("/Fsociety/data/whitelist","r")
  36. whitelistFile.readLine()
  37. for i=1,nbLine do
  38.   whitelist[i] = whitelistFile.readLine()
  39. end
  40. for x=1,nbLine do print(whitelist[x]) end
  41. whitelistFile.close()
  42. while true do
  43.   local event , param1 , param2 , param3 , param4 = os.pullEvent()
  44.   if event == "modem_message" then
  45.     print(param2)
  46.     print(param3)
  47.     print(param4)
  48.     if param4 ~= "pim" then  
  49.       test = true
  50.       for i=1,nbLine do
  51.         test = test and whitelist[i] ~= param4
  52.       end
  53.       if test == false then
  54.         m.transmit(101,55,"User allowed")
  55.       elseif test == true then
  56.         m.transmit(101,55,"User not allowed")
  57.       end
  58.     else
  59.       m.transmit(101,55,"Nobody")
  60.     end
  61.   end
  62.   sleep(0.1)
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement