Guest User

reader

a guest
Dec 4th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.19 KB | None | 0 0
  1. if not term.isColor() then
  2.   error('This program works on advanced computers only')
  3. end
  4.  
  5. local safe = true
  6. function draw()
  7. term.setBackgroundColor(colors.cyan)
  8. term.clear()
  9. term.setTextColor(colors.black)
  10. term.setCursorPos(15,7)
  11. write('Website URL')
  12. term.setCursorPos(2,7)
  13. write('Safe Mode')
  14. term.setCursorPos(5,4)
  15. term.setTextColor(colors.gray)
  16. write("Entering the URL 'help' will redirect")
  17. term.setCursorPos(5,5)
  18. write("you to the help page.")
  19. term.setCursorPos(3,8)
  20. term.setTextColor(colors.black)
  21. if safe then
  22. term.setBackgroundColor(colors.lime)
  23. write('O')
  24. else
  25. term.setBackgroundColor(colors.red)
  26. write('|')
  27. end
  28. paintutils.drawLine(15,8,50,8,colors.lightGray)
  29. end
  30.  
  31. local function webget(ad)
  32. local check = true
  33. if http.request(ad) then
  34.   check = true
  35. else
  36.   check = false
  37. end
  38. if check then
  39. local site = http.get(ad)
  40. local web = {}
  41. local cweb = {}
  42. repeat
  43.   local line = site.readLine()
  44.   if line ~= nil then
  45.     table.insert(web,line)
  46.   end
  47. until line == nil
  48. local hts
  49. local hte
  50. for i,v in ipairs(web) do
  51.   if string.find(v,'</cc>') and hte == nil then
  52.       hte = i
  53.   elseif string.find(v,'<cc>') and hts == nil then
  54.     hts = i
  55.   end
  56. end
  57. if not hts or not hte then
  58.   return false
  59. end
  60. for pos = hts+1,hte-1 do
  61.   table.insert(cweb,web[pos])
  62. end
  63. return cweb
  64. else
  65. return false
  66. end
  67. end
  68.  
  69. function evcheck()
  70.   while true do
  71.     local ev = {os.pullEvent('mouse_click')}
  72.     if ev[3] == 3 and ev[4] == 8 then
  73.       local x,y = term.getCursorPos()
  74.       local color1 = term.getTextColor()
  75.       local color2 = term.getBackgroundColor()
  76.       term.setCursorPos(3,8)
  77.       term.setTextColor(colors.black)
  78.       if safe then
  79.         safe = false
  80.         term.setBackgroundColor(colors.red)
  81.         write('|')
  82.       else
  83.         safe = true
  84.         term.setBackgroundColor(colors.lime)
  85.         write('O')
  86.       end
  87.       term.setCursorPos(x,y)
  88.       term.setTextColor(color1)
  89.       term.setBackgroundColor(color2)
  90.     end
  91.   end
  92. end
  93.  
  94. local webcon
  95. local webname
  96.  
  97. function readcheck()
  98.   local report
  99.   local input
  100.   repeat
  101.     paintutils.drawLine(15,8,50,8,colors.lightGray)
  102.     term.setCursorPos(15,8)
  103.     term.setBackgroundColor(colors.lightGray)
  104.     term.setTextColor(colors.gray)
  105.     input = read()
  106.     if input == 'help' then
  107.       input = 'http://jerryrochester.endl.site/'
  108.     end
  109.     report = webget(input)
  110.     if report == false then
  111.       term.setBackgroundColor(colors.cyan)
  112.       term.setCursorPos(10,9)
  113.       term.setTextColor(colors.red)
  114.       write('Website not found/website incompatable')
  115.       sleep(2)
  116.       term.setCursorPos(10,9)
  117.       term.clearLine()
  118.     end
  119.   until report ~= false
  120.   webcon = report
  121.   webname = input
  122. end
  123.  
  124. local sweblist = {}
  125.  
  126. if not http.request('http://jerryrochester.endl.site/trustedlist/') then
  127.   error('Verified website list offline, contact creator')
  128. end
  129.  
  130. local sweb = http.get('http://jerryrochester.endl.site/trustedlist/')
  131.  
  132. repeat
  133.   local line = sweb.readLine()
  134.   if line ~= nil then
  135.     table.insert(sweblist,line)
  136.   end
  137. until line == nil
  138.  
  139. table.remove(sweblist,1)
  140. table.remove(sweblist,1)
  141. table.remove(sweblist,#sweblist-1)
  142. table.remove(sweblist,#sweblist)
  143.  
  144. while true do
  145.   local skip = false
  146.   draw()
  147.   webcon = {}
  148.   parallel.waitForAny(readcheck,evcheck)
  149.   if webname and safe then
  150.     local check = false
  151.     for i,v in pairs(sweblist) do
  152.       if webname == v then
  153.         check = true
  154.       end
  155.     end
  156.     if not check then
  157.       term.setTextColor(colors.red)
  158.       term.setBackgroundColor(colors.cyan)
  159.       term.setCursorPos(6,9)
  160.       write('This website is not on the pre-approved list.')
  161.       term.setCursorPos(6,10)
  162.       write('Please disable safe mode to visit unlisted')
  163.       term.setCursorPos(6,11)
  164.       write('websites.')
  165.       sleep(6)
  166.       skip = true
  167.       for y = 9,11 do
  168.         term.setCursorPos(1,y)
  169.         term.clearLine()
  170.       end
  171.     end
  172.   end
  173.   if not skip then
  174.   local name = 'temp'..tostring(math.random(1,2^10))
  175.   if fs.exists(name) then
  176.     fs.delete(name)
  177.   end
  178.   local tempfile = fs.open(name,'w')
  179.   for i,v in ipairs(webcon) do
  180.     tempfile.writeLine(v)
  181.   end
  182.   tempfile.close()
  183.   shell.run(name)
  184.   fs.delete(name)
  185.   end
  186. end
Advertisement
Add Comment
Please, Sign In to add comment