Class: BetterCap::Proxy::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/proxy/module.rb

Overview

Base class for transparent proxy modules.

Direct Known Subclasses

Injectcss, Injectjs

Constant Summary collapse

@@path =
File.dirname(__FILE__) + '/modules/'
@@modules =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.availableObject

Return a list of available builtin proxy module names.


22
23
24
25
26
27
28
29
30
# File 'lib/bettercap/proxy/module.rb', line 22

def self.available
  avail = []
  Dir.foreach( @@path ) do |file|
    if file =~ /.rb/
      avail << file.gsub('.rb','')
    end
  end
  avail
end

.is_builtin?(name) ⇒ Boolean

Check if the module with name is within the builtin ones.

Returns:

  • (Boolean)

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

def self.is_builtin?(name)
  self.available.include?(name)
end

.load(ctx, opts, name) ⇒ Object

Load the module with name.


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bettercap/proxy/module.rb', line 38

def self.load(ctx, opts, name)
  ctx.options.proxy = true

  if self.is_builtin?(name)
    ctx.options.proxy_module = "#{@@path}/#{name}.rb"
  else
    ctx.options.proxy_module = File.expand_path(name)
  end

  begin
    require ctx.options.proxy_module

    self.register_options(opts)
  rescue LoadError
    raise BetterCap::Error, "Invalid proxy module name '#{name}' ."
  end
end

.modulesObject

Return a list of registered modules.


57
58
59
# File 'lib/bettercap/proxy/module.rb', line 57

def self.modules
  @@modules
end

.register_modulesObject

Register available proxy modules into the system.


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

def self.register_modules
  self.each_module do |const|
    Logger.debug "Registering module #{const}"
    @@modules << const.new
  end
end

.register_options(opts) ⇒ Object

Register custom options for each available module.


67
68
69
70
71
72
73
# File 'lib/bettercap/proxy/module.rb', line 67

def self.register_options(opts)
  self.each_module do |const|
    if const.respond_to?(:on_options)
      const.on_options(opts)
    end
  end
end

Instance Method Details

#enabled?Boolean

Return true if the module is enabled, otherwise false.

Returns:

  • (Boolean)

62
63
64
# File 'lib/bettercap/proxy/module.rb', line 62

def enabled?
  true
end