From d7a55dd9e6fd2ab728ee0f8b8b71ff1d42726158 Mon Sep 17 00:00:00 2001 From: Stefan Midjich Date: Sat, 16 Apr 2016 18:48:03 +0200 Subject: [PATCH] renamed sample plugin to avoid namespace conflict. --- plugins.cfg | 7 +++++- plugins/__init__.py | 0 plugins/iptables.py | 35 +++++++++++++++++++++++++++ plugins/{logging.py => sample_log.py} | 0 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 plugins/__init__.py create mode 100644 plugins/iptables.py rename plugins/{logging.py => sample_log.py} (100%) diff --git a/plugins.cfg b/plugins.cfg index 96bd426..317c0ca 100644 --- a/plugins.cfg +++ b/plugins.cfg @@ -1,4 +1,9 @@ # Lists all the plugins, or jobs, and whether they are enabled or not. Each # section name must correspond to a plugin name in the plugins dir. -[logging] +[sample_log] enabled = True + +[iptables] +enabled = True +command_mac = iptables -t mangle -D internet -m mac --mac-source "{mac_address}" -j RETURN +command_ip = iptables -t mangle -D internet -m tcp --source "{ip_address}" -j RETURN diff --git a/plugins/__init__.py b/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugins/iptables.py b/plugins/iptables.py new file mode 100644 index 0000000..f37c94f --- /dev/null +++ b/plugins/iptables.py @@ -0,0 +1,35 @@ +# Add an iptables rule + +from logging import getLogger, DEBUG, WARN, INFO +from portal import logHandler, logFormatter + +# Try to import arping for mac_from_ip(), otherwise use just the client IP. +only_ip = False +try: + from sh import arping +except ImportError: + only_ip = True + pass + + +def run(arg): + environ = arg['environ'] + + l = getLogger('plugin_logging') + l.addHandler(logHandler) + l.setLevel(DEBUG) + + client_ip = environ.get('REMOTE_ADDR') + if only_ip: + if not client_ip: + return { + 'error': 'Unknown client IP', + 'status': False + } + else: + client_mac = mac_from_ip(client_ip) + + +# Try to get the mac address from the IP. Requires arping installed. +def mac_from_ip(ip): + return diff --git a/plugins/logging.py b/plugins/sample_log.py similarity index 100% rename from plugins/logging.py rename to plugins/sample_log.py