Marlingaming

CC Tweaked CCSPS Iron - Web explorer

Feb 1st, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. local Address
  2. local Lines = {}
  3. local CatchWords = {"pastebin","fs.delete","settings.set","settings.define","while true do","for i = 1","os.reboot","os.shutdown","exit","break","shell.run"}
  4.  
  5. local function Clear()
  6. term.clear()
  7. term.setCursorPos(1,1)
  8. end
  9.  
  10. local function Textbar(y)
  11. term.setCursorPos(1,y)
  12. local input
  13. while true do
  14. local event = {os.pullEvent("key")}
  15. if event[2] == keys.enter then break end
  16. input = read()
  17. end
  18. return(input)
  19. end
  20.  
  21. local function Scan(Fi)
  22. local file = fs.open(fs.combine("os/System/TempFiles",Fi),"r")
  23. local Pass = true
  24. for i = 1, #CatchWords do
  25. if string.find(file.readAll(),CatchWords[i]) then
  26. Pass = false
  27. end
  28. end
  29. return(Pass)
  30. end
  31.  
  32. local function DrawPage(file)
  33. Lines = {}
  34. local page = fs.open(file,"r")
  35. while true do
  36. local Content = page.readLine()
  37. if Content ~= nil then
  38. Lines[#Lines + 1] = Content
  39. else
  40. break
  41. end
  42. end
  43. page.close()
  44. local options = {}
  45. local Actions = {}
  46. for i = 1, #Lines do
  47. loadstring(Lines[i])
  48. end
  49. if #options > 0 then
  50. local n = CUI(options)
  51. loadstring(Actions[n])
  52. end
  53. Menu()
  54. end
  55.  
  56. function CUI(m) --declare function
  57. n=1
  58. local l = #m
  59. while true do
  60. term.setCursorPos(1,5)
  61. for i=1, #m, 1 do --traverse the table of options
  62. if i==n then term.clearLine() print(i, ">",m[i]) else term.clearLine() print(i, "-", m[i]) end --print them
  63. end
  64. a, b= os.pullEvent("key") --wait for keypress
  65. if b==keys.w and n>1 then n=n-1 end
  66. if b==keys.s and n<l then n=n+1 end
  67. if b==keys.enter then break end
  68. end
  69. return n --return the value
  70. end
  71.  
  72. function Menu()
  73. Clear()
  74. print("web browser")
  75. local Search = TextBar(3)
  76. local id = rednet.lookup("1000",Search)
  77. if Search == "exit" then
  78.  
  79. elseif id == nil then
  80. print("failed to find site")
  81. os.sleep(3)
  82. Menu()
  83. else
  84. rednet.send(id,"web_request")
  85. local a, b, c = rednet.receive()
  86. Address = Search
  87. local file = fs.open(fs.combine("os/System/TempFiles",Address),"w")
  88. file.write(b)
  89. file.close()
  90. if Scan(Fi) == true then
  91. DrawPage(fs.combine("os/System/TempFiles",Address))
  92. else
  93. Address = nil
  94. Menu()
  95. end
  96. end
  97. end
  98.  
  99. print("sorry but the Web service is not available atm, you can tell when it’s ready by checking the App Store page once in a while")
  100. os.sleep(5)
Add Comment
Please, Sign In to add comment