def setDNATDescription(self): # Present a nice description of the rule: # DNAT network = unicode(self.dnat_source_combo.currentText()) if not network: return dnat_source_icon = self.getNetwork(network).getIcon() network = unicode(self.dnat_translate_combo.currentText()) if not network: return dnat_destination_icon = self.getNetwork(network).getIcon() table = [ [htmlImage(dnat_source_icon), htmlImage(":/icons/go-next.png"), htmlImage(Resource.ICONS[INTERFACE_RESTYPE]), htmlImage(":/icons/go-next.png"), htmlImage(dnat_destination_icon)] ] src = self.dnat_source_combo.currentText() if self.dnat_port_combo.currentIndex() != 0: src += ' : ' + self.dnat_port_combo.currentText() dst = self.dnat_translate_combo.currentText() if self.dnat_port_combo.currentIndex() != 0 and self.dnat_port_nated_checkbox.checkState() == Qt.Checked: dst += ' : ' + self.dnat_port_nated_combo.currentText() table += [ [src, '', tr('Firewall'), '', dst] ] desc = htmlMultiColTable(table) self.dnat_description.setText(unicode(desc))
def setDescription(self): # Present a nice description of the rule: if self.previous_frame == 1: # SNAT snat_source_icon = self.getNetwork(unicode(self.snat_source_combo.currentText())).getIcon() snat_destination_icon = self.getNetwork(unicode(self.snat_translate_combo.currentText())).getIcon() desc = htmlTitle(tr('Source address translation')) table = [ ('', htmlImage(snat_source_icon) + ' ' + self.snat_source_combo.currentText()), (tr('when connecting to '), htmlImage(snat_destination_icon) + ' ' + self.snat_translate_combo.currentText()), (tr('translates into '), htmlImage(Resource.ICONS[INTERFACE_RESTYPE]) + ' ' + 'Firewall.') ] else: # DNAT dnat_source_icon = self.getNetwork(unicode(self.dnat_source_combo.currentText())).getIcon() dnat_destination_icon = self.getNetwork(unicode(self.dnat_translate_combo.currentText())).getIcon() desc = htmlTitle(tr('Destination address translation')) table = [ ('', htmlImage(dnat_source_icon) + ' ' + self.dnat_source_combo.currentText()), (tr('when connecting to '), htmlImage(Resource.ICONS[INTERFACE_RESTYPE]) + ' ' + 'Firewall.') ] protocols = self.window.getLibrary('protocols') if self.dnat_port_combo.currentIndex() != 0: identifier = unicode(self.dnat_port_combo.currentText()) dnat_port_icon = protocols[identifier].getIcon() table += [ (tr('on port '), htmlImage(dnat_port_icon) + ' ' + self.dnat_port_combo.currentText()) ] table += [ (tr('connects to'), htmlImage(dnat_destination_icon) + ' ' + self.dnat_translate_combo.currentText()) ] if self.dnat_port_combo.currentIndex() != 0 and self.dnat_port_nated_checkbox.checkState() == Qt.Checked: identifier = unicode(self.dnat_port_nated_combo.currentText()) dnat_port_icon = protocols[identifier].getIcon() table += [ (tr('on port '), htmlImage(dnat_port_icon) + ' ' + self.dnat_port_nated_combo.currentText()) ] desc += htmlTable(table) self.rule_description.setText(unicode(desc))
def htmlTitle(title, *icons): title = Html(title) for icon in icons: if not icon: continue title += u' ' + htmlImage(icon) return htmlHeader(3, title)
def formatWarnings(message, warnings): message = htmlParagraph(message) if warnings: html = htmlImage(WARNING_ICON32, align="middle") html += NBSP + Html(tr("Warnings:")) message += htmlParagraph(html) message += htmlList( tr(format) % tuple(arguments) for format, arguments in warnings) return unicode(message)
def _formatMessages(self, title, messages, icon): html = Html() errors = [] for format, args in messages: errors.append(formatMessage(self.window, True, format, args)) if errors: text = htmlImage(icon, align="middle") + NBSP + title html += htmlParagraph(text) html += htmlList(errors) return html
def setSNATDescription(self): # Present a nice description of the rule: # DNAT network = unicode(self.snat_source_combo.currentText()) if not network: return dnat_source_icon = self.getNetwork(network).getIcon() network = unicode(self.snat_translate_combo.currentText()) if not network: return dnat_destination_icon = self.getNetwork(network).getIcon() table = [ [htmlImage(dnat_source_icon), htmlImage(":/icons/go-next.png"), htmlImage(Resource.ICONS[INTERFACE_RESTYPE]), htmlImage(":/icons/go-next.png"), htmlImage(dnat_destination_icon)] ] src = self.snat_source_combo.currentText() dst = self.snat_translate_combo.currentText() table += [ [src, '', tr('Firewall'), '', dst] ] desc = htmlMultiColTable(table) self.snat_description.setText(unicode(desc))
def createInformation(self): options = [] title = unicode(self) extra = [] template = self.getTemplate() if template: extra.append(template) if not self['enabled']: extra.append(tr('disabled')) if not self['mandatory']: extra.append(tr('optional')) if extra: title += ' (%s)' % u', '.join(extra) decision = htmlImage(self.getIcon(), align="middle") decision += NBSP + Html(self['decision']) options.extend(( (tr('Decision'), decision), (tr('Chain'), self['chain']), (tr('Sources'), formatObjects(self.getSources())), (tr('Destinations'), formatObjects(self.getDestinations())), (tr('Protocols'), formatObjects(self['protocols'])), )) if self['user_groups']: options.append((tr('User Groups'), formatObjects(self['user_groups']))) if self['applications']: options.append((tr('Applications'), formatObjects(self['applications']))) if self['operating_systems']: options.append((tr('Operating Systems'), formatObjects(self['operating_systems']))) if self['periodicities']: options.append((tr('Time Criteria'), formatObjects(self['periodicities']))) if self['durations']: options.append((tr('Durations'), formatObjects(self['durations']))) log = htmlBold(humanYesNo(self['log'])) if 'log_prefix' in self: log = tr('%s, prefix="%s"') % (log, htmlBold(self['log_prefix'])) options.extend(( (tr('Logging'), Html(log, escape=False)), (tr('Input'), self['input'].createHTML()), (tr('Output'), self['output'].createHTML()), )) if 'comment' in self: options.append((tr('Comment'), self['comment'])) return title, options
def __init__(self, rule_list, rule_id, edit_key, network, align_right): icon = network.getIcon() icon = htmlImage(icon, align="middle") identifier = network.formatID() if align_right: html = icon + NBSP + Html(identifier) else: html = Html(identifier) + NBSP + icon html = htmlParagraph(html) ClickableLabel.__init__(self, html, network, rule_list, rule_id, edit_key) policy = self.sizePolicy() policy.setHorizontalPolicy(QSizePolicy.Expanding) self.setSizePolicy(policy ) align = Qt.AlignVCenter if align_right: align |= Qt.AlignRight else: align |= Qt.AlignLeft self.setAlignment(align)
def createHTML(self, text=True, link=True, icon=True, tooltip=False): identifier = self.formatID() if icon: image = self.getSmallIcon() else: image = None if image: html = htmlImage(image, align="middle") if text: html += NBSP + identifier else: html = Html(identifier) if link: url = self.library.highlight_format % self['id'] html = htmlLink(url, html) if tooltip: tooltip_text = self.getToolTip() if tooltip_text: html = htmlSpan(html, title=tooltip_text) return html
def createHTML(self, text=True, link=True, icon=True, tooltip=True): identifier = unicode(self) identifier = Html(identifier) if icon: image = self.getSmallIcon() else: image = None if image: html = htmlImage(image) if text: html += NBSP + identifier else: html = identifier if tooltip: tooltip_text = self.getToolTip() if tooltip_text: html = htmlSpan(html, title=tooltip_text) if link: url = self.controler.highlight_format % self['id'] html = htmlLink(url, html) return html
def __init__(self, rule_list, acl): AclWidget.__init__(self) self.layout = QHBoxLayout() if acl['log']: html = htmlImage(LOG_ICON) log = AclLabel(unicode(html)) if 'log_prefix' in acl: tooltip = tr('Log connections: "%s"') % acl['log_prefix'] else: tooltip = tr("Log connections") log.setToolTip(tooltip) self.layout.addWidget(log) for edit_key, objects in ( ('applications', acl['applications']), ('operating_systems', acl['operating_systems']), ('periodicities', acl['periodicities']), ('durations', acl['durations']), ): for object in objects: label = AclOption(rule_list, acl['id'], edit_key, object) self.layout.addWidget(label) self.setLayout(self.layout)
def __init__(self, parent, html, tooltip, widget_key): QFrame.__init__(self, parent) self.setFrameShape(QFrame.StyledPanel) self.setFrameShadow(QFrame.Raised) self.setContentsMargins(2, 2, 2, 2) self.setSizePolicy(QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) label = QLabel(html) if tooltip: label.setToolTip(tooltip) layout.addWidget(label) html = htmlImage(":/icons-32/wrong.png") html = htmlLink(widget_key, html) label = QLabel(unicode(html)) label.setCursor(Qt.PointingHandCursor) label.setTextInteractionFlags( Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) layout.addWidget(label) self.delete_widget = label
def __init__(self, icon, tooltip=None): html = htmlImage(icon) AclLabel.__init__(self, unicode(html)) self.setAlignment(Qt.AlignCenter) if tooltip: self.setToolTip(tooltip)