Advertisement
Guest User

startup

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