Skip to content

Commit

Permalink
Added support for HTTP basic authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanadventurer committed Mar 13, 2011
1 parent d1872f9 commit 9a00207
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Version 0.4.6 Released ? 2010
* Added redirect control. options are 'never',`http-only', `meta-only', `same-site', `same-domain', 'always'
* Added --max-redirects. Control the maximum number of contiguous redirects followed
* Added custom headers. Can be used multiple times. Examples: --header or -H. eg. "foo:bar" or "user-agent: blinky". Specifying a default header will replace it. Specifying an empty value removes hte header, eg. "User-Agent:"
* Added support for HTTP basic authentication. -u and --user

Version 0.4.5 Released August 17th 2010
* Added 5 plugins from Tonmoy Saikia. They are: Commonspot, TextPattern, Mediawiki, DUclassified and Mailman
Expand Down
20 changes: 15 additions & 5 deletions whatweb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ $WAIT=nil
$OUTPUT_ERRORS=nil
$QUIET=false
$CUSTOM_HEADERS={}
$BASIC_AUTH_USER=nil
$BASIC_AUTH_PASS=nil


# precompile regular expressions in plugins for performance
Expand Down Expand Up @@ -596,7 +598,11 @@ def open_target(target)



req=Net::HTTP::Get.new(path + (query.nil? ? "" : "?" + query ) , $CUSTOM_HEADERS)
req=Net::HTTP::Get.new(path + (query.nil? ? "" : "?" + query ) , $CUSTOM_HEADERS)

if $BASIC_AUTH_USER
req.basic_auth $BASIC_AUTH_USER, $BASIC_AUTH_PASS
end
res=http.request(req)

headers={}; res.each_header {|x,y| headers[x]=y }
Expand Down Expand Up @@ -744,6 +750,7 @@ AGGRESSION LEVELS:
HTTP OPTIONS:
--user-agent, -U=AGENT Identify as AGENT instead of WhatWeb/#{$VERSION}.
--user, -u=<user:password> HTTP basic authentication
--header, -H\t\tAdd an HTTP header. eg \"Foo:Bar\". Specifying a default
\t\t\theader will replace it. Specifying an empty value, eg.
\t\t\t\"User-Agent:\" will remove the header.
Expand All @@ -754,10 +761,10 @@ HTTP OPTIONS:
SPIDERING:
--recursion, -r\tFollow links recursively. Only follow links under the
\t\t\tpath (default: off)
\t\t\tpath Default: off
--depth, -d\t\tMaximum recursion depth. Default: #{$RECURSIVE_DEPTH}
--max-links, -m\tMaximum number of links to follow on one page
\t\t\t(default: #{$MAX_LINKS_TO_FOLLOW})
\t\t\tDefault: #{$MAX_LINKS_TO_FOLLOW}
--spider-skip-extensions Redefine extensions to skip.
\t\t\tDefault: #{$ANEMONE_SKIP_EXTENSIONS.join(",")}
Expand Down Expand Up @@ -884,6 +891,7 @@ opts = GetoptLong.new(
[ '--read-timeout', GetoptLong::REQUIRED_ARGUMENT ],
[ '--spider-skip-extensions', GetoptLong::REQUIRED_ARGUMENT ],
[ '--header','-H', GetoptLong::REQUIRED_ARGUMENT ],
[ '--user','-u', GetoptLong::REQUIRED_ARGUMENT ],
[ '--wait', GetoptLong::REQUIRED_ARGUMENT ],
[ '--debug', GetoptLong::NO_ARGUMENT ],
[ '--version', GetoptLong::NO_ARGUMENT ],
Expand Down Expand Up @@ -1024,15 +1032,17 @@ begin
$ANEMONE_SKIP_EXTENSIONS = arg.split(",")
when '--wait'
$WAIT = arg.to_i
when 'H','--header'
when '-H','--header'
begin
x=arg.scan(/([^:]+):(.*)/).flatten
raise if x.empty?
$CUSTOM_HEADERS[x.first]=x.last
rescue
raise("Invalid --header parameter.")
end

when '-u','--user'
$BASIC_AUTH_USER=arg.split(":").first
$BASIC_AUTH_PASS=arg.split(":").last
when '--debug'
$DEBUG = true
when '-h','--help'
Expand Down

0 comments on commit 9a00207

Please sign in to comment.