def save(self, fw=True): policies.set(self.type, self.id, self.policy) policies.save() if config.get("general", "firewall", True) and fw: security.regenerate_firewall(get()) if not storage.policies.get("policies", self.id): storage.policies.add("policies", self)
def save(self, fw=True): """ Save changes to a security policy to disk. :param bool fw: Regenerate the firewall after save? """ if self.type == "custom": for x in policies.get_all("custom"): if self.id == x["id"]: policies.remove_list("custom", x) break policies.append( "custom", { "id": self.id, "name": self.name, "icon": self.icon, "ports": self.ports, "policy": self.policy }) else: policies.set(self.type, self.id, self.policy) policies.save() storage.policies[self.id] = self if config.get("general", "firewall") and fw: security.regenerate_firewall(get())
def refresh_policies(): svcs = get() newpolicies = {} for x in policies.get_all(): if x == "custom": newpolicies["custom"] = policies.get_all("custom") for y in svcs: if x == y.type: if not x in newpolicies: newpolicies[x] = {} for s in policies.get_all(x): if s == y.id: newpolicies[x][s] = policies.get(x, s) policies.config = newpolicies policies.save()
def refresh_policies(): """Recreate security policies based on what is stored in config.""" svcs = get() newpolicies = {} for x in policies.get_all(): if x == "custom": newpolicies["custom"] = policies.get_all("custom") for y in svcs: if x == y.type: if x not in newpolicies: newpolicies[x] = {} for s in policies.get_all(x): if s == y.id: newpolicies[x][s] = policies.get(x, s) policies.config = newpolicies policies.save()
def remove(self, fw=True): """ Remove a security policy from the firewall and config. You should probably use ``tracked_services.deregister()`` for this. :param bool fw: Regenerate the firewall after save? """ if self.type == "custom": for x in policies.get_all("custom"): if self.id == x["id"]: policies.remove_list("custom", x) break else: policies.remove(self.type, self.id) policies.save() if self.id in storage.policies: del storage.policies[self.id] if config.get("general", "firewall") and fw: security.regenerate_firewall(get())
def remove(self, fw=True): policies.remove(self.type, self.id) policies.save() if config.get("general", "firewall", True) and fw: security.regenerate_firewall(get()) storage.policies.remove("policies", self)