Advertisement
Guest User

config.lua

a guest
Apr 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.83 KB | None | 0 0
  1. local ID = os.computerID()
  2. local Au = {}
  3. local user = {}
  4. local Us = {}
  5. local Edt = {}
  6. local Ddt = {}
  7. local u = fs.open("saves/USER"..ID..".txt","r")
  8. local u = fs.open("disk/OaSiS/USER"..ID..".txt","r")
  9. local Us = textutils.unserialize(u.readAll())
  10. local A = fs.open("saves/Admin.txt","r")
  11. local Ad = fs.open("disk/OaSiS/Admin.txt","r")
  12. local Edt = textutils.unserialize(A.readAll())
  13. local Ddt = textutils.unserialize(Ad.readAll())
  14. local guser = Us.name
  15. local gpass = Us.pass
  16. local gtype = Us.type
  17. local gside = Us.side
  18. local duser = Edt.name
  19. local dtype = Edt.type
  20. local dpass = Edt.pass
  21. local Cpass = Ddt.pass
  22. local dside = Edt.side
  23. local Bpass = "Admin"
  24. u.close()
  25. A.close()
  26. Ad.close()
  27.  
  28. local function aCheck()
  29.   Au.name = duser
  30.   Au.type = dtype
  31.   Au.pass = dpass
  32.   Au.side = dside
  33. end
  34.  
  35. local function uCheck()
  36.   user.name = guser
  37.   user.type = gtype
  38.   user.pass = gpass
  39.   user.side = gside
  40. end
  41.  
  42. local function Dis()
  43.  term.setBackgroundColor(colors.white)
  44.  term.clear()
  45.  term.setTextColor(colors.green)
  46.  term.setCursorPos(16, 3)
  47.  term.write("Admin Config")
  48.  term.setTextColor(colors.black)
  49. end
  50.  
  51. local function Edt( user )
  52.  local c = fs.open("saves/USER"..ID..".txt","w")
  53.  local dc = fs.open("disk/OaSiS/USER"..ID..".txt","w")
  54.  c.write(textutils.serialize(user))
  55.  dc.write(textutils.serialize(user))
  56.  dc.close()
  57.   c.close()
  58. end
  59.  
  60.  
  61. local function edit( Au )
  62.    local S = fs.open("saves/Admin.txt", "w")
  63.    local Ds = fs.open("disk/OaSiS/Admin.txt","w")
  64.    S.write(textutils.serialize(Au))
  65.    Ds.write(textutils.serialize(Au))
  66.    S.close()
  67.    Ds.close()
  68.  
  69. end
  70.  
  71. local function Blog()
  72.   paintutils.drawLine(14, 4, 31, 4, colors.blue)
  73.   term.setTextColor(colors.black)
  74.   term.setCursorPos(14,4)
  75.   write("Change Login info")
  76.  
  77. end
  78.  
  79. local function Bside()
  80.  paintutils.drawLine(14, 6, 31, 6, colors.blue)
  81.  term.setTextColor(colors.black)
  82.  term.setCursorPos(16, 6)
  83.  write("Change Side")
  84. end
  85.  
  86. local function Btype()
  87.  paintutils.drawLine(14, 8, 31, 8, colors.blue)
  88.  term.setTextColor(colors.black)
  89.  term.setCursorPos(16, 8)
  90.  write("Change Type")
  91. end
  92.  
  93. local function Bcon()
  94.  paintutils.drawLine(14, 10, 31, 10, colors.blue)
  95.  term.setTextColor(colors.black)
  96.  term.setCursorPos(16, 10)
  97.  write("Adv Config")
  98. end
  99.  
  100. local function Bform()
  101.  paintutils.drawLine(14, 12, 31, 12, colors.blue)
  102.  term.setTextColor(colors.black)
  103.  term.setCursorPos(17, 12)
  104.  write("Format a Disk")
  105. end
  106.  
  107. local function SideP()
  108.   term.setCursorPos(7, 5)
  109.   write("which side do you wish to output to?")
  110.   paintutils.drawLine(10, 7, 30, 7, colors.lightGray)
  111.   term.setCursorPos(11, 7)
  112.   nside = read()
  113.   uCheck()
  114.   aCheck()
  115.   user.side = nside
  116.   Au.side = nside
  117.   Edt( user )
  118.   edit( Au )
  119.   Dis()
  120.   term.setCursorPos(9, 5)
  121.   write("Output side has been changed!")
  122.   sleep(0.2)
  123.   menu()
  124. end
  125.  
  126.  
  127.  
  128. local function LogP()
  129.  while true do
  130.    term.setTextColor(colors.black)
  131.    term.setBackgroundColor(colors.white)
  132.    term.setCursorPos(7, 5)
  133.    write("What login info do you wish to change?")
  134.    paintutils.drawLine(9, 7, 19, 7, colors.green)
  135.    term.setTextColor(colors.white)
  136.    term.setCursorPos(10, 7)
  137.    write("Password")
  138.    paintutils.drawLine(21, 7, 31, 7, colors.green)
  139.    term.setCursorPos(22, 7)
  140.    write("Username")
  141.    paintutils.drawLine(12, 9, 27, 9, colors.green)
  142.    term.setCursorPos(13,9)
  143.    write("Admin password")
  144.    paintutils.drawLine(44, 16, 50, 16, colors.lightGray)
  145.    term.setCursorPos(45, 16)
  146.    write("back")
  147.    sleep(0.5)
  148.     local event, a1, a2, a3 = os.pullEvent()
  149.     if event == "mouse_click" then
  150.       if (a2 >= 9 and a2 <= 19) and (a3 >= 7 and a3 <= 7) then
  151.        Dis()
  152.        term.setCursorPos(10, 6)
  153.        write("Choose a new Password")
  154.        paintutils.drawLine(10, 8, 30, 8, colors.lightGray)
  155.        term.setCursorPos(11,8)
  156.        local npass = read()
  157.         uCheck()
  158.         user.pass = npass
  159.         Edt( user )
  160.         Dis()
  161.         term.setCursorPos(9, 5)
  162.         write("Password successfully changed.")
  163.         menu()
  164.       elseif (a2 >= 21 and a2 <= 31) and (a3 >= 7 and a3 <= 7) then
  165.        Dis()
  166.        term.setCursorPos(10, 6)
  167.        write("Choose a new Username")
  168.        paintutils.drawLine(10, 8, 30, 8, colors.lightGray)
  169.        term.setCursorPos(11, 8)
  170.        local nuser = read()
  171.        aCheck()
  172.        uCheck()
  173.        user.name = nuser
  174.        Au.name = nuser
  175.        Edt( user )
  176.        edit( Au )
  177.        Dis()
  178.        term.setCursorPos(9, 5)
  179.        write("Username successfully changed.")
  180.        menu()
  181.       elseif (a2 >= 12 and a2 <= 27) and (a3 >= 9 and a3 <= 9) then
  182.        Dis()
  183.        term.setCursorPos(10, 6)
  184.        write("Choose a new Admin password")
  185.        paintutils.drawLine(10, 8, 30, 8, colors.lightGray)
  186.        term.setCursorPos(11,8)
  187.        local anpass = read("*")
  188.        if dpass == Cpass then
  189.         aCheck()
  190.         Au.pass = anpass
  191.         edit( Au )
  192.         Dis()
  193.         term.setCursorPos(6, 5)
  194.         write("Admin password successfully changed.")
  195.         menu()
  196.        else
  197.         Dis()
  198.         term.setCursorPos(10, 6)
  199.         write("Invaild card!")
  200.         sleep(2)
  201.         menu()
  202.        end
  203.       elseif (a2 >= 44 and a2 <= 50) and (a3 >= 16 and a3 <= 16) then
  204.        Dis()
  205.        menu()
  206.      
  207.       end
  208.     end
  209.   end
  210. end
  211.  
  212. function menu()
  213.   while true do
  214.     local event, arg1, arg2, arg3 = os.pullEvent()
  215.       sleep(0.5)
  216.       Dis()
  217.       Blog()
  218.       Bside()
  219.       Btype()
  220.       Bcon()
  221.       Bform()
  222.       if event == "mouse_click" then
  223.         if (arg2 >= 8 and arg2 <= 25) and (arg3 >= 4 and arg3 <= 4) then
  224.           Dis()
  225.           LogP()
  226.         elseif (arg2 >= 14 and arg2 <= 31) and (arg3 >= 6 and arg3 <= 6) then
  227.            Dis()
  228.            SideP()
  229.         elseif (arg2 >= 14 and arg2 <= 31) and (arg3 >= 8 and arg3 <= 8) then
  230.            Dis()
  231.            TypeB()
  232.         elseif (arg2 >= 14 and arg2 <= 31) and (arg3 >= 10 and arg3 <= 10) then
  233.      
  234.         elseif (arg2 >= 14 and arg2 <= 31) and (arg3 >= 12 and arg3 <= 12) then
  235.      
  236.        end
  237.      end
  238.   end
  239. end
  240. local function config()
  241.    -- first time ruinng admin config
  242.    if dpass == Bpass then
  243.       Dis()
  244.       term.setCursorPos(8,5)
  245.       term.setTextColor(colors.black)
  246.       write("please setup a proper Admin password")
  247.       paintutils.drawLine(8, 7, 20, 7,colors.lightGray)
  248.       term.setCursorPos(8,7)
  249.   local Apass = read("*")
  250.       aCheck()
  251.       Au.pass = Apass
  252.  
  253.       edit( Au )
  254.       menu()
  255.     else
  256.      Dis()
  257.      term.setTextColor(colors.black)
  258.      term.setCursorPos(4,4)
  259.      write("For secure purposes we ask once more for adm pass")
  260.      paintutils.drawLine(8, 7, 20, 7,colors.lightGray)
  261.      term.setCursorPos(8,7)
  262.      local adpass = read("*")
  263.      if adpass == dpass then
  264.       Dis()
  265.       menu()
  266.     else
  267.      print("incorrect")
  268.      shell.run("startup")
  269.     end
  270.    
  271.   end  
  272. end
  273.  
  274. config()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement