Module: Arachni::Module::Utilities
- Extended by:
- Utilities
- Included in:
- Element::Auditable, Framework, HTTP, Arachni::Mixins::Observable, ElementDB, Utilities, Parser, Parser::Element::Form, Plugin::Manager, RPC::XML::Server::Dispatcher, RPC::XML::Server::Instance, Spider, UI::CLI, UI::XMLRPC
- Defined in:
- lib/module/utilities.rb
Overview
Utilities class
Includes some useful methods for the system, the modules etc…
@author: Tasos “Zapotek” Laskos
<[email protected]>
<[email protected]>
@version: 0.1.1
Instance Method Summary collapse
-
#exception_jail(&block) ⇒ Object
Wraps the “block” in exception handling code and runs it.
-
#get_path(url) ⇒ String
Gets path from URL.
- #normalize_url(url) ⇒ Object
- #read_file(filename, &block) ⇒ Object
- #seed ⇒ Object
Instance Method Details
#exception_jail(&block) ⇒ Object
Wraps the “block” in exception handling code and runs it.
95 96 97 98 99 100 101 102 103 |
# File 'lib/module/utilities.rb', line 95 def exception_jail( &block ) begin block.call rescue Exception => e print_error( e.to_s ) print_debug_backtrace( e ) raise e end end |
#get_path(url) ⇒ String
Gets path from URL
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/module/utilities.rb', line 34 def get_path( url ) uri = URI( URI.escape( url ) ) path = uri.path if !File.extname( path ).empty? path = File.dirname( path ) end path << '/' if path[-1] != '/' return uri.scheme + "://" + uri.host + path end |
#normalize_url(url) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/module/utilities.rb', line 51 def normalize_url( url ) begin return URI.encode( URI.decode( url.to_s ) ).to_s.gsub( '[', '%5B' ).gsub( ']', '%5D' ) rescue begin return URI.encode( URI.decode( url.to_s ) ).to_s rescue return url end end end |
#read_file(filename, &block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/module/utilities.rb', line 69 def read_file( filename, &block ) # the path of the module that called us mod_path = block.source_location[0] # the name of the module that called us mod_name = File.basename( mod_path, ".rb") # the path to the module's data file directory path = File.( File.dirname( mod_path ) ) + '/' + mod_name + '/' file = File.open( path + '/' + filename ).each { |line| yield line.strip } file.close end |
#seed ⇒ Object
47 48 49 |
# File 'lib/module/utilities.rb', line 47 def seed @@seed ||= Digest::SHA2.hexdigest( srand( 1000 ).to_s ) end |