gril002

OverWatch OS server

Jun 3rd, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.59 KB | None | 0 0
  1. autoUpdate = true
  2. function initialize()
  3.     settings.set("shell.allow_disk_startup", false)
  4.     settings.save(".settings")
  5.     getPeripherals()
  6.     rednet.open(modem)
  7.     initUsers()
  8.     exists = fs.exists("saves/updater/update")
  9.         if exists == false then
  10.             file = fs.open("saves/updater/version", "w")
  11.             file.writeLine("0")
  12.             file.close()
  13.             currentVersion = 0
  14.         else file = fs.open("saves/updater/version", "r" )
  15.             currentVersion = file.readLine()
  16.             file.close()
  17.             currentVersion = tonumber(currentVersion)
  18.         end
  19.     pb("r1cCb1Nn", "saves/updater/update")
  20.     print("Updated updater")
  21.     updater()
  22.     multishell.setTitle(multishell.getCurrent(), "Ctrl")
  23.     clear()
  24.     getTime()
  25.     write(time)
  26.     print(": Initializing protocols")
  27.     shell.openTab("protocols")
  28.     getTime()
  29.     write(time)
  30.     print(": Booting up")  
  31.     getTime()
  32.     write(time)
  33.     print(": Initializing userData")
  34.     shell.openTab("userData")
  35.     getTime()
  36.     write(time)
  37.     print(": Initializing sessionKeys")
  38.     shell.openTab("sessionKeys")
  39.     getTime()
  40.     write(time)
  41.     print(": Initializing doorControl")
  42.     shell.openTab("doorControl")
  43.     getTime()
  44.     write(time)
  45.     print(": Initializing users")
  46.     getTime()
  47.     write(time)
  48.     print(": Initializing toDo")
  49.     shell.openTab("toDo")
  50.     getTime()
  51.     write(time)
  52.     print(": Initializing Mail")
  53.     shell.openTab("mail")
  54.     getTime()
  55.     write(time)
  56.     print(": Initializing Voting")
  57.     shell.openTab("voting")
  58.     getTime()
  59.     write(time)
  60.     print(": Initializing Event manager")
  61.     shell.openTab("event")
  62.     clear()
  63.     commandLine()
  64. end
  65.  
  66. function updater()
  67.     if autoUpdate == true then
  68.         file = fs.open("saves/updater/update", "r" )
  69.         file.readLine()
  70.         file.readLine()
  71.         file.readLine()
  72.         newestVersion = file.readLine()
  73.         file.close()
  74.         newestVersion = tonumber(newestVersion)
  75.         if newestVersion > currentVersion then
  76.             clear()
  77.             print("There is a new update available")
  78.             print("Current version:", currentVersion, " Newest version", newestVersion)
  79.             sleep(1)
  80.             fs.delete("startup")
  81.             fs.delete("userData")
  82.             fs.delete("doorControl")
  83.             fs.delete("sessionKeys")
  84.             fs.delete("toDo")
  85.             fs.delete("protocols")
  86.             fs.delete("mail")
  87.             fs.delete("voting")
  88.             fs.delete("event")
  89.             pb("7DszLukn", "startup")
  90.             pb("uLg3X8mG", "userData")
  91.             pb("zCjSRuqK", "doorControl")
  92.             pb("HWMjqcGN", "sessionKeys")
  93.             pb("nNNTNps2", "toDo")
  94.             pb("fdY96RkA", "protocols")
  95.             pb("K3b40auU", "mail")
  96.             pb("ZrnBdvRs", "voting")
  97.             pb("mRmQ69Gr", "event")
  98.             file = fs.open("saves/updater/version", "w" )
  99.             file.write(newestVersion)
  100.             file.close()
  101.             os.reboot()
  102.         else
  103.             print("The newest version is already installed")
  104.         end
  105.     end
  106. end
  107.  
  108. function pb(paste, file)
  109.     response = http.get("http://pastebin.com/raw/"..paste)
  110.     sResponse = response.readAll()
  111.     response.close()
  112.     file = fs.open(file, "w" )
  113.     file.write(sResponse)
  114.     file.close()
  115. end
  116.  
  117. function getPeripherals()
  118.     sides = {"top", "bottom", "left", "right", "back"}
  119.     for i, side in pairs(rs.getSides()) do
  120.         local peripheral = peripheral.getType(side)
  121.         if peripheral == "drive" then
  122.             drive = side elseif
  123.             peripheral == "modem" then
  124.             modem = side
  125.         end
  126.     end
  127.     if modem == nil then
  128.         print("There is no modem attached!")
  129.         print("Shutting down in 10 seconds")
  130.         sleep(10)
  131.         os.shutdown()
  132.     end
  133. end
  134.  
  135. function initUsers()
  136.     exists = fs.exists("saves/userData")
  137.     if exists == false then
  138.         clear()
  139.         line = 0
  140.         text = "Welcome to the OverWatch OS server"
  141.         printCentered()
  142.         sleep(2)
  143.         clear()
  144.         line = 2
  145.         text = "Please add the owner account"
  146.         printCentered()
  147.         sleep(2)
  148.         fs.makeDir("saves/userData")
  149.         clearance = 1
  150.         addUser()
  151.         line = 2
  152.         text = "You have successfully added the account"
  153.         printCentered()
  154.         initUsers()
  155.         sleep(2)
  156.     end
  157. end
  158.  
  159. function getTime()
  160.     time = textutils.formatTime(os.time(), true)
  161. end
  162.  
  163. function addUser()
  164.     clear()
  165.     line = 2
  166.     text = "Username:         "
  167.     printCentered()
  168.     line = 1
  169.     text = "Password:         "
  170.     printCentered()
  171.     line = 2
  172.     centerY()
  173.     a = x/2
  174.     term.setCursorPos(a, b)
  175.     username = read()
  176.     line = 1
  177.     centerY()
  178.     a = x/2
  179.     term.setCursorPos(a, b)
  180.     password1 = read("*")
  181.     clear()
  182.     line = 2
  183.     text  = "Please re-enter the password"
  184.     printCentered()
  185.     line = 1
  186.     text = "Password:          "
  187.     printCentered()
  188.     line = 1
  189.     centerY()
  190.     a = x/2
  191.     term.setCursorPos(a, b)
  192.     password2 = read("*")
  193.     if password1 == password2 then
  194.         admin = fs.exists("saves/userData/user0")
  195.         user1 = fs.exists("saves/userData/user1")
  196.         user2 = fs.exists("saves/userData/user2")
  197.         user3 = fs.exists("saves/userData/user3")
  198.         user4 = fs.exists("saves/userData/user4")
  199.         user5 = fs.exists("saves/userData/user5")
  200.         accounts = 0
  201.         if admin == true then
  202.             accounts = 1 else
  203.             print("admin is false")
  204.         end
  205.         if user1 == true then
  206.             accounts = 2 else
  207.             print("user1 is false")
  208.         end
  209.         if user2 == true then
  210.             accounts = 3 else
  211.             print("user2 is false")
  212.         end
  213.         if user3 == true then
  214.             accounts = 4 else
  215.             print("user3 is false")
  216.         end
  217.         if user4 == true then
  218.             accounts = 5 else
  219.             print("user4 is false")
  220.         end
  221.         if user5 == true then
  222.             accounts = 6 else
  223.             print("user5 is false")
  224.         end
  225.         if accounts == 0 then
  226.             file = fs.open("saves/userData/user0", "w")
  227.             file.writeLine(username)
  228.             file.writeLine(password1)
  229.             file.writeLine(clearance)
  230.             file.close()
  231.             clear()
  232.             line = 0
  233.             text = "User succsessfully added"
  234.             printCentered()
  235.             os.pullEvent()  elseif
  236.             accounts == 1 then
  237.             file = fs.open("saves/userData/user1","w")
  238.             file.writeLine(username)
  239.             file.writeLine(password1)
  240.             file.writeLine(clearance)
  241.             file.close()
  242.             clear()
  243.             line = 0
  244.             text = "User succsessfully added"
  245.             printCentered()
  246.             os.pullEvent()  elseif
  247.             accounts == 2 then
  248.             file = fs.open("saves/userData/user2","w")
  249.             file.writeLine(username)
  250.             file.writeLine(password1)
  251.             file.writeLine(clearance)
  252.             file.close()
  253.             clear()
  254.             line = 0
  255.             text = "User succsessfully added"
  256.             printCentered()
  257.             os.pullEvent()  elseif
  258.             accounts == 3 then
  259.             file = fs.open("saves/userData/user3","w")
  260.             file.writeLine(username)
  261.             file.writeLine(password1)
  262.             file.writeLine(clearance)
  263.             file.close()
  264.             clear()
  265.             line = 0
  266.             text = "User succsessfully added"
  267.             printCentered()
  268.             os.pullEvent()  elseif
  269.             accounts == 4 then
  270.             file = fs.open("saves/userData/user4","w")
  271.             file.writeLine(username)
  272.             file.writeLine(password1)
  273.             file.writeLine(clearance)
  274.             file.close()
  275.             clear()
  276.             line = 0
  277.             text = "User succsessfully added"
  278.             printCentered()
  279.             os.pullEvent()  elseif
  280.             accounts == 5 then
  281.             file = fs.open("saves/userData/user5","w")
  282.             file.writeLine(username)
  283.             file.writeLine(password1)
  284.             file.writeLine(clearance)
  285.             file.close() elseif
  286.             accounts == 6 then
  287.             clear()
  288.             line = 0
  289.             text = "You already have the maximum number of accounts"
  290.             printCentered()
  291.             sleep(1)
  292.             os.pullEvent()
  293.            
  294.         end
  295.         initialize() else
  296.         clear()
  297.         line = 2
  298.         text  = "Passwords do not match"
  299.         printCentered()
  300.         sleep(1)
  301.         os.pullEvent()
  302.         addUser()
  303.     end
  304. end
  305.    
  306. function clear()
  307.     term.clear()
  308.     term.setCursorPos(1,1) 
  309. end
  310.  
  311. function getResolution()
  312.     x,y = term.getSize()
  313. end
  314.  
  315. function centerX()
  316.     lenght = string.len(text)/2
  317.     a = x/2 - lenght
  318. end
  319.    
  320. function centerY()
  321.     b = y/2 - line
  322. end
  323.  
  324.  
  325. function printCentered()
  326.     centerX()
  327.     centerY()
  328.     term.setCursorPos(a,b)
  329.     print(text)
  330. end
  331.  
  332. function listUsers()
  333.     clear()
  334.     print("Registered users:")
  335.     file = fs.open("saves/userData/user0","r")
  336.     user = file.readLine()
  337.     pass = file.readLine()
  338.     clearance = file.readLine()
  339.     file.close()
  340.     printUser()
  341.     user1 = fs.exists("saves/userData/user1")
  342.     user2 = fs.exists("saves/userData/user2")
  343.     user3 = fs.exists("saves/userData/user3")
  344.     user4 = fs.exists("saves/userData/user4")
  345.     user5 = fs.exists("saves/userData/user5")
  346.     if user1 == true then
  347.         file = fs.open("saves/userData/user1","r")
  348.         user = file.readLine()
  349.         pass = file.readLine()
  350.         clearance = file.readLine()
  351.         file.close()
  352.         printUser()
  353.     end
  354.     if user2 == true then
  355.         file = fs.open("saves/userData/user2","r")
  356.         user = file.readLine()
  357.         pass = file.readLine()
  358.         clearance = file.readLine()
  359.         file.close()
  360.         printUser()
  361.     end
  362.     if user3 == true then
  363.         file = fs.open("saves/userData/user3","r")
  364.         user = file.readLine()
  365.         pass = file.readLine()
  366.         clearance = file.readLine()
  367.         file.close()
  368.         printUser()
  369.     end
  370.     if user4 == true then
  371.         file = fs.open("saves/userData/user4","r")
  372.         user = file.readLine()
  373.         pass = file.readLine()
  374.         clearance = file.readLine()
  375.         file.close()
  376.         printUser()
  377.     end
  378.     if user5 == true then
  379.         file = fs.open("saves/userData/user5","r")
  380.         user = file.readLine()
  381.         pass = file.readLine()
  382.         clearance = file.readLine()
  383.         file.close()
  384.         printUser()
  385.     end
  386.     sleep(0.1)
  387.     os.pullEvent()
  388.     commandLine()
  389. end
  390.  
  391. function printUser()
  392.     if clearance == "1.0" then
  393.         term.setTextColor(colors.red)
  394.         print(user)
  395.         term.setTextColor(colors.white) elseif
  396.         clearance == "2" then
  397.         term.setTextColor(colors.green)
  398.         print(user)
  399.         term.setTextColor(colors.white) elseif
  400.         clearance == "3" then
  401.         term.setTextColor(colors.lime)
  402.         print(user)
  403.         term.setTextColor(colors.white) elseif
  404.         clearance == "4" then
  405.         term.setTextColor(colors.blue)
  406.         print(user)
  407.         term.setTextColor(colors.white)
  408.     end
  409. end
  410.  
  411. function commandLine()
  412.     clear()
  413.     term.setCursorPos(1,y)
  414.     term.clearLine()
  415.     term.setCursorPos(1,y-1)
  416.     term.clearLine()
  417.     write("Command:")
  418.     command = read()
  419.     if command == "add user" then
  420.         clear()
  421.         line = 4
  422.         text = "Add a new user"
  423.         printCentered()
  424.         line = 2
  425.         text = "Select a clearance level"
  426.         printCentered()
  427.         line = 1
  428.         centerY()
  429.         a = x/2
  430.         term.setCursorPos(a,b)
  431.         clearance = read()
  432.         if clearance == "1" then
  433.             addUser() elseif
  434.             clearance == "2" then
  435.             addUser() elseif
  436.             clearance == "3" then
  437.             addUser() elseif
  438.             clearance == "4" then
  439.             addUser() else
  440.             clear()
  441.             line = 0
  442.             text = "Invalid number. Must be between 1 and 4"
  443.             printCentered()
  444.             sleep(2)
  445.             initialize()
  446.         end elseif
  447.         command == "list users" then
  448.             listUsers() elseif
  449.         command == "home" then
  450.         commandLine()
  451.     elseif command == "pair device" then
  452.         clear()
  453.         term.setCursorPos(1,1)
  454.         getPeripherals()
  455.         if drive == nil then
  456.             print("To pair a device, please attach a disk drice and reboot the computer")
  457.             sleep(2)
  458.             commandLine()
  459.         end
  460.         print("Doing this will delete everything on the PoC")
  461.         print("Are you sure you wish to proceed (type in yes or no)")
  462.         term.setCursorPos(1,y-1)
  463.         write("Anwser:")
  464.         anwser = read()
  465.         if anwser == "yes" then
  466.             clear()
  467.             term.setCursorPos(1,1)
  468.             print("Insert the turned on PoC into the drive")
  469.             present = disk.isPresent(drive)
  470.             if present == true then
  471.                 fs.delete("disk/startup")
  472.                 print("deleted data")
  473.                 pb("jnZP4DN6", "disk/startup")
  474.                 print("Loaded OS")
  475.                 file = fs.open("disk/saves/OS files/id","w")
  476.                 file.writeLine(os.getComputerID())
  477.                 file.close()
  478.                 file = fs.open("saves/trustedIDs/IDs","w")
  479.                 file.writeLine(disk.getID(drive))
  480.                 file.close()
  481.                 print("Device paired")
  482.                 sleep(1)
  483.                 commandLine()
  484.             else
  485.             clear()
  486.             print("No device detected")
  487.             sleep(2)
  488.             commandLine()
  489.             end
  490.         elseif anwser == "no" then
  491.             print("Pairing aborted")
  492.             sleep(1)
  493.             commandLine()
  494.         end
  495.     elseif command == "wipe device" then
  496.         fs.delete("/disk/")
  497.         print("Disk wiped")
  498.         sleep(1)
  499.         commandLine()
  500.          else
  501.         print("Invalid command")
  502.         sleep(1)
  503.         commandLine()
  504.     end
  505. end
  506.  
  507. function pb(paste, file)
  508.     response = http.get("http://pastebin.com/raw/"..paste)
  509.     sResponse = response.readAll()
  510.     response.close()
  511.     file = fs.open(file, "w" )
  512.     file.write(sResponse)
  513.     file.close()
  514. end
  515.  
  516. getResolution()
  517. initialize()
Add Comment
Please, Sign In to add comment