def load_services(self, service_name=None): ''' load services into selectedConfigurationCombo ''' self.selectedConfigurationCombo.startMultipleChanges() self.selectedConfigurationCombo.deleteAllItems() self.selectedConfigurationCombo.setEnabled(True) self.selectedConfigurationCombo.setLabel( self.configureViews['services']['title']) services = [] if self.runtime_view: services = self.fw.listServices() else: services = self.fw.config().getServiceNames() # services itemColl = yui.YItemCollection() for service in services: item = yui.YItem(service, False) if service == service_name: item.setSelected(True) itemColl.push_back(item) item.this.own(False) self.selectedConfigurationCombo.addItems(itemColl) self.selectedConfigurationCombo.doneMultipleChanges()
def load_ipsets(self): ''' load ipsets into selectedConfigurationCombo ''' self.selectedConfigurationCombo.startMultipleChanges() self.selectedConfigurationCombo.deleteAllItems() self.selectedConfigurationCombo.setEnabled(True) self.selectedConfigurationCombo.setLabel( self.configureViews['ipsets']['title']) ipsets = [] if self.runtime_view: ipsets = self.fw.getIPSets() else: ipsets = self.fw.config().getIPSetNames() # ipsets itemColl = yui.YItemCollection() for ipset in ipsets: item = yui.YItem(ipset, False) itemColl.push_back(item) item.this.own(False) self.selectedConfigurationCombo.addItems(itemColl) self.selectedConfigurationCombo.doneMultipleChanges()
def load_zones(self, selected=None): ''' load zones into selectedConfigurationCombo ''' self.selectedConfigurationCombo.startMultipleChanges() self.selectedConfigurationCombo.deleteAllItems() self.selectedConfigurationCombo.setEnabled(True) self.selectedConfigurationCombo.setLabel( self.configureViews['zones']['title']) zones = [] if self.runtime_view: zones = self.fw.getZones() else: zones = self.fw.config().getZoneNames() selected_zone = selected if selected not in zones: selected_zone = self.fw.getDefaultZone() # zones itemColl = yui.YItemCollection() for zone in zones: item = yui.YItem(zone, False) if zone == selected_zone: item.setSelected(True) itemColl.push_back(item) item.this.own(False) self.selectedConfigurationCombo.addItems(itemColl) self.selectedConfigurationCombo.doneMultipleChanges()
def _serviceConfigurationViewCollection(self): ''' returns an YItemCollection containing Service configuration views ''' ordered_Views = [ 'ports', 'protocols', 'source_ports', 'modules', 'destinations' ] itemColl = yui.YItemCollection() for v in ordered_Views: item = yui.YItem(self.serviceConfigurationView[v]['title'], False) show_item = 'ports' if show_item == v: item.setSelected(True) # adding item to views to find the item selected self.serviceConfigurationView[v]['item'] = item itemColl.push_back(item) item.this.own(False) return itemColl
def _ipsecConfigurationViewCollection(self): ''' returns an YItemCollection containing IPSEC configuration views ''' ordered_Views = [ 'entries', ] itemColl = yui.YItemCollection() for v in ordered_Views: item = yui.YItem(self.ipsecConfigurationView[v]['title'], False) show_item = 'entries' if show_item == v: item.setSelected(True) # adding item to views to find the item selected self.ipsecConfigurationView[v]['item'] = item itemColl.push_back(item) item.this.own(False) return itemColl
def _zoneConfigurationViewCollection(self): ''' returns an YItemCollection containing Zone configuration views ''' ordered_configureViews = [ 'services', 'ports', 'protocols', 'source_ports', 'masquerading', 'port_forwarding', 'icmp_filter', 'rich_rules', 'interfaces', 'sources' ] itemColl = yui.YItemCollection() for v in ordered_configureViews: item = yui.YItem(self.zoneConfigurationView[v]['title'], False) show_item = 'services' if show_item == v: item.setSelected(True) # adding item to views to find the item selected self.zoneConfigurationView[v]['item'] = item itemColl.push_back(item) item.this.own(False) return itemColl
def UIlayout(self, layout): ''' layout to setup UI for Manalog ''' optFactory = yui.YUI.optionalWidgetFactory() dialog = self.factory.createVBox(layout) lbl1 = self.factory.createLabel( (dialog), _("A tool to monitor your logs"),True,False) cols = self.factory.createHBox(layout) col1 = self.factory.createVBox(cols) frame = self.factory.createFrame(col1, _("Options")) vbox = self.factory.createVBox(col1) #### Last Boot self.lastBoot = self.factory.createCheckBox(self.factory.createLeft(vbox),_("Last boot"),True) self.lastBoot.setNotify(True) self.eventManager.addWidgetEvent(self.lastBoot, self.onLastBootEvent) #### Tailing mode self.tailing = self.factory.createCheckBox(self.factory.createLeft(vbox),_("Tail mode"),False) self.tailing.setNotify(True) self.eventManager.addWidgetEvent(self.tailing, self.onTailingEvent) #### Monotonic display for timestamp self.monotonbt = self.factory.createCheckBox(self.factory.createLeft(vbox),_("Monotonic timestamp"),True) self.factory.createVSpacing(vbox,0.5) row1 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row2 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row3 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row4 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row5 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row6 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row7 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row8 = self.factory.createHBox(vbox) self.factory.createVSpacing(vbox, 0.5) row9 = self.factory.createHBox(vbox) #### since and until self.sinceFrame = self.factory.createCheckBoxFrame(row1, _("Since"), True) self.sinceFrame.setWeight(yui.YD_HORIZ, 1) self.sinceFrame.setNotify(True) self.eventManager.addWidgetEvent(self.sinceFrame, self.onSinceFrameEvent) self.untilFrame = self.factory.createCheckBoxFrame(row2, _("Until"), True) self.untilFrame.setWeight(yui.YD_HORIZ, 1) self.untilFrame.setNotify(True) self.eventManager.addWidgetEvent(self.untilFrame, self.onUntilFrameEvent) if (optFactory.hasDateField()): hbox1 = self.factory.createHBox(self.sinceFrame) self.sinceDate = self.optFactory.createDateField(hbox1, "") self.factory.createHSpacing(hbox1, 1.0) self.sinceTime = optFactory.createTimeField(hbox1, ""); sday = date.today().isoformat() self.sinceDate.setValue(sday) self.sinceTime.setValue("00:00:00") hbox1 = self.factory.createHBox(self.untilFrame) self.untilDate = optFactory.createDateField(hbox1, "") self.factory.createHSpacing(hbox1, 1.0) self.untilTime = optFactory.createTimeField(hbox1, "") self.untilDate.setValue(sday) self.untilTime.setValue("23:59:59") else : self.sinceFrame.enable(False) self.untilFrame.enable(False) #### units spacing = self.factory.createHSpacing(row1, 2.0) self.unitsFrame = self.factory.createCheckBoxFrame(row3,_("Select a unit"), True) self.unitsFrame.setNotify(True) self.units = self.factory.createComboBox( self.factory.createLeft(self.unitsFrame), "" ) yui.YUI.app().busyCursor() myserv = mnservices.Services() list_services = myserv.service_info list_units = [] for unit in list_services.keys() : list_units.append(unit) list_units.sort() dlist = [] for unit in list_units : item = yui.YItem(unit) item.this.own(False) dlist.append(item) itemCollection = yui.YItemCollection(dlist) self.units.addItems(itemCollection) #### boots dlist = [] self.bootModel = {} for boot in self.listBoots() : key = boot[0]+' '+boot[2] item = yui.YItem(key) self.bootModel[key] = boot[1] # boot_id item.this.own(False) dlist.append(item) self.bootsFrame = self.factory.createCheckBoxFrame(row4,_("Select a boot"), True) self.bootsFrame.setNotify(True) if dlist == [] : self.eventManager.addWidgetEvent(self.bootsFrame, self.onBootFrameErrorEvent) else : self.eventManager.addWidgetEvent(self.bootsFrame, self.onBootFrameEvent) self.boots = self.factory.createComboBox( self.factory.createLeft(self.bootsFrame), "" ) itemCollection = yui.YItemCollection(dlist) self.boots.addItems(itemCollection) #### priority # From self.factory.createHSpacing(row2, 2.0) self.priorityFromFrame = self.factory.createCheckBoxFrame(row5, _("Priority level"), True) self.priorityFromFrame.setNotify(True) self.priorityFromFrame.setWeight(yui.YD_HORIZ, 1) self.priorityFrom = self.factory.createComboBox( self.priorityFromFrame, "" ) self.pr = ('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') dlist = [] for prio in self.pr: item = yui.YItem(prio) if ( prio == 'debug' ): item.setSelected(True) item.this.own(False) dlist.append(item) itemCollection = yui.YItemCollection(dlist) self.priorityFrom.addItems(itemCollection) #### matching self.matchingInputField = self.factory.createInputField(row6, _("Matching")) self.factory.createSpacing(row3,1) #### not matching self.notMatchingInputField =self.factory.createInputField(row7, _("but not matching")) self.matchingInputField.setWeight(yui.YD_HORIZ, 1) self.notMatchingInputField.setWeight(yui.YD_HORIZ, 1) #### search self.stopButton = self.factory.createPushButton(self.factory.createRight(row8), _("&Stop")) self.eventManager.addWidgetEvent(self.stopButton, self.onStopButton) self.stopButton.setDisabled() self.findButton = self.factory.createPushButton(self.factory.createRight(row8), _("&Find")) self.eventManager.addWidgetEvent(self.findButton, self.onFindButton) #### create log view object self.logView = self.factory.createLogView(cols, _("Log content"), 10, 0) self.logView.setWeight(yui.YD_HORIZ, 4) self.unitsFrame.setValue(False) self.sinceFrame.setValue(False) self.untilFrame.setValue(False) self.priorityFromFrame.setValue(False) self.bootsFrame.setValue(False) # buttons on the last line align = self.factory.createRight(layout) hbox = self.factory.createHBox(align) aboutButton = self.factory.createPushButton(hbox, _("&About") ) self.eventManager.addWidgetEvent(aboutButton, self.onAbout) align = self.factory.createRight(hbox) hbox = self.factory.createHBox(align) saveButton = self.factory.createPushButton(hbox, _("&Save")) self.eventManager.addWidgetEvent(saveButton, self._save) quitButton = self.factory.createPushButton(hbox, _("&Quit")) self.eventManager.addWidgetEvent(quitButton, self.onQuit) # Let's test a cancel event self.eventManager.addCancelEvent(self.onCancelEvent)
def UIlayout(self, layout): ''' layout implementation called in base class to setup UI ''' align = self.factory.createLeft(layout) self.name = self.factory.createInputField(align, _("Name")) align = self.factory.createLeft(layout) self.version = self.factory.createInputField(align, _("Version")) align = self.factory.createLeft(layout) self.short = self.factory.createInputField(align, _("Short")) align = self.factory.createLeft(layout) self.description = self.factory.createMultiLineEdit(align, _("Description")) self.description.setDefaultVisibleLines(5) if 'max_zone_name_len' in self._zoneBaseInfo.keys(): self.name.setInputMaxLength(self._zoneBaseInfo['max_zone_name_len']) if 'name' in self._zoneBaseInfo.keys(): self.name.setValue(self._zoneBaseInfo['name']) if 'version' in self._zoneBaseInfo.keys(): self.version.setValue(self._zoneBaseInfo['version']) if 'short' in self._zoneBaseInfo.keys(): self.short.setValue(self._zoneBaseInfo['short']) if 'description' in self._zoneBaseInfo.keys(): self.description.setValue(self._zoneBaseInfo['description']) hbox = self.factory.createHBox(layout) align = self.factory.createLeft(hbox) self.defaultTarget = self.factory.createCheckBox( align, _("Default Target"), False) self.eventManager.addWidgetEvent(self.defaultTarget, self.onDefaultTargetEvent) self.targets = { 'ACCEPT' : {'title' : _("Accept")}, 'DROP' : {'title' : _("Drop")}, 'REJECT' : {'title' : _("Reject")}, } ordered_targets = [ 'ACCEPT', 'DROP', 'REJECT' ] defaultTgt = "default" if 'target' in self._zoneBaseInfo.keys(): defaultTgt = self._zoneBaseInfo['target'] if self._zoneBaseInfo['target'] != "%%REJECT%%" else "REJECT" self.currentTargetCombobox = self.factory.createComboBox(hbox,"") itemColl = yui.YItemCollection() for v in ordered_targets: item = yui.YItem(self.targets[v]['title'], False) show_item = 'ACCEPT' if defaultTgt == "default" else defaultTgt if show_item == v : item.setSelected(True) # adding item to targets to find the item selected self.targets[v]['item'] = item itemColl.push_back(item) item.this.own(False) self.currentTargetCombobox.addItems(itemColl) self.defaultTarget.setValue(defaultTgt == "default") self.currentTargetCombobox.setEnabled(defaultTgt != "default") self.defaultTarget.setNotify(True) #### buttons on the last line align = self.factory.createRight(layout) bottomLine = self.factory.createHBox(align) cancelButton = self.factory.createPushButton(bottomLine, "&Cancel") self.eventManager.addWidgetEvent(cancelButton, self.onCancelButtonEvent) okButton = self.factory.createPushButton(bottomLine, "&Ok") self.eventManager.addWidgetEvent(okButton, self.onOkEvent) # Let's test a cancel event self.eventManager.addCancelEvent(self.onCancelEvent) if 'builtin' in self._zoneBaseInfo.keys() and 'default' in self._zoneBaseInfo.keys(): # Let's disable name changes for builtin zones enabled = not self._zoneBaseInfo['builtin'] and self._zoneBaseInfo['default'] self.name.setEnabled(enabled)
# ); # UI::UserInput(); # UI::CloseDialog(); # # return; # } factory = yui.YUI.widgetFactory() optional = yui.YUI.optionalWidgetFactory() dialog = factory.createPopupDialog() vbox = factory.createVBox( dialog ) if optional.hasDumbTab(): dumptab = optional.createDumbTab( vbox ) dumptab.addItem( yui.YItem("Page 1") ) dumptab.addItem( yui.YItem("Page 2") ) dumptab.addItem( yui.YItem("Page 3") ) else: factory.createLabel(vbox, "Error: This UI doesn't support the DumbTab widget!") factory.createPushButton( vbox, "&Close" ) event = dialog.waitForEvent() dialog.destroy() # `VBox( # `DumbTab( # [ "Page 1", "Page 2", "Page 3" ], # `RichText(`id(`contents), "Contents" ) # ), # `Right(`PushButton(`id(`close), "&Close" ) )
def UIlayout(self, layout): ''' layout implementation called in base class to setup UI ''' # Let's test a Menu widget self.file_menu = self.factory.createMenuButton( self.factory.createLeft(layout), _("&File")) qm = yui.YMenuItem(_("&Quit")) self.file_menu.addItem(qm) self.file_menu.rebuildMenuTree() sendObjOnEvent = True self.eventManager.addMenuEvent(qm, self.onQuitEvent, sendObjOnEvent) # _______ #| | | # cols = self.factory.createHBox(layout) col1 = self.factory.createVBox(cols) col2 = self.factory.createVBox(cols) # Column 1 self.activeBindingsTree = self.factory.createTree( col1, _("Active bindings")) col1.setWeight(yui.YD_HORIZ, 30) changeBindingsButton = self.factory.createPushButton( col1, _("&Change binding")) self.eventManager.addWidgetEvent(changeBindingsButton, self.onChangeBinding, sendObjOnEvent) #### editFrameBox contains button to modify zones (add, remove, edit, load defaults) self.editFrameBox = self.factory.createFrame(col1, _("Edit zones")) hbox = self.factory.createHBox(self.editFrameBox) vbox1 = self.factory.createVBox(hbox) vbox2 = self.factory.createVBox(hbox) editFrameAddButton = self.factory.createPushButton(vbox1, _("&Add")) self.eventManager.addWidgetEvent(editFrameAddButton, self.onEditFrameAddButtonEvent) editFrameEditButton = self.factory.createPushButton(vbox1, _("&Edit")) self.eventManager.addWidgetEvent(editFrameEditButton, self.onEditFrameEditButtonEvent) editFrameRemoveButton = self.factory.createPushButton( vbox2, _("&Remove")) self.eventManager.addWidgetEvent(editFrameRemoveButton, self.onEditFrameRemoveButtonEvent) editFrameLoadDefaultsButton = self.factory.createPushButton( vbox2, _("&Load default")) self.eventManager.addWidgetEvent( editFrameLoadDefaultsButton, self.onEditFrameLoadDefaultsButtonEvent) self.editFrameBox.setEnabled(False) # Column 2 align = self.factory.createTop(col2) #self.factory.createLeft(col2) align = self.factory.createLeft(align) hbox = self.factory.createHBox(align) col2.setWeight(yui.YD_HORIZ, 80) #label = self.factory.createLabel(hbox, _("Configuration:"),False,False) self.views = { 'runtime': { 'title': _("Runtime") }, 'permanent': { 'title': _("Permanent") }, } ordered_views = ['runtime', 'permanent'] self.currentViewCombobox = self.factory.createComboBox( hbox, _("Configuration")) itemColl = yui.YItemCollection() for v in ordered_views: item = yui.YItem(self.views[v]['title'], False) show_item = 'runtime' if show_item == v: item.setSelected(True) # adding item to views to find the item selected self.views[v]['item'] = item itemColl.push_back(item) item.this.own(False) self.currentViewCombobox.addItems(itemColl) self.currentViewCombobox.setNotify(True) self.eventManager.addWidgetEvent(self.currentViewCombobox, self.onChangeView) # mainNotebook (configure combo box) # TODO icmp_types, helpers, direct_configurations, lockdown_whitelist self.configureViews = { 'zones': { 'title': _("Zones") }, 'services': { 'title': _("Services") }, 'ipsets': { 'title': _("IP Sets") }, } ordered_configureViews = ['zones', 'services', 'ipsets'] self.configureViewCombobox = self.factory.createComboBox( hbox, _("View")) itemColl = yui.YItemCollection() for v in ordered_configureViews: item = yui.YItem(self.configureViews[v]['title'], False) show_item = 'zones' if show_item == v: item.setSelected(True) # adding item to views to find the item selected self.configureViews[v]['item'] = item itemColl.push_back(item) item.this.own(False) self.configureViewCombobox.addItems(itemColl) self.configureViewCombobox.setNotify(True) self.eventManager.addWidgetEvent(self.configureViewCombobox, self.onConfigurationViewChanged) # selectedConfigurationCombo is filled if requested by selected configuration view (which zones, services ...) self.selectedConfigurationCombo = self.factory.createComboBox( hbox, " ") # adding a dummy item to enlarge combobox item = yui.YItem("--------------------", False) item.this.own(False) self.selectedConfigurationCombo.addItem(item) self.selectedConfigurationCombo.setEnabled(False) self.selectedConfigurationCombo.setNotify(True) self.eventManager.addWidgetEvent( self.selectedConfigurationCombo, self.onSelectedConfigurationComboChanged) ### # ZoneNotebook and other (combo box to configure selected thing) self.zoneConfigurationView = { 'services': { 'title': _("Services") }, 'ports': { 'title': _("Ports") }, 'protocols': { 'title': _("Protocols") }, 'source_ports': { 'title': _("Source Ports") }, 'masquerading': { 'title': _("Masquerading") }, 'port_forwarding': { 'title': _("Port Forwarding") }, 'icmp_filter': { 'title': _("ICMP Filter") }, 'rich_rules': { 'title': _("Rich Rules") }, 'interfaces': { 'title': _("Interfaces") }, 'sources': { 'title': _("Sources") }, } # ServiceNotebook self.serviceConfigurationView = { 'ports': { 'title': _("Ports") }, 'protocols': { 'title': _("Protocols") }, 'source_ports': { 'title': _("Source Ports") }, 'modules': { 'title': _("Modules") }, 'destinations': { 'title': _("Destinations") }, } # ServiceNotebook self.ipsecConfigurationView = { 'entries': { 'title': _("Entries") }, } self.configureCombobox = self.factory.createComboBox( hbox, _("Configure")) # adding a dummy item to enlarge combobox itemColl = self._zoneConfigurationViewCollection() self.configureCombobox.addItems(itemColl) self.configureCombobox.setNotify(True) self.eventManager.addWidgetEvent(self.configureCombobox, self.onSelectedConfigurationChanged) ### #### Replace Point to change configuration view #self.rightPaneFrame = self.factory.createFrame(col2, "TEST") self.replacePoint = self.factory.createReplacePoint( col2) #self.rightPaneFrame) self.configurationPanel = self.factory.createVBox(self.replacePoint) self._replacePointServices() #### bottom status lines align = self.factory.createLeft(layout) statusLine = self.factory.createHBox(align) self.statusLabel = self.factory.createLabel( statusLine, self.failed_to_connect_label) align = self.factory.createLeft(layout) statusLine = self.factory.createHBox(align) self.defaultZoneLabel = self.factory.createLabel( statusLine, _("Default Zone: {}").format("--------")) self.logDeniedLabel = self.factory.createLabel( statusLine, _("Log Denied: {}").format("--------")) self.panicLabel = self.factory.createLabel( statusLine, _("Panic Mode: {}").format("--------")) self.automaticHelpersLabel = self.factory.createLabel( statusLine, _("Automatic Helpers: {}").format("--------")) self.lockdownLabel = self.factory.createLabel( statusLine, _("Lockdown: {}").format("--------")) #### buttons on the last line align = self.factory.createRight(layout) bottomLine = self.factory.createHBox(align) aboutButton = self.factory.createPushButton(bottomLine, _("&About")) self.eventManager.addWidgetEvent(aboutButton, self.onAbout) quitButton = self.factory.createPushButton(bottomLine, _("&Quit")) self.eventManager.addWidgetEvent(quitButton, self.onQuitEvent, sendObjOnEvent) # Let's test a cancel event self.eventManager.addCancelEvent(self.onCancelEvent) # Let's check external events every 100 msec self.timeout = 100 #self.eventManager.addTimeOutEvent(self.onTimeOutEvent) # End Dialof layout self.initFWClient()