Пример #1
0
    def __init__(self, parent):
        QFrame.__init__(self, parent)
        self.parent = parent

        form = QVBoxLayout(self)
        title = QLabel("<H1>%s</H1>" % self.tr('SNMP Server Configuration'))
        form.addWidget(title)

        # Enable:
        self.enable_line = QWidget()
        self.enable_line.setLayout(QFormLayout())
        self.enable_server = QCheckBox()
        self.connect(self.enable_server, SIGNAL('stateChanged(int)'),
                     parent.setEnabled)
        self.enable_line.layout().addRow(self.tr("Enable SNMP server"),
                                         self.enable_server)
        form.addWidget(self.enable_line)
        parent.main_window.writeAccessNeeded(self.enable_server)

        # V2c list (source network, community):
        self.v2c_list_groupbox = QGroupBox()
        self.v2c_list_groupbox.setTitle(self.tr("SNMPv2c access list"))
        self.v2c_list_groupbox.setLayout(QVBoxLayout())
        self.v2c_list_edit = ListEdit()
        self.v2c_list_edit.headers = self.getColumnLabelsV2c()
        self.v2c_list_edit.readOnly = self.parent.main_window.readonly
        self.v2c_list_edit.editInPopup = True
        self.v2c_list_edit.displayUpDown = False
        self.v2c_list_edit.setColDelegate(self.createDelegateForColumnV2c)
        self.connect(self.v2c_list_edit, SIGNAL('itemDeleted'),
                     self.setModified)
        self.connect(self.v2c_list_edit, SIGNAL('itemAdded'),
                     self.setModified)
        self.connect(self.v2c_list_edit, SIGNAL('itemModified'),
                     self.setModified)
        self.v2c_list_groupbox.layout().addWidget(self.v2c_list_edit)
        parent.main_window.writeAccessNeeded(self.v2c_list_edit)
        form.addWidget(self.v2c_list_groupbox)

        # V3 list (username, auth passphrase, auth proto, privacy key, algo):
        self.v3_list_groupbox = QGroupBox()
        self.v3_list_groupbox.setTitle(self.tr("SNMPv3 access list"))
        self.v3_list_groupbox.setLayout(QVBoxLayout())
        self.v3_list_edit = ListEdit()
        self.v3_list_edit.readOnly = self.parent.main_window.readonly
        self.v3_list_edit.headers = self.getColumnLabelsV3()
        self.v3_list_edit.displayUpDown = False
        self.v3_list_edit.editInPopup = True
        self.v3_list_edit.setColDelegate(self.createDelegateForColumnV3)
        self.connect(self.v3_list_edit, SIGNAL('itemDeleted'),
                     self.setModified)
        self.connect(self.v3_list_edit, SIGNAL('itemAdded'),
                     self.setModified)
        self.connect(self.v3_list_edit, SIGNAL('itemModified'),
                     self.setModified)
        self.v3_list_groupbox.layout().addWidget(self.v3_list_edit)
        parent.main_window.writeAccessNeeded(self.v3_list_edit)
        form.addWidget(self.v3_list_groupbox)
Пример #2
0
    def __init__(self, client, mainwindow, parent=None):
        QFrame.__init__(self, parent)
        self.init_done = False
        self.modified = False
        self.client = client
        self.mainwindow = mainwindow
        self._parent = parent

        form_layout = QVBoxLayout(self)
        title = QLabel("<H1>%s</H1>" % tr('NTP Configuration'))
        form_layout.addWidget(title)

        self.ntpServers = ListEdit()
        self.ntpServers.headers = self.getColumnLabels()
        self.ntpServers.displayUpDown = True
        self.ntpServers.readOnly = mainwindow.readonly
        self.ntpServers.editInPopup = True
        self.ntpServers.setColDelegate(self.createDelegateForColumn)
        self.mainwindow.writeAccessNeeded(self.ntpServers)

        self.connect(self.ntpServers, SIGNAL('itemDeleted'), self.serverDeleted)
        self.connect(self.ntpServers, SIGNAL('itemAdded'), self.serverAdded)
        self.connect(self.ntpServers, SIGNAL('itemModified'), self.serverModified)
        self.connect(self.ntpServers, SIGNAL('itemSorted'), self.serverSorted)

        self.addToInfoArea = mainwindow.addToInfoArea

        if self.resetConf():
            self.addToInfoArea(tr("NTP interface enabled"))
        else:
            self.addToInfoArea(tr("NTP interface disabled: NTP backend not loaded"), category=COLOR_CRITICAL)
            raise NuConfModuleDisabled("NTP")

        self.build()
        self.init_done = True
