Class: Arachni::Report::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/report/registry.rb

Overview

Arachni::Report::Registry class

Holds and manages the registry of the reports.

@author: Anastasios “Zapotek” Laskos

                                     <tasos.laskos@gmail.com>
                                     <zapotek@segfault.gr> <br/>

@version: 0.1-pre

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Registry) initialize(lib)

A new instance of Registry



32
33
34
35
36
# File 'lib/report/registry.rb', line 32

def initialize( lib )
    @lib = lib
    @@registry = []
    @available   = Hash.new
end

Class Attribute Details

+ (Object) registry (readonly)

Returns the value of attribute registry



29
30
31
# File 'lib/report/registry.rb', line 29

def registry
  @registry
end

Class Method Details

+ (Array<Arachni::Reports>) clean

Class method

Empties the report registry

Returns:



127
128
129
# File 'lib/report/registry.rb', line 127

def Registry.clean( )
    @@registry = []
end

+ (Array<Arachni::Reports>) clean_up

Class method

Cleans the registry from boolean values passed with the Arachni::Reports objects and updates it

Returns:



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/report/registry.rb', line 167

def Registry.clean_up( )

    clean_reg = []
    @@registry.each {
        |report|

        
        begin
            if report < Arachni::Report::Base
                clean_reg << report
            end
        rescue Exception => e
        end

    }

    @@registry = clean_reg.uniq.flatten
end

+ (Array<Arachni::Reports>) get_registry

Class method

Lists the loaded reports

Returns:



116
117
118
# File 'lib/report/registry.rb', line 116

def Registry.get_registry( )
    @@registry.uniq
end

+ (Object) register(report)

Registers a report with the framework

Used by the Registrar only



153
154
155
156
# File 'lib/report/registry.rb', line 153

def Registry.register( report )
    @@registry << report
    Registry.clean_up(  )
end

Instance Method Details

- (Arachni::Reports) get_by_name(name)

Gets a report by its filename, without the extension

Parameters:

  • (String) name

    the name of the report

Returns:



65
66
67
68
69
70
71
# File 'lib/report/registry.rb', line 65

def get_by_name( name )
    begin
        load( get_path_from_name( name ) )
    rescue Exception => e
        raise e
    end
end

- (String) get_path_from_name(name)

Gets the path of the specified report

Parameters:

  • (String) name

    the name of the report

Returns:

  • (String)

    the path of the report



80
81
82
83
84
85
86
87
# File 'lib/report/registry.rb', line 80

def get_path_from_name( name )
    begin
        return ls_available( )[name]['path'].to_s
    rescue Exception => e
        raise( Arachni::Exceptions::ReportNotFound,
            'Uknown report \'' + name + '\'.' )
    end
end

- (Hash) info(reg_id)

Grabs the information of a report based on its ID in the @@registry

Parameters:

  • (Integer) reg_id

Returns:

  • (Hash)

    the info of the module



139
140
141
142
143
144
145
146
# File 'lib/report/registry.rb', line 139

def info( reg_id )
    @@registry.each_with_index {
        |mod, i|
        if i == reg_id
            return mod.info
        end
    }
end

- (Hash<Hash<String, String>>) ls_available

Lists all available reports and puts them in a Hash

Returns:

  • (Hash<Hash<String, String>>)


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/report/registry.rb', line 95

def ls_available( )

    Dir.glob( @lib + '*.rb' ).each {
        |class_path|

        filename = class_path.gsub( Regexp.escape( @lib ) , '' )
        filename.gsub!( Regexp.new( '.rb' ) , '' )

        @available[filename] = Hash.new
        @available[filename]['path'] = class_path
    }
    @available
end

- (Array<Arachni::Reports>) ls_loaded

Lists the loaded modules

Returns:



54
55
56
# File 'lib/report/registry.rb', line 54

def ls_loaded( )
    Registry.get_registry( )
end

- (Arachni::Reports) rep_load(name)

Loads and registers a report by it’s filename, without the extension

Parameters:

  • (String) name

    the report to load

Returns:



45
46
47
# File 'lib/report/registry.rb', line 45

def rep_load( name )
    Registry.register( get_by_name( name ) )
end