returning out of process to create only one rule each.

This commit is contained in:
Stefan Midjich 2016-04-17 10:21:34 +02:00
parent 630a1f93c5
commit f5f4106273

View file

@ -23,7 +23,8 @@ def run(arg):
# Setup plugin logging # Setup plugin logging
l = getLogger('plugin_iptables') l = getLogger('plugin_iptables')
l.addHandler(logHandler) l.addHandler(logHandler)
l.setLevel(DEBUG) if config.get('debug', False):
l.setLevel(DEBUG)
client_ip = environ.get( client_ip = environ.get(
'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR',
@ -63,6 +64,13 @@ def run(arg):
error = BytesIO() error = BytesIO()
try: try:
rc = sudo.iptables(iptables_mac, _out=output, _err=error) rc = sudo.iptables(iptables_mac, _out=output, _err=error)
if rc.exit_code == 0:
l.debug('Created iptables MAC rule successfully')
return {
'error': error_msg,
'failed': False
}
except ErrorReturnCode: except ErrorReturnCode:
error.seek(0) error.seek(0)
error_msg = error.read() error_msg = error.read()
@ -96,6 +104,13 @@ def run(arg):
error = BytesIO() error = BytesIO()
try: try:
rc = sudo.iptables(iptables_ip, _out=output, _err=error) rc = sudo.iptables(iptables_ip, _out=output, _err=error)
if rc.exit_code == 0:
l.debug('Created iptables IP rule successfully')
return {
'error': error_msg,
'failed': False
}
except ErrorReturnCode: except ErrorReturnCode:
error.seek(0) error.seek(0)
error_msg = error.read() error_msg = error.read()