Class: BetterCap::Proxy::HTTP::Module

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

Overview

Base class for transparent proxy modules.

Direct Known Subclasses

InjectCSS, InjectHTML, 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.



27
28
29
30
31
32
33
34
35
# File 'lib/bettercap/proxy/http/module.rb', line 27

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)


38
39
40
# File 'lib/bettercap/proxy/http/module.rb', line 38

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

.load(ctx, opts, name) ⇒ Object

Load the module with name.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bettercap/proxy/http/module.rb', line 43

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

  begin
    require ctx.options.proxies.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.



60
61
62
# File 'lib/bettercap/proxy/http/module.rb', line 60

def self.modules
  @@modules
end

.register_modulesObject

Register available proxy modules into the system.



79
80
81
82
83
84
# File 'lib/bettercap/proxy/http/module.rb', line 79

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.



70
71
72
73
74
75
76
# File 'lib/bettercap/proxy/http/module.rb', line 70

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)


65
66
67
# File 'lib/bettercap/proxy/http/module.rb', line 65

def enabled?
  true
end

#on_pre_request(request) ⇒ Object



23
# File 'lib/bettercap/proxy/http/module.rb', line 23

def on_pre_request( request ); end

#on_request(request, response) ⇒ Object



24
# File 'lib/bettercap/proxy/http/module.rb', line 24

def on_request( request, response ); end