Пример #3
0
    def __init__(self, client, parent):
        ScrollArea.__init__(self)
        self.mainwindow = parent
        self._modified = False
        self.q_netobject = QNetObject.getInstance()
        self.connect(self.q_netobject, SIGNAL('cancelled'), self.resetConf)
        box_layout = QVBoxLayout(self)

        title = QLabel("<H1>%s</H1>" % tr("Routed networks"))
        box_layout.addWidget(title)
        if self.q_netobject.netcfg is None:
            debug("Routes can not load: no netcfg loaded")
            msg_area = MessageArea()
            msg_area.setMessage(
                tr("Routes not loaded"),
                tr("Could not get networking information from the appliance"),
                "critical"
                )
            box_layout.addWidget(msg_area)
            box_layout.addStretch()
            return

        self.ifaces_frontend = parent.widgets['Network']
        self.connect(self.ifaces_frontend, SIGNAL('modified'), self.resetConf)

        # TODO write useful routesList.setEditBoxDescription('') (used when a route is modified)
        self.routesList = ListEdit()
        self.routesList.headers = [self.tr('Destination'), self.tr('Gateway'), 'Interfaces']
        # Interfaces column is hidden
        self.routesList.hideColumn(2)
        self.routesList.readOnly = self.mainwindow.readonly
        self.routesList.displayUpDown = False
        self.routesList.editInPopup = True
        self.routesList.setColDelegate(self.createDelegateForColumn)
        self.routesList.setEditBox(self.createWizard)
        self.mainwindow.writeAccessNeeded(self.routesList)

        self.connect(self.routesList, SIGNAL('itemDeleted'), self.routeDeleted)
        self.connect(self.routesList, SIGNAL('itemAdded'), self.routeAdded)
        self.connect(self.routesList, SIGNAL('itemModified'), self.routeModified)

        box_layout.addWidget(self.routesList)

        self.resetConf()
Пример #4
0
    def buildIncoming(self, layout, row, col):
        incoming = QGroupBox(self)
        incoming.setTitle(tr('Incoming emails'))
        incoming_layout = QGridLayout(incoming)

        incoming_info = QLabel(tr('Domains for which EdenWall relays emails'))
        relayed_domains = ListEdit()
        relayed_domains.headers = self.getColumnLabels()
        relayed_domains.readOnly = self.mainwindow.readonly
        relayed_domains.setColDelegate(self.createDelegateForColumn)
        relayed_domains.setEditInPopup(True)
        relayed_domains.displayUpDown = False
        self.connect(relayed_domains, SIGNAL('itemDeleted'), self.incomingDeleted)
        self.connect(relayed_domains, SIGNAL('itemAdded'), self.incomingAdded)
        self.connect(relayed_domains, SIGNAL('itemModified'), self.incomingModified)
        self.connect(relayed_domains, SIGNAL('itemDeleted'), self.updateConfig)
        self.connect(relayed_domains, SIGNAL('itemAdded'), self.updateConfig)
        self.connect(relayed_domains, SIGNAL('itemModified'), self.updateConfig)

        incoming_layout.addWidget(incoming_info, 0, 0)
        incoming_layout.addWidget(relayed_domains, 1, 0)

        layout.addWidget(incoming, row, col)
        return relayed_domains
