Advertisement
Terraniel

Secure Portal

Jan 26th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. sense = peripheral.wrap("left")
  3. local plist = sense.getPlayerNames()
  4. local cScan = textutils.serialize(plist)
  5. local RadarActive = true
  6. local isSecure = false
  7. local lockdown = false
  8.  
  9. mon.setTextScale(1)
  10. mon.clear()
  11.  
  12. --Terminal Main()
  13. function termMain
  14. local attempts = 0
  15.  while true do
  16.   term.clear()
  17.   term.setCursorPos(1,1)
  18.   local locked = true
  19.   print("This is a secure Terminal. Your actions may be monitored")
  20.   print("for quality assurance purposes.")
  21.   print("Please enter your name:")
  22.   local chek = read()
  23.   if fs.exists("Clearance/"..chek) then
  24.    local csec=tonumber(curr.readLine())
  25.     if csec==1 then
  26.      local chek=curr.readLine()
  27.      print("Welcome "..cList[i]..". Please enter your password")
  28.      local chek2 = read()
  29.      if chek2 == chek then
  30.        adminTerm()
  31.      end
  32.     end
  33.   end
  34.  end     
  35. end
  36.  
  37.  
  38. --admin functions on terminal
  39. function adminTerm()
  40.  term.setBackgroundColor(colors.black)
  41.  term.clear()
  42.  term.setTextColor(colors.white)
  43.  term.setCursorPos(1,1)
  44.  term.setBackgroundColor(colors.gray)
  45.  term.clearLine()
  46.  print("Set Player Security Status")
  47.  term.setCursorPos(1,3)
  48.  term.clearLine()
  49.  print("Reset Player Security Status")
  50.  term.setCursorPos(1,5)
  51.  term.clearLine()
  52.  print("Set Book Clearance Level")
  53.  term.setCursorPos(1,7)
  54.  term.clearLine()
  55.  print("Remove Secured Book")
  56.  term.setCursorPos(1,9)
  57.  term.clearLine()
  58.  print("Lock Down Gate")
  59.  term.setCursorPos(1,11)
  60.  term.clearLine()
  61.  print("Quit")
  62.  local b,x,y = term.mouse_click()
  63.  if y == 13 then
  64.   print("Goodbye.")
  65.   os.sleep(0.5)
  66.   termMain()
  67.  end
  68.  
  69. end
  70.  
  71. adminTerm()
  72.  
  73. --resets the security status of a player
  74. function resetSec(qName)
  75.  setSecStat(qName,0)
  76. end
  77.  
  78. --sets the security status of a player
  79. --does not allow the editing of an admin
  80. function setSecStat(qName,newSS)
  81.  local locked = false
  82.  if fs.exists("Clearances/"..qName) then
  83.   local curr = fs.open("Clearances/"..qName,"r")
  84.   local cSec = tonumber(curr.readLine())
  85.   if cSec == 1 then
  86.    locked=true
  87.   end
  88.  end
  89.  if locked==false then
  90.   local curr = fs.open("Clearances/"..qName,"w")
  91.   curr.writeLine(newSS)
  92.   curr.close()
  93.  elseif locked==true then
  94.   print("You do not have permission to edit this user.")
  95.  end
  96. end
  97.  
  98. --checks if user has file, if not creates it
  99. --if so, returns security level
  100. function secStatus(qName)
  101.  local qList = fs.list("Clearances/")
  102.  local sLev = 0
  103.  local found = false
  104.  for i=1, #qList do --check user files, return secLev
  105.   if qName==qList[i] then
  106.    local curr = fs.open("Clearances/"..qName,"r")
  107.    print("Player: "..qName)
  108.    sLev = tonumber(curr.readLine())
  109.    print("sLev: "..sLev)
  110.    curr.close()
  111.    found = true
  112.    end
  113.   end
  114.  if found == false then --create a new default user
  115.   local curr = fs.open("Clearances/"..qName,"w")
  116.   curr.writeLine("0")
  117.   curr.close()
  118.  end
  119.  return sLev
  120. end
  121.    
  122.  
  123. --checks for Clearances directory, if not creates
  124. --it and stores a new admin
  125. function startChk()
  126.  if fs.exists("Clearances/") == false then
  127.   fs.makeDir("Clearances")
  128.   term.clear()
  129.   term.setCursorPos(1,1)
  130.   local admin
  131.   if RadarActive == true then
  132.    if #plist>1 then
  133.     print("Please Secure Area. Only 1 admin is allowed")
  134.     while #plist>1 do
  135.      plist = sense.getPlayerNames()
  136.     end
  137.     term.clear()
  138.    end
  139.    admin = plist[1]
  140.   else
  141.    print("Radar is currently offline")
  142.    print("Please enter your name")
  143.    admin = read()
  144.   end
  145.   term.clear()
  146.   term.setCursorPos(1,1)
  147.   print("Welcome "..admin)
  148.   print("Please enter a password")
  149.   local adpass = read()
  150.   local secStat = 1
  151.   local file = fs.open("Clearances/"..admin,"w")
  152.   file.writeLine(secStat)
  153.   file.writeLine(adpass)
  154.   file.close()
  155.  end
  156. end
  157.    
  158.  
  159. function scan()
  160.  while true do
  161.   plist = sense.getPlayerNames()
  162.   local nScan = textutils.serialize(plist)
  163.   os.sleep(0.15)
  164.   for i=1,#plist do
  165.    mon.setTextColor(colors.white)
  166.    mon.setCursorPos(2,2*i-1)
  167.    mon.write(plist[i])
  168.    local level = secStatus(plist[i])
  169.    mon.setTextColor(colors.red)
  170.    mon.write(" "..level)
  171.   end
  172.   if cScan~=nScan then
  173.    mon.clear()
  174.    cScan=nScan
  175.   end
  176.  end
  177. end
  178.  
  179. function getClick()
  180.  event,side,x,y = os.pullEvent("monitor_touch")
  181.  mon.setCursorPos(x,y)
  182.  mon.setBackgroundColor(colors.cyan)
  183.  mon.write(" ")
  184.  mon.setBackgroundColor(colors.black)
  185. end
  186.  
  187. function main()
  188.  while true do
  189.   getClick()
  190.  end
  191. end
  192.  
  193. startChk()
  194.  
  195. --parallel.waitForAll(scan, main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement