Advertisement
DOGGYWOOF

Untitled

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