Advertisement
superkh

Manage Admin

Sep 15th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --Vars----------------------------------------------------------------
  3. local rng = true
  4. local Exit = nil
  5. local cm = 1
  6. local w,h = term.getSize()
  7. local conf = A.getT("os/files/config")
  8. local Ctimer = nil
  9. local m = {"Reboot     ","Shutdown   ","Termanate  ","Login In  ","Create User","Delete User","Edit Pass  "}
  10. --Buffers-------------------------------------------------------------
  11. local bgb = buf.createBuffer() --background buffer
  12. ----------------------------------------------------------------------
  13. local function dtable(t)
  14.     for v,k in ipairs(t) do
  15.         if cm==v then
  16.             buf.wCentered(bgb,"[             ]",math.floor((h/2-(#t/2)))+v,colors.red,colors.black)
  17.             buf.wCentered(bgb,k,math.floor((h/2-(#t/2)))+v,colors.red,colors.black)
  18.         else
  19.             buf.wCentered(bgb,k,math.floor((h/2-(#t/2)))+v,colors.red,colors.black)
  20.         end
  21.     end
  22. end
  23. local function dm()
  24.     buf.drawFilledBox(bgb,1,2,w,h-1,colors.black)
  25.     dtable(m)
  26.     buf.drawBuffer(bgb)
  27.     A.Time(w-4,h,colors.gray,colors.white)
  28. end
  29. local function Startdm()
  30.     buf.tc(colors.red)
  31.     buf.bc(colors.black)
  32.     buf.clsB(bgb,colors.black,colors.red)
  33.     buf.clsLx(bgb,1,colors.gray)
  34.     buf.clsLx(bgb,h,colors.gray)
  35.     buf.wCentered(bgb,"Admin Console",1,colors.white,colors.gray)
  36.     buf.wLeft(bgb," Version: "..conf["VER"],h,colors.white,colors.gray)
  37. end
  38. local function WriteLeft(y,str)
  39.     term.setCursorPos(2,y)
  40.     term.setBackgroundColor(colors.black)
  41.     term.setTextColor(colors.red)
  42.     term.write(str)
  43. end
  44. --Main content tables-------------------------------------------------
  45. local f = {}
  46. table.insert(f,function() os.reboot() end)
  47. table.insert(f,function() os.shutdown() end)
  48. table.insert(f,function() error("Terminated") end)
  49. table.insert(f,function() Exit = "login"; rng = false end)
  50. table.insert(f,function()
  51.     local NUser = A.userin(2,2,4)
  52.     if fs.exists("os/users/"..NUser) == false then
  53.         fs.copy("os/files/UserData","os/users/"..NUser)
  54.     end
  55.     dm()
  56.     WriteLeft(3,"Created Account: "..NUser)
  57. end)
  58. table.insert(f,function()
  59.     local NUser = A.userin(2,2,4)
  60.     if fs.exists("os/users/"..NUser) and NUser~="Admin" then
  61.         fs.delete("os/users/"..NUser)
  62.     end
  63.     dm()
  64.     WriteLeft(3,"Deleted Account: "..NUser)
  65. end)
  66. table.insert(f,function()
  67.     local src = "os/users/Admin/Uconfig"
  68.     local Aconf = A.getT(src)
  69.     local Npass = A.userin(2,2,4)
  70.     if Npass ~= Aconf["PW"] then
  71.         Aconf["PW"] = Npass
  72.         A.setT(src,Aconf)
  73.     end
  74.     dm()
  75.     WriteLeft(3,"Saved Password: "..Npass)
  76. end)
  77. -- table.insert(f,function() end) --used for copy and paste for new meun options
  78. --function that must go after the table setup
  79. local function runFunction()
  80.     for v,k in ipairs(f) do
  81.         if cm == v then
  82.             k()
  83.         end
  84.     end
  85. end
  86. --Main----------------------------------------------------------------
  87. local function main()
  88.     --setup functions
  89.     Startdm()
  90.     dm()
  91.     Ctimer = os.startTimer(.1)
  92.     --main loop
  93.     while rng do
  94.         local arg = { os.pullEvent() }
  95.         if arg[1]=="timer" and arg[2]==Ctimer then
  96.             A.Time(w-4,h,colors.gray,colors.white)
  97.             Ctimer = os.startTimer(.01)
  98.         elseif arg[1]=="key" then
  99.             local function up()
  100.                 if cm==1 then
  101.                     cm=#m
  102.                 else
  103.                     cm = cm-1
  104.                 end
  105.                 dm()
  106.             end
  107.             local function down()
  108.                 if cm==#m then
  109.                     cm=1
  110.                 else
  111.                     cm = cm+1
  112.                 end
  113.                 dm()
  114.             end
  115.             if arg[2] == 208 then
  116.                 down()
  117.             elseif arg[2] == 205 then
  118.                 down()
  119.             elseif arg[2] == 200 then
  120.                 up()
  121.             elseif arg[2] == 203 then
  122.                 up()
  123.             elseif arg[2] == 28 then
  124.                 runFunction()
  125.             end
  126.         end
  127.     end
  128. end
  129. local ok, err = pcall(main)
  130. if not ok then
  131.     if err == "manage:48: Terminated" then
  132.         term.setBackgroundColor(colors.black)
  133.         term.setTextColor(colors.red)
  134.         term.clear()
  135.         term.setCursorPos(1,1)
  136.         print("Terminated")
  137.         term.setTextColor(colors.white)
  138.     else
  139.         A.Error(err)
  140.     end
  141. end
  142. if Exit == "login" then
  143.     shell.run("os/login")
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement