Class: BetterCap::Proxy::TCP::Module
- Inherits:
-
BetterCap::Pluggable
- Object
- BetterCap::Pluggable
- BetterCap::Proxy::TCP::Module
- Defined in:
- lib/bettercap/proxy/tcp/module.rb
Overview
Base class for transparent TCP proxy modules, example:
class SampleModule < BetterCap::Proxy::TCP::Module
def on_data( event )
event.data = 'aaa'
end
def on_response( event )
event.data = 'bbb'
end
end
Constant Summary collapse
- @@loaded =
Loaded modules.
{}
Class Method Summary collapse
-
.dispatch(event_name, event) ⇒ Object
Execute method
even_namefor each loaded module instance usingeventas its argument. -
.inherited(subclass) ⇒ Object
Called when a class inherits this base class.
-
.load(file, opts) ⇒ Object
Load
fileas a proxy module. -
.register_options(opts) ⇒ Object
Register custom options for each available module.
Instance Method Summary collapse
- #check_opts ⇒ Object
-
#on_data(event) ⇒ Object
This callback is called when the target is sending data to the upstream server.
-
#on_finish(event) ⇒ Object
This callback is called when the connection is terminated.
- #on_options(opts) ⇒ Object
-
#on_response(event) ⇒ Object
This callback is called when the upstream server is sending data to the target.
Methods inherited from BetterCap::Pluggable
Class Method Details
.dispatch(event_name, event) ⇒ Object
Execute method even_name for each loaded module instance using event as its argument.
78 79 80 81 82 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 78 def dispatch( event_name, event ) @@loaded.each do |name,mod| mod.send( event_name, event ) end end |
.inherited(subclass) ⇒ Object
Called when a class inherits this base class.
56 57 58 59 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 56 def inherited(subclass) name = subclass.name.upcase @@loaded[name] = subclass end |
.load(file, opts) ⇒ Object
Load file as a proxy module.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 62 def load( file, opts ) begin require file rescue LoadError => e raise BetterCap::Error, "Invalid TCP proxy module specified: #{e.message}" end @@loaded.each do |name,mod| @@loaded[name] = mod.new end self.(opts) end |
.register_options(opts) ⇒ Object
Register custom options for each available module.
47 48 49 50 51 52 53 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 47 def (opts) @@loaded.each do |name,mod| if mod.respond_to?(:on_options) mod.(opts) end end end |
Instance Method Details
#check_opts ⇒ Object
31 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 31 def check_opts; end |
#on_data(event) ⇒ Object
This callback is called when the target is sending data to the upstream server. event is an instance of the BetterCap::Proxy::TCP::Event class.
34 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 34 def on_data( event ); end |
#on_finish(event) ⇒ Object
This callback is called when the connection is terminated. event is an instance of the BetterCap::Proxy::TCP::Event class.
40 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 40 def on_finish( event ); end |
#on_options(opts) ⇒ Object
30 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 30 def ( opts ); end |
#on_response(event) ⇒ Object
This callback is called when the upstream server is sending data to the target. event is an instance of the BetterCap::Proxy::TCP::Event class.
37 |
# File 'lib/bettercap/proxy/tcp/module.rb', line 37 def on_response( event ); end |