ronin 0.0.9
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/COPYING.txt +339 -0
- data/History.txt +34 -0
- data/Manifest.txt +157 -0
- data/README.txt +131 -0
- data/Rakefile +23 -0
- data/TODO.txt +6 -0
- data/bin/ronin +12 -0
- data/lib/ronin.rb +35 -0
- data/lib/ronin/arch.rb +86 -0
- data/lib/ronin/author.rb +88 -0
- data/lib/ronin/cache.rb +27 -0
- data/lib/ronin/cache/config.rb +34 -0
- data/lib/ronin/cache/exceptions.rb +25 -0
- data/lib/ronin/cache/exceptions/extension_not_found.rb +29 -0
- data/lib/ronin/cache/exceptions/overlay_cached.rb +29 -0
- data/lib/ronin/cache/exceptions/overlay_not_found.rb +29 -0
- data/lib/ronin/cache/extension.rb +706 -0
- data/lib/ronin/cache/extension_cache.rb +108 -0
- data/lib/ronin/cache/overlay.rb +418 -0
- data/lib/ronin/cache/overlay_cache.rb +228 -0
- data/lib/ronin/cache/ronin.rb +50 -0
- data/lib/ronin/chars.rb +25 -0
- data/lib/ronin/chars/char_set.rb +121 -0
- data/lib/ronin/chars/chars.rb +180 -0
- data/lib/ronin/config.rb +31 -0
- data/lib/ronin/console.rb +127 -0
- data/lib/ronin/context.rb +233 -0
- data/lib/ronin/database.rb +122 -0
- data/lib/ronin/environment.rb +39 -0
- data/lib/ronin/exceptions/context_not_found.rb +27 -0
- data/lib/ronin/exceptions/invalid_database_config.rb +27 -0
- data/lib/ronin/exceptions/object_context_not_found.rb +27 -0
- data/lib/ronin/exceptions/unknown_context.rb +27 -0
- data/lib/ronin/exceptions/unknown_object_context.rb +27 -0
- data/lib/ronin/extensions.rb +28 -0
- data/lib/ronin/extensions/hash.rb +62 -0
- data/lib/ronin/extensions/kernel.rb +34 -0
- data/lib/ronin/extensions/meta.rb +24 -0
- data/lib/ronin/extensions/meta/object.rb +24 -0
- data/lib/ronin/extensions/string.rb +37 -0
- data/lib/ronin/extensions/uri.rb +24 -0
- data/lib/ronin/extensions/uri/http.rb +78 -0
- data/lib/ronin/extensions/uri/query_params.rb +97 -0
- data/lib/ronin/formatting.rb +29 -0
- data/lib/ronin/formatting/binary.rb +24 -0
- data/lib/ronin/formatting/digest.rb +24 -0
- data/lib/ronin/formatting/extensions.rb +26 -0
- data/lib/ronin/formatting/extensions/binary.rb +25 -0
- data/lib/ronin/formatting/extensions/binary/integer.rb +59 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +73 -0
- data/lib/ronin/formatting/extensions/digest.rb +24 -0
- data/lib/ronin/formatting/extensions/digest/string.rb +65 -0
- data/lib/ronin/formatting/extensions/html.rb +24 -0
- data/lib/ronin/formatting/extensions/html/string.rb +75 -0
- data/lib/ronin/formatting/extensions/http.rb +24 -0
- data/lib/ronin/formatting/extensions/http/string.rb +69 -0
- data/lib/ronin/formatting/extensions/text.rb +24 -0
- data/lib/ronin/formatting/extensions/text/string.rb +96 -0
- data/lib/ronin/formatting/html.rb +24 -0
- data/lib/ronin/formatting/http.rb +24 -0
- data/lib/ronin/formatting/text.rb +24 -0
- data/lib/ronin/license.rb +87 -0
- data/lib/ronin/model.rb +44 -0
- data/lib/ronin/models.rb +34 -0
- data/lib/ronin/network.rb +31 -0
- data/lib/ronin/network/esmtp.rb +24 -0
- data/lib/ronin/network/extensions.rb +31 -0
- data/lib/ronin/network/extensions/esmtp.rb +24 -0
- data/lib/ronin/network/extensions/esmtp/net.rb +68 -0
- data/lib/ronin/network/extensions/http.rb +24 -0
- data/lib/ronin/network/extensions/http/net.rb +303 -0
- data/lib/ronin/network/extensions/imap.rb +24 -0
- data/lib/ronin/network/extensions/imap/net.rb +92 -0
- data/lib/ronin/network/extensions/pop3.rb +24 -0
- data/lib/ronin/network/extensions/pop3/net.rb +65 -0
- data/lib/ronin/network/extensions/smtp.rb +24 -0
- data/lib/ronin/network/extensions/smtp/net.rb +80 -0
- data/lib/ronin/network/extensions/tcp.rb +24 -0
- data/lib/ronin/network/extensions/tcp/net.rb +94 -0
- data/lib/ronin/network/extensions/telnet.rb +24 -0
- data/lib/ronin/network/extensions/telnet/net.rb +132 -0
- data/lib/ronin/network/extensions/udp.rb +24 -0
- data/lib/ronin/network/extensions/udp/net.rb +99 -0
- data/lib/ronin/network/http.rb +128 -0
- data/lib/ronin/network/http/exceptions.rb +24 -0
- data/lib/ronin/network/http/exceptions/unknown_request.rb +31 -0
- data/lib/ronin/network/imap.rb +47 -0
- data/lib/ronin/network/pop3.rb +47 -0
- data/lib/ronin/network/smtp.rb +26 -0
- data/lib/ronin/network/smtp/email.rb +126 -0
- data/lib/ronin/network/smtp/smtp.rb +55 -0
- data/lib/ronin/network/tcp.rb +24 -0
- data/lib/ronin/network/telnet.rb +95 -0
- data/lib/ronin/network/udp.rb +24 -0
- data/lib/ronin/object_context.rb +257 -0
- data/lib/ronin/objects.rb +29 -0
- data/lib/ronin/parameters.rb +27 -0
- data/lib/ronin/parameters/class_param.rb +45 -0
- data/lib/ronin/parameters/exceptions.rb +25 -0
- data/lib/ronin/parameters/exceptions/missing_param.rb +29 -0
- data/lib/ronin/parameters/exceptions/param_not_found.rb +29 -0
- data/lib/ronin/parameters/instance_param.rb +57 -0
- data/lib/ronin/parameters/param.rb +45 -0
- data/lib/ronin/parameters/parameters.rb +275 -0
- data/lib/ronin/path.rb +70 -0
- data/lib/ronin/pending_context.rb +42 -0
- data/lib/ronin/persistence.rb +32 -0
- data/lib/ronin/platform.rb +95 -0
- data/lib/ronin/product.rb +56 -0
- data/lib/ronin/ronin.rb +49 -0
- data/lib/ronin/rpc.rb +27 -0
- data/lib/ronin/rpc/call.rb +75 -0
- data/lib/ronin/rpc/client.rb +91 -0
- data/lib/ronin/rpc/console.rb +79 -0
- data/lib/ronin/rpc/exceptions.rb +25 -0
- data/lib/ronin/rpc/exceptions/not_implemented.rb +29 -0
- data/lib/ronin/rpc/exceptions/response_missing.rb +29 -0
- data/lib/ronin/rpc/interactive.rb +55 -0
- data/lib/ronin/rpc/interactive_console.rb +58 -0
- data/lib/ronin/rpc/interactive_shell.rb +59 -0
- data/lib/ronin/rpc/response.rb +57 -0
- data/lib/ronin/rpc/service.rb +69 -0
- data/lib/ronin/rpc/shell.rb +66 -0
- data/lib/ronin/runner.rb +24 -0
- data/lib/ronin/runner/program.rb +26 -0
- data/lib/ronin/runner/program/command.rb +204 -0
- data/lib/ronin/runner/program/commands.rb +33 -0
- data/lib/ronin/runner/program/commands/add.rb +73 -0
- data/lib/ronin/runner/program/commands/help.rb +52 -0
- data/lib/ronin/runner/program/commands/install.rb +65 -0
- data/lib/ronin/runner/program/commands/list.rb +81 -0
- data/lib/ronin/runner/program/commands/remove.rb +57 -0
- data/lib/ronin/runner/program/commands/uninstall.rb +57 -0
- data/lib/ronin/runner/program/commands/update.rb +55 -0
- data/lib/ronin/runner/program/exceptions.rb +24 -0
- data/lib/ronin/runner/program/exceptions/unknown_command.rb +31 -0
- data/lib/ronin/runner/program/options.rb +205 -0
- data/lib/ronin/runner/program/program.rb +173 -0
- data/lib/ronin/runner/program/runner.rb +35 -0
- data/lib/ronin/sessions.rb +32 -0
- data/lib/ronin/sessions/esmtp.rb +76 -0
- data/lib/ronin/sessions/imap.rb +73 -0
- data/lib/ronin/sessions/pop3.rb +70 -0
- data/lib/ronin/sessions/session.rb +52 -0
- data/lib/ronin/sessions/smtp.rb +76 -0
- data/lib/ronin/sessions/tcp.rb +111 -0
- data/lib/ronin/sessions/telnet.rb +76 -0
- data/lib/ronin/sessions/udp.rb +99 -0
- data/lib/ronin/sessions/web.rb +83 -0
- data/lib/ronin/shell.rb +81 -0
- data/lib/ronin/target.rb +40 -0
- data/lib/ronin/version.rb +27 -0
- data/lib/ronin/web.rb +24 -0
- data/lib/ronin/web/web.rb +265 -0
- data/spec/spec_helper.rb +9 -0
- data/tasks/spec.rb +7 -0
- metadata +324 -0
data/lib/ronin/shell.rb
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Ronin
|
|
2
|
+
class Shell
|
|
3
|
+
|
|
4
|
+
# Default shell prompt
|
|
5
|
+
DEFAULT_PROMPT = '>'
|
|
6
|
+
|
|
7
|
+
# Shell name to use
|
|
8
|
+
attr_accessor :name
|
|
9
|
+
|
|
10
|
+
# Shell prompt
|
|
11
|
+
attr_accessor :prompt
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# Creates a new Shell object with the given _options_. If a _block_ is
|
|
15
|
+
# given it will be passed the newly created Shell object.
|
|
16
|
+
#
|
|
17
|
+
# _options_ may contain the following keys:
|
|
18
|
+
# <tt>:name</tt>:: The name of the shell.
|
|
19
|
+
# <tt>:prompt</tt>::The prompt to use for the shell.
|
|
20
|
+
#
|
|
21
|
+
def initialize(options={},&block)
|
|
22
|
+
@name = options[:name]
|
|
23
|
+
@prompt = (options[:prompt] || DEFAULT_PROMPT)
|
|
24
|
+
|
|
25
|
+
block.call(self) if block
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Creates and starts a new Shell object with the specified _options_.
|
|
30
|
+
# If a _block_ is given, it will be passed the newly created Shell
|
|
31
|
+
# object before it is started.
|
|
32
|
+
#
|
|
33
|
+
def self.start(options={},&block)
|
|
34
|
+
self.new(options,&block).start
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Starts the shell.
|
|
39
|
+
#
|
|
40
|
+
def start
|
|
41
|
+
history_rollback = 0
|
|
42
|
+
|
|
43
|
+
loop do
|
|
44
|
+
line = Readline.readline("#{@name}#{@prompt} ")
|
|
45
|
+
|
|
46
|
+
if line =~ /^\s*exit\s*$/
|
|
47
|
+
exit_shell
|
|
48
|
+
break
|
|
49
|
+
else
|
|
50
|
+
Readline::HISTORY << line
|
|
51
|
+
history_rollback += 1
|
|
52
|
+
|
|
53
|
+
begin
|
|
54
|
+
process_command(line)
|
|
55
|
+
rescue => e
|
|
56
|
+
puts "#{e.class.name}: #{e.message}"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
history_rollback.times do
|
|
62
|
+
Readline::HISTORY.pop
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
return nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
# Default method that processes commands.
|
|
70
|
+
#
|
|
71
|
+
def process_command(command)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#
|
|
75
|
+
# Default method that will be called when the shell is exited.
|
|
76
|
+
#
|
|
77
|
+
def exit_shell
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
data/lib/ronin/target.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Ronin - A Ruby platform designed for information security and data
|
|
3
|
+
# exploration tasks.
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
|
6
|
+
#
|
|
7
|
+
# This program is free software; you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
#
|
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
# GNU General Public License for more details.
|
|
16
|
+
#
|
|
17
|
+
# You should have received a copy of the GNU General Public License
|
|
18
|
+
# along with this program; if not, write to the Free Software
|
|
19
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
require 'ronin/model'
|
|
23
|
+
require 'ronin/platform'
|
|
24
|
+
require 'ronin/arch'
|
|
25
|
+
|
|
26
|
+
module Ronin
|
|
27
|
+
class Target
|
|
28
|
+
|
|
29
|
+
include Model
|
|
30
|
+
|
|
31
|
+
property :id, Serial
|
|
32
|
+
|
|
33
|
+
# Targeted platform
|
|
34
|
+
belongs_to :platform
|
|
35
|
+
|
|
36
|
+
# Targeted architecture
|
|
37
|
+
belongs_to :arch
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
# Ronin version
|
|
26
|
+
VERSION = '0.0.9'
|
|
27
|
+
end
|
data/lib/ronin/web.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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/web/web'
|
|
@@ -0,0 +1,265 @@
|
|
|
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/network/http'
|
|
25
|
+
|
|
26
|
+
require 'uri/http'
|
|
27
|
+
require 'mechanize'
|
|
28
|
+
require 'open-uri'
|
|
29
|
+
|
|
30
|
+
module Ronin
|
|
31
|
+
module Web
|
|
32
|
+
#
|
|
33
|
+
# Returns the default Ronin Web proxy port.
|
|
34
|
+
#
|
|
35
|
+
def Web.default_proxy_port
|
|
36
|
+
Network::HTTP.default_proxy_port
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# Sets the default Ronin Web proxy port to the specified _port_.
|
|
41
|
+
#
|
|
42
|
+
def Web.default_proxy_port=(port)
|
|
43
|
+
Network::HTTP.default_proxy_port = port
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# Returns the +Hash+ of the Ronin Web proxy information.
|
|
48
|
+
#
|
|
49
|
+
def Web.proxy
|
|
50
|
+
Network::HTTP.proxy
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Resets the Web proxy settings.
|
|
55
|
+
#
|
|
56
|
+
def Web.disable_proxy
|
|
57
|
+
Network::HTTP.disable_proxy
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
# Creates a HTTP URI based from the given _proxy_info_ hash. The
|
|
62
|
+
# _proxy_info_ hash defaults to Web.proxy, if not given.
|
|
63
|
+
#
|
|
64
|
+
def Web.proxy_url(proxy_info=Web.proxy)
|
|
65
|
+
if Web.proxy[:host]
|
|
66
|
+
userinfo = nil
|
|
67
|
+
|
|
68
|
+
if (Web.proxy[:user] || Web.proxy[:password])
|
|
69
|
+
userinfo = "#{Web.proxy[:user]}:#{Web.proxy[:password]}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
return URI::HTTP.build(:host => Web.proxy[:host],
|
|
73
|
+
:port => Web.proxy[:port],
|
|
74
|
+
:userinfo => userinfo,
|
|
75
|
+
:path => '/')
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# Returns the supported Web User-Agent Aliases.
|
|
81
|
+
#
|
|
82
|
+
def Web.user_agent_aliases
|
|
83
|
+
WWW::Mechanize::AGENT_ALIASES
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Returns the Ronin Web User-Agent
|
|
88
|
+
#
|
|
89
|
+
def Web.user_agent
|
|
90
|
+
Network::HTTP.user_agent
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Sets the Ronin Web User-Agent to the specified _new_agent_.
|
|
95
|
+
#
|
|
96
|
+
def Web.user_agent=(new_agent)
|
|
97
|
+
Network::HTTP.user_agent = new_agent
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# Sets the Ronin Web User-Agent to the specified user agent alias
|
|
102
|
+
# _name_.
|
|
103
|
+
#
|
|
104
|
+
def Web.user_agent_alias=(name)
|
|
105
|
+
Network::HTTP.user_agent = Web.user_agent_aliases[name.to_s]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
#
|
|
109
|
+
# Opens the _url_ with the given _options_. The contents of the _url_
|
|
110
|
+
# will be returned.
|
|
111
|
+
#
|
|
112
|
+
# _options_ may contain the following keys:
|
|
113
|
+
# <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
|
|
114
|
+
# <tt>:user_agent</tt>:: The User-Agent string to use.
|
|
115
|
+
# <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
|
|
116
|
+
#
|
|
117
|
+
# Web.open('http://www.hackety.org/')
|
|
118
|
+
#
|
|
119
|
+
# Web.open('http://tenderlovemaking.com/',
|
|
120
|
+
# :user_agent_alias => 'Linux Mozilla')
|
|
121
|
+
#
|
|
122
|
+
# Web.open('http://www.wired.com/', :user_agent => 'the future')
|
|
123
|
+
#
|
|
124
|
+
def Web.open(url,options={})
|
|
125
|
+
headers = {}
|
|
126
|
+
|
|
127
|
+
if options[:user_agent_alias]
|
|
128
|
+
headers['User-Agent'] = Web.user_agent_aliases[options[:user_agent_alias]]
|
|
129
|
+
elsif options[:user_agent]
|
|
130
|
+
headers['User-Agent'] = options[:user_agent]
|
|
131
|
+
elsif Web.user_agent
|
|
132
|
+
headers['User-Agent'] = Web.user_agent
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
proxy = (options[:proxy] || Web.proxy)
|
|
136
|
+
if proxy[:host]
|
|
137
|
+
headers[:proxy] = Web.proxy_url(proxy)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
return Kernel.open(url,headers)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
#
|
|
144
|
+
# Creates a new Mechanize agent with the given _options_.
|
|
145
|
+
#
|
|
146
|
+
# _options_ may contain the following keys:
|
|
147
|
+
# <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
|
|
148
|
+
# <tt>:user_agent</tt>:: The User-Agent string to use.
|
|
149
|
+
# <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
|
|
150
|
+
#
|
|
151
|
+
# Web.agent
|
|
152
|
+
# Web.agent(:user_agent_alias => 'Linux Mozilla')
|
|
153
|
+
# Web.agent(:user_agent => 'wooden pants')
|
|
154
|
+
#
|
|
155
|
+
def Web.agent(options={},&block)
|
|
156
|
+
agent = WWW::Mechanize.new
|
|
157
|
+
|
|
158
|
+
if options[:user_agent_alias]
|
|
159
|
+
agent.user_agent_alias = options[:user_agent_alias]
|
|
160
|
+
elsif options[:user_agent]
|
|
161
|
+
agent.user_agent = options[:user_agent]
|
|
162
|
+
elsif Web.user_agent
|
|
163
|
+
agent.user_agent = Web.user_agent
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
proxy = (options[:proxy] || Web.proxy)
|
|
167
|
+
if proxy[:host]
|
|
168
|
+
agent.set_proxy(proxy[:host],proxy[:port],proxy[:user],proxy[:password])
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
block.call(agent) if block
|
|
172
|
+
return agent
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
#
|
|
176
|
+
# Gets the specified _url_ with the given _options_. If a _block_ is
|
|
177
|
+
# given, it will be passed the retrieved page.
|
|
178
|
+
#
|
|
179
|
+
# _options_ may contain the following keys:
|
|
180
|
+
# <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
|
|
181
|
+
# <tt>:user_agent</tt>:: The User-Agent string to use.
|
|
182
|
+
# <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
|
|
183
|
+
#
|
|
184
|
+
# Web.get('http://www.0x000000.com') # => WWW::Mechanize::Page
|
|
185
|
+
#
|
|
186
|
+
# Web.get('http://www.rubyinside.com') do |page|
|
|
187
|
+
# page.search('div.post/h2/a').each do |title|
|
|
188
|
+
# puts title.inner_text
|
|
189
|
+
# end
|
|
190
|
+
# end
|
|
191
|
+
#
|
|
192
|
+
def Web.get(url,options={},&block)
|
|
193
|
+
page = Web.agent(options).get(url)
|
|
194
|
+
|
|
195
|
+
block.call(page) if block
|
|
196
|
+
return page
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
#
|
|
200
|
+
# Gets the specified _url_ with the given _options_, returning the body
|
|
201
|
+
# of the requested page. If a _block_ is given, it will be passed the
|
|
202
|
+
# body of the retrieved page.
|
|
203
|
+
#
|
|
204
|
+
# _options_ may contain the following keys:
|
|
205
|
+
# <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
|
|
206
|
+
# <tt>:user_agent</tt>:: The User-Agent string to use.
|
|
207
|
+
# <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
|
|
208
|
+
#
|
|
209
|
+
# Web.get_body('http://www.rubyinside.com') # => String
|
|
210
|
+
#
|
|
211
|
+
# Web.get_body('http://www.rubyinside.com') do |body|
|
|
212
|
+
# puts body
|
|
213
|
+
# end
|
|
214
|
+
#
|
|
215
|
+
def Web.get_body(url,options={},&block)
|
|
216
|
+
body = Web.get(url,options).body
|
|
217
|
+
|
|
218
|
+
block.call(body) if block
|
|
219
|
+
return body
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
#
|
|
223
|
+
# Posts the specified _url_ with the given _options_. If a _block_ is
|
|
224
|
+
# given, it will be passed the posted page.
|
|
225
|
+
#
|
|
226
|
+
# _options_ may contain the following keys:
|
|
227
|
+
# <tt>:query</tt>:: The query parameters to post to the specified _url_.
|
|
228
|
+
# <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
|
|
229
|
+
# <tt>:user_agent</tt>:: The User-Agent string to use.
|
|
230
|
+
# <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
|
|
231
|
+
#
|
|
232
|
+
# Web.post('http://www.rubyinside.com') # => WWW::Mechanize::Page
|
|
233
|
+
#
|
|
234
|
+
def Web.post(url,options={},&block)
|
|
235
|
+
query = (options[:query] || {})
|
|
236
|
+
page = Web.agent(options).post(url,query)
|
|
237
|
+
|
|
238
|
+
block.call(page) if block
|
|
239
|
+
return page
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
#
|
|
243
|
+
# Poststhe specified _url_ with the given _options_, returning the body
|
|
244
|
+
# of the posted page. If a _block_ is given, it will be passed the
|
|
245
|
+
# body of the posted page.
|
|
246
|
+
#
|
|
247
|
+
# _options_ may contain the following keys:
|
|
248
|
+
# <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
|
|
249
|
+
# <tt>:user_agent</tt>:: The User-Agent string to use.
|
|
250
|
+
# <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
|
|
251
|
+
#
|
|
252
|
+
# Web.post_body('http://www.rubyinside.com') # => String
|
|
253
|
+
#
|
|
254
|
+
# Web.post_body('http://www.rubyinside.com') do |body|
|
|
255
|
+
# puts body
|
|
256
|
+
# end
|
|
257
|
+
#
|
|
258
|
+
def Web.post_body(url,options={},&block)
|
|
259
|
+
body = Web.post(url,options).body
|
|
260
|
+
|
|
261
|
+
block.call(body) if block
|
|
262
|
+
return body
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|