Advertisement
Guest User

startup

a guest
Apr 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.39 KB | None | 0 0
  1. local Page = window.create( term.current(), 0, 3, 52,17)
  2. local Hd = window.create( term.current(), 0, 0, 52, 3)
  3. local box = window.create( term.current(), 0, 19, 52, 1)
  4. local time = os.time()
  5. local Tbe = {}
  6. local ID = os.getComputerID()
  7.  local Adpass = "Admin"
  8. local Hs = "hom"
  9. local B = "biz"
  10. local function start()
  11.  
  12.  if fs.exists("startup") == false then
  13.    term.setBackgroundColor(colors.white)
  14.    term.clear()
  15.    Page.setCursorPos(17, 6)
  16.    term.setTextColor(colors.green)
  17.    textutils.slowPrint("installing OaSiS")
  18.    term.setTextColor(colors.lightGray)
  19.    term.setCursorPos(6, 12)
  20.    write("Tip:Put a disk in while setting up config!")
  21.    term.setTextColor(colors.black)
  22.    Page.setCursorPos(33, 6)
  23.    sleep(0.7)
  24.    textutils.slowPrint("...")
  25.    fs.copy("disk/startup", "startup")
  26.    fs.copy("disk/config.lua","config.lua")
  27.    Page.setCursorPos(33, 6)
  28.    sleep(0.7)
  29.    textutils.slowPrint("   ")
  30.    Page.setCursorPos(33, 6)
  31.    sleep(0.7)
  32.    textutils.slowPrint("...")
  33.    sleep(0.7)
  34.    Page.setCursorPos(33, 6)
  35.    textutils.slowPrint("   ")
  36.    term.setBackgroundColor(colors.white)
  37.    term.clear()
  38.    term.setTextColor(colors.green)
  39.    Page.setCursorPos(15, 10)
  40.    write("Installation complete.")
  41.   local Driveside
  42.     for _, side in ipairs(rs.getSides()) do
  43.       if peripheral.isPresent(side) and peripheral.getType(side) == "drive" then
  44.         Driveside = side
  45.        break
  46.       end
  47.      end
  48.     disk.eject(Driveside)
  49.    sleep(1)
  50.   else
  51.  end
  52. end
  53.  
  54. os.pullEvent = os.pullEventRaw
  55. function SecureV()
  56.  
  57.    local u = fs.open("saves/Admin.txt", "r")
  58.    local Mt = textutils.unserialise(u.readAll())
  59.    local name = Mt.name
  60.      u.close()
  61.        box.setBackgroundColor(colors.white)
  62.        box.clear()
  63.        Hd.setCursorPos(21,2)
  64.        box.setTextColor(colors.gray)
  65.      if type == Hs then
  66.        Hd.write("User:"..name)
  67.       else
  68.        box.setCursorPos(2,1)
  69.        box.write("Authorized personnel use only")
  70.      end
  71.        box.setCursorPos(48,1)
  72.        box.setTextColor(colors.gray)
  73.        box.write("V2.0")
  74.        Hd.setCursorPos(2, 2)
  75.        Hd.write("Pc:"..os.getComputerLabel())
  76. end          
  77.                        
  78.                                    
  79.                                                
  80.                                                            
  81.                                                                        
  82.                                                                                                
  83.                                                                                                
  84. local time = os.time()
  85.  
  86. local function time()
  87.    Hd.setCursorPos(45,2)
  88.    Hd.setBackgroundColor( colors.white )
  89.    Hd.clear()
  90.    Hd.setTextColor(colors.gray)
  91.    Hd.write(""..textutils.formatTime(os.time()))
  92.    TimeDisplay = os.startTimer(1)
  93. end
  94.  
  95. local function Reg( Au )
  96.  
  97.          local A = fs.open("saves/Admin.txt", "w")
  98.          A.write(textutils.serialize(Au))
  99.          A.close()
  100. end
  101.  
  102. local function reg( user )
  103.         local f = fs.open("saves/USER"..ID..".txt","w")
  104.          f.write(textutils.serialize(user))
  105.          f.close()
  106. end  
  107. start()
  108. local T = false
  109.  
  110. local function Regist()
  111. if fs.exists("saves/Admin.txt") == false then
  112.  
  113.   Page.setBackgroundColor(colors.white)
  114.   Page.clear()
  115.   time()
  116.   local Au = {}
  117.   local user = {}
  118.   Page.setCursorPos(8, 3)
  119.   Page.setTextColor(colors.black)
  120.   Page.write("Is this for Business or Personal use?")
  121.   Page.setBackgroundColor(colors.blue)
  122.   Page.setCursorPos(15, 10)
  123.   Page.write("Business")
  124.   Page.setBackgroundColor(colors.green)
  125.   Page.setTextColor(colors.white)
  126.   Page.setCursorPos(33, 10)
  127.   Page.write("personal")    
  128.     repeat  
  129.       local event, s1, s2, s3 = os.pullEvent()
  130.         if event == "mouse_click" then
  131.          if (s2 >= 15 and s2 <= 23) and (s3 >= 12 and s3 <= 12) then
  132.             stype = "biz"
  133.            T = true
  134.            Page.clear()
  135.           elseif (s2 >= 33 and s2 <= 41) and (s3 >= 12 and s3 <= 12) then
  136.             stype = "hom"
  137.            T = true
  138.            Page.clear()
  139.          end
  140.         else
  141.         T = false
  142.         end
  143.     until T == true
  144.   user.type = stype
  145.   Au.type = stype
  146.   Page.setCursorPos(14, 3)
  147.   Page.setBackgroundColor(colors.white)
  148.   Page.clear()
  149.   Page.setTextColor(colors.green)
  150.   Page.write("Config")
  151.   Page.setTextColor(colors.black)
  152.   paintutils.drawLine(13, 7, 38, 7, colors.lightGray)
  153.   Page.setCursorPos(14, 4)
  154.   Page.write("Enter your desired name")
  155.   fs.makeDir("saves")
  156.   time()
  157.   Page.setCursorPos(14, 8)
  158.   paintutils.drawLine(13, 10, 38, 10, colors.lightGray)
  159.   Page.setCursorPos(14, 7)
  160.   Page.write("Enter a Password")
  161.   Page.setCursorPos(14, 10)
  162.   Page.write("PC-Name")
  163.   paintutils.drawLine(13, 13, 38, 13, colors.lightGray)
  164.   Page.setCursorPos(14, 13)
  165.   Page.write("Redstone side?"   )
  166.   paintutils.drawLine(13, 16, 38, 16, colors.lightGray)
  167.   Page.setCursorPos(14, 5)
  168.  
  169.   Uname = read()
  170.   user.name = Uname
  171.   Au.name = Uname
  172.   time()
  173.   paintutils.drawPixel(11, 7, colors.green)
  174.   term.setCursorPos(11, 7)
  175.   print("+")
  176.   term.setBackgroundColor(colors.lightGray)
  177.   Page.setCursorPos(14, 8)
  178.   user.pass = read()
  179.   Au.pass = Adpass
  180.   time()
  181.   paintutils.drawPixel(11, 10, colors.green)
  182.   term.setCursorPos(11, 10)
  183.   print("+")
  184.   term.setBackgroundColor(colors.lightGray)
  185.   Page.setCursorPos(14, 11)
  186.   local Pc = read()
  187.   os.setComputerLabel(Pc)
  188.   paintutils.drawPixel(11, 13, colors.green)
  189.   term.setCursorPos(11, 13)
  190.   print("+")
  191.   Page.setCursorPos(14, 14)
  192.   term.setBackgroundColor(colors.lightGray)
  193.   Uside = read()
  194.  
  195.   Au.side = Uside
  196.   user.side = Uside
  197.   time()
  198.   paintutils.drawPixel(11, 16, colors.green)
  199.   term.setCursorPos(11, 16)
  200.   print("+")
  201.   sleep(1)
  202.    reg( user )
  203.    Reg( Au )
  204.  if fs.exists("disk/") == false then
  205.    Page.clear()
  206.    time()
  207.     Page.setCursorPos(9, 5)
  208.     Page.write("No disk was found to be formatted.")
  209.     Page.setCursorPos(11, 6)
  210.     Page.write("do you wish to format a disk?")
  211.     Page.setTextColor(colors.black)
  212.     paintutils.drawLine(15, 10, 19, 10, colors.green)
  213.     Page.setCursorPos(17, 8)
  214.     print("Yes")
  215.     paintutils.drawLine(26, 10, 29, 10,colors.red)
  216.     Page.setCursorPos(28, 8)
  217.     print("No")
  218.   while true do  
  219.    local event, arg1, arg2, arg3 = os.pullEvent()
  220.    if event == "mouse_click" then
  221.         if (arg2 >= 15 and arg2 <= 19) and (arg3 >= 10 and arg3 <= 10) then
  222.    
  223.          term.setBackgroundColor(colors.white)
  224.          Page.clear()
  225.          Page.setCursorPos(16, 12)
  226.          
  227.          Page.write("waiting for input..")
  228.          repeat
  229.          local S = os.pullEvent()
  230.            Page.setCursorPos(33, 12)
  231.            textutils.slowPrint("...")
  232.            Page.setCursorPos(33, 12)
  233.            textutils.slowPrint("   ")
  234.            Page.setCursorPos(33, 12)
  235.            textutils.slowPrint("...")
  236.            if S == "disk" then
  237.    
  238.               sleep(0.5)
  239.              
  240.               o = true
  241.              
  242.            else
  243.              o = false
  244.            end
  245.              until o == true
  246.                 diskb()
  247.                
  248.         elseif (arg2 >= 26 and arg2 <= 29) and (arg3 >= 10 and arg3 <= 10) then
  249.           term.setBackgroundColor(colors.white)
  250.           Page.clear()
  251.           Page.setCursorPos(13,12)
  252.           print("No disk has been formatted")
  253.           sleep(1)
  254.           os.reboot()
  255.          end
  256.       elseif event == "disk" then
  257.            diskb()
  258.            
  259.          end
  260.       end
  261.     else
  262.      diskb()
  263.     end
  264.   end
  265. end
  266.  
  267.  
  268. function diskb()
  269.             term.setBackgroundColor(colors.white)
  270.             Page.setCursorPos(16, 15)
  271.             print("formatting disk..")
  272.             sleep(1)            
  273.           if fs.exists("disk/") == true then
  274.                if fs.exists("disk/OaSiS/USER"..ID.."txt") then
  275.                    fs.delete("disk/OaSiS/USER"..ID..".txt")
  276.                end
  277.                
  278.                fs.copy("saves/Admin.txt", "disk/OaSiS/Admin.txt")
  279.                fs.copy("saves/USER"..ID..".txt", "disk/OaSiS/USER"..ID..".txt")  
  280.                   Page.write("Note: This will be your Admin card.")
  281.                   Page.setTextColor(colors.green)
  282.                   Page.setCursorPos(14, 3)
  283.                  
  284.                   Page.setCursorPos(16, 16)
  285.                   Page.write("Formatted!")
  286.                   name()
  287.           else
  288.                 print("No disk!")
  289.           end
  290. end
  291.          
  292.              
  293.              
  294. function name()
  295.              
  296.              if fs.exists("disk/OaSiS/Admin.txt") == true then
  297.              
  298.              
  299.               local driveside
  300.                 for _, side in ipairs(rs.getSides()) do
  301.                    if peripheral.isPresent(side) and peripheral.getType(side) == "drive" then
  302.                    driveside = side
  303.                 break
  304.                  end
  305.                end
  306.  
  307.       if driveside then
  308.             disk.getLabel(driveside)
  309.             disk.setLabel(driveside, "AdminKey")
  310.  
  311.             Page.setCursorPos(13, 16)
  312.             term.setBackgroundColor(colors.white)
  313.             Page.write("Configuration finalized!")
  314.              sleep(2)
  315.              os.reboot()
  316.          else
  317.          
  318.           term.setBackgroundColor(colors.white)
  319.           term.setTextColor(colors.red)
  320.           Page.setCursorPos(14, 16)
  321.           print("formatting failed")
  322.          
  323.         end
  324.       end
  325.     end  
  326.  
  327.  
  328. Regist()
  329.  
  330.                                      
  331. function Login()
  332.  
  333.  
  334.   Page.setBackgroundColor( colors.black )
  335.   Page.clear()
  336.   box.clear()
  337.   time()
  338.   SecureV()
  339.   Hd.setBackgroundColor( colors.white)
  340.   term.setTextColor( colors.gray)
  341.   Page.setTextColor( colors.lime )
  342.   Page.setCursorPos(24,4)
  343.   Page.write("OaSiS")
  344.   paintutils.drawLine(13, 10, 38, 10, colors.gray)
  345.   paintutils.drawLine(12, 9, 12, 10, colors.gray)
  346.   paintutils.drawLine(13, 9, 38, 9, colors.lightGray)
  347.   Page.setTextColor(colors.gray)
  348.   Page.setCursorPos(17,7)
  349.   print("Type Password")  
  350. end
  351.  
  352.   local Gbe = {}
  353.    local s = fs.open("saves/Admin.txt","r")
  354.    local g = fs.open("saves/USER"..ID..".txt","r")
  355.    local Gbe = textutils.unserialize(g.readAll())
  356.    local Tbe = textutils.unserialize(s.readAll())
  357.    local user1 = Tbe.name
  358.    local pass1 = Tbe.pass
  359.    local side1 = Tbe.side
  360.    local type = Tbe.type
  361.    local Gpass = Gbe.pass
  362.    
  363.    s.close()
  364.    g.close()
  365.   -- local d = fs.open("disk/USERS.txt","r")
  366.   -- local Dtb = textutils.unserialize(d.readAll()
  367.    
  368.      
  369.  
  370.  
  371. function P()
  372.  Login()
  373.   Page.setCursorPos(14, 7)
  374.   password = read("*")
  375.  if (password == Gpass) then
  376.    if type == B then
  377.      U()
  378.  elseif (password == pass1) then
  379.    
  380.     shell.run("config")  
  381.    else
  382.    
  383.     pass()
  384.    end
  385.  else
  386.    Page.setTextColor(colors.red)
  387.    Page.setCursorPos(17, 10)
  388.    Page.write("Wrong Password.")
  389.    sleep(0.8)
  390.   P()
  391.  end
  392. end
  393.  
  394. function U()
  395.   paintutils.drawLine(12, 9, 12, 10, colors.gray)
  396.   paintutils.drawLine(13, 9, 38, 9, colors.lightGray)
  397.   Page.setCursorPos(17, 7)
  398.   print("Type Username")
  399.   Page.setCursorPos(14, 7)
  400.   username = read("*")
  401.  if (username == user1) then
  402.   pass()
  403.  else
  404.   Inv()
  405.  end
  406. end
  407.  
  408.  
  409. function Con()
  410.  
  411.  shell.run("config")
  412. end
  413.  
  414. local Dtb = {}
  415.  
  416.      
  417. function Disk()
  418.  
  419.  while true do
  420.   local driveSide
  421.     for _, side in ipairs(rs.getSides()) do
  422.        if peripheral.isPresent(side) and peripheral.getType(side) == "drive" then
  423.            driveSide = side
  424.            break
  425.         end
  426.     end
  427.      
  428.    
  429.     if disk.hasData(driveSide) == true then
  430.       Login()
  431.         Page.setTextColor(colors.green)
  432.         Page.setCursorPos(16, 10)
  433.         Page.write("Disk inserted!   ")
  434.         sleep(0.8)
  435.      if fs.exists("disk/OaSiS/") then  
  436.       if fs.exists("disk/OaSiS/USER"..ID..".txt") then
  437.    
  438.          if fs.exists("disk/OaSiS/Admin.txt") then
  439.               local Atb ={}
  440.               local a = fs.open("disk/OaSiS/Admin.txt","r")
  441.               local Atb = textutils.unserialize(a.readAll())
  442.               local aPass = Atb.pass
  443.               local auser = Atb.name
  444.               a.close()
  445.             if pass1 == aPass and user1 == auser then
  446.                  Page.setBackgroundColor(colors.white)
  447.                  Page.clear()
  448.                  Page.setCursorPos(10, 4)
  449.                  Page.write("setting up config page..")
  450.                  sleep(0.5)
  451.                  
  452.                  Con()
  453.                  error()
  454.             else
  455.              Inv()
  456.           end
  457.          
  458.          end
  459.          
  460.           local d = fs.open("disk/OaSiS/USER"..ID..".txt","r")
  461.           local Dtb = textutils.unserialize(d.readAll())
  462.            local gpass = Dtb.pass
  463.            local guser = Dtb.name
  464.            d.close()
  465.          
  466.          
  467.          if guser == nil then
  468.           error("value = nil")
  469.        else
  470.           Page.setTextColor(colors.black)
  471.           Page.setCursorPos(17, 12)
  472.           Page.write("testing var ".. Gpass)
  473.           Page.write("testing var ".. guser)
  474.           Page.write("testing var ".. gpass)
  475.           Page.write("testing var ".. user1)
  476.        end
  477.        if Gpass == gpass and user1 == guser then
  478.          disk.eject(driveSide)
  479.           pass()
  480.         else
  481.         disk.eject(driveSide)
  482.          Inv()
  483.          P()
  484.         end
  485.       else
  486.        Page.setTextColor(colors.red)
  487.        Page.setCursorPos(16, 10)
  488.        Page.write("Invaild KeyCard!  ")
  489.        sleep(0.5)
  490.       touch()
  491.       end
  492.      else
  493.       Page.setTextColor(colors.orange)
  494.       Page.setCursorPos(16, 10)
  495.       Page.write("Invaild disk type!")
  496.       sleep(0.5)
  497.      touch()
  498.      end
  499.     else
  500.     Page.setCursorPos(15,10)
  501.     Page.write(" no disk is inserted.")
  502.     sleep(0.5)
  503.      touch()
  504.         end
  505.      end
  506.  end
  507.      
  508.      local  ds = false
  509.          
  510.     function touch()
  511.  
  512.       repeat
  513.      
  514.          Page.setTextColor(colors.gray)
  515.          Page.setCursorPos(19, 16)
  516.          Page.write("checking...")
  517.          sleep(0.2)
  518.          Page.setCursorPos(19, 16)
  519.          Page.write("           ")
  520.      
  521.      
  522.        local event, p1, p2, p3 = os.pullEvent()
  523.            if event == "disk" then
  524.                     Disk()
  525.                   ds = true
  526.                  
  527.            elseif event == "mouse_click" then
  528.          if (p2 > 12  and p2 < 38) and (p3 > 8 and p3 < 11) then
  529.          
  530.           P()
  531.        
  532.          else
  533.               Disk()
  534.              ds = true
  535.             end
  536.           success = 0
  537.          end
  538.       until ds
  539.      end
  540.  
  541.  
  542. function format()
  543.   local DriveSide
  544.    for _, side in ipairs(rs.getSides()) do
  545.     if peripheral.isPresent(side) and peripheral.getType(side) == "drive" then
  546.     DriveSide = side
  547.     break
  548.    end
  549.   end
  550.   if DriveSide then
  551.     if disk.hasData(DriveSide) == true then
  552.       if fs.exists("disk/") == true then
  553.         if fs.exists("disk/OaSiS/USER"..ID..".txt") == false then
  554.                 Login()
  555.                   Page.setCursorPos(9, 6)  
  556.                   Page.write("An unformatted disk had been found,")
  557.                   Page.setCursorPos(10, 7)
  558.                   Page.write("would you like to format it?")
  559.                           paintutils.drawLine(12, 10, 38, 10, colors.lightGray)
  560.                           Page.setCursorPos(14, 8)
  561.                           write("   [ Y / N ]")
  562.                           Page.setCursorPos(14, 8)
  563.                           local input = read()
  564.                           local y = "y","Y"
  565.                           local n = "n","N"
  566.                            if input == y then
  567.                              fs.copy("saves/USER"..ID..".txt","disk/OaSiS/USER"..ID..".txt")
  568.                               disk.getLabel(DriveSide)
  569.                               disk.setLabel(DriveSide,"U"..os.getComputerID())
  570.                               Page.setCursorPos(14, 11)
  571.                               Page.write("Formatted")
  572.                              sleep(1)
  573.                              shell.run("startup")
  574.                             elseif input == n then
  575.                               print("formatting cancelled")
  576.                               sleep(1)
  577.                               shell.run("startup")
  578.                              else
  579.                               print("formatting failed.")
  580.                               sleep(1)
  581.                               shell.run("startup")
  582.                             end
  583.                            
  584.                            end
  585.                          end
  586.                      end
  587.                  end
  588.           end
  589.                                  
  590.          
  591.        
  592.  
  593. function pass()
  594.  
  595.     time()
  596.     SecureV()
  597.    Page.setTextColor( colors.green )
  598.    Page.setCursorPos( 16, 10)
  599.    Page.write(" Access Granted")
  600.    sleep(0.5)
  601.    time()
  602.    SecureV()
  603.    redstone.setOutput(side1, true)
  604.    time()
  605.    SecureV()
  606.    sleep(3)
  607.    redstone.setOutput(side1, false)
  608.    format()
  609.    shell.run("startup")
  610. end
  611.  
  612.  
  613. function Inv()
  614.  
  615.    time()
  616.    SecureV()
  617.    sleep(0.2)
  618.    Page.setTextColor( colors.red)
  619.    Page.setCursorPos( 16, 10)
  620.    Page.write(" Access Denied")
  621.    Page.setCursorPos( 22, 15)
  622.    time()
  623.    SecureV()
  624.    sleep(0.5)
  625.    time()
  626.    SecureV()
  627.    sleep(0.5)
  628.    time()
  629.    SecureV()
  630.    sleep(1)
  631.   shell.run("startup")
  632. end  
  633.  
  634.  
  635. function void()
  636. while true do
  637.  D = os.pullEvent()
  638.   if D == "disk" then
  639.     if fs.exists("disk/startup") then
  640.  
  641.        fs.move("disk/startup", "disk/noope")
  642.      else
  643.      end
  644.    end
  645.  end
  646. end
  647.  
  648.  
  649. repeat
  650.  Login()
  651.  
  652.  touch()
  653. until success
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement