Module: CMSScanner::Finders::Finder::Enumerator

Defined in:
lib/cms_scanner/finders/finder/enumerator.rb

Overview

Module to provide an easy way to enumerate items such as plugins, themes etc

Instance Method Summary collapse

Instance Method Details

#browserCMSScanner::Browser

Returns:



49
50
51
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 49

def browser
  @browser ||= NS::Browser.instance
end

#enumerate(opts = {}) {|Typhoeus::Response, String| ... } ⇒ Object

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :show_progression (Boolean)

    Wether or not to display the progress bar

  • :exclude_content (Regexp)

Yields:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 11

def enumerate(opts = {})
  targets = target_urls(opts)
  bar     = progress_bar(targets.size, progress_bar_title) if opts[:show_progression]

  targets.each do |url, id|
    request = browser.forge_request(url, request_params)

    request.on_complete do |res|
      bar.progress += 1 if opts[:show_progression]

      next if target.homepage_or_404?(res)
      next if opts[:exclude_content] && res.body.match(opts[:exclude_content])

      yield res, id
    end

    hydra.queue(request)
  end

  hydra.run
end

#hydraTyphoeus::Hydra

Returns:

  • (Typhoeus::Hydra)


61
62
63
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 61

def hydra
  @hydra ||= browser.hydra
end

#progress_bar_titleString

Progress Bar title to use, allow instance using this module to display a custom title if needed

Returns:

  • (String)


44
45
46
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 44

def progress_bar_title
  ' ' # Used to create a left margin
end

#request_paramsObject



53
54
55
56
57
58
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 53

def request_params
  # disabling the cache, as it causes a 'stack level too deep' exception
  # with a large number of requests :/
  # See https://github.com/typhoeus/typhoeus/issues/408
  { cache_ttl: 0 }
end

#target_urls(_opts = {}) ⇒ Hash

Parameters:

  • opts (Hash)

Returns:

  • (Hash)


36
37
38
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 36

def target_urls(_opts = {})
  fail NotImplementedError
end