Advertisement
DOGGYWOOF

embeded sys

Feb 10th, 2025 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. -- GUI setup
  2. local w, h = term.getSize()
  3. local screen = window.create(term.current(), 1, 1, w, h)
  4.  
  5. -- Function to clear the screen and reset cursor
  6. local function clearScreen()
  7. screen.clear()
  8. screen.setCursorPos(1, 1)
  9. end
  10.  
  11. -- Function to create borders for the UI
  12. local function createBorder()
  13. -- Top border
  14. screen.setCursorPos(1, 1)
  15. for i = 1, w do
  16. screen.write("-")
  17. end
  18. -- Bottom border
  19. screen.setCursorPos(1, h)
  20. for i = 1, w do
  21. screen.write("-")
  22. end
  23. end
  24.  
  25. -- Function to draw a header section
  26. local function drawHeader(title)
  27. screen.setCursorPos(1, 1)
  28. createBorder()
  29. screen.setCursorPos(math.floor((w - #title) / 2), 2)
  30. screen.write(title)
  31. screen.setCursorPos(1, 3)
  32. for i = 1, w do
  33. screen.write("-")
  34. end
  35. end
  36.  
  37. -- Function to check if file exists
  38. local function fileExists(path)
  39. local file = fs.open(path, "r")
  40. if file then
  41. file.close()
  42. return true
  43. else
  44. return false
  45. end
  46. end
  47.  
  48. -- Function to get user input for authentication
  49. local function authenticateUser()
  50. clearScreen()
  51. drawHeader("Kiosk Setup - Authentication")
  52. screen.setCursorPos(1, 4)
  53. screen.write("Enter your username: ")
  54. local username = read()
  55. local passwordFile = "/disk/users/" .. username .. "/password.txt"
  56.  
  57. if not fileExists(passwordFile) then
  58. screen.setCursorPos(1, 6)
  59. screen.write("User does not exist.")
  60. sleep(2)
  61. return false
  62. end
  63.  
  64. local file = fs.open(passwordFile, "r")
  65. local storedPassword = file.readAll()
  66. file.close()
  67.  
  68. screen.setCursorPos(1, 6)
  69. screen.write("Enter your password: ")
  70. local enteredPassword = read()
  71.  
  72. if enteredPassword == storedPassword then
  73. local adminFile = "/disk/users/" .. username .. "/admin.txt"
  74. if fileExists(adminFile) then
  75. return true
  76. else
  77. screen.setCursorPos(1, 7)
  78. screen.write("Admin privileges required.")
  79. sleep(2)
  80. return false
  81. end
  82. else
  83. screen.setCursorPos(1, 7)
  84. screen.write("Invalid password.")
  85. sleep(2)
  86. return false
  87. end
  88. end
  89.  
  90. -- Function to check Kiosk setup and app status
  91. local function checkKioskApp()
  92. clearScreen()
  93. drawHeader("Kiosk Setup Status")
  94.  
  95. if not fileExists("/disk/embeded/sysapp.lua") then
  96. screen.setCursorPos(1, 4)
  97. screen.write("ERROR: Kiosk not set up or application missing.")
  98. sleep(2)
  99. return false
  100. else
  101. local file = fs.open("/disk/embeded/sysapp.lua", "r")
  102. local appContent = file.readAll()
  103. file.close()
  104.  
  105. -- Check for a corrupted app (example: check if file is empty)
  106. if #appContent == 0 then
  107. screen.setCursorPos(1, 4)
  108. screen.write("ERROR: Application file is corrupted.")
  109. sleep(2)
  110. return false
  111. else
  112. screen.setCursorPos(1, 4)
  113. screen.write("Kiosk is set up and ready.")
  114. sleep(2)
  115. return true
  116. end
  117. end
  118. end
  119.  
  120. -- Function to allow setting up a new Kiosk app
  121. local function setupKioskApp()
  122. clearScreen()
  123. drawHeader("Set Up New Kiosk App")
  124.  
  125. if authenticateUser() then
  126. clearScreen()
  127. drawHeader("Kiosk Setup - New App")
  128.  
  129. screen.setCursorPos(1, 4)
  130. screen.write("Is the new app a local file or a Pastebin program? (file/pastebin): ")
  131. local appType = read()
  132.  
  133. if appType == "file" then
  134. clearScreen()
  135. drawHeader("Local File Upload")
  136. screen.setCursorPos(1, 4)
  137. screen.write("Enter the file path of the new app: ")
  138. local appPath = read()
  139.  
  140. if not fileExists(appPath) then
  141. clearScreen()
  142. drawHeader("Error")
  143. screen.setCursorPos(1, 4)
  144. screen.write("File does not exist.")
  145. sleep(2)
  146. else
  147. local appFile = fs.open(appPath, "r")
  148. local appContent = appFile.readAll()
  149. appFile.close()
  150.  
  151. local sysAppFile = fs.open("/disk/embeded/sysapp.lua", "w")
  152. sysAppFile.write(appContent)
  153. sysAppFile.close()
  154.  
  155. clearScreen()
  156. drawHeader("Success")
  157. screen.setCursorPos(1, 4)
  158. screen.write("App copied successfully to /disk/embeded/sysapp.lua")
  159. sleep(2)
  160. end
  161. elseif appType == "pastebin" then
  162. clearScreen()
  163. drawHeader("Pastebin Program")
  164. screen.setCursorPos(1, 4)
  165. screen.write("Enter the Pastebin program ID: ")
  166. local pastebinID = read()
  167.  
  168. local pastebinURL = "https://pastebin.com/raw/" .. pastebinID
  169. local pastebinContent = http.get(pastebinURL).readAll()
  170.  
  171. local sysAppFile = fs.open("/disk/embeded/sysapp.lua", "w")
  172. sysAppFile.write(pastebinContent)
  173. sysAppFile.close()
  174.  
  175. clearScreen()
  176. drawHeader("Success")
  177. screen.setCursorPos(1, 4)
  178. screen.write("App copied from Pastebin to /disk/embeded/sysapp.lua")
  179. sleep(2)
  180. else
  181. clearScreen()
  182. drawHeader("Error")
  183. screen.setCursorPos(1, 4)
  184. screen.write("Invalid choice.")
  185. sleep(2)
  186. end
  187. else
  188. clearScreen()
  189. drawHeader("Error")
  190. screen.setCursorPos(1, 4)
  191. screen.write("Authentication failed.")
  192. sleep(2)
  193. end
  194. end
  195.  
  196. -- Main program
  197. if checkKioskApp() then
  198. shell.run("/disk/embeded/sysapp.lua")
  199. else
  200. setupKioskApp()
  201. end
  202.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement