Advertisement
DOGGYWOOF

Untitled

Jul 15th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. -- Function for Security Card Login (insert or enter ID)
  2. function securityCardLogin()
  3. while true do
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. print("Security Card Manager")
  7. print("Enter username:")
  8. local username = read()
  9.  
  10. -- Validate username
  11. if fs.exists("/disk/users/" .. username) then
  12. showSecurityCardMenu(username)
  13. break
  14. else
  15. print("User not found. Press any key to try again.")
  16. read()
  17. end
  18. end
  19. end
  20.  
  21. -- Function to display Security Card Manager menu for a specific user
  22. function showSecurityCardMenu(username)
  23. while true do
  24. term.clear()
  25. term.setCursorPos(1, 1)
  26. print("Security Card Manager for User: " .. username)
  27. print("1. Add Card")
  28. print("2. Remove Cards")
  29. print("3. Show All Security Cards")
  30. print("4. Disable Security Card Login")
  31. print("5. Back to Main Menu")
  32.  
  33. local choice = read()
  34.  
  35. if choice == "1" then
  36. addCardMenu(username)
  37. elseif choice == "2" then
  38. removeCardsMenu(username)
  39. elseif choice == "3" then
  40. showAllSecurityCards(username)
  41. elseif choice == "4" then
  42. disableSecurityCardLogin(username)
  43. elseif choice == "5" then
  44. break -- Back to main menu
  45. else
  46. print("Invalid choice. Press any key to try again.")
  47. read()
  48. end
  49. end
  50. end
  51.  
  52. -- Function for Add Card submenu
  53. function addCardMenu(username)
  54. while true do
  55. term.clear()
  56. term.setCursorPos(1, 1)
  57. print("Add Card for User: " .. username)
  58. print("1. Insert Security Card")
  59. print("2. Enter Security Card ID")
  60. print("3. Back to Security Card Manager")
  61.  
  62. local choice = read()
  63.  
  64. if choice == "1" then
  65. grabAndSaveDiskID(username)
  66. elseif choice == "2" then
  67. saveDiskID(username)
  68. elseif choice == "3" then
  69. break -- Back to Security Card Manager
  70. else
  71. print("Invalid choice. Press any key to try again.")
  72. read()
  73. end
  74. end
  75. end
  76.  
  77. -- Function for Remove Cards submenu
  78. function removeCardsMenu(username)
  79. while true do
  80. term.clear()
  81. term.setCursorPos(1, 1)
  82. print("Remove Cards for User: " .. username)
  83. print("1. Insert Security Card to delete")
  84. print("2. Enter Security Card ID to delete")
  85. print("3. Back to Security Card Manager")
  86.  
  87. local choice = read()
  88.  
  89. if choice == "1" then
  90. grabAndDeleteDiskID(username)
  91. elseif choice == "2" then
  92. deleteSpecificCard(username)
  93. elseif choice == "3" then
  94. break -- Back to Security Card Manager
  95. else
  96. print("Invalid choice. Press any key to try again.")
  97. read()
  98. end
  99. end
  100. end
  101.  
  102. -- Function to delete a specific security card by ID
  103. function deleteSpecificCard(username)
  104. term.clear()
  105. term.setCursorPos(1, 1)
  106. print("Enter Card ID to delete for User: " .. username)
  107. local cardID = read()
  108.  
  109. local filePath = "/disk/users/" .. username .. "/ID/" .. cardID .. ".file"
  110.  
  111. if fs.exists(filePath) then
  112. fs.delete(filePath)
  113. print("Security Card deleted successfully.")
  114. else
  115. print("Security Card not found.")
  116. end
  117.  
  118. sleep(2)
  119. end
  120.  
  121. -- Function to grab disk ID and delete it for a user
  122. function grabAndDeleteDiskID(username)
  123. term.clear()
  124. term.setCursorPos(1, 1)
  125. print("Insert Security Card to delete ID for User: " .. username)
  126.  
  127. while true do
  128. local peripherals = peripheral.getNames()
  129.  
  130. for _, name in ipairs(peripherals) do
  131. if peripheral.getType(name) == "drive" then
  132. local diskID = disk.getID(name)
  133. if diskID then
  134. local filePath = "/disk/users/" .. username .. "/ID/" .. diskID .. ".file"
  135.  
  136. if fs.exists(filePath) then
  137. fs.delete(filePath)
  138. print("Security Card ID deleted successfully.")
  139. else
  140. print("Security Card ID not found.")
  141. end
  142.  
  143. return -- Exit function after deleting ID
  144. end
  145. end
  146. end
  147.  
  148. sleep(1) -- Check every second
  149. end
  150. end
  151.  
  152. -- Function to save disk ID for a user
  153. function saveDiskID(username)
  154. term.clear()
  155. term.setCursorPos(1, 1)
  156. print("Enter Card ID for User: " .. username)
  157. local cardID = read()
  158.  
  159. -- Create directory if it doesn't exist
  160. local idDir = "/disk/users/" .. username .. "/ID"
  161. if not fs.exists(idDir) then
  162. fs.makeDir(idDir)
  163. end
  164.  
  165. -- Save disk ID as a file
  166. local filePath = idDir .. "/" .. cardID .. ".file"
  167. local file = fs.open(filePath, "w")
  168. file.writeLine("Disk ID: " .. cardID)
  169. file.close()
  170.  
  171. print("Disk ID saved successfully.")
  172. sleep(2)
  173. end
  174.  
  175. -- Function to grab disk ID and save it for a user
  176. function grabAndSaveDiskID(username)
  177. term.clear()
  178. term.setCursorPos(1, 1)
  179. print("Insert Security Card to grab ID for User: " .. username)
  180.  
  181. while true do
  182. local peripherals = peripheral.getNames()
  183.  
  184. for _, name in ipairs(peripherals) do
  185. if peripheral.getType(name) == "drive" then
  186. local diskID = disk.getID(name)
  187. if diskID then
  188. -- Create directory if it doesn't exist
  189. local idDir = "/disk/users/" .. username .. "/ID"
  190. if not fs.exists(idDir) then
  191. fs.makeDir(idDir)
  192. end
  193.  
  194. -- Save disk ID as a file
  195. local filePath = idDir .. "/" .. diskID .. ".file"
  196. local file = fs.open(filePath, "w")
  197. file.writeLine("Disk ID: " .. diskID)
  198. file.close()
  199.  
  200. print("Disk ID grabbed and saved successfully.")
  201. return -- Exit function after saving
  202. end
  203. end
  204. end
  205.  
  206. sleep(1) -- Check every second
  207. end
  208. end
  209.  
  210. -- Function to disable Security Card Login (delete all IDs)
  211. function disableSecurityCardLogin(username)
  212. term.clear()
  213. term.setCursorPos(1, 1)
  214. print("Are you sure you want to disable Security Card Login for User: " .. username .. "? (y/n)")
  215. local confirm = read()
  216. if confirm:lower() == "y" then
  217. local idDir = "/disk/users/" .. username .. "/ID"
  218. if fs.exists(idDir) then
  219. fs.delete(idDir)
  220. print("Security Card Login disabled successfully.")
  221. else
  222. print("No security cards found to delete.")
  223. end
  224. else
  225. print("Operation canceled.")
  226. end
  227.  
  228. sleep(2)
  229. end
  230.  
  231. -- Function to show all security cards for a user
  232. function showAllSecurityCards(username)
  233. term.clear()
  234. term.setCursorPos(1, 1)
  235. print("Security Cards for User: " .. username)
  236.  
  237. local idDir = "/disk/users/" .. username .. "/ID"
  238. if fs.exists(idDir) then
  239. local files = fs.list(idDir)
  240. for _, file in ipairs(files) do
  241. if fs.isDir(idDir .. "/" .. file) == false then
  242. print(file)
  243. end
  244. end
  245. else
  246. print("No security cards found.")
  247. end
  248.  
  249. print("Press any key to continue...")
  250. read()
  251. end
  252.  
  253. -- Main program
  254. securityCardLogin()
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement