Class: Dradis::Plugins::Mediawiki::Filters::FullTextSearch

Inherits:
Import::Filters::Base
  • Object
show all
Defined in:
lib/dradis/plugins/mediawiki/filters.rb

Instance Method Summary collapse

Instance Method Details

#query(params = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dradis/plugins/mediawiki/filters.rb', line 3

def query(params={})
  results = []

  host   = Dradis::Plugins::Mediawiki::Engine.settings.host
  path   = Dradis::Plugins::Mediawiki::Engine.settings.path
  port   = Dradis::Plugins::Mediawiki::Engine.settings.port
  scheme = Dradis::Plugins::Mediawiki::Engine.settings.scheme

  port   = (scheme == 'https' ? 443 : 80) if port.blank?

  begin
    # Parameters required by MediaWiki API
    # http://localhost/mediawiki-1.21.1/api.php?action=query&prop=revisions&generator=search&gsrwhat=text&gsrsearch=Directory&rvprop=content&format=xml
    filter_params = {
         action: 'query',
           prop: 'revisions',
      generator: 'search',
        gsrwhat: 'text',
      gsrsearch: CGI::escape(params[:query]), # user query
         rvprop: 'content',
         format: 'xml'
    }

    # Get the results over HTTP
    Net::HTTP.start(host, port, use_ssl: scheme == 'https') do |http|
      res = http.get("#{path}?#{filter_params.to_query}")
      xml_doc = Nokogiri::XML( res.body )
      results += xml_doc.xpath('api/query/pages/page').map do |xml_page|
        Dradis::Plugins::Import::Result.new(
                title: xml_page[:title],
          description: fields_from_wikitext(xml_page.at_xpath('revisions/rev').text())
        )
      end
    end

  #rescue Exception => e
  #  records << {
  #              :title => 'Error fetching records',
  #              :description => e.message + "\n\n\n" +
  #                            "This error can be cause by a configuration " +
  #                            "issue (i.e. dradis not finding the MediaWiki instance). " +
  #                            "Please review the configuration settings located at:\n\n" +
  #                            "./server/vendor/plugins/wiki_import/lib/wiki_import/filters.rb"
  #             }
  end

  return results
end