Пример #5
0
class RoutesFrontend(ScrollArea):
    COMPONENT = 'network'
    IDENTIFIER = 'routes'
    LABEL = tr('Routed networks')
    REQUIREMENTS = ('network',)
    ICON = ':/icons/network.png'

    def __init__(self, client, parent):
        ScrollArea.__init__(self)
        self.mainwindow = parent
        self._modified = False
        self.q_netobject = QNetObject.getInstance()
        self.connect(self.q_netobject, SIGNAL('cancelled'), self.resetConf)
        box_layout = QVBoxLayout(self)

        title = QLabel("<H1>%s</H1>" % tr("Routed networks"))
        box_layout.addWidget(title)
        if self.q_netobject.netcfg is None:
            debug("Routes can not load: no netcfg loaded")
            msg_area = MessageArea()
            msg_area.setMessage(
                tr("Routes not loaded"),
                tr("Could not get networking information from the appliance"),
                "critical"
                )
            box_layout.addWidget(msg_area)
            box_layout.addStretch()
            return

        self.ifaces_frontend = parent.widgets['Network']
        self.connect(self.ifaces_frontend, SIGNAL('modified'), self.resetConf)

        # TODO write useful routesList.setEditBoxDescription('') (used when a route is modified)
        self.routesList = ListEdit()
        self.routesList.headers = [self.tr('Destination'), self.tr('Gateway'), 'Interfaces']
        # Interfaces column is hidden
        self.routesList.hideColumn(2)
        self.routesList.readOnly = self.mainwindow.readonly
        self.routesList.displayUpDown = False
        self.routesList.editInPopup = True
        self.routesList.setColDelegate(self.createDelegateForColumn)
        self.routesList.setEditBox(self.createWizard)
        self.mainwindow.writeAccessNeeded(self.routesList)

        self.connect(self.routesList, SIGNAL('itemDeleted'), self.routeDeleted)
        self.connect(self.routesList, SIGNAL('itemAdded'), self.routeAdded)
        self.connect(self.routesList, SIGNAL('itemModified'), self.routeModified)

        box_layout.addWidget(self.routesList)

        self.resetConf()

    # for ListEdit

    def createDelegateForColumn(self, column):
        return EditColumnDelegate(IpOrFqdnEdit)

    def createWizard(self, data, options, title, parent=None):
        return RouteWizard(data, title, parent)
    # ... for ListEdit

    def setModified(self, isModified=True):
        self._modified = True
        if self._modified:
            self.mainwindow.setModified(self, True)

    def isModified(self):
        return self._modified

    def resetConf(self):
        netcfg = self.q_netobject.netcfg
        routes = []
        for route in netcfg.iterRoutes():
            interface = netcfg.getRouteInterface(route)
            routes.append([unicode(route.dst), unicode(route.router), interface.system_name, route])
        self.routesList.reset(routes)

    def routeDeleted(self):
        self.setModified(True)
        self.updateRoutes()
        self.ifaces_frontend.setModified(tr("Route deleted", "This text appears in ufwi_conf log console"))

    def routeAdded(self):
        self.setModified(True)
        self.updateRoutes()
        self.ifaces_frontend.setModified(tr("New route", "This text appears in ufwi_conf log console"))

    def routeModified(self):
        self.setModified(True)
        self.updateRoutes()
        self.ifaces_frontend.setModified(tr("Route edited", "This text appears in ufwi_conf log console"))

    def updateRoutes(self):
        netcfg = self.q_netobject.netcfg

        for iface in self.q_netobject.netcfg.iterInterfaces():
            iface.routes.clear()

        routes = self.routesList.rawData()
        for route in routes:
            dest = unicode(route[DESTINATION])
            gateway = unicode(route[GATEWAY])
            iface = unicode(route[INTERFACE])
            interface = netcfg.getInterfaceBySystemName(iface)
            assert interface is not None
            interface.addRoute(RouteRW(dest, gateway))
