Class: BetterCap::Proxy::HTTP::Module
- Inherits:
-
BetterCap::Pluggable
- Object
- BetterCap::Pluggable
- BetterCap::Proxy::HTTP::Module
- Defined in:
- lib/bettercap/proxy/http/module.rb
Overview
Base class for transparent proxy modules.
Direct Known Subclasses
Constant Summary collapse
- @@path =
File.dirname(__FILE__) + '/modules/'
- @@modules =
[]
Class Method Summary collapse
-
.available ⇒ Object
Return a list of available builtin proxy module names.
-
.is_builtin?(name) ⇒ Boolean
Check if the module with
name
is within the builtin ones. -
.load(ctx, opts, name) ⇒ Object
Load the module with
name
. -
.modules ⇒ Object
Return a list of registered modules.
-
.register_modules ⇒ Object
Register available proxy modules into the system.
-
.register_options(opts) ⇒ Object
Register custom options for each available module.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Return true if the module is enabled, otherwise false.
- #on_pre_request(request) ⇒ Object
- #on_request(request, response) ⇒ Object
Methods inherited from BetterCap::Pluggable
Class Method Details
.available ⇒ Object
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.
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..proxies.proxy_module = "#{@@path}/#{name}.rb" else ctx..proxies.proxy_module = File.(name) end begin require ctx..proxies.proxy_module self.(opts) rescue LoadError => e raise BetterCap::Error, "Invalid proxy module name '#{name}': #{e.}" end end |
.modules ⇒ Object
Return a list of registered modules.
60 61 62 |
# File 'lib/bettercap/proxy/http/module.rb', line 60 def self.modules @@modules end |
.register_modules ⇒ Object
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.(opts) self.each_module do |const| if const.respond_to?(:on_options) const.(opts) end end end |
Instance Method Details
#enabled? ⇒ Boolean
Return true if the module is enabled, otherwise false.
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 |