scannotebook.py
来自「Ubuntu packages of security software。 相」· Python 代码 · 共 1,296 行 · 第 1/4 页
PY
1,296 行
#!/usr/bin/env python# -*- coding: utf-8 -*-# Copyright (C) 2005 Insecure.Com LLC.## Author: Adriano Monteiro Marques <py.adriano@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 gobjectimport refrom higwidgets.hignotebooks import HIGNotebook, HIGAnimatedTabLabelfrom higwidgets.higboxes import HIGVBoxfrom higwidgets.higdialogs import HIGAlertDialog, HIGDialogfrom higwidgets.higscrollers import HIGScrolledWindowfrom zenmapGUI.NmapOutputViewer import NmapOutputViewerfrom zenmapGUI.ScanHostDetailsPage import ScanHostDetailsPagefrom zenmapGUI.ScanToolbar import ScanCommandToolbar, ScanToolbarfrom zenmapGUI.ScanHostsView import ScanHostsView, SCANNINGfrom zenmapGUI.ScanOpenPortsPage import ScanOpenPortsPagefrom zenmapGUI.ScanRunDetailsPage import ScanRunDetailsPagefrom zenmapGUI.ScanNmapOutputPage import ScanNmapOutputPagefrom zenmapGUI.Icons import get_os_icon, get_os_logo, get_vulnerability_logofrom zenmapCore.NmapCommand import NmapCommandfrom zenmapCore.NmapCommand import CommandConstructorfrom zenmapCore.UmitConf import CommandProfile, ProfileNotFound, is_maemofrom zenmapCore.NmapParser import NmapParserfrom zenmapCore.Paths import Pathfrom zenmapCore.UmitLogging import logfrom zenmapCore.I18N import _icon_dir = Path.pixmaps_dirclass PageStatus(object): """ Pages status: The page status can be one of the following: * saved: there is nothing to be saved in the current scan tab * unsaved_unchanged: for recently scanned results that were parsed and is unchanged. * unsaved_changed: for recently scanned results that were parsed and got some changes on its contents (like a comment) * loaded_unchanged: for scan results that were loaded from a file and got no modifications * loaded_changed: for scan results that were loaded from a file and got some modifications (like comments) * parsing_result: the result is been parsed to be displayed at the tab * scanning: there is no parsed result related to this tab, but there is a related scan running to show results on that tab * empty: there is nothing related to this tab. His widgets are disabled and this is the initial state of a new tab * unknown: the page status is unknown * scan_failed: the scan has failed * search_loaded: the scan was loaded from a search result """ def __init__(self, status=False): if status: self.status = status else: self.set_unknown() def set_empty(self): self._status = "empty" def set_saved(self): self._status = "saved" def set_unsaved_unchanged(self): self._status = "unsaved_unchanged" def set_unsaved_changed(self): self._status = "unsaved_changed" def set_loaded_unchanged(self): self._status = "loaded_unchanged" def set_loaded_changed(self): self._status = "loaded_changed" def set_parsing_result(self): self._status = "parsing_result" def set_scanning(self): self._status = "scanning" def set_unknown(self): self._status = "unknown" def set_scan_failed(self): self._status = "scan_failed" def set_search_loaded(self): self._status = "search_loaded" def get_status(self): return self._status def set_status(self, status): if status in self.available_status: self._status = status else: raise Exception("Unknown status!") def _verify_status(self, status): if self._status == status: return True return False def get_unsaved_unchanged(self): return self._verify_status("unsaved_unchanged") def get_unsaved_changed(self): return self._verify_status("unsaved_changed") def get_loaded_unchanged(self): return self._verify_status("loaded_unchanged") def get_loaded_changed(self): return self._verify_status("loaded_changed") def get_parsing_result(self): return self._verify_status("parsing_result") def get_scanning(self): return self._verify_status("scanning") def get_empty(self): return self._verify_status("empty") def get_unknown(self): return self._verify_status("unknown") def get_saved(self): return self._verify_status("saved") def get_scan_failed(self): return self._verify_status("scan_failed") def get_search_loaded(self): return self._verify_status("search_loaded") status = property(get_status, set_status) saved = property(get_saved) unsaved_unchanged = property(get_unsaved_unchanged) unsaved_changed = property(get_unsaved_changed) loaded_unchanged = property(get_loaded_unchanged) loaded_changed = property(get_loaded_changed) parsing_result = property(get_parsing_result) scanning = property(get_scanning) empty = property(get_empty) unknown = property(get_unknown) scan_failed = property(get_scan_failed) search_loaded = property(get_search_loaded) _status = "unknown" available_status = ["saved", "unsaved_unchanged", "unsaved_changed", "loaded_unchanged", "loaded_changed", "parsing_result", "scanning", "empty", "unknown", "search_loaded"]class ScanNotebook(HIGNotebook): def __init__(self): HIGNotebook.__init__(self) self.set_scrollable(True) self.tab_titles = [] self.scan_num = 1 self.close_scan_cb = None def remove_page(self, page_num): page = self.get_nth_page(page_num) self.remove_tab_title(self.get_tab_title(page)) HIGNotebook.remove_page(self, page_num) def add_scan_page(self, title): page = ScanNotebookPage() page.select_first_profile() self.append_page(page, self.close_scan_cb, tab_title=title) page.show_all() self.set_current_page(-1) # Put focus at the target combo. page.target_focus() return page def append_page(self, page, close_cb, tab_label=None, tab_title=None): log.debug(">>> Appending Scan Tab.") if tab_label: tab_label.set_text(self.sanitize_tab_title(tab_label.get_text())) elif tab_title: tab_label = HIGAnimatedTabLabel(self.sanitize_tab_title(tab_title)) else: tab_label = HIGAnimatedTabLabel(self.get_new_tab_title()) tab_label.connect("close-clicked", close_cb, page) HIGNotebook.append_page(self, page, tab_label) def sanitize_tab_title(self, title): #log.debug(">>> Sanitize this title: %s" % title) scan_id = 1 title2 = title while title2 in self.tab_titles: title2 = "%s (%s)" % (title, scan_id) scan_id += 1 self.add_tab_title(title2) #log.debug(">>> Title sanitized: %s" % title2) return title2 def remove_tab_title(self, title): log.debug(">>> Remove tab title: %s" % title) try: self.tab_titles.remove(title) except: pass def get_new_tab_title(self, parsed_result=None): log.debug(">>> Get new tab title") if parsed_result: if parsed_result.scan_name: return self.sanitize_tab_title(parsed_result.scan_name) try: filename = parsed_result.nmap_xml_file if filename and type(filename) in StringTypes: return self.sanitize_tab_title(filename) except: pass index = self.scan_num self.scan_num += 1 return self.sanitize_tab_title(_('untitled_scan%s') % index) def add_tab_title(self, title): log.debug(">>> Add tab title: %s" % title) self.tab_titles.append(title) def get_tab_title(self, page): log.debug(">>> Get tab title") return self.get_tab_label(page).get_text() def set_tab_title(self, page, title): log.debug(">>> Set tab title: %s" % title) old_title = self.get_tab_title(page) if old_title: self.remove_tab_title(old_title) if not title: title = self.get_new_tab_title(page.parsed) else: title = self.sanitize_tab_title(title) self.get_tab_label(page).set_text(title)class ScanNotebookPage(HIGVBox): def __init__(self): HIGVBox.__init__(self) # The borders are consuming too much space on Maemo. Setting it to # 0 pixels while on Maemo if is_maemo(): self.set_border_width(0) self.set_spacing(0) self.status = PageStatus() self.status.set_empty() self.changes = False self.comments = {} self.parsed = NmapParser() self.top_box = HIGVBox() self.__create_toolbar() self.__create_command_toolbar() self.__create_scan_result() self.disable_widgets() self.saved = False self.saved_filename = '' self.top_box.set_border_width(6) self.top_box.set_spacing(5) self.top_box._pack_noexpand_nofill(self.toolbar) self.top_box._pack_noexpand_nofill(self.command_toolbar) self._pack_noexpand_nofill(self.top_box) self._pack_expand_fill(self.scan_result) def target_focus(self): self.toolbar.target_entry.child.grab_focus() def select_first_profile(self): self.toolbar.profile_entry.child.set_text(self.toolbar.profile_entry.get_model()[0][0]) def verify_changes(self): return self.__verify_comments_changes() def go_to_host(self, host):
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?