From 37d501c42b99ea1e4261bc8b1de8fce839d8ea4c Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Wed, 12 Jul 2017 14:10:43 +0200 Subject: [PATCH] rewrite firewall --- qubesmanager/firewall.py | 157 +++++++++++++++++++++++++++++++++++---- 1 file changed, 141 insertions(+), 16 deletions(-) diff --git a/qubesmanager/firewall.py b/qubesmanager/firewall.py index dff6ff3..35397b1 100644 --- a/qubesmanager/firewall.py +++ b/qubesmanager/firewall.py @@ -19,18 +19,24 @@ # # -import sys +import datetime +import ipaddress import os import re +import sys import xml.etree.ElementTree from PyQt4.QtCore import * from PyQt4.QtGui import * -import datetime + +import qubesadmin.firewall from . import ui_newfwruledlg +class FirewallModifiedOutsideError(ValueError): + pass + class QIPAddressValidator(QValidator): def __init__(self, parent = None): super (QIPAddressValidator, self).__init__(parent) @@ -39,10 +45,10 @@ class QIPAddressValidator(QValidator): hostname = str(input) if len(hostname) > 255 or len(hostname) == 0: - return (QValidator.Intermediate, pos) + return (QValidator.Intermediate, input, pos) if hostname == "*": - return (QValidator.Acceptable, pos) + return (QValidator.Acceptable, input, pos) unmask = hostname.split("/", 1) if len(unmask) == 2: @@ -50,25 +56,25 @@ class QIPAddressValidator(QValidator): mask = unmask[1] if mask.isdigit() or mask == "": if re.match("^([0-9]{1,3}\.){3}[0-9]{1,3}$", hostname) is None: - return (QValidator.Invalid, pos) + return (QValidator.Invalid, input, pos) if mask != "": mask = int(unmask[1]) if mask < 0 or mask > 32: - return (QValidator.Invalid, pos) + return (QValidator.Invalid, input, pos) else: - return (QValidator.Invalid, pos) + return (QValidator.Invalid, input, pos) if hostname[-1:] == ".": hostname = hostname[:-1] if hostname[-1:] == "-": - return (QValidator.Intermediate, pos) + return (QValidator.Intermediate, input, pos) allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?