Class: Snackhack2::Robots
- Inherits:
-
Object
- Object
- Snackhack2::Robots
- Defined in:
- lib/snackhack2/robots.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
-
#port ⇒ Object
Returns the value of attribute port.
-
#save_file ⇒ Object
Returns the value of attribute save_file.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #allow_robots ⇒ Object
- #disallow_robots ⇒ Object
-
#initialize(site: "", save_file: true) ⇒ Robots
constructor
A new instance of Robots.
-
#run ⇒ Object
attr_reader :save_file.
Constructor Details
#initialize(site: "", save_file: true) ⇒ Robots
Returns a new instance of Robots.
6 7 8 9 |
# File 'lib/snackhack2/robots.rb', line 6 def initialize(site: "", save_file: true) @site = site end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
5 6 7 |
# File 'lib/snackhack2/robots.rb', line 5 def http @http end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/snackhack2/robots.rb', line 5 def port @port end |
#save_file ⇒ Object
Returns the value of attribute save_file.
5 6 7 |
# File 'lib/snackhack2/robots.rb', line 5 def save_file @save_file end |
#site ⇒ Object
Returns the value of attribute site.
5 6 7 |
# File 'lib/snackhack2/robots.rb', line 5 def site @site end |
Instance Method Details
#allow_robots ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/snackhack2/robots.rb', line 50 def allow_robots allow_dir = [] http = Snackhack2.get(@http) if http.code == 200 body = http.body.lines body.each do |l| allow_dir << l.split('Allow: ')[1] if l.match(/Allow:/) end else puts "[+] Not giving code 200.\n" end open_links = [] allow_dir.each do |path| link = Snackhack2.get(@http) if link.code == 200 valid_links = "#{@site}#{path}" open_links << valid_links end end [ open_links, allow_dir] end |
#disallow_robots ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/snackhack2/robots.rb', line 72 def disallow_robots http = Snackhack2.get(@http) disallow_dir = [] if http.code == 200 body = http.body.lines body.each do |l| if l.match(/Disallow:/) disallow_dir << l.split('Disallow: ')[1] end end else puts "[+] Not giving code 200.\n" end open_links = [] disallow_dir.each do |path| link = Snackhack2.get(File.join(@site, path.strip)) if link.code == 200 valid_links = "#{@site}#{path}" open_links << valid_links end rescue StandardError end [ open_links, disallow_dir] end |
#run ⇒ Object
attr_reader :save_file
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/snackhack2/robots.rb', line 16 def run save_txt_file = '' allow = allow_robots disallow = disallow_robots if @save_file save_txt_file += "ALLOW:\n\n" unless allow.empty? allow.each do |list| save_txt_file += list end end save_txt_file += "DISALLOW:\n\n" unless disallow.empty? disallow.each do |list| save_txt_file += list end end else unless allow[1].empty? puts "ALLOW: " allow[1].each do |a| puts a end end unless disallow[1].empty? puts "Disallow: " disallow[1].each do |d| puts d end end end Snackhack2.file_save(@site, 'robots', save_txt_file) if @save_file end |