Пример #6
0
class NTPWidget(QFrame):
    def __init__(self, client, mainwindow, parent=None):
        QFrame.__init__(self, parent)
        self.init_done = False
        self.modified = False
        self.client = client
        self.mainwindow = mainwindow
        self._parent = parent

        form_layout = QVBoxLayout(self)
        title = QLabel("<H1>%s</H1>" % tr('NTP Configuration'))
        form_layout.addWidget(title)

        self.ntpServers = ListEdit()
        self.ntpServers.headers = self.getColumnLabels()
        self.ntpServers.displayUpDown = True
        self.ntpServers.readOnly = mainwindow.readonly
        self.ntpServers.editInPopup = True
        self.ntpServers.setColDelegate(self.createDelegateForColumn)
        self.mainwindow.writeAccessNeeded(self.ntpServers)

        self.connect(self.ntpServers, SIGNAL('itemDeleted'), self.serverDeleted)
        self.connect(self.ntpServers, SIGNAL('itemAdded'), self.serverAdded)
        self.connect(self.ntpServers, SIGNAL('itemModified'), self.serverModified)
        self.connect(self.ntpServers, SIGNAL('itemSorted'), self.serverSorted)

        self.addToInfoArea = mainwindow.addToInfoArea

        if self.resetConf():
            self.addToInfoArea(tr("NTP interface enabled"))
        else:
            self.addToInfoArea(tr("NTP interface disabled: NTP backend not loaded"), category=COLOR_CRITICAL)
            raise NuConfModuleDisabled("NTP")

        self.build()
        self.init_done = True

    def createDeleg(self):
        return EditColumnDelegate(IpOrFqdnEdit)

    def build(self):

        #Texts for buttons
        sync_text = tr('Force synchronization')
        get_time_text = tr('Get the EdenWall appliance time')

        #we need to use the longest string to set correct and same
        #width of the buttons
        sync_len = len(sync_text)
        get_time_len = len(get_time_text)
        if sync_len > get_time_len:
            longest_text = sync_text
        else:
            longest_text = get_time_text

        #sync button
        synchronize = TestButton(text=sync_text)
        self.mainwindow.writeAccessNeeded(synchronize)
        self.connect(synchronize, SIGNAL('clicked()'), self.callSynchronize)

        #get time button
        server_time = TestButton(text=get_time_text)
        self.connect(server_time, SIGNAL('clicked()'), self.getServerTime)

        #add to layout and set the same width
        layout = self.layout()
        for button in (synchronize, server_time):
            layout.addWidget(button)
            button.fixWidth(longest_text)

        #the ntp servers tabular
        self.layout().addWidget(self.ntpServers)

    def callSynchronize(self):
        self.mainwindow.addToInfoArea(tr('Launch NTP synchronization'))
        async = self.client.async()
        async.call("ntp", "syncTime",
            callback = self.success_sync,
            errback = self.error_sync
            )
        #TODO: implement callback/errback
        #return self.client.call("ntp", "syncTime")

    def getServerTime(self):
        async = self.client.async()
        async.call("ntp", "getServerTime",
            callback = self.printServerTime,
            errback = self.error_time
            )

    def printServerTime(self, time):
        server_time = unicode(datetime.fromtimestamp(float(time)))
        server_time = unicode(htmlBold(server_time))
        html = tr("Server time: %s") % server_time
        html = Html(html, escape=False)
        self.addToInfoArea(html)
        QMessageBox.information(self, tr("Server time"), tr("Server time: %s") % server_time)

    def success_sync(self, time):
        self.addToInfoArea(tr("NTP synchronization succeeded"), category=COLOR_SUCCESS)
        self.printServerTime(time)

    def error_sync(self, error):
        self.addToInfoArea(tr("NTP synchronization failed"), category=COLOR_ERROR)
        warning = QMessageBox(self)
        warning.setWindowTitle(tr('NTP synchronization failed'))
        warning.setText(tr('An error occurred during NTP synchronization'))
        warning.setDetailedText(exceptionAsUnicode(error))
        warning.setIcon(QMessageBox.Warning)
        warning.exec_()

    def error_time(self, *args):
        self.addToInfoArea(tr("Problem getting server time: %s") % args)

    def resetConf(self):
        try:
            self.ntpcfg = self.mainwindow.init_call("ntp", "getNtpConfig")
        except RpcdError:
            QWidget.setEnabled(self, False)
            return False

        data = []
        for server in self.ntpcfg['ntpservers'].split(' '):
            data.append([server])

        self.ntpServers.reset(data)

        return True

    def saveConf(self, message):
        self.ntpcfg['ntpservers'] = ''
        servers = []
        for server in self.ntpServers.rawData():
            servers.append(unicode(server[0]).strip())
        self.ntpcfg['ntpservers'] = ' '.join(servers)

        self.client.call("ntp", 'setNtpConfig', self.ntpcfg, message)
        self.setModified(False)

    def setModified(self, isModified=True, message=""):
        if self.init_done:
            if isModified:
                self.modified = True
                self.mainwindow.setModified(self._parent, True)
                if message:
                    self.mainwindow.addToInfoArea(message)
            else:
                self.modified = False

    def isModified(self):
        return self.modified

    def isValid(self):
        return True

    # for ListEdit
    def getColumnLabels(self):
        return [tr('NTP servers')]

    def createDelegateForColumn(self, column):
        return EditColumnDelegate(IpOrFqdnEdit)
    # ... for ListEdit

    def serverAdded(self):
        self.setModified(True, tr("NTP: server added"))

    def serverDeleted(self):
        self.setModified(True, tr("NTP: server deleted"))

    def serverModified(self):
        self.setModified(True, tr("NTP: server edited"))

    def serverSorted(self):
        self.setModified(True, tr("NTP: order of servers changed"))
