def __init__(self, dryrun, backend_type="iptables"): if backend_type == "iptables": try: self.backend = UFWBackendIptables(dryrun) except Exception: # pragma: no cover raise else: raise UFWError("Unsupported backend type '%s'" % (backend_type)) # Initialize input strings for translations self.no = _("n") self.yes = _("y") self.yes_full = _("yes")
#!/usr/bin/env python3 import ufw from ufw.backend_iptables import UFWBackendIptables from ufw.frontend import parse_command import gettext import shlex import sys # Install gettext as _() used in objects gettext.install(ufw.common.programName, **{}) # Init backend object with dryrun flag - output will be redirected to stdout backend = UFWBackendIptables(dryrun=True, rootdir=None, datadir=None) # Clear rules read on object init backend.rules = [] backend.rules6 = [] # Remember errors in loop errors = False # Init empty rules lists rules_with_insert = [] rules_other = [] rules = [] # Read rules src file and append rules in backend object with open("/etc/ufw/user.rules.src") as rules_file: for rule in rules_file: if "ufw insert " in rule: rules_with_insert.append(rule)