ronin 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +39 -0
- data/Manifest.txt +46 -34
- data/README.txt +81 -20
- data/Rakefile +6 -4
- data/TODO.txt +1 -5
- data/bin/ronin +2 -2
- data/lib/ronin.rb +3 -3
- data/lib/ronin/arch.rb +5 -3
- data/lib/ronin/author.rb +2 -1
- data/lib/ronin/cache/cache.rb +78 -0
- data/lib/ronin/cache/extension.rb +6 -6
- data/lib/ronin/cache/extension_cache.rb +3 -21
- data/lib/ronin/{parameters/instance_param.rb → cache/maintainer.rb} +22 -17
- data/lib/ronin/cache/overlay.rb +74 -23
- data/lib/ronin/cache/overlay_cache.rb +3 -21
- data/lib/ronin/chars/char_set.rb +114 -31
- data/lib/ronin/chars/chars.rb +20 -10
- data/lib/ronin/{parameters/param.rb → code/emittable.rb} +29 -11
- data/lib/ronin/code/symbol_table.rb +13 -0
- data/lib/ronin/{parameters/class_param.rb → code/token.rb} +37 -10
- data/lib/ronin/config.rb +33 -0
- data/lib/ronin/context.rb +32 -29
- data/lib/ronin/database.rb +1 -2
- data/lib/ronin/extensions.rb +0 -1
- data/lib/ronin/extensions/string.rb +41 -0
- data/lib/ronin/extensions/uri/query_params.rb +8 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +10 -0
- data/lib/ronin/{program.rb → hexdump.rb} +2 -2
- data/lib/ronin/{parameters/exceptions/missing_param.rb → hexdump/extensions.rb} +2 -6
- data/lib/ronin/{extensions/kernel.rb → hexdump/extensions/file.rb} +8 -6
- data/lib/ronin/{persistence.rb → hexdump/extensions/kernel.rb} +7 -6
- data/lib/ronin/hexdump/hexdump.rb +76 -0
- data/lib/ronin/license.rb +5 -3
- data/lib/ronin/model.rb +4 -2
- data/lib/ronin/models.rb +8 -2
- data/lib/ronin/object_context.rb +89 -62
- data/lib/ronin/rpc/console.rb +6 -4
- data/lib/ronin/rpc/shell.rb +4 -4
- data/lib/ronin/sessions/http.rb +144 -0
- data/lib/ronin/sessions/session.rb +2 -1
- data/lib/ronin/sessions/telnet.rb +3 -1
- data/lib/ronin/sessions/udp.rb +1 -1
- data/lib/ronin/sessions/web.rb +7 -2
- data/lib/ronin/translators/translator.rb +75 -0
- data/lib/ronin/ui/command_line.rb +25 -0
- data/lib/ronin/ui/command_line/command.rb +165 -0
- data/lib/ronin/ui/command_line/command_line.rb +117 -0
- data/lib/ronin/{program → ui/command_line}/commands.rb +12 -9
- data/lib/ronin/ui/command_line/commands/add.rb +75 -0
- data/lib/ronin/{program/commands/help.rb → ui/command_line/commands/default.rb} +26 -17
- data/lib/ronin/ui/command_line/commands/extension.rb +85 -0
- data/lib/ronin/ui/command_line/commands/help.rb +70 -0
- data/lib/ronin/{program → ui/command_line}/commands/install.rb +26 -23
- data/lib/ronin/ui/command_line/commands/list.rb +93 -0
- data/lib/ronin/ui/command_line/commands/overlay.rb +187 -0
- data/lib/ronin/{program/commands/uninstall.rb → ui/command_line/commands/remove.rb} +25 -17
- data/lib/ronin/{program/commands/update.rb → ui/command_line/commands/uninstall.rb} +27 -17
- data/lib/ronin/{program/commands/remove.rb → ui/command_line/commands/update.rb} +24 -18
- data/lib/ronin/{program → ui/command_line}/exceptions.rb +1 -1
- data/lib/ronin/{program → ui/command_line}/exceptions/unknown_command.rb +4 -2
- data/lib/ronin/ui/command_line/options.rb +148 -0
- data/lib/ronin/{console.rb → ui/console.rb} +0 -0
- data/lib/ronin/ui/shell.rb +117 -0
- data/lib/ronin/version.rb +1 -1
- data/lib/ronin/web.rb +1 -0
- data/lib/ronin/web/extensions.rb +1 -0
- data/lib/ronin/web/extensions/hpricot.rb +5 -0
- data/lib/ronin/web/extensions/hpricot/comment.rb +19 -0
- data/lib/ronin/web/extensions/hpricot/container.rb +46 -0
- data/lib/ronin/web/extensions/hpricot/doc.rb +21 -0
- data/lib/ronin/web/extensions/hpricot/elem.rb +25 -0
- data/lib/ronin/web/extensions/hpricot/tag.rb +19 -0
- data/lib/ronin/web/extensions/hpricot/text.rb +19 -0
- data/lib/ronin/web/web.rb +70 -4
- data/spec/arch_spec.rb +1 -1
- data/spec/author_spec.rb +1 -1
- data/spec/chars/char_set_spec.rb +177 -0
- data/spec/code/symbol_table_spec.rb +6 -0
- data/spec/extensions/string_spec.rb +12 -0
- data/spec/formatting/binary_spec.rb +9 -0
- data/spec/license_spec.rb +1 -1
- data/spec/object_context/object_context_spec.rb +29 -0
- data/spec/platform_spec.rb +1 -1
- data/spec/product_spec.rb +1 -1
- data/spec/ronin_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/target_spec.rb +1 -1
- data/spec/translators/translator_spec.rb +63 -0
- data/spec/web/extensions/hpricot_spec.rb +62 -0
- data/static/extension.rb.erb +16 -0
- data/static/overlay.xsl +103 -0
- data/tasks/spec.rb +2 -0
- metadata +72 -42
- data/FAQ.txt +0 -103
- data/lib/ronin/environment.rb +0 -39
- data/lib/ronin/objects.rb +0 -27
- data/lib/ronin/parameters.rb +0 -27
- data/lib/ronin/parameters/exceptions.rb +0 -25
- data/lib/ronin/parameters/exceptions/param_not_found.rb +0 -29
- data/lib/ronin/parameters/parameters.rb +0 -286
- data/lib/ronin/program/command.rb +0 -203
- data/lib/ronin/program/commands/add.rb +0 -71
- data/lib/ronin/program/commands/list.rb +0 -79
- data/lib/ronin/program/options.rb +0 -201
- data/lib/ronin/program/program.rb +0 -168
- data/lib/ronin/rpc/interactive.rb +0 -55
- data/lib/ronin/rpc/interactive_console.rb +0 -58
- data/lib/ronin/rpc/interactive_shell.rb +0 -59
- data/lib/ronin/shell.rb +0 -81
- data/spec/parameters/parameters_spec.rb +0 -109
data/FAQ.txt
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
= FAQ
|
2
|
-
|
3
|
-
Q:: Is Ronin a Framework?
|
4
|
-
A:: Ronin is not a framework. Instead, we like to call it a Platform, since
|
5
|
-
Ronin was designed for developing code on top of it. Besides,
|
6
|
-
"framework" is totally the developer buzz-word of the 2000s.
|
7
|
-
|
8
|
-
Q:: How well documented is Ronin?
|
9
|
-
A:: Ronin has extensive RDoc documentation of it's API. Various Tutorials
|
10
|
-
and HOWTOs are always in the works.
|
11
|
-
|
12
|
-
Q:: How readable is Ronin's code-base?
|
13
|
-
A:: Other projects have been criticized for having poor programming
|
14
|
-
conventions or a lack of documentation. To avoid this, Ronin enforces a
|
15
|
-
set of coding style guidelines to ensure that all source-code is clean
|
16
|
-
and readable. The coding style guidelines can be reviewed here:
|
17
|
-
http://ronin.rubyforge.org/style.html
|
18
|
-
|
19
|
-
Q:: Does Ronin have a test-suite so that I can ensure that Ronin is bug
|
20
|
-
free?
|
21
|
-
A:: Yes, Ronin comes with extensive RSpec specification tests.
|
22
|
-
|
23
|
-
Q:: Ronin comes with code which can be used to scan for and exploit
|
24
|
-
security vulnerabilities, aren't you making everyone less secure by
|
25
|
-
doing so?
|
26
|
-
A:: Yeah, so? There are plenty of similar projects which are freely
|
27
|
-
available on-line, that can be used to scan and exploit vulnerabilities.
|
28
|
-
|
29
|
-
Q:: By publishing a hacking tool, aren't you helping to support the
|
30
|
-
TERRORISTS!!!1111oneoneone
|
31
|
-
A:: Technically we're helping everyone, since Ronin is freely available
|
32
|
-
for download. What people choose to do with Ronin is their own ethical
|
33
|
-
responsibility. If you are scared of Hackers or TERRORISTS, we suggest
|
34
|
-
you help raise awareness of bad programming habits which helped to
|
35
|
-
create all those vulnerabilities in the first place. Perhaps you could
|
36
|
-
stand outside Computer Science departments holding up signs such as:
|
37
|
-
|
38
|
-
"Parametrize your SQL data"
|
39
|
-
|
40
|
-
Or the classic:
|
41
|
-
|
42
|
-
"Don't use strcpy!"
|
43
|
-
|
44
|
-
Q:: Does Ronin ship with 0day?
|
45
|
-
A:: Ronin was never intended to ship with any built-in exploits or
|
46
|
-
payloads. Ronin's design allows user to checkout various
|
47
|
-
overlays of exploits, payloads and extensions. This design choice
|
48
|
-
allows for users to selectively choose which overlay they want to
|
49
|
-
use, update them when they like and possibly even create their own
|
50
|
-
overlays.
|
51
|
-
|
52
|
-
Q:: What exactly are overlays?
|
53
|
-
A:: Overlays are directories which can contain objects (such as exploits or
|
54
|
-
payloads) or extensions which can be used by Ronin. An overlay also
|
55
|
-
contains a small XML file called <tt>ronin.xml</tt> which describes
|
56
|
-
the overlay, it's authors and it's licensing.
|
57
|
-
|
58
|
-
Q:: How are overlays hosted?
|
59
|
-
A:: An overlay can be hosed on any Subversion (SVN), CVS, Git or Rsync
|
60
|
-
server.
|
61
|
-
|
62
|
-
Q:: How can I install an Overlay?
|
63
|
-
A:: Simply pass the URL of the overlay to the +ronin+ +install+ sub-command.
|
64
|
-
|
65
|
-
$ ronin install svn://www.example.com/overlay
|
66
|
-
|
67
|
-
If you have previously checked out an overlay, then simply pass the
|
68
|
-
path of the local overlay to the +ronin+ +add+ sub-command.
|
69
|
-
|
70
|
-
$ ronin add path/to/local/overlay
|
71
|
-
|
72
|
-
Q:: Does Ronin have a GUI or Web-interface?
|
73
|
-
A:: Not currently. The developers of Ronin are considering creating a GUI
|
74
|
-
using JRuby + Swing or possibly Shoes. A Web-interface would be possible
|
75
|
-
once Merb becomes stable.
|
76
|
-
|
77
|
-
Q:: I don't know a lot of Ruby, is there a command-line interface to the
|
78
|
-
various libraries of Ronin?
|
79
|
-
A:: Why yes. Ronin's design allows for the libraries of Ronin to add various
|
80
|
-
sub-commands to the main +ronin+ command. To view all available commands
|
81
|
-
simply run the following command:
|
82
|
-
|
83
|
-
$ ronin help
|
84
|
-
|
85
|
-
To view help information on a specific command:
|
86
|
-
|
87
|
-
$ ronin help command_here
|
88
|
-
|
89
|
-
Q:: Does Ronin offer certification or special training courses?
|
90
|
-
A:: No, we're not that kind of project. Besides, you shouldn't need a
|
91
|
-
certificate to feel good about yourself.
|
92
|
-
|
93
|
-
Q:: What is Ronin licensed under?
|
94
|
-
A:: GPL-2.
|
95
|
-
|
96
|
-
Q:: Can I include Ronin in my (companies) commercial product?
|
97
|
-
A:: No, you cannot. Ronin is licensed under the GPL-2 license.
|
98
|
-
|
99
|
-
Q:: But we are a struggling Information Security company, could we purchase
|
100
|
-
the rights to Ronin?
|
101
|
-
A:: Go struggle somewhere else. No one is selling Ronin, we don't want to
|
102
|
-
see it become another Nessus.
|
103
|
-
|
data/lib/ronin/environment.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#--
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
-
#
|
8
|
-
# This program is free software; you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation; either version 2 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'ronin/config'
|
25
|
-
|
26
|
-
module Ronin
|
27
|
-
module Environment
|
28
|
-
# Ronin environment file
|
29
|
-
ENVIRONMENT_FILE = File.join(Config::PATH,'environment.rb')
|
30
|
-
|
31
|
-
#
|
32
|
-
# Requires the environment configuration file at the given _path_.
|
33
|
-
# If _path_ is not given, it will default to <tt>ENVIRONMENT_FILE</tt>.
|
34
|
-
#
|
35
|
-
def Environment.load(path=ENVIRONMENT_FILE)
|
36
|
-
require path if File.file?(path)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/ronin/objects.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#--
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
-
#
|
8
|
-
# This program is free software; you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation; either version 2 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'ronin/extensions/kernel'
|
25
|
-
require 'ronin/object_context'
|
26
|
-
|
27
|
-
ronin_require 'ronin/objects'
|
data/lib/ronin/parameters.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#--
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
-
#
|
8
|
-
# This program is free software; you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation; either version 2 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'ronin/parameters/param'
|
25
|
-
require 'ronin/parameters/class_param'
|
26
|
-
require 'ronin/parameters/instance_param'
|
27
|
-
require 'ronin/parameters/parameters'
|
@@ -1,25 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#--
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
-
#
|
8
|
-
# This program is free software; you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation; either version 2 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'ronin/parameters/exceptions/param_not_found'
|
25
|
-
require 'ronin/parameters/exceptions/missing_param'
|
@@ -1,29 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#--
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
-
#
|
8
|
-
# This program is free software; you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation; either version 2 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
|
-
#
|
23
|
-
|
24
|
-
module Ronin
|
25
|
-
module Parameters
|
26
|
-
class ParamNotFound < RuntimeError
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,286 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#--
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
5
|
-
#
|
6
|
-
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
-
#
|
8
|
-
# This program is free software; you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation; either version 2 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'ronin/parameters/class_param'
|
25
|
-
require 'ronin/parameters/instance_param'
|
26
|
-
require 'ronin/parameters/exceptions'
|
27
|
-
require 'ronin/extensions/meta'
|
28
|
-
|
29
|
-
module Ronin
|
30
|
-
module Parameters
|
31
|
-
def self.included(base) # :nodoc:
|
32
|
-
base.metaclass_eval do
|
33
|
-
#
|
34
|
-
# Returns the +Hash+ of parameters for the class.
|
35
|
-
#
|
36
|
-
def params
|
37
|
-
@params ||= {}
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Adds a new parameters with the specified _name_ and the given
|
42
|
-
# _options_ to the Class.
|
43
|
-
#
|
44
|
-
# parameter 'var'
|
45
|
-
#
|
46
|
-
# parameter 'var', :default => 3, :description => 'my variable'
|
47
|
-
#
|
48
|
-
def parameter(name,options={})
|
49
|
-
name = name.to_sym
|
50
|
-
|
51
|
-
# add the parameter to the class params list
|
52
|
-
params[name] = ClassParam.new(name,options[:description],options[:default])
|
53
|
-
|
54
|
-
# define the reader class method for the parameter
|
55
|
-
meta_def(name) do
|
56
|
-
params[name].value
|
57
|
-
end
|
58
|
-
|
59
|
-
# define the writer class method for the parameter
|
60
|
-
meta_def("#{name}=") do |value|
|
61
|
-
params[name].value = value
|
62
|
-
end
|
63
|
-
|
64
|
-
# define the getter/setter instance methods for the parameter
|
65
|
-
attr_accessor(name)
|
66
|
-
end
|
67
|
-
|
68
|
-
#
|
69
|
-
# Returns the class parameter with the specified _name_. If no
|
70
|
-
# such class parameter exists, a ParamNotFound exception will be
|
71
|
-
# raised.
|
72
|
-
#
|
73
|
-
def get_param(name)
|
74
|
-
name = name.to_sym
|
75
|
-
|
76
|
-
ancestors.each do |ancestor|
|
77
|
-
if ancestor.include?(Parameters)
|
78
|
-
if ancestor.params.has_key?(name)
|
79
|
-
return ancestor.params[name]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
raise(ParamNotFound,"parameter #{name.to_s.dump} was not found in class #{self.name.dump}",caller)
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
# Returns +true+ if a class parameters with the specified _name_
|
89
|
-
# exists, returns +false+ otherwise.
|
90
|
-
#
|
91
|
-
def has_param?(name)
|
92
|
-
name = name.to_sym
|
93
|
-
|
94
|
-
ancestors.each do |ancestor|
|
95
|
-
if ancestor.include?(Parameters)
|
96
|
-
return true if ancestor.params.has_key?(name)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
return false
|
101
|
-
end
|
102
|
-
|
103
|
-
#
|
104
|
-
# Iterates over all class parameters, passing each one to the
|
105
|
-
# specified _block_.
|
106
|
-
#
|
107
|
-
def each_param(&block)
|
108
|
-
ancestors.each do |ancestor|
|
109
|
-
if ancestor.include?(Parameters)
|
110
|
-
ancestor.params.each_value(&block)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
return self
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Returns the description of the class parameters with the
|
119
|
-
# specified _name_. If no such class parameter exists, a
|
120
|
-
# ParamNotFound exception will be raised.
|
121
|
-
#
|
122
|
-
def describe_param(name)
|
123
|
-
get_param(name).description
|
124
|
-
end
|
125
|
-
|
126
|
-
#
|
127
|
-
# Returns the value of the class parameters with the specified
|
128
|
-
# _name_. If no such class parameter exists, a ParamNotFound
|
129
|
-
# exception will be raised.
|
130
|
-
#
|
131
|
-
def param_value(name)
|
132
|
-
get_param(name).value
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
#
|
138
|
-
# Calls initialize_parameters and then proceeds to call the
|
139
|
-
# super-classes initialize.
|
140
|
-
#
|
141
|
-
def initialize(*args,&block)
|
142
|
-
initialize_parameters()
|
143
|
-
|
144
|
-
super(*args,&block)
|
145
|
-
end
|
146
|
-
|
147
|
-
#
|
148
|
-
# Initializes all instance parameters based off the class parameter's
|
149
|
-
# descriptions and default values.
|
150
|
-
#
|
151
|
-
def initialize_parameters
|
152
|
-
# import the class parameters
|
153
|
-
self.class.each_param { |param| initialize_param(param) }
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Adds a new parameters with the specified _name_ and the given
|
158
|
-
# _options_ to the object.
|
159
|
-
#
|
160
|
-
# obj.parameter('var')
|
161
|
-
#
|
162
|
-
# obj.parameter('var',:default => 3, :description => 'my variable')
|
163
|
-
#
|
164
|
-
def parameter(name,options={})
|
165
|
-
name = name.to_sym
|
166
|
-
|
167
|
-
# set the instance variable
|
168
|
-
instance_variable_set("@#{name}",options[:default])
|
169
|
-
|
170
|
-
# add the new parameter
|
171
|
-
params[name] = InstanceParam.new(self,name,options[:description])
|
172
|
-
|
173
|
-
# define the reader method for the parameter
|
174
|
-
instance_eval %{
|
175
|
-
def #{name}
|
176
|
-
instance_variable_get("@#{name}")
|
177
|
-
end
|
178
|
-
}
|
179
|
-
|
180
|
-
# define the writer method for the parameter
|
181
|
-
instance_eval %{
|
182
|
-
def #{name}=(value)
|
183
|
-
instance_variable_set("@#{name}",value)
|
184
|
-
end
|
185
|
-
}
|
186
|
-
|
187
|
-
return params[name]
|
188
|
-
end
|
189
|
-
|
190
|
-
#
|
191
|
-
# Returns a Hash of the classes params.
|
192
|
-
#
|
193
|
-
def class_params
|
194
|
-
self.class.params
|
195
|
-
end
|
196
|
-
|
197
|
-
#
|
198
|
-
# Returns a +Hash+ of the instance parameters.
|
199
|
-
#
|
200
|
-
def params
|
201
|
-
@params ||= {}
|
202
|
-
end
|
203
|
-
|
204
|
-
#
|
205
|
-
# Returns +true+ if the a parameter with the specified _name_ exists,
|
206
|
-
# returns +false+ otherwise.
|
207
|
-
#
|
208
|
-
# obj.has_param?('rhost') # => true
|
209
|
-
#
|
210
|
-
def has_param?(name)
|
211
|
-
params.has_key?(name.to_sym)
|
212
|
-
end
|
213
|
-
|
214
|
-
#
|
215
|
-
# Returns the parameter with the specified _name_. If no such parameter
|
216
|
-
# exists, a ParamNotFound exception will be raised.
|
217
|
-
#
|
218
|
-
# obj.get_param('var') # => InstanceParam
|
219
|
-
#
|
220
|
-
def get_param(name)
|
221
|
-
name = name.to_sym
|
222
|
-
|
223
|
-
unless has_param?(name)
|
224
|
-
raise(ParamNotFound,"parameter #{name.to_s.dump} was not found within #{self.to_s.dump}",caller)
|
225
|
-
end
|
226
|
-
|
227
|
-
return params[name]
|
228
|
-
end
|
229
|
-
|
230
|
-
#
|
231
|
-
# Returns the description of the parameter with the specified _name_.
|
232
|
-
# If no such parameter exists, a ParamNotFound exception will be raised.
|
233
|
-
#
|
234
|
-
# obj.describe_param('rhost') # => "remote host"
|
235
|
-
#
|
236
|
-
def describe_param(name)
|
237
|
-
get_param(name).description
|
238
|
-
end
|
239
|
-
|
240
|
-
#
|
241
|
-
# Returns the value of the parameter with the specified _name_. If no
|
242
|
-
# such parameter exists, a ParamNotFound exception will be raised.
|
243
|
-
#
|
244
|
-
# obj.value_param('rhost') # => 80
|
245
|
-
#
|
246
|
-
def param_value(name)
|
247
|
-
get_param(name).value
|
248
|
-
end
|
249
|
-
|
250
|
-
#
|
251
|
-
# Sets the values of the parameters listed in the specified _values_.
|
252
|
-
#
|
253
|
-
# obj.set_params(:rhost => 'www.example.com', :rport => 80)
|
254
|
-
# # => {:rhost=>"www.example.com", :rport=>80}
|
255
|
-
#
|
256
|
-
def set_params(values={})
|
257
|
-
values.each do |name,value|
|
258
|
-
get_param(name).value = value
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
protected
|
263
|
-
|
264
|
-
#
|
265
|
-
# Initializes the specified class _param_.
|
266
|
-
#
|
267
|
-
def initialize_param(param)
|
268
|
-
# set the instance variable if the param has a value
|
269
|
-
if param.value
|
270
|
-
# do not override existing instance value if present
|
271
|
-
unless instance_variable_get("@#{param.name}")
|
272
|
-
begin
|
273
|
-
value = param.value.clone
|
274
|
-
rescue TypeError
|
275
|
-
value = param.value
|
276
|
-
end
|
277
|
-
|
278
|
-
instance_variable_set("@#{param.name}",value)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
params[param.name] = InstanceParam.new(self,param.name,param.description)
|
283
|
-
return params[param.name]
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|