Class: Arachni::Plugins::Proxy::TemplateScope

Inherits:
Object
  • Object
show all
Includes:
UI::Output, Utilities
Defined in:
components/plugins/proxy/template_scope.rb

Overview

Helper class including method for rendering templates for the proxy.

Author:

Constant Summary collapse

PANEL_BASEDIR =
"#{Arachni::Plugins::Proxy::BASEDIR}panel/"
PANEL_TEMPLATE =
"#{PANEL_BASEDIR}panel.html.erb"
PANEL_URL =
"#{Arachni::Plugins::Proxy::BASE_URL}panel/"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UI::Output

#caller_location, #debug?, #debug_level, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, #disable_only_positives, #error_buffer, #error_log_fd, #error_logfile, #has_error_log?, #included, #log_error, #mute, #muted?, #only_positives, #only_positives?, #print_bad, #print_debug, #print_debug_backtrace, #print_debug_exception, #print_debug_level_1, #print_debug_level_2, #print_debug_level_3, #print_debug_level_4, #print_error, #print_error_backtrace, #print_exception, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?, reset_output_options, #set_error_logfile, #unmute, #verbose?, #verbose_off, #verbose_on

Methods included from Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Constructor Details

#initialize(params = {}) ⇒ TemplateScope

Returns a new instance of TemplateScope.



24
25
26
# File 'components/plugins/proxy/template_scope.rb', line 24

def initialize( params = {} )
    update( params )
end

Class Method Details

.getObject



32
33
34
# File 'components/plugins/proxy/template_scope.rb', line 32

def self.get
    new
end

.new(*args) ⇒ Object



28
29
30
# File 'components/plugins/proxy/template_scope.rb', line 28

def self.new( *args )
    @self ||= super( *args )
end

Instance Method Details

#clearObject



130
131
132
# File 'components/plugins/proxy/template_scope.rb', line 130

def clear
    instance_variables.each { |v| instance_variable_set( v, nil ) }
end

#content_for(name, value = :nil) ⇒ Object



83
84
85
86
87
88
89
90
# File 'components/plugins/proxy/template_scope.rb', line 83

def content_for( name, value = :nil )
    if value == :nil
        instance_variable_get( "@#{name.to_s}" )
    else
        set( name, html_encode( value.to_s ) )
        nil
    end
end

#content_for?(ivar) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'components/plugins/proxy/template_scope.rb', line 79

def content_for?( ivar )
    !!instance_variable_get( "@#{ivar.to_s}" )
end

#css_urlObject



44
45
46
# File 'components/plugins/proxy/template_scope.rb', line 44

def css_url
    "#{root_url}css/"
end

#erb(tpl, params = {}) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'components/plugins/proxy/template_scope.rb', line 92

def erb( tpl, params = {} )
    params = params.dup
    params[:params] ||= {}

    with_layout = true
    with_layout = !!params.delete( :layout ) if params.include?( :layout )
    format       = params.delete( :format ) || 'html'

    update( params )

    tpl = "#{tpl}.#{format}.erb" if tpl.is_a?( Symbol )

    path = File.exist?( tpl ) ? tpl : PANEL_BASEDIR + tpl

    evaled = ERB.new( IO.read( path ) ).result( get_binding )
    with_layout ? layout { evaled } : evaled
end

#get_bindingObject



126
127
128
# File 'components/plugins/proxy/template_scope.rb', line 126

def get_binding
    binding
end

#img_urlObject



48
49
50
# File 'components/plugins/proxy/template_scope.rb', line 48

def img_url
    "#{root_url}img/"
end

#inspect_urlObject



52
53
54
# File 'components/plugins/proxy/template_scope.rb', line 52

def inspect_url
    "#{root_url}inspect"
end

#js_urlObject



40
41
42
# File 'components/plugins/proxy/template_scope.rb', line 40

def js_url
    "#{root_url}js/"
end

#layoutObject



118
119
120
# File 'components/plugins/proxy/template_scope.rb', line 118

def layout
    ERB.new( IO.read( PANEL_BASEDIR + 'layout.html.erb' ) ).result( binding )
end

#panelObject



122
123
124
# File 'components/plugins/proxy/template_scope.rb', line 122

def panel
    erb :panel
end

#render(tpl, opts) ⇒ Object



110
111
112
113
114
115
116
# File 'components/plugins/proxy/template_scope.rb', line 110

def render( tpl, opts )
    erb tpl, opts.merge( layout: false )
rescue => e
    print_error "Error when rendering: #{tpl}"
    print_exception e
    nil
end

#root_urlObject



36
37
38
# File 'components/plugins/proxy/template_scope.rb', line 36

def root_url
    PANEL_URL
end

#set(name, value) ⇒ Object



73
74
75
76
77
# File 'components/plugins/proxy/template_scope.rb', line 73

def set( name, value )
    self.class.send( :attr_accessor, name )
    instance_variable_set( "@#{name.to_s}", value )
    self
end

#shutdown_urlObject



56
57
58
# File 'components/plugins/proxy/template_scope.rb', line 56

def shutdown_url
    url_for :shutdown
end

#update(params) ⇒ Object



68
69
70
71
# File 'components/plugins/proxy/template_scope.rb', line 68

def update( params )
    params.each { |name, value| set( name, value ) }
    self
end

#url_for(*args) ⇒ Object



64
65
66
# File 'components/plugins/proxy/template_scope.rb', line 64

def url_for( *args )
    Arachni::Plugins::Proxy.url_for( *args )
end

#vectors_urlObject



60
61
62
# File 'components/plugins/proxy/template_scope.rb', line 60

def vectors_url
    "#{root_url}vectors.yml"
end