Advertisement
LazerAio

AST.lua (AioSecureTerminal)

Jul 4th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. --Creddits to Aio 2022
  2. --Created on july the 4:th 2022 this is a somewhat safer terminal program called
  3. --AST (AioSecureTerminal)
  4. --NOTE: It IS escapable and is only intended to reduce the risk of operator error
  5.  
  6. print("Starting")
  7. function reset()
  8. term.setCursorPos(1,1)
  9. term.clear()
  10. history={}
  11. shell.run("mkdir ./trash")
  12. shell.run("mkdir ./home")
  13. LLCPath = {}
  14. CPath = "."
  15. CPI = CPath
  16. for s=1,20 do
  17. shell.run("cd ..")
  18. end
  19. LastCommand = ""
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. term.setTextColor(colors.white)
  23. end
  24.  
  25. function command(s)
  26. if s == "" or s == "last" then
  27. command(LastCommand)
  28. else
  29. LastCommand = s
  30. end
  31. print("")
  32.  
  33. if s == "ls" then
  34. shell.run("dir")
  35. return "safe exit"
  36. end
  37.  
  38. if s == "reset" or s == "clear" then
  39. reset()
  40. end
  41. if s == "help" then
  42. term.setTextColor(colors.white)
  43. print("exit - esacpe the terminal")
  44. print("cd - change directory")
  45. print("'cd' or 'cd ~' will change to ./home")
  46. print("Due to bad coding, recursive CD:s breaks the pwd and CPI functions")
  47. print("pwd - attempts to show the current directory")
  48. print("rm - will move files/folders to ./trash")
  49. print("reset / clear - clears the screen and moves to ./")
  50. print("'' / last - activates the last command")
  51. print("")
  52. print("1/2 press enter to continue")
  53. read()
  54. end
  55. if string.sub(s,1,2) == "cd" then
  56. CPI = CPath
  57. if s == "cd ~" or s == "cd" then
  58. shell.run("cd ./")
  59. shell.run("cd home")
  60. LLCPath = {"./~"}
  61. CPath = "./home"
  62. elseif s == "cd .." then
  63. CPI = CPath
  64. if CPath == "." then
  65. printError("Already on ./")
  66. else
  67. shell.run("cd ..")
  68. t = CPath
  69. CPath = LLCPath[#LLCPath]
  70. LLCPath[#LLCPath] = nil
  71. end
  72. elseif string.sub(s,1,3) == "cd " then
  73. CPI = "?"
  74. u = 1
  75. LLCPath = {}
  76. for i=1,string.len(s.."/"..CPath) do
  77. if string.sub(CPath.."/"..s,i,i) == "/" then
  78. LLCPath[#LLCPath+1] = string.sub(CPath.."/"..s,u,(i-1))
  79. u = i
  80. end
  81. end
  82. shell.run(s)
  83. --LLCPath[#LLCPath+1] = CPath
  84. CPath = CPath.."/"..string.sub(s,3,string.len(s))
  85. else
  86. shell.run(s)
  87. end
  88. elseif s == "pwd" then
  89. print(CPath)
  90. elseif string.sub(s,1,3) == "rm " then
  91. if fs.exists(string.sub(s,4,string.len(s))) then
  92. if fs.isDir(string.sub(s,4,string.len(s))) then
  93. term.setTextColor(colors.yellow)
  94. print("You are about to remove a directory!")
  95. print("Are you sure? [Y/n]")
  96. if string.upper(read()) == "Y" then
  97. shell.run("mv",string.sub(s,3,string.len(s)),"./trash")
  98. end
  99. else
  100. shell.run("mv", string.sub(s,3,string.len(s)),"./trash")
  101. end
  102. else
  103. printError("File or directory not found")
  104. end
  105. return "safe exit"
  106. elseif s == "ls" then
  107. shell.run("dir")
  108. elseif string.sub(s,1,3) == "bg " or string.sub(s,1,3) == "fg " or s == "fg" or s == "bg" then
  109. printError("Multitasking is not allowed for safety reasons")
  110. else
  111. shell.run(s)
  112. end
  113. end
  114.  
  115.  
  116. reset()
  117. print("Welcome!")
  118. History = {}
  119. bo = 0
  120. while true do
  121. if bo == 5 then
  122. term.setTextColor(colors.brown)
  123. command("pwd")
  124. print("")
  125. sleep(0)
  126. bo = 0
  127. else
  128. bo = bo + 1
  129. end
  130. OX,OY = term.getCursorPos()
  131. term.setCursorPos(1,OY-1)
  132. term.setTextColor(colors.white)
  133. term.clearLine()
  134. print(" > ")
  135. term.setCursorPos(string.len(" > "),OY-1)
  136. term.setTextColor(colors.gray)
  137. print(os.date())
  138. term.setTextColor(colors.blue)
  139. term.setCursorPos(string.len(" >",os.date())+1,OY-1)
  140. o = read()
  141. History[#History+1] = o
  142. if o == "save" then
  143. print("Location from ./?")
  144. o = read()
  145. if fs.exists(o) then
  146. printError("Location exists aborting")
  147. else
  148. h = fs.open(o,"w")
  149. for i=1,#History do
  150. h.writeLine(History[i])
  151. end
  152. h.close()
  153. end
  154. elseif o == "exit" then
  155. break
  156. end
  157. command(o)
  158. end
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement