Class: CMSScanner::WebSite

Inherits:
Object
  • Object
show all
Defined in:
lib/cms_scanner/web_site.rb

Overview

WebSite Implementation

Direct Known Subclasses

Target

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_url) ⇒ WebSite

Returns a new instance of WebSite.



6
7
8
# File 'lib/cms_scanner/web_site.rb', line 6

def initialize(site_url)
  self.url = site_url.dup
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



4
5
6
# File 'lib/cms_scanner/web_site.rb', line 4

def uri
  @uri
end

Instance Method Details

#http_auth?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/cms_scanner/web_site.rb', line 37

def http_auth?
  NS::Browser.get(url).code == 401
end

#online?Boolean

Checks if the remote website is up.

Returns:

  • (Boolean)


32
33
34
# File 'lib/cms_scanner/web_site.rb', line 32

def online?
  NS::Browser.get(url).code != 0
end

#proxy_auth?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/cms_scanner/web_site.rb', line 42

def proxy_auth?
  NS::Browser.get(url).code == 407
end

#redirection(url = nil) ⇒ String

See if the remote url returns 30x redirect This method is recursive

Parameters:

  • url (String) (defaults to: nil)

Returns:

  • (String)

    The redirection url or nil



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cms_scanner/web_site.rb', line 52

def redirection(url = nil)
  url    ||= @uri.to_s
  response = NS::Browser.get(url)

  if response.code == 301 || response.code == 302
    redirection = response.headers_hash['location']

    # Let's check if there is a redirection in the redirection
    if (other_redirection = redirection(redirection))
      redirection = other_redirection
    end
  end

  redirection
end

#url(path = nil) ⇒ String

Used for convenience

Parameters:

  • path (String) (defaults to: nil)

    Optional path to merge with the uri

Returns:

  • (String)


25
26
27
# File 'lib/cms_scanner/web_site.rb', line 25

def url(path = nil)
  @uri.join(path || '').to_s
end

#url=(site_url) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/cms_scanner/web_site.rb', line 10

def url=(site_url)
  # Add a trailing slash to the site url
  site_url << '/' if site_url[-1, 1] != '/'

  # Use the validator to ensure the site_url has a correct format
  OptParseValidator::OptURL.new([]).validate(site_url)

  @uri = Addressable::URI.parse(site_url)
end