mainwindow.py

来自「Ubuntu packages of security software。 相」· Python 代码 · 共 910 行 · 第 1/3 页

PY
910
字号
               or page.status.parsing_result\               or page.status.scanning\               or page.status.search_loaded:            return False        else:            return True        def _load(self, filename=None, parsed_result=None, title=None):        scan_page = None                if filename or parsed_result:            current_page = self.scan_notebook.get_nth_page(self.scan_notebook.get_current_page())            if self._verify_page_usage(current_page):                log.debug(">>> Loading inside current scan page.")                scan_page = current_page            else:                log.debug(">>> Creating a new page to load it.")                scan_page = self._new_scan_cb()            log.debug(">>> Enabling page widgets")            scan_page.enable_widgets()        if filename and os.access(filename, os.R_OK):            # Load scan result from file            log.debug(">>> Loading file: %s" % filename)            log.debug(">>> Permissions to access file? %s" % os.access(filename, os.R_OK))            # Parse result            f = open(filename)            scan_page.parse_result(f)            scan_page.saved_filename = filename                        # Closing file to avoid problems with file descriptors            f.close()            log.debug(">>> Setting tab label")            self.scan_notebook.set_tab_title(scan_page, title)                    elif parsed_result:            # Load scan result from parsed object            scan_page.load_from_parsed_result(parsed_result)            log.debug(">>> Setting tab label")            self.scan_notebook.set_tab_title(scan_page, None)        elif filename and not os.access(filename, os.R_OK):            alert = HIGAlertDialog(message_format=_('Permission denied'),                                   secondary_text=_('Don\'t have read access to the path'))            alert.run()            alert.destroy()            return         else:            alert = HIGAlertDialog(message_format=_('Could not load result'),                                   secondary_text=_('An unidentified error occouried and the \scan result was unable to be loaded properly.'))            alert.run()            alert.destroy()            return         log.debug(">>> Setting flag that defines that there is no changes at \this scan result yet")        scan_page.changes = False        scan_page.status.set_loaded_unchanged()        log.debug(">>> Showing loaded result page")        self.scan_notebook.set_current_page(self.scan_notebook.get_n_pages()-1)        return scan_page        def _save_scan_results_cb(self, saving_page):        current_page = self.scan_notebook.get_nth_page(self.scan_notebook.get_current_page())        try:            status = current_page.status        except:            alert = HIGAlertDialog(message_format=_('No scan tab'),                                   secondary_text=_('There is no scan tab or scan result \been shown. Run a scan and then try to save it.'))            alert.run()            alert.destroy()            return None        log.debug(">>> Page status: %s" % current_page.status.status)        if status.empty or status.unknown:    # EMPTY or UNKNOWN            # Show a dialog saying that there is nothing to be saved            alert = HIGAlertDialog(message_format=_('Nothing to save'),                                   secondary_text=_('No scan on this tab. Start a scan an \then try again'))            alert.run()            alert.destroy()        elif status.scan_failed:            alert = HIGAlertDialog(message_format=_('Nothing to save'),                                   secondary_text=_('The scan has failed! There is nothing \to be saved.'))            alert.run()            alert.destroy()        elif status.parsing_result:    # PARSING_RESULT            # Say that the result is been parsed            alert = HIGAlertDialog(message_format=_('Parsing the result'),                                   secondary_text=_('The result is still been parsed. \You can not save the result yet.'))            alert.run()            alert.destroy()        elif status.scanning:    # SCANNING            # Say that the scan is still running            alert = HIGAlertDialog(message_format=_('Scan is running'),                                   secondary_text=_('The scan process is not finished yet. \Wait until the scan is finished and then try to save it again.'))            alert.run()            alert.destroy()        elif status.unsaved_unchanged or status.unsaved_changed or status.search_loaded:            # UNSAVED_UNCHANGED and UNSAVED_CHANGED            # Show the dialog to choose the path to save scan result            self._save_results_filechooser_dialog = SaveResultsFileChooserDialog(\                                                                    title=_('Save Scan'))                response = self._save_results_filechooser_dialog.run()            filename = None            if (response == gtk.RESPONSE_OK):                filename = self._save_results_filechooser_dialog.get_filename()                # add .usr to filename if there is no other extension                if filename.find('.') == -1:                    filename += ".usr"                self._save(current_page, filename)                            self._save_results_filechooser_dialog.destroy()            self._save_results_filechooser_dialog = None            return filename        elif status.loaded_changed:    # LOADED_CHANGED            # Save the current result at the loaded file            self._save(current_page, current_page.saved_filename)        elif status.saved or status.loaded_unchanged:            pass        else:    # UNDEFINED status            alert = HIGAlertDialog(message_format=_('Nothing to save'),                                   secondary_text=_('No scan on this tab. Start a scan \ an then try again'))            alert.run()            alert.destroy()    def _show_about_cb(self, widget):        a = About()        a.show_all()        def _save(self, saving_page, saved_filename):        log.debug(">>> File been saved: %s" % saved_filename)        if os.access(split(saved_filename)[0], os.W_OK):            f = None            try:                f = open(saved_filename, 'w')            except:                alert = HIGAlertDialog(message_format=_('Can\'t save file'),                            secondary_text=_('Can\'t open file to write'))                alert.run()                alert.destroy()            else:                saving_page.saved = True                saving_page.changes = False                saving_page.saved_filename = saved_filename                saving_page.collect_umit_info()                log.debug(">>> Page saved? %s" % saving_page.status.saved)                log.debug(">>> Changes on page? %s" % saving_page.status.status)                log.debug(">>> File to be saved at: %s" % saving_page.saved_filename)                                saving_page.parsed.write_xml(f)                # Closing file to avoid problems with file descriptors                f.close()                # Setting page status to saved                saving_page.status.set_saved()                # Saving recent scan information                recent_scans.add_recent_scan(saved_filename)                recent_scans.save()        else:            alert = HIGAlertDialog(message_format=_('Permission denied'),                                   secondary_text=_('Don\'t have write access to this path.'))            alert.run()            alert.destroy()        def _new_scan_cb(self, widget=None, data=None):        """Append a new ScanNotebookPage to ScanNotebook        New tab properties:        - Empty        - Disabled widgets        - Ready to start a new scan        - Untitled scan        """        return self.scan_notebook.add_scan_page(data)    def _new_scan_profile_cb(self, p):        pe = ProfileEditor()        pe.set_notebook(self.scan_notebook)                pe.show_all()        def _edit_scan_profile_cb(self, p):        page = self.scan_notebook.get_nth_page\                (self.scan_notebook.get_current_page())        profile = page.toolbar.selected_profile                pe = ProfileEditor(profile)        pe.set_notebook(self.scan_notebook)                pe.show_all()        def _new_scan_profile_with_selected_cb(self, p):        page = self.scan_notebook.get_nth_page(self.scan_notebook.get_current_page())        profile = page.toolbar.selected_profile                pe = ProfileEditor(profile, delete=False)        pe.clean_profile_info()        pe.set_notebook(self.scan_notebook)                pe.show_all()        def _alert_with_action_name_cb(self, p):        d = HIGAlertDialog(parent=self,                           message_format=p.get_name(),                           secondary_text=_("The text above is this action's name"))        d.run()        d.destroy()    def _show_help(self, action):        import webbrowser        new = 0        if sys.hexversion >= 0x2050000:            new = 2        doc_path = abspath(join(Path.docs_dir, "help.html"))        if exists(doc_path):            webbrowser.open("file://%s" % doc_path, new=new)        else:            d = HIGAlertDialog(parent=self,                               message_format=_("Couldn't find documentation files!"),                               secondary_text=_("""%s couldn't find the \documentation files. Please, go to %s's website and have the latest \documentation in our Support & Development section.""" % (APP_DISPLAY_NAME, APP_DISPLAY_NAME)))            d.run()            d.destroy()    def _exit_cb (self, widget=None, extra=None):        for page in self.scan_notebook.get_children():            if not self._close_scan_cb(page):                self.show_all()                return True        else:            # Cleaning up data base            UmitDB().cleanup(SearchConfig().converted_save_time)                        gtk.main_quit()    def _load_diff_compare_cb (self, widget=None, extra=None):        # We must change this test dict        # This dict has the following sintax:        # key = Scan name        # value = nmap output in string format        dic = {}                for i in range(self.scan_notebook.get_n_pages()):            page = self.scan_notebook.get_nth_page(i)            scan_name = self.scan_notebook.get_tab_title(page)            if not scan_name:                scan_name = _("Scan ") + str(i+1)                        dic[scan_name] = page.parsed                self.diff_window = DiffWindow(dic)                self.diff_window.show_all()class NonRootWarning (HIGAlertDialog):    def __init__(self):        warning_text = _('''You are trying to run %s with a non-root user!\nSome %s options need root privileges to work.''' % (APP_DISPLAY_NAME, NMAP_DISPLAY_NAME))                HIGAlertDialog.__init__(self, message_format=_('Non root user'),                                secondary_text=warning_text)        self.run()        self.destroy()if __name__ == '__main__':    w = MainWindow()    w.show_all()    gtk.main()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?