Пример #7
0
class SnmpdWidget(QFrame):
    def __init__(self, parent):
        QFrame.__init__(self, parent)
        self.parent = parent

        form = QVBoxLayout(self)
        title = QLabel("<H1>%s</H1>" % self.tr('SNMP Server Configuration'))
        form.addWidget(title)

        # Enable:
        self.enable_line = QWidget()
        self.enable_line.setLayout(QFormLayout())
        self.enable_server = QCheckBox()
        self.connect(self.enable_server, SIGNAL('stateChanged(int)'),
                     parent.setEnabled)
        self.enable_line.layout().addRow(self.tr("Enable SNMP server"),
                                         self.enable_server)
        form.addWidget(self.enable_line)
        parent.main_window.writeAccessNeeded(self.enable_server)

        # V2c list (source network, community):
        self.v2c_list_groupbox = QGroupBox()
        self.v2c_list_groupbox.setTitle(self.tr("SNMPv2c access list"))
        self.v2c_list_groupbox.setLayout(QVBoxLayout())
        self.v2c_list_edit = ListEdit()
        self.v2c_list_edit.headers = self.getColumnLabelsV2c()
        self.v2c_list_edit.readOnly = self.parent.main_window.readonly
        self.v2c_list_edit.editInPopup = True
        self.v2c_list_edit.displayUpDown = False
        self.v2c_list_edit.setColDelegate(self.createDelegateForColumnV2c)
        self.connect(self.v2c_list_edit, SIGNAL('itemDeleted'),
                     self.setModified)
        self.connect(self.v2c_list_edit, SIGNAL('itemAdded'),
                     self.setModified)
        self.connect(self.v2c_list_edit, SIGNAL('itemModified'),
                     self.setModified)
        self.v2c_list_groupbox.layout().addWidget(self.v2c_list_edit)
        parent.main_window.writeAccessNeeded(self.v2c_list_edit)
        form.addWidget(self.v2c_list_groupbox)

        # V3 list (username, auth passphrase, auth proto, privacy key, algo):
        self.v3_list_groupbox = QGroupBox()
        self.v3_list_groupbox.setTitle(self.tr("SNMPv3 access list"))
        self.v3_list_groupbox.setLayout(QVBoxLayout())
        self.v3_list_edit = ListEdit()
        self.v3_list_edit.readOnly = self.parent.main_window.readonly
        self.v3_list_edit.headers = self.getColumnLabelsV3()
        self.v3_list_edit.displayUpDown = False
        self.v3_list_edit.editInPopup = True
        self.v3_list_edit.setColDelegate(self.createDelegateForColumnV3)
        self.connect(self.v3_list_edit, SIGNAL('itemDeleted'),
                     self.setModified)
        self.connect(self.v3_list_edit, SIGNAL('itemAdded'),
                     self.setModified)
        self.connect(self.v3_list_edit, SIGNAL('itemModified'),
                     self.setModified)
        self.v3_list_groupbox.layout().addWidget(self.v3_list_edit)
        parent.main_window.writeAccessNeeded(self.v3_list_edit)
        form.addWidget(self.v3_list_groupbox)

    def createDelegateForColumnV2c(self, column):
        if column == INDEX_V2C_SOURCE:
            return EditColumnDelegate(NetworkEdit)
        return EditColumnDelegate(CommunityEdit)

    def createDelegateForColumnV3(self, column):
        if column == INDEX_V3_USERNAME:
            return EditColumnDelegate(UsernameEdit)
        elif column == INDEX_V3_AUTHENTICATION_PASS:
            return PasswordColumnDelegate(PassEdit)
        elif column == INDEX_V3_AUTHENTICATION_PROTO:
            return ComboBoxColumnDelegate(("SHA", "MD5"))
        elif column == INDEX_V3_ENCRYPTION_PASS:
            return PasswordColumnDelegate(PassEdit)
        elif column == INDEX_V3_ENCRYPTION_ALGO:
            return ComboBoxColumnDelegate(("AES", "DES"))
        return EditColumnDelegate(PassEdit)

    def getColumnLabelsV2c(self):
        return [self.tr("Source host or network"), self.tr("Community")]

    def getColumnLabelsV3(self):
        return [self.tr("Username"), self.tr("Passphrase"),
                self.tr("Protocol"), self.tr("Privacy key"),
                self.tr("Encrypting algorithm")]

    def setModified(self, *unused):
        self.parent.setModified()