fixing some config issues with plugins.

This commit is contained in:
Stefan Midjich 2016-04-18 18:13:57 +02:00
parent 4271143896
commit 972140afe4
4 changed files with 13 additions and 7 deletions

View file

@ -4,11 +4,13 @@
# This is just a sample plugin, comment out or remove in production. # This is just a sample plugin, comment out or remove in production.
[sample_log] [sample_log]
enabled = True enabled = True
debug = True
# Runs an iptables command to add a rule, commonly used for captive portal # Runs an iptables command to add a rule, commonly used for captive portal
# firewalls. # firewalls.
[iptables] [iptables]
enabled = True enabled = False
debug = True
# If you know you won't be able to get the clients HW address then use this. # If you know you won't be able to get the clients HW address then use this.
only_ip = True only_ip = True
@ -16,7 +18,7 @@ only_ip = True
# Command templates for arping and iptables. # Command templates for arping and iptables.
# Arping might block so make sure you use a timeout and limit the number of # Arping might block so make sure you use a timeout and limit the number of
# packets it sends. # packets it sends.
arping = -f -c 1 -w 30 -I wlp3s0 {ip_address} arping = -f -c 1 -w 30 -I eth0 {ip_address}
iptables_mac = -t mangle -I internet 1 -m mac --mac-source {mac_address} -j RETURN iptables_mac = -t mangle -I internet 1 -m mac --mac-source {mac_address} -j RETURN
iptables_ip = -t mangle -I internet 1 -m tcp -p tcp --source {ip_address} -j RETURN iptables_ip = -t mangle -I internet 1 -m tcp -p tcp --source {ip_address} -j RETURN

View file

@ -28,13 +28,15 @@ def run(arg):
plugin_config = arg['config'] plugin_config = arg['config']
config = RawConfigParser(defaults=plugin_config) config = RawConfigParser(defaults=plugin_config)
config.add_section(plugin_config.get('__name__', 'iptables')) config.add_section('iptables')
config._sections['iptables'] = plugin_config
# Setup plugin logging # Setup plugin logging
l = getLogger('plugin_iptables') l = getLogger('plugin_iptables')
l.addHandler(logHandler) l.addHandler(logHandler)
if config.getboolean('iptables', 'debug', False): if config.getboolean('iptables', 'debug'):
l.setLevel(DEBUG) l.setLevel(DEBUG)
l.debug('debug logging enabled')
client_ip = environ.get( client_ip = environ.get(
'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR',

View file

@ -17,12 +17,14 @@ def run(arg):
plugin_config = arg['config'] plugin_config = arg['config']
config = RawConfigParser(defaults=plugin_config) config = RawConfigParser(defaults=plugin_config)
config.add_section(plugin_config.get('__name__', 'sample_log')) config.add_section('sample_log')
config._sections['sample_log'] = plugin_config
l = getLogger('plugin_log') l = getLogger('plugin_log')
l.addHandler(logHandler) l.addHandler(logHandler)
if config.getboolean('sample_log', 'debug', False): if config.getboolean('sample_log', 'debug', False):
l.setLevel(DEBUG) l.setLevel(DEBUG)
l.debug('debug logging enabled')
log_url = '{proto}://{server}:{port}{request}'.format( log_url = '{proto}://{server}:{port}{request}'.format(
proto=environ.get('wsgi.url_scheme'), proto=environ.get('wsgi.url_scheme'),

View file

@ -27,7 +27,7 @@ config.read(['/etc/captiveportal/portal.cfg', './portal_local.cfg'])
# their section removed/commented from the config file. # their section removed/commented from the config file.
plugin_config = RawConfigParser() plugin_config = RawConfigParser()
plugin_config.readfp(open('./plugins.cfg')) plugin_config.readfp(open('./plugins.cfg'))
plugin_config.read(['/etc/captiveportal/plugins.cfg']) plugin_config.read(['/etc/captiveportal/plugins.cfg', './plugins_local.cfg'])
# Setup logging # Setup logging
logFormatter = Formatter(config.get('logging', 'log_format')) logFormatter = Formatter(config.get('logging', 'log_format'))
@ -104,7 +104,7 @@ def dispatch_plugins():
# Import all the plugin configuration values as OrderedDict # Import all the plugin configuration values as OrderedDict
config_sections = plugin_config._sections config_sections = plugin_config._sections
arg['config'] = dict(config_sections[plugin]) arg['config'] = config_sections[plugin]
# Is plugin enabled? # Is plugin enabled?
if not plugin_config.getboolean(plugin, 'enabled'): if not plugin_config.getboolean(plugin, 'enabled'):