ronin 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +53 -0
- data/Manifest.txt +26 -18
- data/README.txt +12 -19
- data/Rakefile +9 -9
- data/TODO.txt +5 -5
- data/lib/ronin/cacheable.rb +246 -0
- data/lib/ronin/database/database.rb +21 -3
- data/lib/ronin/database/exceptions/invalid_config.rb +1 -1
- data/lib/ronin/environment.rb +5 -2
- data/lib/ronin/extensions.rb +2 -0
- data/lib/ronin/{models.rb → extensions/array.rb} +19 -6
- data/lib/ronin/extensions/ip_addr.rb +127 -0
- data/lib/ronin/{objectify/exceptions/object_context_not_found.rb → extensions/kernel.rb} +14 -3
- data/lib/ronin/extensions/uri/query_params.rb +4 -2
- data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +14 -12
- data/lib/ronin/formatting/extensions/text/string.rb +37 -19
- data/lib/ronin/has_license.rb +4 -2
- data/lib/ronin/model.rb +0 -1
- data/lib/ronin/network/extensions/http/net.rb +30 -3
- data/lib/ronin/network/extensions/telnet/net.rb +0 -18
- data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -1
- data/lib/ronin/platform/exceptions/extension_not_found.rb +1 -1
- data/lib/ronin/platform/exceptions/overlay_cached.rb +1 -1
- data/lib/ronin/platform/exceptions/overlay_not_found.rb +1 -1
- data/lib/ronin/platform/extension.rb +18 -3
- data/lib/ronin/platform/extension_cache.rb +7 -1
- data/lib/ronin/platform/object_cache.rb +13 -12
- data/lib/ronin/platform/overlay.rb +14 -6
- data/lib/ronin/platform/overlay_cache.rb +11 -5
- data/lib/ronin/product.rb +20 -3
- data/lib/ronin/ronin.rb +0 -15
- data/lib/ronin/rpc/exceptions/response_missing.rb +1 -1
- data/lib/ronin/sessions/esmtp.rb +1 -10
- data/lib/ronin/{objectify.rb → sessions/exceptions.rb} +3 -3
- data/lib/ronin/{objectify/exceptions/unknown_object_context.rb → sessions/exceptions/variable_missing.rb} +4 -4
- data/lib/ronin/sessions/http.rb +3 -10
- data/lib/ronin/sessions/imap.rb +1 -10
- data/lib/ronin/sessions/pop3.rb +1 -9
- data/lib/ronin/sessions/session.rb +11 -21
- data/lib/ronin/sessions/smtp.rb +1 -10
- data/lib/ronin/sessions/tcp.rb +10 -13
- data/lib/ronin/sessions/telnet.rb +2 -17
- data/lib/ronin/sessions/udp.rb +6 -11
- data/lib/ronin/static/finders.rb +24 -0
- data/lib/ronin/ui/command_line/command_line.rb +41 -21
- data/lib/ronin/ui/command_line/commands/help.rb +7 -3
- data/lib/ronin/ui/command_line/commands/ls.rb +1 -1
- data/lib/ronin/ui/command_line/commands/rm.rb +1 -1
- data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -1
- data/lib/ronin/ui/diagnostics.rb +12 -5
- data/lib/ronin/ui/hexdump/extensions/file.rb +3 -1
- data/lib/ronin/ui/hexdump/hexdump.rb +1 -1
- data/lib/ronin/ui/verbose.rb +14 -0
- data/lib/ronin/version.rb +1 -1
- data/spec/cacheable_spec.rb +150 -0
- data/spec/classes/cacheable_model.rb +15 -0
- data/spec/classes/licensed_model.rb +12 -0
- data/spec/code/classes/thing.rb +13 -0
- data/spec/code/reference_spec.rb +1 -14
- data/spec/extensions/array_spec.rb +34 -0
- data/spec/extensions/ip_addr_spec.rb +44 -0
- data/spec/extensions/kernel_spec.rb +19 -0
- data/spec/extensions/uri/query_params_spec.rb +8 -0
- data/spec/formatting/binary/string_spec.rb +1 -1
- data/spec/formatting/digest/string_spec.rb +84 -0
- data/spec/formatting/http/string_spec.rb +84 -0
- data/spec/formatting/text/string_spec.rb +51 -0
- data/spec/has_license_spec.rb +29 -0
- data/spec/helpers/cacheable.rb +7 -0
- data/spec/helpers/contexts/ronin_cacheable_model.rb +13 -0
- data/spec/helpers/database.rb +5 -0
- data/spec/platform/helpers/overlays/hello/lib/init.rb +1 -0
- data/spec/platform/helpers/overlays/hello/lib/stuff/another_test.rb +6 -0
- data/spec/platform/helpers/overlays/hello/lib/stuff/test.rb +4 -0
- data/spec/platform/overlay_cache_spec.rb +1 -1
- data/spec/platform/overlay_spec.rb +28 -0
- data/spec/product_spec.rb +7 -0
- data/spec/sessions/classes/test_session.rb +11 -0
- data/spec/sessions/classes/uses_test_session.rb +10 -0
- data/spec/sessions/session_spec.rb +13 -44
- data/spec/spec_helper.rb +0 -5
- data/spec/static/{helpers → classes}/static_class.rb +0 -0
- data/spec/static/helpers/static.rb +0 -1
- data/spec/static/static_spec.rb +1 -0
- metadata +44 -35
- data/lib/ronin/objectify/exceptions.rb +0 -25
- data/lib/ronin/objectify/objectify.rb +0 -240
- data/lib/ronin/target.rb +0 -44
- data/lib/ronin/ui/command_line/param_parser.rb +0 -93
- data/spec/formatting/digest_spec.rb +0 -54
- data/spec/formatting/http_spec.rb +0 -53
- data/spec/formatting/text_spec.rb +0 -40
- data/spec/helpers.rb +0 -0
- data/spec/objectify/objectify_spec.rb +0 -31
- data/spec/target_spec.rb +0 -16
- data/spec/ui/command_line/helpers/example_command.rb +0 -21
- data/spec/ui/command_line/param_parser_spec.rb +0 -49
data/History.txt
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
+
=== 0.2.3 / 2009-05-06
|
|
2
|
+
|
|
3
|
+
* Require extlib >= 0.9.12.
|
|
4
|
+
* Require dm-core >= 0.9.11.
|
|
5
|
+
* Require data_objects >= 0.9.11.
|
|
6
|
+
* Require do_sqlite3 >= 0.9.11.
|
|
7
|
+
* Require dm-types >= 0.9.11.
|
|
8
|
+
* Require dm-serializer >= 0.9.11.
|
|
9
|
+
* Require dm-validations >= 0.9.11.
|
|
10
|
+
* Require chars >= 0.1.1.
|
|
11
|
+
* Require parameters >= 0.1.5.
|
|
12
|
+
* No longer require dm-aggregates.
|
|
13
|
+
* Added Kernel#try.
|
|
14
|
+
* Added String#pad.
|
|
15
|
+
* Added Array#power_set.
|
|
16
|
+
* Added IPAddr#each for iterating over CIDR address ranges.
|
|
17
|
+
* Added IPAddr.each for iterating over CIDR and globbed address ranges.
|
|
18
|
+
* Added Net.http_powered_by that returns the HTTP X-Powered-By header.
|
|
19
|
+
* Added Net.http_server that returns the HTTP Server header.
|
|
20
|
+
* Added Database.setup?.
|
|
21
|
+
* Added Database.update!.
|
|
22
|
+
* Added Extension#exposed_methods.
|
|
23
|
+
* Added ExtensionCache#names.
|
|
24
|
+
* Added OverlayCache#names.
|
|
25
|
+
* Added Diagnostics#print_debug.
|
|
26
|
+
* Added more specs.
|
|
27
|
+
* Properly escape URI::HTTP#query_params.
|
|
28
|
+
* Fixed a bug in File.hexdump where the file was not being closed.
|
|
29
|
+
* Fixed a bug in HasLicense#licensed_under.
|
|
30
|
+
* Fixed a bug in Product#to_s.
|
|
31
|
+
* Moved Ronin::Target to the ronin-exploits library.
|
|
32
|
+
* Renamed Net.http_prop_path to Net.http_prop_patch.
|
|
33
|
+
* Removed the Parameters code from Ronin::Sessions.
|
|
34
|
+
* Replaced Ronin::Objectify with Ronin::Cacheable.
|
|
35
|
+
* Removed 'ronin/models'.
|
|
36
|
+
* Catch exceptions when loading Extensions and carry on.
|
|
37
|
+
* Renamed Overlay#deactive! to Overlay#deactivate!.
|
|
38
|
+
* Allow Overlays to automatically load the 'lib/init.rb' file when
|
|
39
|
+
activated.
|
|
40
|
+
* Rewrote Ronin::Platform::ObjectCache to use the new Ronin::Cacheable
|
|
41
|
+
module.
|
|
42
|
+
* Enable Diagnostic#print_info and Diagnostic#print_error by default.
|
|
43
|
+
* Refactored Ronin::UI::CommandLine:
|
|
44
|
+
* Added CommandLine.get_command which loads command classes on-demand.
|
|
45
|
+
* CommandLine.commands now stores all the available command names.
|
|
46
|
+
* Renamed Ronin::UI::CommandLine::Commands::LS to
|
|
47
|
+
Ronin::UI::CommandLine::Commands::Ls.
|
|
48
|
+
* Renamed Ronin::UI::CommandLine::Commands::RM to
|
|
49
|
+
Ronin::UI::CommandLine::Commands::Rm.
|
|
50
|
+
* Moved Ronin::UI::CommandLine::ParamParser into the Parameters library.
|
|
51
|
+
* Refactored specs to run on Ruby 1.9.1-p0.
|
|
52
|
+
* All specs now pass on Ruby 1.9.1-p0.
|
|
53
|
+
|
|
1
54
|
=== 0.2.2 / 2009-03-26
|
|
2
55
|
|
|
3
56
|
* Split out Ronin::Chars into the Chars library.
|
data/Manifest.txt
CHANGED
|
@@ -21,12 +21,15 @@ lib/ronin/static/finders.rb
|
|
|
21
21
|
lib/ronin/extensions.rb
|
|
22
22
|
lib/ronin/extensions/meta.rb
|
|
23
23
|
lib/ronin/extensions/meta/object.rb
|
|
24
|
+
lib/ronin/extensions/kernel.rb
|
|
25
|
+
lib/ronin/extensions/array.rb
|
|
24
26
|
lib/ronin/extensions/hash.rb
|
|
25
27
|
lib/ronin/extensions/uri.rb
|
|
26
28
|
lib/ronin/extensions/uri/query_params.rb
|
|
27
29
|
lib/ronin/extensions/uri/http.rb
|
|
28
30
|
lib/ronin/extensions/string.rb
|
|
29
31
|
lib/ronin/extensions/file.rb
|
|
32
|
+
lib/ronin/extensions/ip_addr.rb
|
|
30
33
|
lib/ronin/formatting.rb
|
|
31
34
|
lib/ronin/formatting/digest.rb
|
|
32
35
|
lib/ronin/formatting/binary.rb
|
|
@@ -78,7 +81,6 @@ lib/ronin/network/http/exceptions/unknown_request.rb
|
|
|
78
81
|
lib/ronin/code/emittable.rb
|
|
79
82
|
lib/ronin/code/token.rb
|
|
80
83
|
lib/ronin/code/reference.rb
|
|
81
|
-
lib/ronin/code/reference.rb
|
|
82
84
|
lib/ronin/code/symbol_table.rb
|
|
83
85
|
lib/ronin/rpc.rb
|
|
84
86
|
lib/ronin/rpc/exceptions.rb
|
|
@@ -91,6 +93,8 @@ lib/ronin/rpc/service.rb
|
|
|
91
93
|
lib/ronin/rpc/console.rb
|
|
92
94
|
lib/ronin/rpc/shell.rb
|
|
93
95
|
lib/ronin/sessions.rb
|
|
96
|
+
lib/ronin/sessions/exceptions.rb
|
|
97
|
+
lib/ronin/sessions/exceptions/variable_missing.rb
|
|
94
98
|
lib/ronin/sessions/session.rb
|
|
95
99
|
lib/ronin/sessions/tcp.rb
|
|
96
100
|
lib/ronin/sessions/udp.rb
|
|
@@ -110,14 +114,8 @@ lib/ronin/license.rb
|
|
|
110
114
|
lib/ronin/has_license.rb
|
|
111
115
|
lib/ronin/arch.rb
|
|
112
116
|
lib/ronin/os.rb
|
|
113
|
-
lib/ronin/target.rb
|
|
114
117
|
lib/ronin/product.rb
|
|
115
|
-
lib/ronin/
|
|
116
|
-
lib/ronin/objectify/exceptions.rb
|
|
117
|
-
lib/ronin/objectify/exceptions/object_context_not_found.rb
|
|
118
|
-
lib/ronin/objectify/exceptions/unknown_object_context.rb
|
|
119
|
-
lib/ronin/objectify/objectify.rb
|
|
120
|
-
lib/ronin/models.rb
|
|
118
|
+
lib/ronin/cacheable.rb
|
|
121
119
|
lib/ronin/environment.rb
|
|
122
120
|
lib/ronin/platform.rb
|
|
123
121
|
lib/ronin/platform/tasks/spec.rb
|
|
@@ -148,7 +146,6 @@ lib/ronin/ui/command_line/exceptions.rb
|
|
|
148
146
|
lib/ronin/ui/command_line/exceptions/unknown_command.rb
|
|
149
147
|
lib/ronin/ui/command_line/command.rb
|
|
150
148
|
lib/ronin/ui/command_line/options.rb
|
|
151
|
-
lib/ronin/ui/command_line/param_parser.rb
|
|
152
149
|
lib/ronin/ui/command_line/commands/console.rb
|
|
153
150
|
lib/ronin/ui/command_line/commands/add.rb
|
|
154
151
|
lib/ronin/ui/command_line/commands/install.rb
|
|
@@ -161,21 +158,27 @@ lib/ronin/ui/command_line/command_line.rb
|
|
|
161
158
|
lib/ronin/ronin.rb
|
|
162
159
|
lib/ronin/version.rb
|
|
163
160
|
tasks/spec.rb
|
|
164
|
-
spec/helpers.rb
|
|
165
161
|
spec/spec_helper.rb
|
|
162
|
+
spec/classes/licensed_model.rb
|
|
163
|
+
spec/classes/cacheable_model.rb
|
|
164
|
+
spec/helpers/database.rb
|
|
165
|
+
spec/helpers/cacheable.rb
|
|
166
|
+
spec/helpers/contexts/ronin_cacheable_model.rb
|
|
167
|
+
spec/static/classes/static_class.rb
|
|
166
168
|
spec/static/helpers/static1/one.txt
|
|
167
169
|
spec/static/helpers/static1/dir/two.txt
|
|
168
170
|
spec/static/helpers/static2/dir/two.txt
|
|
169
171
|
spec/static/helpers/static.rb
|
|
170
|
-
spec/static/helpers/static_class.rb
|
|
171
172
|
spec/static/finders_spec.rb
|
|
172
173
|
spec/static/static_spec.rb
|
|
173
174
|
spec/arch_spec.rb
|
|
174
175
|
spec/author_spec.rb
|
|
175
176
|
spec/translators/translator_spec.rb
|
|
176
|
-
spec/
|
|
177
|
+
spec/extensions/kernel_spec.rb
|
|
178
|
+
spec/extensions/array_spec.rb
|
|
177
179
|
spec/extensions/hash_spec.rb
|
|
178
180
|
spec/extensions/string_spec.rb
|
|
181
|
+
spec/extensions/ip_addr_spec.rb
|
|
179
182
|
spec/extensions/uri/http_spec.rb
|
|
180
183
|
spec/extensions/uri/query_params_spec.rb
|
|
181
184
|
spec/formatting/binary/helpers/hexdumps.rb
|
|
@@ -201,16 +204,20 @@ spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt
|
|
|
201
204
|
spec/formatting/binary/helpers/hexdumps/od_repeated.txt
|
|
202
205
|
spec/formatting/binary/integer_spec.rb
|
|
203
206
|
spec/formatting/binary/string_spec.rb
|
|
204
|
-
spec/formatting/
|
|
205
|
-
spec/formatting/
|
|
206
|
-
spec/formatting/
|
|
207
|
+
spec/formatting/digest/string_spec.rb
|
|
208
|
+
spec/formatting/http/string_spec.rb
|
|
209
|
+
spec/formatting/text/string_spec.rb
|
|
210
|
+
spec/code/classes/thing.rb
|
|
207
211
|
spec/code/reference_spec.rb
|
|
208
212
|
spec/code/symbol_table_spec.rb
|
|
209
213
|
spec/license_spec.rb
|
|
214
|
+
spec/has_license_spec.rb
|
|
210
215
|
spec/path_spec.rb
|
|
211
216
|
spec/os_spec.rb
|
|
212
217
|
spec/product_spec.rb
|
|
213
|
-
spec/
|
|
218
|
+
spec/cacheable_spec.rb
|
|
219
|
+
spec/sessions/classes/test_session.rb
|
|
220
|
+
spec/sessions/classes/uses_test_session.rb
|
|
214
221
|
spec/sessions/session_spec.rb
|
|
215
222
|
spec/platform/helpers/overlays.rb
|
|
216
223
|
spec/platform/helpers/overlays.yaml.erb
|
|
@@ -219,6 +226,9 @@ spec/platform/helpers/overlays/test1/test/extension.rb
|
|
|
219
226
|
spec/platform/helpers/overlays/test2/ronin.xml
|
|
220
227
|
spec/platform/helpers/overlays/test2/test/extension.rb
|
|
221
228
|
spec/platform/helpers/overlays/hello/ronin.xml
|
|
229
|
+
spec/platform/helpers/overlays/hello/lib/init.rb
|
|
230
|
+
spec/platform/helpers/overlays/hello/lib/stuff/test.rb
|
|
231
|
+
spec/platform/helpers/overlays/hello/lib/stuff/another_test.rb
|
|
222
232
|
spec/platform/helpers/overlays/hello/hello/extension.rb
|
|
223
233
|
spec/platform/helpers/overlays/random/ronin.xml
|
|
224
234
|
spec/platform/helpers/overlays/random/random/extension.rb
|
|
@@ -229,7 +239,5 @@ spec/platform/extension_cache_spec.rb
|
|
|
229
239
|
spec/platform/platform_spec.rb
|
|
230
240
|
spec/platform/ronin_spec.rb
|
|
231
241
|
spec/ui/verbose_spec.rb
|
|
232
|
-
spec/ui/command_line/helpers/example_command.rb
|
|
233
|
-
spec/ui/command_line/param_parser_spec.rb
|
|
234
242
|
spec/ronin_spec.rb
|
|
235
243
|
static/ronin/platform/overlay.xsl
|
data/README.txt
CHANGED
|
@@ -48,6 +48,7 @@ of Ronin.
|
|
|
48
48
|
* Provides convenience methods for:
|
|
49
49
|
* Formatting data:
|
|
50
50
|
* Binary
|
|
51
|
+
* Text
|
|
51
52
|
* HTTP
|
|
52
53
|
* URIs
|
|
53
54
|
* Generating random text.
|
|
@@ -58,7 +59,7 @@ of Ronin.
|
|
|
58
59
|
* POP
|
|
59
60
|
* Imap
|
|
60
61
|
* Telnet
|
|
61
|
-
* HTTP
|
|
62
|
+
* HTTP / HTTPS
|
|
62
63
|
* Provides an IRB styled console with:
|
|
63
64
|
* Tab-completion enabled.
|
|
64
65
|
* Auto-indentation enabled.
|
|
@@ -69,18 +70,18 @@ of Ronin.
|
|
|
69
70
|
* {libsqlite3}[http://sqlite.org/]
|
|
70
71
|
* {nokogiri}[http://nokogiri.rubyforge.org/] >= 1.2.0
|
|
71
72
|
* {DataMapper}[http://datamapper.org/]:
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* dm-
|
|
77
|
-
* dm-
|
|
78
|
-
* dm-
|
|
73
|
+
* extlib >= 0.9.12
|
|
74
|
+
* dm-core >= 0.9.11
|
|
75
|
+
* data_objects >= 0.9.11
|
|
76
|
+
* do_sqlite3 >= 0.9.11
|
|
77
|
+
* dm-types >= 0.9.11
|
|
78
|
+
* dm-serializer >= 0.9.11
|
|
79
|
+
* dm-validations >= 0.9.11
|
|
79
80
|
* {dm-prefined}[http://dm-predefined.rubyforge.org/] >= 0.1.0
|
|
80
|
-
* {parameters}[http://parameters.rubyforge.org/] >= 0.1.
|
|
81
|
-
* {contextify}[http://contextify.rubyforge.org/] >= 0.1.
|
|
81
|
+
* {parameters}[http://parameters.rubyforge.org/] >= 0.1.5
|
|
82
|
+
* {contextify}[http://contextify.rubyforge.org/] >= 0.1.2
|
|
82
83
|
* {reverse-require}[http://reverserequire.rubyforge.org/] >= 0.3.1
|
|
83
|
-
* {repertoire}[http://repertoire.rubyforge.org/] >= 0.1
|
|
84
|
+
* {repertoire}[http://repertoire.rubyforge.org/] >= 0.2.1
|
|
84
85
|
|
|
85
86
|
== INSTALL:
|
|
86
87
|
|
|
@@ -88,14 +89,6 @@ of Ronin.
|
|
|
88
89
|
|
|
89
90
|
== SYNOPSIS:
|
|
90
91
|
|
|
91
|
-
* Generate an Overlay:
|
|
92
|
-
|
|
93
|
-
$ ronin overlay path/to/overlay/name/
|
|
94
|
-
|
|
95
|
-
* Generate an Extension within an Overlay:
|
|
96
|
-
|
|
97
|
-
$ ronin ext path/to/overlay/extension/
|
|
98
|
-
|
|
99
92
|
* Install an Overlay:
|
|
100
93
|
|
|
101
94
|
$ ronin install svn://example.com/var/svn/overlay
|
data/Rakefile
CHANGED
|
@@ -11,16 +11,16 @@ Hoe.new('ronin', Ronin::VERSION) do |p|
|
|
|
11
11
|
p.remote_rdoc_dir = 'docs/ronin'
|
|
12
12
|
p.extra_deps = [
|
|
13
13
|
['nokogiri', '>=1.2.0'],
|
|
14
|
-
['
|
|
15
|
-
['
|
|
16
|
-
['
|
|
17
|
-
['
|
|
18
|
-
['dm-
|
|
19
|
-
['dm-
|
|
20
|
-
['dm-validations', '>=0.9.
|
|
14
|
+
['extlib', '>=0.9.12'],
|
|
15
|
+
['dm-core', '>=0.9.11'],
|
|
16
|
+
['data_objects', '>=0.9.11'],
|
|
17
|
+
['do_sqlite3', '>=0.9.11'],
|
|
18
|
+
['dm-types', '>=0.9.11'],
|
|
19
|
+
['dm-serializer', '>=0.9.11'],
|
|
20
|
+
['dm-validations', '>=0.9.11'],
|
|
21
21
|
['dm-predefined', '>=0.1.0'],
|
|
22
|
-
['chars', '>=0.1.
|
|
23
|
-
['parameters', '>=0.1.
|
|
22
|
+
['chars', '>=0.1.1'],
|
|
23
|
+
['parameters', '>=0.1.5'],
|
|
24
24
|
['contextify', '>=0.1.2'],
|
|
25
25
|
['reverse-require', '>=0.3.1'],
|
|
26
26
|
['repertoire', '>=0.2.1']
|
data/TODO.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
== TODO
|
|
1
|
+
== TODO:
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Look into using Ronin over Tor/i2p.
|
|
4
|
+
* Discuss ideas for a Web UI:
|
|
5
|
+
* Configurable menu-bar / side-bar.
|
|
6
|
+
* Sinatra would be a worthy candidate.
|
|
7
7
|
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
4
|
+
# exploration tasks.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-2009 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/model'
|
|
25
|
+
|
|
26
|
+
require 'contextify'
|
|
27
|
+
|
|
28
|
+
module Ronin
|
|
29
|
+
module Cacheable
|
|
30
|
+
def self.included(base)
|
|
31
|
+
base.module_eval do
|
|
32
|
+
include Contextify
|
|
33
|
+
include Ronin::Model
|
|
34
|
+
|
|
35
|
+
# The path to the file where the object was defined in
|
|
36
|
+
property :cached_path, DataMapper::Types::FilePath
|
|
37
|
+
|
|
38
|
+
# The timestamp of the cached file
|
|
39
|
+
property :cached_timestamp, DataMapper::Types::EpochTime
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Initializes the cacheable object.
|
|
43
|
+
#
|
|
44
|
+
def initialize(*arguments,&block)
|
|
45
|
+
@original_loaded = false
|
|
46
|
+
@cache_prepared = false
|
|
47
|
+
|
|
48
|
+
super(*arguments,&block)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# Returns the first instance of the model that matches the given
|
|
53
|
+
# query _arguments_.
|
|
54
|
+
#
|
|
55
|
+
def self.first(*arguments)
|
|
56
|
+
if (obj = super(*arguments))
|
|
57
|
+
obj.instance_variable_set('@cache_prepared',true)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
return obj
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
# Returns all instances of the model that matches the given query
|
|
65
|
+
# _arguments_.
|
|
66
|
+
#
|
|
67
|
+
def self.all(*arguments)
|
|
68
|
+
super(*arguments).each do |obj|
|
|
69
|
+
obj.instance_variable_set('@cache_prepared',true)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#
|
|
74
|
+
# Loads an object from the file at the specified _path_.
|
|
75
|
+
#
|
|
76
|
+
def self.load_from(path)
|
|
77
|
+
path = File.expand_path(path)
|
|
78
|
+
obj = self.load_context(path)
|
|
79
|
+
|
|
80
|
+
obj.instance_variable_set('@original_loaded',true)
|
|
81
|
+
obj.cached_path = path
|
|
82
|
+
obj.cached_timestamp = File.mtime(path)
|
|
83
|
+
obj.prepare_cache
|
|
84
|
+
return obj
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
#
|
|
88
|
+
# Caches an object from the file at the specified _path_.
|
|
89
|
+
#
|
|
90
|
+
def self.cache(path)
|
|
91
|
+
obj = self.load_from(File.expand_path(path))
|
|
92
|
+
|
|
93
|
+
obj.cache!
|
|
94
|
+
return obj
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#
|
|
98
|
+
# Loads all objects with the matching _attributes_.
|
|
99
|
+
#
|
|
100
|
+
def self.load_all(attributes={})
|
|
101
|
+
self.all(attributes).map { |obj| obj.load_original }
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#
|
|
105
|
+
# Loads the first object with the matching _attributes_.
|
|
106
|
+
#
|
|
107
|
+
def self.load_first(attributes={})
|
|
108
|
+
self.first(attributes).load_original!
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
unless Cacheable.models.include?(base)
|
|
113
|
+
Cacheable.models << base
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# List of cacheable models.
|
|
119
|
+
#
|
|
120
|
+
def Cacheable.models
|
|
121
|
+
@@ronin_cacheable_models ||= []
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
#
|
|
125
|
+
# Loads all cacheable objects from the specified _path_. If a _block_
|
|
126
|
+
# is given, it will be passed each loaded object.
|
|
127
|
+
#
|
|
128
|
+
def Cacheable.load_all_from(path,&block)
|
|
129
|
+
path = File.expand_path(path)
|
|
130
|
+
objs = Contextify.load_contexts(path).select do |obj|
|
|
131
|
+
obj.class.include?(Cacheable)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
objs.each do |obj|
|
|
135
|
+
obj.instance_variable_set('@original_loaded',true)
|
|
136
|
+
obj.cached_path = path
|
|
137
|
+
obj.cached_timestamp = File.mtime(path)
|
|
138
|
+
obj.prepare_cache
|
|
139
|
+
|
|
140
|
+
block.call(obj) if block
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
return objs
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
#
|
|
147
|
+
# Cache all objects defined in the file at the specified _path_.
|
|
148
|
+
#
|
|
149
|
+
def Cacheable.cache_all(path)
|
|
150
|
+
path = File.expand_path(path)
|
|
151
|
+
|
|
152
|
+
Cacheable.load_all_from(path) do |obj|
|
|
153
|
+
obj.cache!
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
#
|
|
158
|
+
# Load the code from the cached file for the object.
|
|
159
|
+
#
|
|
160
|
+
def load_original!
|
|
161
|
+
if (self.cached_path && !(@original_loaded))
|
|
162
|
+
block = self.class.load_context_block(self.cached_path)
|
|
163
|
+
|
|
164
|
+
instance_eval(&block) if block
|
|
165
|
+
@original_loaded = true
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
return self
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#
|
|
172
|
+
# Deletes any previously cached copies of the object and caches it into
|
|
173
|
+
# the database. Returns +true+ if the object was successfully cached,
|
|
174
|
+
# returns +false+ otherwise.
|
|
175
|
+
#
|
|
176
|
+
def cache!
|
|
177
|
+
if self.cached_path
|
|
178
|
+
# delete any existing objects
|
|
179
|
+
self.class.all(:cached_path => self.cached_path).destroy!
|
|
180
|
+
|
|
181
|
+
self.cached_timestamp = File.mtime(self.cached_path)
|
|
182
|
+
return save!
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
return false
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
#
|
|
189
|
+
# Deletes any previous cached copies of the object and caches it into
|
|
190
|
+
# the database, only if the file where the object was originally cached
|
|
191
|
+
# from was modified. The object will also be destroyed if the file
|
|
192
|
+
# where the object was originally cached from is missing. Returns
|
|
193
|
+
# +true+ if the object was successfully synced, returns +false+
|
|
194
|
+
# otherwise.
|
|
195
|
+
#
|
|
196
|
+
def sync!
|
|
197
|
+
if (self.cached_path && self.cached_timestamp)
|
|
198
|
+
if File.file?(self.cached_path)
|
|
199
|
+
if File.mtime(self.cached_path) > self.cached_timestamp
|
|
200
|
+
self.class.cache(self.cached_path)
|
|
201
|
+
else
|
|
202
|
+
return false
|
|
203
|
+
end
|
|
204
|
+
else
|
|
205
|
+
self.destroy
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
return true
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
return false
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
#
|
|
215
|
+
# Prepares the object for caching.
|
|
216
|
+
#
|
|
217
|
+
def prepare_cache
|
|
218
|
+
unless @cache_prepared
|
|
219
|
+
instance_eval(&(@cache_block)) if @cache_block
|
|
220
|
+
@cache_prepared = true
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
protected
|
|
225
|
+
|
|
226
|
+
#
|
|
227
|
+
# Will run the specified _block_ when the object is about to be cached.
|
|
228
|
+
#
|
|
229
|
+
def cache(&block)
|
|
230
|
+
@cache_block = block
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
#
|
|
234
|
+
# Will load the context from the cached file and attempt to call the
|
|
235
|
+
# method again.
|
|
236
|
+
#
|
|
237
|
+
def method_missing(name,*arguments,&block)
|
|
238
|
+
unless @original_loaded
|
|
239
|
+
load_original!
|
|
240
|
+
return self.send(name,*arguments,&block)
|
|
241
|
+
else
|
|
242
|
+
return super(name,*arguments,&block)
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|