Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 70 lines (55 sloc) 2.379 kb
e8bd2c3 @txus first commit
authored
1 #!/usr/bin/env ruby -w
2 # hijacker server
3 $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
5 require 'hijacker'
1f06388 @txus Finished custom Handlers support :)
authored
6 require 'hijacker/version'
e8bd2c3 @txus first commit
authored
7
1f06388 @txus Finished custom Handlers support :)
authored
8 SUB_COMMANDS = Hijacker::Handler.handlers
e8bd2c3 @txus first commit
authored
9 opts = Trollop::options do
1f06388 @txus Finished custom Handlers support :)
authored
10 version "hijacker #{Hijacker::VERSION} (c) 2010 Josep M. Bach"
e8bd2c3 @txus first commit
authored
11 banner <<-EOS
1f06388 @txus Finished custom Handlers support :)
authored
12 Hijacker server listens for reports by hijackers spying on ruby objects,
13 and passes them to a given handler to process those reports.
14
15 Specific handlers may accept specific options. To learn about which options
16 does a particular handler accept, try:
17
18 hijacker <handler> --help
19
20 The available handlers are:
21 #{SUB_COMMANDS.join(', ')}
e8bd2c3 @txus first commit
authored
22
23 Usage:
1f06388 @txus Finished custom Handlers support :)
authored
24 hijacker <handler> [options]
e8bd2c3 @txus first commit
authored
25 where [options] are:
26 EOS
27 opt :port, "DRb port to use (default is 8787)", :default => 8787
1f06388 @txus Finished custom Handlers support :)
authored
28 stop_on SUB_COMMANDS
e8bd2c3 @txus first commit
authored
29 end
30
1f06388 @txus Finished custom Handlers support :)
authored
31 # Port resolution
e8bd2c3 @txus first commit
authored
32 begin
33 raise unless opts[:port].to_i > 0 && opts[:port].to_i < 9999
34 rescue
35 Trollop::die :port, "must be a valid number between 0 and 9999"
36 end
37
38 DRB_URI="druby://localhost:#{opts[:port]}"
39
1f06388 @txus Finished custom Handlers support :)
authored
40 # Handler resolution
41 handler = ARGV.shift # get the handler
42 Trollop::die "You need to specify a handler, which must be one of the following: #{SUB_COMMANDS.join(', ')}\n\nMaybe you just feel a bit lost.." unless SUB_COMMANDS.include?(handler)
43
44 handler_class = eval("Hijacker::#{handler.capitalize}")
45 Trollop::options(&handler_class.cli_options)
46
e8bd2c3 @txus first commit
authored
47 # Start up the DRb service
1f06388 @txus Finished custom Handlers support :)
authored
48 DRb.start_service DRB_URI, handler_class.new(opts)
e8bd2c3 @txus first commit
authored
49
50 ANSI = Hijacker::Logger::ANSI
51 # We need the uri of the service to connect a client
52 welcome = []
53 welcome << ANSI[:BOLD] + "hijacker server"
54 welcome << "listening on"
1f06388 @txus Finished custom Handlers support :)
authored
55 welcome << ANSI[:BOLD] + DRb.uri
56 welcome << "\nUsing " + ANSI[:GREEN] + handler.capitalize + ANSI[:RESET] + " handler" + ANSI[:RESET]
e8bd2c3 @txus first commit
authored
57 puts welcome.join("#{ANSI[:RESET]} ") + "\n"
58
59 # We need the uri of the service to connect a client
60 instructions = "Put this code in the configuration of your ruby program #{ANSI[:BOLD]}before any call to Hijacker#{ANSI[:RESET]}:\n\n"
78335c7 @txus Words
authored
61 instructions += "\t" + "Hijacker.configure do\n"
e8bd2c3 @txus first commit
authored
62 instructions += "\t" + " uri '#{DRb.uri}'\n"
63 instructions += "\t" + "end\n\n"
64 puts instructions
65 instructions = "Or optionally attach a particular hijacked object to this server adding :uri => '#{DRb.uri}' when calling Hijacker's :spy or :spying method.\n\n"
66 puts instructions
67
68 # wait for the DRb service to finish before exiting
69 DRb.thread.join
Something went wrong with that request. Please try again.