Skip to content

Commit

Permalink
Implement configurable timeout option to Wayback Machine collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Henriksen committed Sep 30, 2017
1 parent efa7458 commit afa3b04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/aquatone/collectors/wayback_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@ class WaybackMachine < Aquatone::Collector
self.meta = {
:name => "Wayback Machine",
:author => "Joel (@jolle)",
:description => "Uses Wayback Machine by Internet Archive to find unique hostnames"
:description => "Uses Wayback Machine by Internet Archive to find unique hostnames",
:cli_options => {
"wayback-machine-timeout SECONDS" => "Timeout for Wayback Machine collector in seconds (default: 30)"
}
}

def run
response = get_request("http://web.archive.org/cdx/search/cdx?url=*.#{url_escape(domain.name)}&output=json&fl=original&collapse=urlkey")
DEFAULT_TIMEOUT = 30.freeze

def run
response = nil
Timeout::timeout(timeout) do
response = get_request("http://web.archive.org/cdx/search/cdx?url=*.#{url_escape(domain.name)}&output=json&fl=original&collapse=urlkey")
end
response.parsed_response.each do |page|
if page[0] != "original"
add_host(URI.parse(page[0]).host)
end
end
end

private

def timeout
if has_cli_option?("wayback-machine-timeout")
return get_cli_option("wayback-machine-timeout").to_i
end
DEFAULT_TIMEOUT
end
end
end
end
2 changes: 2 additions & 0 deletions lib/aquatone/commands/discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def run_collectors
rescue Aquatone::Collector::MissingKeyRequirement => e
output(yellow("Skipped\n"))
output(yellow(" -> #{e.message}\n"))
rescue Timeout::Error
output(red("Timed out\n"))
rescue => e
output(red("Error\n"))
output(red(" -> #{e.message}\n"))
Expand Down

0 comments on commit afa3b04

Please sign in to comment.