Skip to content

Commit

Permalink
Fixed sitemap bug and tap 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Sep 26, 2022
1 parent 16f1a2e commit ec169dc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
66 changes: 36 additions & 30 deletions lib/deadfinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,42 @@

class DeadFinderRunner
def run(target, options)
page = Nokogiri::HTML(URI.open(target))

nodeset_a = page.css('a')
link_a = nodeset_a.map { |element| element['href'] }.compact
nodeset_script = page.css('script')
link_script = nodeset_script.map { |element| element['src'] }.compact
nodeset_link = page.css('link')
link_link = nodeset_link.map { |element| element['href'] }.compact

link_merged = []
link_merged.concat link_a, link_script, link_link

Logger.target target
Logger.sub_info "Found #{link_merged.length} point. [a:#{link_a.length}/s:#{link_script.length}/l:#{link_link.length}]"
Logger.sub_info 'Checking'
jobs = Channel.new(buffer: :buffered, capacity: 1000)
results = Channel.new(buffer: :buffered, capacity: 1000)

(1..options['concurrency']).each do |w|
Channel.go { worker(w, jobs, results, target, options) }
end
begin
page = Nokogiri::HTML(URI.open(target))

nodeset_a = page.css('a')
link_a = nodeset_a.map { |element| element['href'] }.compact
nodeset_script = page.css('script')
link_script = nodeset_script.map { |element| element['src'] }.compact
nodeset_link = page.css('link')
link_link = nodeset_link.map { |element| element['href'] }.compact

link_merged = []
link_merged.concat link_a, link_script, link_link

Logger.target target
Logger.sub_info "Found #{link_merged.length} point. [a:#{link_a.length}/s:#{link_script.length}/l:#{link_link.length}]"
Logger.sub_info 'Checking'
jobs = Channel.new(buffer: :buffered, capacity: 1000)
results = Channel.new(buffer: :buffered, capacity: 1000)

(1..options['concurrency']).each do |w|
Channel.go { worker(w, jobs, results, target, options) }
end

link_a.uniq.each do |node|
result = generate_url node, target
jobs << result
end
jobs.close
link_merged.uniq.each do |node|
result = generate_url node, target
jobs << result
end
jobs.close

(1..link_a.uniq.length).each do
~results
(1..link_merged.uniq.length).each do
~results
end
Logger.sub_done 'Done'
rescue => e
Logger.error "[#{e}] #{target}"
end
Logger.sub_done 'Done'
end

def worker(_id, jobs, results, target, options)
Expand Down Expand Up @@ -102,9 +106,11 @@ def run_url(url, options)

def run_sitemap(sitemap_url, options)
app = DeadFinderRunner.new
base_uri = URI(sitemap_url)
sitemap = SitemapParser.new sitemap_url, { recurse: true }
sitemap.to_a.each do |url|
app.run url, options
turl = generate_url url, base_uri
app.run turl, options
end
gen_output
end
Expand Down
4 changes: 4 additions & 0 deletions lib/deadfinder/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def self.info(text)
puts 'ℹ '.colorize(:blue) + text.to_s.colorize(:light_blue)
end

def self.error(text)
puts '⚠︎ '.colorize(:red) + text.to_s
end

def self.target(text)
puts '► '.colorize(:green) + text.to_s.colorize(:light_green)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/deadfinder/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

VERSION = '1.2.1'
VERSION = '1.2.2'

0 comments on commit ec169dc

Please sign in to comment.