Class: BetterCap::Proxy::UDP::Module

Inherits:
BetterCap::Pluggable show all
Defined in:
lib/bettercap/proxy/udp/module.rb

Overview

Base class for transparent UDP proxy modules, example:

class SampleModule < BetterCap::Proxy::UDP::Module
  def on_data( event )
    event.data = 'aaa'
  end

  def on_response( event )
    event.data = 'aaa'
  end
end

Constant Summary collapse

@@loaded =

Loaded modules.

{}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BetterCap::Pluggable

meta, metadata

Class Method Details

.dispatch(event_name, event) ⇒ Object

Execute method even_name for each loaded module instance using event as its argument.



75
76
77
78
79
# File 'lib/bettercap/proxy/udp/module.rb', line 75

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.



53
54
55
56
# File 'lib/bettercap/proxy/udp/module.rb', line 53

def inherited(subclass)
  name = subclass.name.upcase
  @@loaded[name] = subclass
end

.load(file, opts) ⇒ Object

Load file as a proxy module.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bettercap/proxy/udp/module.rb', line 59

def load( file, opts )
  begin
    require file
  rescue LoadError => e
    raise BetterCap::Error, "Invalid UDP proxy module specified: #{e.message}"
  end

  @@loaded.each do |name,mod|
    @@loaded[name] = mod.new
  end

  self.register_options(opts)
end

.register_options(opts) ⇒ Object

Register custom options for each available module.



44
45
46
47
48
49
50
# File 'lib/bettercap/proxy/udp/module.rb', line 44

def register_options(opts)
  @@loaded.each do |name,mod|
    if mod.respond_to?(:on_options)
      mod.on_options(opts)
    end
  end
end

Instance Method Details

#check_optsObject



31
# File 'lib/bettercap/proxy/udp/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::UDP::Event class.



34
# File 'lib/bettercap/proxy/udp/module.rb', line 34

def on_data( event ); end

#on_options(opts) ⇒ Object



30
# File 'lib/bettercap/proxy/udp/module.rb', line 30

def on_options( 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::UDP::Event class.



37
# File 'lib/bettercap/proxy/udp/module.rb', line 37

def on_response( event ); end