Module: Arachni::UI::Web::Utilities

Included in:
AddonManager, Addons::AutoDeploy::Manager, InstanceManager, Scheduler, Server
Defined in:
lib/arachni/ui/web/utilities.rb

Overview

General utility methods.

@author: Tasos “Zapotek” Laskos

<[email protected]>
<[email protected]>

@version: 0.1

Instance Method Summary collapse

Instance Method Details

#escape(str) ⇒ String

Escapes HTML chars.

Parameters:

Returns:

See Also:

  • CGI.escapeHTML


34
35
36
# File 'lib/arachni/ui/web/utilities.rb', line 34

def escape( str )
    CGI.escapeHTML( str )
end

#escape_hash(hash) ⇒ Hash

Recursively escapes all HTML characters.

Parameters:

  • hash (Hash)

Returns:

  • (Hash)


58
59
60
61
62
63
64
65
66
# File 'lib/arachni/ui/web/utilities.rb', line 58

def escape_hash( hash )
    hash.each_pair {
        |k, v|
        hash[k] = escape( hash[k] ) if hash[k].is_a?( String )
        hash[k] = escape_hash( v ) if v.is_a? Hash
    }

    return hash
end

#parse_datetime(datetime) ⇒ Time

Parses datetime strings such as 07/23/2011 15:34 into Time objects.

Parameters:

Returns:

  • (Time)


92
93
94
95
96
97
98
99
# File 'lib/arachni/ui/web/utilities.rb', line 92

def parse_datetime( datetime )
    date, time = datetime.split( ' ' )

    month, day, year = date.split( '/' )
    hour, minute     = time.split( ':' )

    Time.new( year, month, day, hour, minute )
end

#port_to_url(port, dispatcher_url, no_scheme = nil) ⇒ String

Constructs an instance URL by port using its dispatcher’s url.

Parameters:

  • port (Integer)
  • dispatcher_url (String)

    URL of the dispatcher

  • no_scheme (Bool) (defaults to: nil)

    include scheme in the URL?

Returns:



110
111
112
113
114
115
116
117
# File 'lib/arachni/ui/web/utilities.rb', line 110

def port_to_url( port, dispatcher_url, no_scheme = nil )
    uri = URI( dispatcher_url )
    uri.port = port.to_i
    uri = uri.to_s

    uri = remove_proto( uri ) if no_scheme
    return uri
end

#remove_proto(url) ⇒ String

Removes the protocol from URL string.

Parameters:

Returns:



126
127
128
129
130
131
132
133
134
# File 'lib/arachni/ui/web/utilities.rb', line 126

def remove_proto( url )
    begin
        url = URI.parse( url )
        scheme = url.scheme + '://'
        escape( url.to_s.gsub( scheme, '' ) )
    rescue
        return url
    end
end

#unescape(str) ⇒ String

Unescapes HTML chars.

Parameters:

Returns:

See Also:

  • CGI.unescapeHTML


47
48
49
# File 'lib/arachni/ui/web/utilities.rb', line 47

def unescape( str )
    CGI.unescapeHTML( str )
end

#unescape_hash(hash) ⇒ Hash

Recursively unescapes all HTML characters.

Parameters:

  • hash (Hash)

Returns:

  • (Hash)


75
76
77
78
79
80
81
82
83
# File 'lib/arachni/ui/web/utilities.rb', line 75

def unescape_hash( hash )
    hash.each_pair {
        |k, v|
        hash[k] = unescape( hash[k] ) if hash[k].is_a?( String )
        hash[k] = unescape_hash( v ) if v.is_a? Hash
    }

    return hash
end