mainwindow.py

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

PY
910
字号
#!/usr/bin/env python# -*- coding: utf-8 -*-# Copyright (C) 2005 Insecure.Com LLC.## Author: Adriano Monteiro Marques <py.adriano@gmail.com>#         Cleber Rodrigues <cleber.gnu@gmail.com>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAimport gtkimport sysimport osfrom os.path import split, isfile, join, abspath, existsimport xml.sax.saxutilsfrom types import StringTypesfrom time import timefrom tempfile import mktempfrom higwidgets.higwindows import HIGMainWindowfrom higwidgets.higdialogs import HIGDialog, HIGAlertDialogfrom higwidgets.higlabels import HIGEntryLabelfrom higwidgets.higboxes import HIGHBox, HIGVBoxfrom zenmapGUI.FileChoosers import ResultsFileChooserDialog, SaveResultsFileChooserDialogfrom zenmapGUI.ScanNotebook import ScanNotebook, ScanNotebookPagefrom zenmapGUI.ProfileEditor import ProfileEditorfrom zenmapGUI.Wizard import Wizardfrom zenmapGUI.About import Aboutfrom zenmapGUI.DiffCompare import DiffWindowfrom zenmapGUI.SearchWindow import SearchWindowfrom zenmapGUI.BugReport import BugReportfrom zenmapCore.Name import APP_DISPLAY_NAME, NMAP_DISPLAY_NAMEfrom zenmapCore.Paths import Pathfrom zenmapCore.RecentScans import recent_scansfrom zenmapCore.UmitLogging import logfrom zenmapCore.I18N import _from zenmapCore.UmitOptionParser import option_parserfrom zenmapCore.UmitConf import SearchConfig, is_maemofrom zenmapCore.UmitDB import Scans, UmitDBroot = Falsetry:    if sys.platform == 'win32':        root = True    elif is_maemo():        root = True    elif os.getuid() == 0:        root = Trueexcept: passUmitMainWindow = Nonehildon = Noneif is_maemo():    import hildon    class UmitMainWindow(hildon.Window):        def __init__(self):            hildon.Window.__init__(self)            self.set_resizable(False)            self.set_border_width(0)            self.vbox = gtk.VBox()            self.vbox.set_border_width(0)            self.vbox.set_spacing(0)else:    class UmitMainWindow(HIGMainWindow):        def __init__(self):            HIGMainWindow.__init__(self)            self.vbox = gtk.VBox()class MainWindow(UmitMainWindow):    def __init__(self):        UmitMainWindow.__init__(self)        self.set_title(_(APP_DISPLAY_NAME))        self._icontheme = gtk.IconTheme()        self.main_accel_group = gtk.AccelGroup()                self.add_accel_group(self.main_accel_group)                self.add(self.vbox)                self.connect ('delete-event', self._exit_cb)        self._create_ui_manager()        self._create_menubar()        self._create_toolbar()        self._create_scan_notebook()        self._verify_root()                # These dialogs should be instanciated on demand        # Unfortunately, due to a GTK bug on the filefilters (or our own        # stupidity), we are creating/destroying them at each callback        # invocation. sigh.        self._profile_filechooser_dialog = None        self._results_filechooser_dialog = None        # Loading files passed as argument        files = option_parser.get_open_results()        if len(files) >= 1:            for file in files:                self._load(filename=file)    def configure_focus_chain(self):        self.vbox.set_focus_chain()    def _verify_root(self):        if not root:            non_root = NonRootWarning()    def _create_ui_manager(self):        self.ui_manager = gtk.UIManager()                # See info on ActionGroup at:        # * http://www.pygtk.org/pygtk2reference/class-gtkactiongroup.html        # * http://www.gtk.org/api/2.6/gtk/GtkActionGroup.html        self.main_action_group = gtk.ActionGroup('MainActionGroup')                # See info on Action at:        # * http://www.pygtk.org/pygtk2reference/class-gtkaction.html        # * http://www.gtk.org/api/2.6/gtk/GtkAction.html                # Each action tuple can go from 1 to six fields, example:        # ('Open Scan Results',      -> Name of the action        #   gtk.STOCK_OPEN,          ->         #   _('_Open Scan Results'), ->         #   None,        #   _('Open the results of a previous scan'),        #   lambda x: True)                 about_icon = None        try: about_icon = gtk.STOCK_ABOUT        except: pass                self.main_actions = [ \            # Top level            ('Scan', None, _('Sc_an'), None),                         ('Wizard',                gtk.STOCK_CONVERT,                _('_Command Wizard'),                '<Control>i',                _('Open nmap command constructor wizard'),                self._wizard_cb),                        ('Save Scan',                gtk.STOCK_SAVE,                _('_Save Scan'),                None,                _('Save current scan results'),                self._save_scan_results_cb),                        ('Open Scan',                gtk.STOCK_OPEN,                _('_Open Scan'),                None,                _('Open the results of a previous scan'),                self._load_scan_results_cb),                                            ('Tools', None, _('_Tools'), None),                         ('New Scan',                gtk.STOCK_NEW,                _('_New Scan'),                "<Control>T",                _('Create a new Scan Tab'),                self._new_scan_cb),                        ('Close Scan',                gtk.STOCK_CLOSE,                _('Close Scan'),                "<Control>w",                _('Close current scan tab'),                self._close_scan_cb),                        ('New Profile',                gtk.STOCK_JUSTIFY_LEFT,                _('New _Profile'),                '<Control>p',                _('Create a new scan profile'),                self._new_scan_profile_cb),            ('Search Scan',                gtk.STOCK_FIND,                _('Search Scan Results'),                '<Control>f',                _('Search for a scan result'),                self._search_scan_result),                        ('Edit Profile',                gtk.STOCK_PROPERTIES,                _('_Edit Selected Profile'),                '<Control>e',                _('Edit selected scan profile'),                self._edit_scan_profile_cb),                        ('New Profile with Selected',                gtk.STOCK_PROPERTIES,                _('New P_rofile with Selected'),                '<Control>r',                _('Use the selected scan profile to create another'),                self._new_scan_profile_with_selected_cb),                        ('Quit',                gtk.STOCK_QUIT,                _('_Quit'),                None,            _('Quit this application'),                self._exit_cb),                                    # Top Level            ('Profile', None, _('_Profile'), None),                        ('Compare Results',                gtk.STOCK_DND_MULTIPLE,                _('Compare Results'),                "<Control>D",                _('Compare Scan Results using Diffies'),                self._load_diff_compare_cb),                                    # Top Level            ('Help', None, _('_Help'), None),            ('Report a bug',                gtk.STOCK_DIALOG_INFO,                _('_Report a bug'),                '<Control>b',                _("Report a bug"),                self._show_bug_report                ),                        ('About',                about_icon,                _('_About'),                '<Control>a',                _("About %s" % APP_DISPLAY_NAME),                self._show_about_cb                ),                        ('Show Help',                gtk.STOCK_HELP,                _('_Help'),                None,                _('Shows the application help'),                self._show_help),            ]                # See info on UIManager at:        # * http://www.pygtk.org/pygtk2reference/class-gtkuimanager.html                # * http://www.gtk.org/api/2.6/gtk/GtkUIManager.html                # UIManager supports UI "merging" and "unmerging". So, suppose there's        # no scan running or scan results opened, we should have a minimal        # interface. When we one scan running, we should "merge" the scan UI.        # When we get multiple tabs opened, we might merge the tab UI.                # This is the default, minimal UI        self.default_ui = """<menubar>        <menu action='Scan'>            <menuitem action='New Scan'/>            <menuitem action='Close Scan'/>            <menuitem action='Save Scan'/>            <menuitem action='Open Scan'/>             %s            <menuitem action='Quit'/>        </menu>        <menu action='Tools'>            <menuitem action='Wizard'/>            <menuitem action='Compare Results'/>            <menuitem action='Search Scan'/>         </menu>                <menu action='Profile'>            <menuitem action='New Profile'/>            <menuitem action='New Profile with Selected'/>            <menuitem action='Edit Profile'/>        </menu>                <menu action='Help'>            <menuitem action='Show Help'/>            <menuitem action='Report a bug'/>            <menuitem action='About'/>        </menu>

⌨️ 快捷键说明

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