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

34 行
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