Saltstack Official UFW Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

41 行
1008B

  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