Saltstack Official UFW Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
907B

  1. """
  2. Execution module for UFW.
  3. """
  4. import re
  5. def is_enabled():
  6. cmd = 'ufw status | grep "Status: active"'
  7. out = __salt__['cmd.run'](cmd, python_shell=True)
  8. return True if out else False
  9. def get_default_incoming():
  10. cmd = 'ufw status verbose | grep "Default:"'
  11. out = __salt__['cmd.run'](cmd, python_shell=True)
  12. policy = re.search('(\w+) \(incoming\)', out).group(1)
  13. return policy
  14. def get_default_outgoing():
  15. cmd = 'ufw status verbose | grep "Default:"'
  16. out = __salt__['cmd.run'](cmd, python_shell=True)
  17. policy = re.search('(\w+) \(outgoing\)', out).group(1)
  18. return policy
  19. def set_enabled(enabled):
  20. cmd = 'ufw --force enable' if enabled else 'ufw disable'
  21. __salt__['cmd.run'](cmd)
  22. def add_rule(rule):
  23. cmd = "ufw " + rule
  24. out = __salt__['cmd.run'](cmd)
  25. # __salt__['cmd.run']("ufw reload") # why reload after adding a rule? :/
  26. return out