Browse Source

Inserts deny rules first, to ensure they take precedence

tags/v0.2.0
Rob Ruana 6 years ago
parent
commit
62fbb150de
1 changed files with 8 additions and 1 deletions
  1. +8
    -1
      _states/ufw.py

+ 8
- 1
_states/ufw.py View File

try: try:
out = __salt__['ufw.add_rule'](rule) out = __salt__['ufw.add_rule'](rule)
except (CommandExecutionError, CommandNotFoundError) as e: except (CommandExecutionError, CommandNotFoundError) as e:
if method.startswith('insert 1 deny') and "Invalid position '1'" in e.message:
# This is probably the first rule to be added, so try again without "insert 1"
return _add_rule('deny', name, app, interface, protocol, from_addr, from_port, to_addr, to_port, comment)
return _error(name, e.message) return _error(name, e.message)


adds = False adds = False
if __opts__['test']: if __opts__['test']:
return _test(name, "{0} would have been configured".format(name)) return _test(name, "{0} would have been configured".format(name))
break break

if method.startswith('insert 1 deny') and "Invalid position '1'" in line:
# This is probably the first rule to be added, so try again without "insert 1"
return _add_rule('deny', name, app, interface, protocol, from_addr, from_port, to_addr, to_port, comment)
return _error(name, line) return _error(name, line)


if adds: if adds:
def deny(name, app=None, interface=None, protocol=None, def deny(name, app=None, interface=None, protocol=None,
from_addr=None, from_port=None, to_addr=None, to_port=None, comment=None): from_addr=None, from_port=None, to_addr=None, to_port=None, comment=None):


return _add_rule('deny', name, app, interface, protocol, from_addr, from_port, to_addr, to_port, comment)
return _add_rule('insert 1 deny', name, app, interface, protocol, from_addr, from_port, to_addr, to_port, comment)




def limit(name, app=None, interface=None, protocol=None, def limit(name, app=None, interface=None, protocol=None,

Loading…
Cancel
Save