def add_matrix_flow_tab(self, file_name): """Add the matrix flow file in a new tab. Parameters ---------- file_name : string. The file name to show""" with open(file_name, "r") as myfile: data = myfile.read() text_view = gtk.TextView() text_view.set_editable(True) text_buffer = text_view.get_buffer() text_buffer.insert(text_buffer.get_end_iter(), data) scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_window.add_with_viewport(text_view) self.search_bar = Gtk_SearchBar(text_view, text_view, scrolled_window) launch_button = gtk.Button('Launch matrix verification') self.search_bar.vbox.add(launch_button) self.add_tab(self.search_bar.vbox, "Matrix flow", can_close=True, ref=file_name) Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message\ (Gtk_HelpMessage.Gtk_Message.ON_IMPORT_MATRIX_FLOW)
def add_conf_tab(self, file_name, fw_name): """Add the configuration file in a new tab. Parameters ---------- file_name : string. The file name to show fw_name : string. The firewall name of the file name""" with open(file_name, "r") as myfile: data = myfile.read() text_view = gtk.TextView() text_view.set_editable(False) text_buffer = text_view.get_buffer() text_buffer.insert(text_buffer.get_end_iter(), data) scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_window.add_with_viewport(text_view) self.search_bar = Gtk_SearchBar(text_view, text_view, scrolled_window) self.add_tab(self.search_bar.vbox, fw_name, can_close=True, ref=file_name) Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message( Gtk_HelpMessage.Gtk_Message.ON_SHOW_CONFIGURATION)
def add_interface_tab(self, obj): """Add an interface page Parameters ---------- obj : the interface instance """ if obj not in self.tab_dict: # strangely if you remove self to tab_interface, we have problems with garbage collector deleting attributes name = "%s (%s)" % (obj.name, NetworkGraph.NetworkGraph.NetworkGraph(). get_firewall_from_acl(obj).hostname) self.tab_interface = Gtk_TabInterface(name, obj) self.tab_interface.add_rules(obj.get_rules()) self.search_bar = Gtk_SearchBar(obj, self.tab_interface, self.tab_interface.scrolled_window) self.add_tab(self.search_bar.vbox, name, can_close=True) page_num = self.notebook.notebook.page_num( self.tab_interface.scrolled_window) self.tab_dict[obj] = self.search_bar.vbox self.notebook.notebook.set_current_page(page_num) Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message( Gtk_HelpMessage.Gtk_Message.ON_SHOW_RULES) else: if self.notebook.notebook.page_num(self.tab_dict[obj]): self.notebook.notebook.set_current_page( self.notebook.notebook.page_num(self.tab_dict[obj])) elif self.notebook_split.notebook.page_num(self.tab_dict[obj]): self.notebook_split.notebook.set_current_page( self.notebook_split.notebook.page_num(self.tab_dict[obj]))
def add_internal_anomaly_tab(self, internal_detection): """Add an internal anomaly page Parameters ---------- obj : the internal anomaly instance """ def on_cursor_changed(tree_view): tree_row = tree_view.get_selection().get_selected()[1] if not tree_row: return model = tree_view.get_model() lateral_pane = Gtk_Main.Gtk_Main().lateral_pane lateral_pane.details.clear() lateral_pane.details.add_row( AnomalyError.get_error_help(model[tree_row][0], 'internal')) lateral_pane.focus_details() internal_anomaly = Gtk_ListView("Anomaly detection (internal) : " + internal_detection.firewall.hostname) internal_anomaly.tree_view.connect('cursor-changed', on_cursor_changed) count = 0 for elem in internal_detection.result: for error in elem: fg = 'darkorange' if error.startswith( 'WARNING') else 'darkgreen' bg = '#FFFFFF' if count % 2 == 0 else '#DCDCDC' internal_anomaly.add_row(error, foreground=fg, background=bg) count += 1 self.search_bar = Gtk_SearchBar(internal_detection, internal_anomaly, internal_anomaly.scrolled_window) self.add_tab(self.search_bar.vbox, "Anomaly detection (%s)" % internal_detection.firewall.hostname, can_close=True, ref=internal_detection, export=Gtk_Export.export_internal_detection)
def add_distributed_anomaly_tab(self, distributed_detection): """Add an distributed anomaly page Parameters ---------- obj : the distributed anomaly instance """ def on_cursor_changed(tree_view): tree_row = tree_view.get_selection().get_selected()[1] if not tree_row: return model = tree_view.get_model() lateral_pane = Gtk_Main.Gtk_Main().lateral_pane lateral_pane.details.clear() if not model[tree_row].parent: lateral_pane.details.add_row("") else: lateral_pane.details.add_row( AnomalyError.get_error_help(model[tree_row][0], 'distributed')) lateral_pane.focus_details() distributed_anomaly = Gtk_TreeView("Anomaly detection (distributed)") distributed_anomaly.treeview.connect('cursor-changed', on_cursor_changed) self._add_distributed_anomaly(distributed_detection.error_path, distributed_anomaly) self.search_bar = Gtk_SearchBar(distributed_detection, distributed_anomaly, distributed_anomaly.scrolled_window) self.add_tab(self.search_bar.vbox, "Anomaly (Distributed)", can_close=True, ref=distributed_detection, export=Gtk_Export.export_distributed_detection) Gtk_Main.Gtk_Main().lateral_pane.help_message.change_message( Gtk_Message.ON_DISTRIBUTED_ANOMALY)