Advertisement
ComputerMan123

a

Jun 29th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. protocols.rdnt = {}
  2. protocols.http = {}
  3.  
  4. protocols.rdnt.getSearchResults = function()
  5. dnsDatabase = {[1] = {}, [2] = {}}
  6. local resultIDs = {}
  7. local conflict = {}
  8.  
  9. rednet.broadcast("firewolf.broadcast.dns.list")
  10. local startClock = os.clock()
  11. while os.clock() - startClock < timeout do
  12. local id, i = rednet.receive(timeout)
  13. if id then
  14. if i:sub(1, 14) == "firewolf-site:" then
  15. i = i:sub(15, -1)
  16. local bl, wl = verifyBlacklist(id), verifyWhitelist(id, i)
  17. if not i:find(" ") and i:len() < 40 and (not bl or (bl and wl)) then
  18. if not resultIDs[tostring(id)] then resultIDs[tostring(id)] = 1
  19. else resultIDs[tostring(id)] = resultIDs[tostring(id)] + 1 end
  20.  
  21. if not i:find("rdnt://") then i = ("rdnt://" .. i) end
  22. local x = false
  23. if conflict[i] then
  24. x = true
  25. table.insert(conflict[i], id)
  26. else
  27. for m, n in pairs(dnsDatabase[1]) do
  28. if n:lower() == i:lower() then
  29. x = true
  30. table.remove(dnsDatabase[1], m)
  31. table.remove(dnsDatabase[2], m)
  32. if conflict[i] then table.insert(conflict[i], id)
  33. else conflict[i] = {} table.insert(conflict[i], id) end
  34. break
  35. end
  36. end
  37. end
  38.  
  39. if not x and resultIDs[tostring(id)] <= 3 then
  40. table.insert(dnsDatabase[1], i)
  41. table.insert(dnsDatabase[2], id)
  42. end
  43. end
  44. end
  45. else break end
  46. end
  47.  
  48. for k, v in pairs(conflict) do
  49. table.sort(v)
  50. table.insert(dnsDatabase[1], k)
  51. table.insert(dnsDatabase[2], v[1])
  52. end
  53. end
  54.  
  55. protocols.rdnt.getWebsite = function(site)
  56. local id, content, status = nil, nil, nil
  57. local clock = os.clock()
  58. local websiteID = nil
  59. for k, v in pairs(dnsDatabase[1]) do
  60. local web = site:gsub("rdnt://", "")
  61. if web:find("/") then web = web:sub(1, web:find("/") - 1) end
  62. if web == v:gsub("rdnt://", "") then websiteID = dnsDatabase[2][k] break end
  63. end
  64. if not websiteID then return nil, nil, nil end
  65.  
  66. sleep(timeout)
  67. rednet.send(websiteID, site)
  68. clock = os.clock()
  69. while os.clock() - clock < timeout do
  70. id, content = rednet.receive(timeout)
  71. if id and id == websiteID then
  72. local bl, wl = verifyBlacklist(id), verifyWhitelist(id, site)
  73. status = nil
  74. if (bl and not wl) or site == "" or site == "." or site == ".." then
  75. -- Ignore
  76. elseif wl then status = "whitelist" break
  77. else status = "safe" break end
  78. end
  79. end
  80.  
  81. return id, content, status
  82. end
  83.  
  84. protocols.http.getSearchResults = function()
  85. dnsDatabase = {[1] = {}, [2] = {}}
  86. end
  87.  
  88. protocols.http.getWebsite = function(site)
  89. return nil, nil, nil
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement