Advertisement
Guest User

startup

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