Advertisement
Guest User

startup

a guest
Dec 22nd, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.18 KB | None | 0 0
  1. -- Fold OS Boot
  2.  
  3. -- Secure the OS
  4. --os.pullEvent = os.pullEventRaw
  5. settings.set("shell.allow_disk_startup", false)
  6. settings.save(".settings")
  7.  
  8. local dir = ""
  9.  
  10. local ts = term.setCursorPos
  11. local tc = term.clear
  12. local tw = term.write
  13. local tb = term.setBackgroundColor
  14. local ttc = term.setTextColor
  15.  
  16. -- Add ons from pastebin
  17.  
  18. local Malte_encrypt = "DdH8naJ7"
  19. local Fold_desktop = "5Zfx9LZZ"
  20.  
  21. ------------
  22. -- Install add ons
  23. if fs.exists( "/encrypt" ) then
  24.     os.loadAPI( "/encrypt")
  25. else
  26.     tc()
  27.     ts(1,1)
  28.     tb(colors.black)
  29.     ttc(colors.white)
  30.     tw("Installing: Malte_Encrypt")
  31.     sleep(0.5)
  32.     ts(1,3)
  33.     shell.run("pastebin get "..Malte_encrypt.." encrypt")
  34. end
  35. os.loadAPI( "/desktop")
  36.  
  37. if fs.exists( "/desktop" ) then
  38.     os.loadAPI( "/desktop")
  39. else
  40.     tc()
  41.     ts(1,1)
  42.     tb(colors.black)
  43.     ttc(colors.white)
  44.     tw("Installing: Fold_Desktop")
  45.     sleep(0.5)
  46.     ts(1,3)
  47.     shell.run("pastebin get "..Fold_desktop.." desktop")
  48. end
  49. ---------------------
  50.  
  51. local Booting = true
  52.  
  53. local start = {}
  54. start["register"] = {}
  55. start["register"]["x1"] = 3
  56. start["register"]["x2"] = 49
  57. start["register"]["y1"] = 3
  58. start["register"]["y2"] = 17
  59. start["register"]["color"] = colors.white
  60.  
  61. start["noUsr"] = {}
  62. start["noUsr"]["text"] = "Would you like to create a profile?"
  63. start["noUsr"]["len"] = start["noUsr"]["text"]:len()
  64. start["noUsr"]["x"] = ( ( start["register"]["x2"] - start["register"]["x1"] ) / 2 ) - ( start["noUsr"]["len"] / 2 ) +4
  65. start["noUsr"]["y"] = 4
  66. start["noUsr"]["color"] = colors.white
  67.  
  68. start["box"] = {}
  69. start["box"]["color"] = colors.black
  70. start["box"]["x1"] = start["noUsr"]["x"]-1
  71. start["box"]["y1"] = start["noUsr"]["y"]-1
  72. start["box"]["x2"] = start["noUsr"]["x"] + start["noUsr"]["len"]
  73. start["box"]["y2"] = start["noUsr"]["y"]+1
  74. ----------------
  75. start["create"] = {}
  76. start["create"]["text"] = "Create a profile"
  77. start["create"]["len"] = start["create"]["text"]:len()
  78. start["create"]["x"] = ( ( start["register"]["x2"] - start["register"]["x1"] ) / 2 ) - ( start["create"]["len"] / 2 ) +4
  79. start["create"]["y"] = 4
  80. start["create"]["color"] = colors.white
  81.  
  82. start["login"] = {}
  83. start["login"]["text"] = "Login"
  84. start["login"]["len"] = start["login"]["text"]:len()
  85. start["login"]["x"] = ( ( start["register"]["x2"] - start["register"]["x1"] ) / 2 ) - ( start["login"]["len"] / 2 ) +4
  86. start["login"]["y"] = 4
  87. start["login"]["color"] = colors.white
  88.  
  89. start["box2"] = {}
  90. start["box2"]["color"] = colors.black
  91. start["box2"]["x1"] = start["create"]["x"]-1
  92. start["box2"]["y1"] = start["create"]["y"]-1
  93. start["box2"]["x2"] = start["create"]["x"] + start["create"]["len"]
  94. start["box2"]["y2"] = start["create"]["y"]+1
  95.  
  96. start["box3"] = {}
  97. start["box3"]["color"] = colors.black
  98. start["box3"]["x1"] = start["login"]["x"]-1
  99. start["box3"]["y1"] = start["login"]["y"]-1
  100. start["box3"]["x2"] = start["login"]["x"] + start["login"]["len"]
  101. start["box3"]["y2"] = start["login"]["y"]+1
  102. ----------------
  103. start["yes"] = {}
  104. start["yes"]["text"] = "Yes"
  105. start["yes"]["len"] = start["yes"]["text"]:len()
  106. start["yes"]["x1"] = 50 / 2 - start["yes"]["len"]
  107. start["yes"]["y1"] = 8
  108. start["yes"]["x2"] = 50 / 2 + start["yes"]["len"]
  109. start["yes"]["y2"] = start["yes"]["y1"] + 2
  110. start["yes"]["color"] = colors.green
  111. start["yes"]["pressed"] = false
  112.  
  113. start["no"] = {}
  114. start["no"]["text"] = "No, uninstall"
  115. start["no"]["len"] = start["no"]["text"]:len()
  116. start["no"]["x1"] = 50 / 2 - start["no"]["len"]
  117. start["no"]["y1"] = 13
  118. start["no"]["x2"] = 50 / 2 + start["no"]["len"]
  119. start["no"]["y2"] = start["no"]["y1"] + 2
  120. start["no"]["color"] = colors.red
  121. start["no"]["pressed"] = false
  122.  
  123. start["username"] = {}
  124. start["username"]["text"] = " Username:"
  125. start["username"]["len"] = start["username"]["text"]:len()
  126. start["username"]["x1"] = start["register"]["x1"] + 1
  127. start["username"]["y1"] = start["register"]["y1"] + 4
  128. start["username"]["x2"] = start["username"]["text"]:len() + start["username"]["x1"]
  129. start["username"]["y2"] = start["username"]["y1"] + 2
  130. start["username"]["color"] = colors.black
  131.  
  132. start["password"] = {}
  133. start["password"]["text"] = " Password:"
  134. start["password"]["len"] = start["password"]["text"]:len()
  135. start["password"]["x1"] = start["register"]["x1"] + 1
  136. start["password"]["y1"] = start["register"]["y1"] + 8
  137. start["password"]["x2"] = start["password"]["text"]:len() + start["password"]["x1"]
  138. start["password"]["y2"] = start["password"]["y1"] + 2
  139. start["password"]["color"] = colors.black
  140.  
  141. start["input1"] = {}
  142. start["input1"]["add"] = 12
  143. start["input1"]["x1"] = start["username"]["x1"] + start["input1"]["add"]
  144. start["input1"]["y1"] = start["username"]["y1"]
  145. start["input1"]["x2"] = start["input1"]["add"] + start["username"]["x2"] + 22
  146. start["input1"]["y2"] = start["username"]["y2"]
  147. start["input1"]["color"] = colors.black
  148.  
  149. start["input2"] = {}
  150. start["input2"]["add"] = 12
  151. start["input2"]["x1"] = start["password"]["x1"] + start["input1"]["add"]
  152. start["input2"]["y1"] = start["password"]["y1"]
  153. start["input2"]["x2"] = start["input2"]["add"] + start["password"]["x2"] + 22
  154. start["input2"]["y2"] = start["password"]["y2"]
  155. start["input2"]["color"] = colors.black
  156.  
  157.  
  158.  
  159. local waittime = 0.07
  160.  
  161. local psw = {}
  162.  
  163.  
  164. function create() -- Creates a profile
  165.     paintutils.drawFilledBox(start["register"]["x1"], start["register"]["y1"], start["register"]["x2"], start["register"]["y2"], start["register"]["color"])
  166.  
  167.     paintutils.drawFilledBox(start["box2"]["x1"], start["box2"]["y1"], start["box2"]["x2"], start["box2"]["y2"], start["box2"]["color"] )
  168.  
  169.     ts(start["create"]["x"], start["create"]["y"])
  170.     ttc(start["create"]["color"])
  171.     tw(start["create"]["text"])
  172.  
  173.     --------------- Make a name and password field
  174.  
  175.     paintutils.drawFilledBox(start["username"]["x1"], start["username"]["y1"], start["username"]["x2"], start["username"]["y2"], start["username"]["color"] )
  176.     ts(start["username"]["x1"], start["username"]["y1"]+1)
  177.     tw(start["username"]["text"])
  178.  
  179.     paintutils.drawFilledBox(start["password"]["x1"], start["password"]["y1"], start["password"]["x2"], start["password"]["y2"], start["password"]["color"] )
  180.     ts(start["password"]["x1"], start["password"]["y1"]+1)
  181.     tw(start["password"]["text"])
  182.  
  183.     paintutils.drawFilledBox(start["input1"]["x1"], start["input1"]["y1"], start["input1"]["x2"] , start["input1"]["y2"], start["input1"]["color"])
  184.     paintutils.drawFilledBox(start["input2"]["x1"], start["input2"]["y1"], start["input2"]["x2"] , start["input2"]["y2"], start["input2"]["color"])
  185.  
  186.     ts(start["input1"]["x1"] + 1, start["input1"]["y1"] + 1)
  187.     local iUser = read()
  188.     ts(start["input2"]["x1"] + 1, start["input2"]["y1"] + 1)
  189.     local iPsw = read()
  190.  
  191.     local userDir = fs.makeDir( dir.."/user" )
  192.     local file = fs.open( dir.."/user/username", "w")
  193.    
  194.     file.writeLine(iUser)
  195.     file.close()
  196.  
  197.     local file = fs.open( "/user/password", "w")
  198.  
  199.     iPsw = encrypt.encrypt(iPsw, "key") -- Encrypt's the string using Malte's encrypting software
  200.  
  201.     if iPsw == nil or iPsw == "" then
  202.         uninstall()
  203.     else
  204.         file.writeLine(iPsw)
  205.         file.close()
  206.     end
  207.  
  208.     os.reboot()
  209. end
  210.  
  211.  
  212. function drawYes(var)
  213.     local old = start["yes"]["color"]
  214.     if var then
  215.         start["yes"]["color"] = colors.black
  216.     end
  217.     paintutils.drawFilledBox(start["yes"]["x1"], start["yes"]["y1"], start["yes"]["x2"], start["yes"]["y2"], start["yes"]["color"])
  218.     ts(start["yes"]["x1"] + start["yes"]["len"] / 2 + 1, start["yes"]["y1"] +1)
  219.     tw(start["yes"]["text"])
  220.  
  221.     start["yes"]["color"] = old
  222. end
  223.  
  224.  
  225. function drawNo(var)
  226.     local old = start["no"]["color"]
  227.     if var then
  228.         start["no"]["color"] = colors.black
  229.     end
  230.     paintutils.drawFilledBox(start["no"]["x1"], start["no"]["y1"], start["no"]["x2"], start["no"]["y2"], start["no"]["color"])
  231.     ts(start["no"]["x1"] + start["no"]["len"] / 2 + 1, start["no"]["y1"] +1)
  232.     tw(start["no"]["text"])
  233.  
  234.     start["no"]["color"] = old
  235. end
  236.  
  237.  
  238. function uninstall()
  239.     fs.delete( "/user")
  240.     fs.delete( "/encrypt")
  241.     fs.delete( "/desktop")
  242.     fs.delete( "/startup")
  243.     fs.delete( "/files" )
  244.     fs.delete( "/filesystem" )
  245.     os.reboot()
  246. end
  247.  
  248.  
  249. function login()
  250.     tb(colors.blue)
  251.     tc()
  252.     paintutils.drawFilledBox(start["register"]["x1"], start["register"]["y1"], start["register"]["x2"], start["register"]["y2"], start["register"]["color"])
  253.     paintutils.drawFilledBox(start["box3"]["x1"], start["box3"]["y1"], start["box3"]["x2"], start["box3"]["y2"], start["box3"]["color"] )
  254.  
  255.     ts(start["login"]["x"], start["login"]["y"])
  256.     ttc(start["login"]["color"])
  257.     tw(start["login"]["text"])
  258.  
  259.     paintutils.drawFilledBox(start["username"]["x1"], start["username"]["y1"], start["username"]["x2"], start["username"]["y2"], start["username"]["color"] )
  260.     ts(start["username"]["x1"], start["username"]["y1"]+1)
  261.     tw(start["username"]["text"])
  262.  
  263.     paintutils.drawFilledBox(start["password"]["x1"], start["password"]["y1"], start["password"]["x2"], start["password"]["y2"], start["password"]["color"] )
  264.     ts(start["password"]["x1"], start["password"]["y1"]+1)
  265.     tw(start["password"]["text"])
  266.  
  267.     paintutils.drawFilledBox(start["input1"]["x1"], start["input1"]["y1"], start["input1"]["x2"] , start["input1"]["y2"], start["input1"]["color"])
  268.     paintutils.drawFilledBox(start["input2"]["x1"], start["input2"]["y1"], start["input2"]["x2"] , start["input2"]["y2"], start["input2"]["color"])
  269.  
  270.     ts(start["input1"]["x1"] + 1, start["input1"]["y1"] + 1)
  271.     local iUser = read()
  272.     ts(start["input2"]["x1"] + 1, start["input2"]["y1"] + 1)
  273.     local iPsw = read("*")
  274.  
  275.     local file = fs.open("/user/username", "r")
  276.     local realUsr = file.readLine()
  277.     file.close()
  278.     local file = fs.open("/user/password", "r")
  279.     local realPsw = file.readLine()
  280.     file.close()
  281.  
  282.     realPsw = encrypt.decrypt(realPsw, "key") -- Decrypt's the string using Malte's encrypting software
  283.  
  284.     if iUser == realUsr and iPsw == realPsw then
  285.         -- Logged succesfully in!
  286.  
  287.         desktop.launch()
  288.  
  289.     else
  290.         login()
  291.     end
  292. end
  293.  
  294.  
  295. function boot()
  296.  
  297.     if start["yes"]["pressed"] then
  298.         Booting = false
  299.     end
  300.  
  301.     if start["no"]["pressed"] then
  302.         Booting = false
  303.     end
  304.  
  305.     ts(1,2)
  306.     tb(colors.blue)
  307.     tc()
  308.  
  309.     local file = fs.exists("/user")
  310.  
  311.     if file and Booting then
  312.         login()
  313.         Booting = false
  314.     else
  315.         paintutils.drawFilledBox(start["register"]["x1"], start["register"]["y1"], start["register"]["x2"], start["register"]["y2"], start["register"]["color"])
  316.        
  317.  
  318.         paintutils.drawFilledBox(start["box"]["x1"], start["box"]["y1"], start["box"]["x2"], start["box"]["y2"], start["box"]["color"] )
  319.  
  320.         ts(start["noUsr"]["x"], start["noUsr"]["y"])
  321.         ttc(start["noUsr"]["color"])
  322.         tw(start["noUsr"]["text"])
  323.         ts(1,1)
  324.  
  325.         drawYes()
  326.  
  327.         drawNo()
  328.  
  329.         ts(1,1)
  330.     end
  331.  
  332.     if Booting then
  333.         if file then
  334.         else
  335.             local event, button, x, y = os.pullEvent( "mouse_click" )
  336.  
  337.             if x >= start["yes"]["x1"] and x <= start["yes"]["x2"] and y >= start["yes"]["y1"] and y <= start["yes"]["y2"] then
  338.                 drawYes(true)
  339.                 start["yes"]["pressed"] = true
  340.             elseif x >= start["no"]["x1"] and x <= start["no"]["x2"] and y >= start["no"]["y1"] and y <= start["no"]["y2"] then
  341.                 drawNo(true)
  342.                 start["no"]["pressed"] = true
  343.             elseif x == 1 and y == 1 then
  344.                 os.reboot()
  345.             end
  346.  
  347.             sleep(waittime)
  348.             boot()
  349.         end
  350.     else
  351.  
  352.         if start["yes"]["pressed"] then
  353.             start["yes"]["pressed"] = false
  354.             Booting = false
  355.             create()
  356.         end
  357.  
  358.         if start["no"]["pressed"] then
  359.             start["no"]["pressed"] = false
  360.             Booting = false
  361.             uninstall()
  362.         end
  363.     end
  364. end
  365.  
  366.  
  367. boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement