Advertisement
Catboy_Riku

Secure NyatOS

Aug 22nd, 2024 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.29 KB | None | 0 0
  1. local side = "back"
  2. local opentime = 5
  3. local userFile = "users.dat"
  4. local maxAttempts = 3
  5. local lockoutFile = "lockout.dat"
  6. local lockoutDuration = 600
  7.  
  8. -- User data
  9. local users = {
  10. {username = "Riku", password = "1111", admin = true},
  11. --Yo a little help here!?... Alright alright I got it, stand back son.. One, one, one, uhhmmmuhhhhh one!
  12. {username = "Guest", password = "$pass42", admin = false},
  13. }
  14.  
  15. -- Function to read the lockout state from the file
  16. local function readLockoutState()
  17. local file, err = fs.open(lockoutFile, "r")
  18. if file then
  19. local state = file.readAll()
  20. file.close()
  21. return tonumber(state) or 0
  22. else
  23. print("Error reading lockout file:", err)
  24. return 0
  25. end
  26. end
  27.  
  28. -- Function to write the lockout state to the file
  29. local function writeLockoutState(attempts)
  30. local file, err = fs.open(lockoutFile, "w")
  31. if file then
  32. file.write(tostring(attempts))
  33. file.close()
  34. else
  35. print("Error writing to lockout file:", err)
  36. end
  37. end
  38.  
  39. -- Function to load user data from file
  40. local function loadUserData()
  41. local file, err = fs.open(userFile, "r")
  42. if file then
  43. local data = file.readAll()
  44. file.close()
  45. return textutils.unserialize(data) or users
  46. else
  47. print("Error reading user file:", err)
  48. return users
  49. end
  50. end
  51.  
  52. -- Function to save user data to file
  53. local function saveUserData()
  54. local file, err = fs.open(userFile, "w")
  55. if file then
  56. file.write(textutils.serialize(users))
  57. file.close()
  58. else
  59. print("Error writing to user file:", err)
  60. end
  61. end
  62.  
  63. -- Forest Quest Code
  64. local function playForestQuest()
  65. term.clear()
  66. term.setCursorPos(1, 1)
  67. print("Welcome to Forest Quest!")
  68. print("You find yourself at the edge of an ancient forest.")
  69. print("What do you want to do?")
  70. print("[1.] Enter the forest")
  71. print("[2.] Walk along the edge")
  72. print("[3.] Check your inventory")
  73. print("[4.] Quit game")
  74.  
  75. local choice = read()
  76.  
  77. if choice == "1" then
  78. term.clear()
  79. term.setCursorPos(1, 1)
  80. print("You step into the forest and feel the temperature drop.")
  81. print("You see a path to the north leading deeper into the forest and a small hut to the east.")
  82. print("What do you want to do?")
  83. print("[1.] Follow the path north")
  84. print("[2.] Investigate the hut")
  85. print("[3.] Go back")
  86. local nextChoice = read()
  87. if nextChoice == "1" then
  88. term.clear()
  89. term.setCursorPos(1, 1)
  90. print("You follow the path north and find yourself at a large, ancient tree.")
  91. print("You can see a rope ladder hanging from the tree and a hidden entrance to a cave nearby.")
  92. print("What do you want to do?")
  93. print("[1.] Climb the rope ladder")
  94. print("[2.] Enter the cave")
  95. print("[3.] Return to the forest path")
  96. local treeChoice = read()
  97. if treeChoice == "1" then
  98. term.clear()
  99. term.setCursorPos(1, 1)
  100. print("You climb the rope ladder and find yourself in a treehouse with a great view.")
  101. print("There's a box here, but it seems to be locked.")
  102. print("What do you want to do?")
  103. print("[1.] Try to unlock the box")
  104. print("[2.] Climb down and go to the cave")
  105. print("[3.] Go back to the forest path")
  106. local boxChoice = read()
  107. if boxChoice == "1" then
  108. term.clear()
  109. term.setCursorPos(1, 1)
  110. print("You manage to unlock the box and find a key inside!")
  111. print("With this key, you can now open the hidden treasure chest in the clearing.")
  112. print("What do you want to do?")
  113. print("[1.] Return to the forest path")
  114. print("[2.] Quit game")
  115. local keyChoice = read()
  116. if keyChoice == "1" then
  117. term.clear()
  118. term.setCursorPos(1, 1)
  119. print("You return to the forest path with the key.")
  120. print("You find a hidden clearing with a treasure chest.")
  121. print("What do you want to do?")
  122. print("[1.] Open the treasure chest")
  123. print("[2.] Quit game")
  124. local chestChoice = read()
  125. if chestChoice == "1" then
  126. term.clear()
  127. term.setCursorPos(1, 1)
  128. print("You unlock the chest with the key and find a treasure!")
  129. print("Congratulations! You've won the game!")
  130. elseif chestChoice == "2" then
  131. term.clear()
  132. term.setCursorPos(1, 1)
  133. print("You quit the game. Goodbye!")
  134. else
  135. term.clear()
  136. term.setCursorPos(1, 1)
  137. print("Invalid choice. You remain at the clearing.")
  138. end
  139. elseif keyChoice == "2" then
  140. term.clear()
  141. term.setCursorPos(1, 1)
  142. print("You quit the game. Goodbye!")
  143. else
  144. term.clear()
  145. term.setCursorPos(1, 1)
  146. print("Invalid choice. You remain in the treehouse.")
  147. end
  148. elseif boxChoice == "2" then
  149. term.clear()
  150. term.setCursorPos(1, 1)
  151. print("You climb down the ladder and head towards the cave.")
  152. print("Inside the cave, you find some ancient ruins but no treasure.")
  153. print("You decide to leave and head back to the forest path.")
  154. playForestQuest()
  155. elseif boxChoice == "3" then
  156. playForestQuest()
  157. else
  158. term.clear()
  159. term.setCursorPos(1, 1)
  160. print("Invalid choice. You remain at the large tree.")
  161. playForestQuest()
  162. end
  163. elseif treeChoice == "2" then
  164. term.clear()
  165. term.setCursorPos(1, 1)
  166. print("You enter the cave and find some ancient ruins.")
  167. print("There's nothing of interest here. You decide to return to the forest path.")
  168. playForestQuest()
  169. elseif treeChoice == "3" then
  170. playForestQuest()
  171. else
  172. term.clear()
  173. term.setCursorPos(1, 1)
  174. print("Invalid choice. You remain at the large tree.")
  175. playForestQuest()
  176. end
  177. elseif nextChoice == "2" then
  178. term.clear()
  179. term.setCursorPos(1, 1)
  180. print("You walk along the forest edge but don't find anything interesting.")
  181. print("You can return to the forest entrance.")
  182. print("What do you want to do?")
  183. print("[1.] Enter the forest")
  184. print("[2.] Quit game")
  185. local edgeChoice = read()
  186. if edgeChoice == "1" then
  187. playForestQuest()
  188. elseif edgeChoice == "2" then
  189. term.clear()
  190. term.setCursorPos(1, 1)
  191. print("You quit the game. Goodbye!")
  192. else
  193. term.clear()
  194. term.setCursorPos(1, 1)
  195. print("Invalid choice. You remain walking along the forest edge.")
  196. playForestQuest()
  197. end
  198. elseif nextChoice == "3" then
  199. term.clear()
  200. term.setCursorPos(1, 1)
  201. print("You check your inventory but find it empty. There's nothing to see here.")
  202. print("What do you want to do?")
  203. print("[1.] Enter the forest")
  204. print("[2.] Walk along the edge")
  205. print("[3.] Quit game")
  206. local inventoryChoice = read()
  207. if inventoryChoice == "1" then
  208. playForestQuest()
  209. elseif inventoryChoice == "2" then
  210. playForestQuest()
  211. elseif inventoryChoice == "3" then
  212. term.clear()
  213. term.setCursorPos(1, 1)
  214. print("You quit the game. Goodbye!")
  215. else
  216. term.clear()
  217. term.setCursorPos(1, 1)
  218. print("Invalid choice. You remain at the forest edge.")
  219. playForestQuest()
  220. end
  221. elseif choice == "4" then
  222. term.clear()
  223. term.setCursorPos(1, 1)
  224. print("Thank you for playing. Goodbye!")
  225. else
  226. term.clear()
  227. term.setCursorPos(1, 1)
  228. print("Invalid choice. You are still at the edge of the forest.")
  229. playForestQuest()
  230. end
  231. end
  232. end
  233.  
  234. -- Function to authenticate user credentials
  235. local function authenticateUser(inputUser, inputPass)
  236. for _, user in ipairs(users) do
  237. if user.username == inputUser and user.password == inputPass then
  238. return true, nil, user
  239. end
  240. end
  241. return false, "Invalid credentials!"
  242. end
  243.  
  244. -- Function to handle user login with input validation
  245. local function handleLogin()
  246. term.clear()
  247. term.setCursorPos(1, 1)
  248. print("NyatOS Secure v2.4")
  249. print("")
  250. print("")
  251. print("")
  252. print("Please log in to continue.")
  253. print("")
  254. print("")
  255. print("[AUTHORIZED PERSONNEL ONLY!]")
  256. print("")
  257.  
  258. local inputUser
  259. repeat
  260. write("Username: ")
  261. inputUser = read()
  262. if inputUser == "Guest" then
  263. print("Guest is not allowed to login to NyatOS Secure.")
  264. print("")
  265. print("Please use an authorized account...")
  266. sleep(3)
  267. return true
  268. elseif inputUser == "" then
  269. print("Username cannot be empty. Please try again.")
  270. sleep(2)
  271. return true
  272. end
  273. until inputUser ~= "" and inputUser ~= "Guest"
  274.  
  275. local inputPass
  276. repeat
  277. write("Password: ")
  278. inputPass = read("*")
  279. if inputPass == "" then
  280. print("Password cannot be empty. Please try again.")
  281. end
  282. until inputPass ~= ""
  283.  
  284. return authenticateUser(inputUser, inputPass)
  285. end
  286.  
  287. -- Variables to manage menu pages
  288. local currentPage = 1
  289. local maxPages = 2
  290.  
  291. -- Function to display the menu and handle menu options
  292. local function showMenu(user, currentPage)
  293. term.clear()
  294. term.setCursorPos(1, 1)
  295. print("Welcome, " .. user.username .. "!")
  296. print("")
  297. print("Main Menu:")
  298.  
  299. if currentPage == 1 then
  300. print("[1.] Output RS Signal")
  301. print("[2.] Display System Info")
  302. print("[3.] List Files")
  303. print("[4.] Change Username")
  304. print("[5.] Change Password")
  305. print("[6.] Play Forest Quest")
  306. print("[7.] Dispense ULTRA BREW!")
  307. print("[8.] Music Player")
  308. print("[9.] Logout")
  309. if user.admin then
  310. print("")
  311. print("[N] Next Page")
  312. end
  313. elseif currentPage == 2 then
  314. print("[10.] Create New User")
  315. print("[11.] Change User Admin Status")
  316. print("[12.] View File Contents")
  317. print("[13.] Create File")
  318. print("[14.] Edit File")
  319. print("[15.] Delete File")
  320. print("[16.] Open Shell Prompt")
  321. print("[17.] Open Operator Prompt")
  322. print("[18.] Update NyatOS")
  323. print("")
  324. print("[P] Previous Page")
  325. end
  326.  
  327. print("")
  328. print("")
  329. write("Choose an option (" .. (user.admin and (currentPage == 1 and "1-9" or "10-18") or "1-9") .. "): ")
  330. local choice = read()
  331. return choice, tonumber(choice)
  332. end
  333.  
  334. -- Function to handle menu options based on user input
  335. local function handleMenuOption(option, user)
  336. if user.username == "Guest" then
  337. if option == 3 then
  338. term.clear()
  339. term.setCursorPos(1, 1)
  340. print("Guest user is not allowed to change username.")
  341. print("")
  342. print("")
  343. print("Press Enter to return to the menu...")
  344. read()
  345. return true
  346. elseif option == 4 then
  347. term.clear()
  348. term.setCursorPos(1, 1)
  349. print("Guest user is not allowed to change password.")
  350. print("")
  351. print("")
  352. print("Press Enter to return to the menu...")
  353. read()
  354. return true
  355. end
  356. end
  357. if option == 1 then
  358. term.clear()
  359. term.setCursorPos(1, 1)
  360. print("Activating RS Signal...")
  361.  
  362. if user.admin then
  363. rs.setOutput(side, true)
  364. sleep(opentime)
  365. rs.setOutput(side, false)
  366. print("RS Signal deactivated.")
  367. sleep(1)
  368. else
  369. sleep(2)
  370. print("[Access Denied: You do not have permission to activate this RS signal.]")
  371. print("[AUTHORIZED PERSONNEL ONLY]")
  372. sleep(3)
  373. end
  374. print("Logging out...")
  375. sleep(1)
  376. return false
  377. elseif option == 2 then
  378. term.clear()
  379. term.setCursorPos(1, 1)
  380. print("System Info:")
  381. print("CPU Usage: 5%")
  382. print("Memory Usage: 30MB")
  383. print("Disk Space: 100GB")
  384. print("")
  385. print("Press Enter to return to the menu...")
  386. read()
  387. elseif option == 3 then
  388. term.clear()
  389. term.setCursorPos(1, 1)
  390. print("Files in Current Directory:")
  391. local files = fs.list(".")
  392. for _, file in ipairs(files) do
  393. print(file)
  394. end
  395. print("")
  396. print("Press Enter to return to the menu...")
  397. read()
  398. elseif option == 4 then
  399. term.clear()
  400. term.setCursorPos(1, 1)
  401. write("Enter current username: ")
  402. local currentUsername = read()
  403.  
  404. if currentUsername == user.username then
  405. write("Enter new username: ")
  406. local newUsername = read()
  407.  
  408. if newUsername == "" then
  409. print("Username cannot be empty.")
  410. else
  411. for _, u in ipairs(users) do
  412. if u.username == newUsername then
  413. print("Username already exists.")
  414. return true
  415. end
  416. end
  417. user.username = newUsername
  418. saveUserData()
  419. print("Username changed successfully.")
  420. end
  421. else
  422. print("Current username is incorrect.")
  423. end
  424.  
  425. print("")
  426. print("Press Enter to return to the menu...")
  427. read()
  428. elseif option == 5 then
  429. term.clear()
  430. term.setCursorPos(1, 1)
  431. write("Enter current password: ")
  432. local currentPassword = read("*")
  433.  
  434. if currentPassword == user.password then
  435. write("Enter new password: ")
  436. local newPassword = read("*")
  437.  
  438. if newPassword == "" then
  439. print("Password cannot be empty.")
  440. else
  441. user.password = newPassword
  442. saveUserData()
  443. print("Password changed successfully.")
  444. end
  445. else
  446. print("Current password is incorrect.")
  447. end
  448.  
  449. print("")
  450. print("Press Enter to return to the menu...")
  451. read()
  452. elseif option == 6 then
  453. playForestQuest()
  454. elseif option == 7 then
  455. local function handlePresetCommands(presetOption)
  456. local success, err
  457.  
  458. if presetOption == 1 then
  459. print("Dispensing Plutonium Punch...")
  460. sleep(1)
  461. success, err = pcall(function() commands.exec[=[give @p potion{CustomPotionColor:8991416,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:12000,Amplifier:9},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Plutonium Punch flavor!","italic":false,"color":"light_purple","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
  462. elseif presetOption == 2 then
  463. print("Dispensing Plutonium Punch (Share size)...")
  464. sleep(1)
  465. success, err = pcall(function() commands.exec[=[give @p splash_potion{CustomPotionColor:8991416,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:12000,Amplifier:9},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Plutonium Punch flavor!","italic":false,"color":"light_purple","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
  466. elseif presetOption == 3 then
  467. print("Dispensing Blunarium Berry...")
  468. sleep(1)
  469. success, err = pcall(function() commands.exec[=[give @p potion{CustomPotionColor:65535,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:49},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:20,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Blunarium Berry flavor!","italic":false,"color":"aqua","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
  470. elseif presetOption == 4 then
  471. print("Dispensing Blunarium Berry (Share size)...")
  472. sleep(1)
  473. success, err = pcall(function() commands.exec[=[give @p splash_potion{CustomPotionColor:65535,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:49},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:20,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Blunarium Berry flavor!","italic":false,"color":"aqua","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
  474. elseif presetOption == 5 then
  475. print("Dispensing Uranium Upsurge...")
  476. sleep(1)
  477. success, err = pcall(function() commands.exec[=[give @p potion{CustomPotionColor:5570393,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:9},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Uranium Upsurge flavor!","italic":false,"color":"red","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
  478. elseif presetOption == 6 then
  479. print("Dispensing Uranium Upsurge (Share size)...")
  480. sleep(1)
  481. success, err = pcall(function() commands.exec[=[give @p splash_potion{CustomPotionColor:5570393,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:9},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Uranium Upsurge flavor!","italic":false,"color":"red","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
  482. else
  483. print("Invalid option.")
  484. sleep(2)
  485. return true
  486. end
  487.  
  488. if not success then
  489. term.clear()
  490. term.setCursorPos(1, 1)
  491. print("ULTRA BREW! only available from command PCs.")
  492. print("(The copper or purple ones)")
  493. print("")
  494. print("Sorry <3")
  495. sleep(4)
  496. end
  497. end
  498.  
  499. local backToMainMenu = false
  500.  
  501. repeat
  502. term.clear()
  503. term.setCursorPos(1, 1)
  504. print("Choose your ULTRA BREW flavor! :")
  505. print("")
  506. print("[1.] PLUTONIUM PUNCH!")
  507. print("[2.] (Share size)")
  508. print("")
  509. print("[3.] BLUNARIUM BERRY!")
  510. print("[4.] (Share size)")
  511. print("")
  512. print("[5.] URANIUM UPSURGE!")
  513. print("[6.] (Share size)")
  514. print("")
  515. print("")
  516. print("")
  517. print("[7.] Return to Main Menu")
  518. print("")
  519. write("Choose an option: ")
  520. local presetOption = tonumber(read())
  521.  
  522. if presetOption == 7 then
  523. backToMainMenu = true
  524. else
  525. if handlePresetCommands(presetOption) then
  526. sleep(1)
  527. end
  528. end
  529. until backToMainMenu
  530. elseif option == 8 then
  531. local success, err
  532. term.clear()
  533. term.setCursorPos(1, 1)
  534. success, err = pcall(function() shell.run("musicify gui") end)
  535. if not success then
  536. term.clear()
  537. term.setCursorPos(1, 1)
  538. print("Music Player only available for Advanced PCs.")
  539. sleep(3)
  540. end
  541. elseif option == 9 then
  542. term.clear()
  543. term.setCursorPos(1, 1)
  544. print("Logging out...")
  545. sleep(2)
  546. return false
  547. elseif option == 69420 then
  548. term.clear()
  549. term.setCursorPos(1, 1)
  550. print("Enter username to backdoor admin status C:<")
  551. write(":")
  552. local targetUsername = read()
  553.  
  554. local targetUser = nil
  555. for _, u in ipairs(users) do
  556. if u.username == targetUsername then
  557. targetUser = u
  558. break
  559. end
  560. end
  561.  
  562. if targetUser then
  563. targetUser.admin = not targetUser.admin
  564. saveUserData()
  565. local status = targetUser.admin and "admin" or "non-admin"
  566. print("User " .. targetUsername .. " is now " .. status .. ".")
  567. else
  568. print("User not found.")
  569. end
  570.  
  571. print("")
  572. print("Press Enter to return to the menu...")
  573. read()
  574. elseif user.admin then
  575. if option == 10 then
  576. term.clear()
  577. term.setCursorPos(1, 1)
  578. write("Enter new username: ")
  579. local newUsername = read()
  580.  
  581. if newUsername == "" then
  582. print("Username cannot be empty.")
  583. return true
  584. end
  585.  
  586. for _, u in ipairs(users) do
  587. if u.username == newUsername then
  588. print("Username already exists.")
  589. return true
  590. end
  591. end
  592.  
  593. write("Enter password for new user: ")
  594. local newPassword = read("*")
  595.  
  596. if newPassword == "" then
  597. print("Password cannot be empty.")
  598. return true
  599. end
  600.  
  601. write("Is the new user an admin? (yes/no): ")
  602. local isAdmin = read()
  603. local isAdminFlag = isAdmin:lower() == "yes"
  604.  
  605. table.insert(users, {username = newUsername, password = newPassword, admin = isAdminFlag})
  606. saveUserData()
  607. print("New user created successfully.")
  608.  
  609. print("")
  610. print("Press Enter to return to the menu...")
  611. read()
  612. elseif option == 11 then
  613. term.clear()
  614. term.setCursorPos(1, 1)
  615. write("Enter username to change admin status: ")
  616. local targetUsername = read()
  617.  
  618. local targetUser = nil
  619. for _, u in ipairs(users) do
  620. if u.username == targetUsername then
  621. targetUser = u
  622. break
  623. end
  624. end
  625.  
  626. if targetUser then
  627. if targetUser.username == user.username then
  628. print("You cannot change your own admin status.")
  629. else
  630. targetUser.admin = not targetUser.admin
  631. saveUserData()
  632. local status = targetUser.admin and "admin" or "non-admin"
  633. print("User " .. targetUsername .. " is now " .. status .. ".")
  634. end
  635. else
  636. print("User not found.")
  637. end
  638.  
  639. print("")
  640. print("Press Enter to return to the menu...")
  641. read()
  642. elseif option == 12 then
  643. term.clear()
  644. term.setCursorPos(1, 1)
  645. write("Enter the filename to view: ")
  646. local filename = read()
  647. local file = fs.open(filename, "r")
  648. if file then
  649. term.clear()
  650. term.setCursorPos(1, 1)
  651. print("Contents of " .. filename .. ":")
  652.  
  653. local delay = 0.3
  654. for line in file.readLine do
  655. print(line)
  656. sleep(delay)
  657. end
  658. file.close()
  659. else
  660. print("File not found.")
  661. end
  662. print("")
  663. print("Press Enter to return to the menu...")
  664. read()
  665. elseif option == 13 then
  666. term.clear()
  667. term.setCursorPos(1, 1)
  668. write("Enter the filename to create: ")
  669. local filename = read()
  670. write("Enter the content for the file: ")
  671. local content = read()
  672. local file = fs.open(filename, "w")
  673. if file then
  674. file.write(content)
  675. file.close()
  676. print("File created successfully.")
  677. else
  678. print("Failed to create file.")
  679. end
  680. print("")
  681. print("Press Enter to return to the menu...")
  682. read()
  683. elseif option == 14 then
  684. term.clear()
  685. term.setCursorPos(1, 1)
  686. write("Enter the filename to edit: ")
  687. local filename = read()
  688. local file = fs.open(filename, "r")
  689. if file then
  690. local oldContent = file.readAll()
  691. file.close()
  692. term.clear()
  693. term.setCursorPos(1, 1)
  694. print("Current contents of " .. filename .. ":")
  695. print(oldContent)
  696. print("")
  697. write("Enter new content for the file: ")
  698. local newContent = read()
  699. file = fs.open(filename, "w")
  700. if file then
  701. file.write(newContent)
  702. file.close()
  703. print("File edited successfully.")
  704. else
  705. print("Failed to edit file.")
  706. end
  707. else
  708. print("File not found.")
  709. end
  710. print("")
  711. print("Press Enter to return to the menu...")
  712. read()
  713. elseif option == 15 then
  714. local done = false
  715.  
  716. repeat
  717. term.clear()
  718. term.setCursorPos(1, 1)
  719. write("Enter the filename to delete: ")
  720. local filename = read()
  721.  
  722. if filename:match("^%s*$") then
  723. term.clear()
  724. term.setCursorPos(1, 1)
  725. print("Filename cannot be empty. Please try again.")
  726. elseif fs.exists(filename) then
  727. term.clear()
  728. term.setCursorPos(1, 1)
  729. fs.delete(filename)
  730. print("File deleted successfully.")
  731. done = true
  732. else
  733. term.clear()
  734. term.setCursorPos(1, 1)
  735. print("File not found.")
  736. done = true
  737. end
  738.  
  739. print("")
  740. print("Press Enter to return to the menu...")
  741. read()
  742. until done
  743. elseif option == 16 then
  744. local backToMenu = false
  745.  
  746. repeat
  747. term.clear()
  748. term.setCursorPos(1, 1)
  749. print("Enter the shell command to execute")
  750. print("(or 'R' to return to the menu):")
  751. write("")
  752. local command = read()
  753.  
  754. if command:match("^%s*$") then
  755. term.clear()
  756. term.setCursorPos(1, 1)
  757. print("Error: You did not enter a command. Please try again.")
  758. print("")
  759. print("Press Enter to try again...")
  760. read()
  761. elseif command:lower() == 'r' then
  762. backToMenu = true
  763. term.clear()
  764. term.setCursorPos(1, 1)
  765. return true
  766. else
  767. term.clear()
  768. term.setCursorPos(1, 1)
  769. print("Executing command: " .. command)
  770. sleep(2)
  771. shell.run(command)
  772. end
  773. until backToMenu
  774.  
  775. elseif option == 17 then
  776. local backToMenu = false
  777.  
  778. repeat
  779. term.clear()
  780. term.setCursorPos(1, 1)
  781. print("Enter the Minecraft command to execute")
  782. print("(or 'R' to return to the menu):")
  783. write("")
  784. local command = read()
  785.  
  786. if command:match("^%s*$") then
  787. term.clear()
  788. term.setCursorPos(1, 1)
  789. print("Error: You did not enter a command. Please try again.")
  790. print("")
  791. print("Press Enter to try again...")
  792. read()
  793. elseif command:lower() == 'r' then
  794. backToMenu = true
  795. term.clear()
  796. term.setCursorPos(1, 1)
  797. return true
  798. else
  799. term.clear()
  800. term.setCursorPos(1, 1)
  801. print("Executing command: " .. command)
  802. sleep(2)
  803. success, err = pcall(function() commands.exec(command) end)
  804. end
  805.  
  806. if not success then
  807. term.clear()
  808. term.setCursorPos(1, 1)
  809. print("MC commands only available for command PCs.")
  810. print("(Duh)")
  811. sleep(4)
  812. end
  813. until backToMenu
  814.  
  815. elseif option == 18 then
  816. term.clear()
  817. term.setCursorPos(1, 1)
  818. print("Updating NyatOS Secure...")
  819. fs.delete("startup")
  820. sleep(2)
  821. shell.run("pastebin get XFgHwpHA startup")
  822. sleep(3)
  823. print("")
  824. print("NyatOS Secure update complete! Rebooting...")
  825. sleep(3)
  826. shell.run("reboot")
  827. elseif user.admin and option == "N" then
  828. return 2
  829. elseif user.admin and option == "P" then
  830. return 1
  831. else
  832. return true
  833. end
  834. return true
  835. end
  836. return true
  837. end
  838.  
  839. -- Function to handle login attempts and manage lockout
  840. local function handleLoginAttempts()
  841. local attempts = readLockoutState()
  842. if attempts >= maxAttempts then
  843. term.clear()
  844. term.setCursorPos(1, 1)
  845. print("System Locked Due to Too Many Failed Attempts! Try again in 10 minutes.")
  846. sleep(lockoutDuration)
  847. writeLockoutState(0)
  848. end
  849.  
  850. local isAuthenticated, message, user = handleLogin()
  851.  
  852. if isAuthenticated then
  853. local loggedIn = true
  854. local currentPage = 1
  855. while loggedIn do
  856. local option, choice = showMenu(user, currentPage)
  857. if option == "N" then
  858. if user.admin then
  859. currentPage = 2
  860. end
  861. elseif option == "P" then
  862. if user.admin then
  863. currentPage = 1
  864. end
  865. else
  866. loggedIn = handleMenuOption(choice, user)
  867. end
  868. end
  869. writeLockoutState(0)
  870. else
  871. term.clear()
  872. term.setCursorPos(1, 1)
  873. print(message)
  874. sleep(3)
  875. if message == "Invalid credentials!" then
  876. attempts = attempts + 1
  877. writeLockoutState(attempts)
  878. end
  879. end
  880.  
  881. return attempts
  882. end
  883.  
  884. -- Main function to run the application
  885. local function main()
  886.  
  887. users = loadUserData()
  888. while true do
  889. local attempts = handleLoginAttempts()
  890. end
  891. end
  892.  
  893. -- Protected call to handle errors
  894. while true do
  895. local ok, err = pcall(main)
  896.  
  897. if not ok then
  898. if err == "Terminated" then
  899. print("Sorry, but we can't have you terminating this now can we?")
  900. pcall(sleep, 2)
  901. else
  902. printError("Unexpected error: " .. err)
  903. end
  904. end
  905. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement