Exemple #1
0
    def __init__(self, window):
        Ui_Dialog.__init__(self)
        self.window = window
        self.dialog = QDialog(window)
        self.setupUi(self.dialog)
        self.rules = self.window.ruleset("getCustomRules")

        self.ipv_combo.clear()
        for ipv in IPTABLES_TABLES.keys():
            # Fill IPVersion the combo box:
            self.ipv_combo.addItem(ipv)

            # set default string if necessary:
            for table in IPTABLES_TABLES[ipv]:
                if self.rules[ipv][table + "-pre"] == "":
                    self.rules[ipv][table + "-pre"] = DEFAULT_STR % (ipv, table, tr("before"))
                if self.rules[ipv][table + "-post"] == "":
                    self.rules[ipv][table + "-post"] = DEFAULT_STR % (ipv, table, tr("after"))

        self.refreshTableCombo()
        self.refreshFrameText()

        self.previous_ipv, self.previous_table = self.currentIndex()

        self.ipv_combo.connect(self.ipv_combo, SIGNAL("currentIndexChanged (int)"), self.onIPVClick)
        self.table_combo.connect(self.table_combo, SIGNAL("currentIndexChanged (int)"), self.onTableClick)
        self.position_combo.connect(self.position_combo, SIGNAL("currentIndexChanged (int)"), self.onTableClick)

        if self.dialog.exec_():
            self.saveRules()
Exemple #2
0
    def saveRules(self):
        self.saveFrameText()

        # First remove occurence that only contains the default conf
        for ipv in IPTABLES_TABLES.keys():
            for table in IPTABLES_TABLES[ipv]:
                rules = self.rules[ipv][table + "-pre"]
                if rules == tr(DEFAULT_STR) % (ipv, table, tr("before")):
                    self.rules[ipv][table + "-pre"] = u""
                rules = self.rules[ipv][table + "-post"]
                if rules == tr(DEFAULT_STR) % (ipv, table, tr("after")):
                    self.rules[ipv][table + "-post"] = u""

        # Save the rules
        self.window.ruleset("setCustomRules", self.rules)
        self.window.refreshUndo()