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.

12345678910111213141516171819202122232425262728293031323334353637383940
  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. if __opts__['test']:
  21. cmd = "ufw --dry-run "
  22. else:
  23. cmd = "ufw "
  24. cmd += '--force enable' if enabled else 'disable'
  25. __salt__['cmd.run'](cmd)
  26. def add_rule(rule):
  27. if __opts__['test']:
  28. cmd = "ufw --dry-run "
  29. else:
  30. cmd = "ufw "
  31. cmd += rule
  32. out = __salt__['cmd.run'](cmd, python_shell=True)
  33. return out