Advertisement
DOGGYWOOF

Untitled

Aug 17th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. termutils = {}
  2.  
  3. -- Clears the terminal and resets the cursor position
  4. termutils.clear = function()
  5. term.clear()
  6. term.setCursorPos(1, 1)
  7. end
  8.  
  9. -- Resets text and background colors to default
  10. termutils.clearColor = function()
  11. term.setTextColor(colors.white)
  12. term.setBackgroundColor(colors.black)
  13. end
  14.  
  15. -- Prompts the user for input and returns the entered value
  16. function input()
  17. term.setTextColor(colors.blue)
  18. local dir = shell.dir() .. "/> "
  19. write(dir)
  20. termutils.clearColor()
  21. return io.read()
  22. end
  23.  
  24. -- Checks if the command involves protected paths or files and handles protection
  25. function checkProtection(command)
  26. local blockedCommands = { "sh", "shell" }
  27. local protectedPaths = {
  28. "/disk/boot/",
  29. "/disk/os/",
  30. "/disk/bootloader/",
  31. "/disk/users/",
  32. "/recovery/", -- Directory path
  33. "startup", -- File name
  34. "no-os", -- File name
  35. "dev.cfg" -- File name
  36. }
  37.  
  38. -- Handle specific commands for reboot and shutdown
  39. if command:lower() == "reboot" then
  40. executeCommand("/disk/ACPI/reboot")
  41. return false -- Prevent further command processing
  42. elseif command:lower() == "shutdown" then
  43. executeCommand("/disk/ACPI/shutdown")
  44. return false -- Prevent further command processing
  45. end
  46.  
  47. -- Block specific commands
  48. for _, blocked in ipairs(blockedCommands) do
  49. if command:lower() == blocked then
  50. print("Error: The command '" .. blocked .. "' is not allowed.")
  51. return false
  52. end
  53. end
  54.  
  55. -- Check for protected paths/files
  56. for _, path in ipairs(protectedPaths) do
  57. if isInProtectedPath(command, path) then
  58. if checkDevConfig() then
  59. print("Failed to verify system... continuing with shell command")
  60. end
  61. if not requestAdminCredentials() then
  62. return false
  63. end
  64. print("Warning: This command may modify critical files. Proceed with caution.")
  65. return true
  66. end
  67. end
  68.  
  69. return true
  70. end
  71.  
  72. -- Checks if the command involves a protected path or its subdirectories
  73. function isInProtectedPath(command, path)
  74. -- Check if the command starts with the protected path or if the protected path is found in the command
  75. return command:find(path, 1, true) ~= nil
  76. end
  77.  
  78. -- Requests admin credentials from the user
  79. function requestAdminCredentials()
  80. termutils.clear()
  81.  
  82. local width, height = term.getSize()
  83. local boxWidth = 40
  84. local boxHeight = 10
  85. local startX = math.floor((width - boxWidth) / 2)
  86. local startY = math.floor((height - boxHeight) / 2)
  87.  
  88. term.setBackgroundColor(colors.gray)
  89. term.setTextColor(colors.white)
  90.  
  91. -- Draw the box
  92. term.setCursorPos(startX, startY)
  93. write("+" .. string.rep("-", boxWidth - 2) .. "+")
  94.  
  95. for y = startY + 1, startY + boxHeight - 1 do
  96. term.setCursorPos(startX, y)
  97. write("|" .. string.rep(" ", boxWidth - 2) .. "|")
  98. end
  99.  
  100. term.setCursorPos(startX, startY + boxHeight)
  101. write("+" .. string.rep("-", boxWidth - 2) .. "+")
  102.  
  103. term.setBackgroundColor(colors.black)
  104. term.setTextColor(colors.white)
  105.  
  106. -- Display prompts inside the box
  107. local contentX = startX + 2
  108. local contentY = startY + 2
  109.  
  110. term.setCursorPos(contentX, contentY)
  111. write("Doggy OS File System Protection")
  112.  
  113. term.setCursorPos(contentX, contentY + 2)
  114. write("Enter Administrator login.")
  115.  
  116. term.setCursorPos(contentX, contentY + 4)
  117. write("Username: ")
  118. local username = io.read()
  119.  
  120. term.setCursorPos(contentX, contentY + 6)
  121. write("Password: ")
  122. term.setTextColor(colors.black) -- Change text color to black to hide the input
  123. local password = io.read()
  124. term.setTextColor(colors.white) -- Reset text color
  125.  
  126. -- Verify credentials and handle access
  127. local isVerified = verifyPassword(username, password)
  128. if not isVerified then
  129. termutils.clear() -- Clear the screen if verification fails
  130. end
  131. return isVerified
  132. end
  133.  
  134. -- Verifies the entered username and password
  135. function verifyPassword(username, password)
  136. local passwordFilePath = "/disk/users/" .. username .. "/password.txt"
  137. local file = fs.open(passwordFilePath, "r")
  138.  
  139. if file then
  140. local correctPassword = file.readAll()
  141. file.close()
  142.  
  143. if password == correctPassword and userIsAdmin(username) then
  144. return true
  145. else
  146. print("Invalid credentials or insufficient privileges.")
  147. return false
  148. end
  149. else
  150. print("User not found.")
  151. return false
  152. end
  153. end
  154.  
  155. -- Checks if the user has admin privileges
  156. function userIsAdmin(username)
  157. local adminFilePath = "/disk/users/" .. username .. "/admin.txt"
  158. local file = fs.open(adminFilePath, "r")
  159.  
  160. if file then
  161. file.close()
  162. return true
  163. else
  164. return false
  165. end
  166. end
  167.  
  168. -- Executes the command with error handling
  169. function executeCommand(command)
  170. local success, err = pcall(function() shell.run(command) end)
  171. if not success then
  172. print("Error executing command:", err)
  173. end
  174. end
  175.  
  176. -- Checks if dev.cfg exists in the root directory
  177. function checkDevConfig()
  178. local file = fs.open("/dev.cfg", "r")
  179. if file then
  180. file.close()
  181. return true
  182. else
  183. return false
  184. end
  185. end
  186.  
  187. -- Main execution starts here
  188. termutils.clear()
  189. print("Doggy OS Terminal (13.0)")
  190.  
  191. while true do
  192. local command = input()
  193.  
  194. if checkProtection(command) then
  195. executeCommand(command)
  196. else
  197. print("Command aborted.")
  198. end
  199. end
  200.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement