wizard.py
来自「Ubuntu packages of security software。 相」· Python 代码 · 共 522 行 · 第 1/2 页
PY
522 行
#!/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 os.pathfrom higwidgets.higwindows import HIGWindowfrom higwidgets.higboxes import HIGVBox, HIGHBox, hig_box_space_holderfrom higwidgets.higlabels import HIGEntryLabelfrom higwidgets.higdialogs import HIGAlertDialogfrom higwidgets.higtables import HIGTablefrom zenmapGUI.OptionBuilder import *from zenmapGUI.ProfileEditor import *from zenmapCore.Name import NMAP_DISPLAY_NAMEfrom zenmapCore.Paths import Pathfrom zenmapCore.WizardConf import wizard_filefrom zenmapCore.TargetList import target_listfrom zenmapCore.NmapCommand import *from zenmapCore.UmitConf import Profile, CommandProfilefrom zenmapCore.I18N import _# Don't show any logo.logo = None# Uncomment this to bring the logo back.# pixmaps_dir = Path.pixmaps_dir# if pixmaps_dir:# logo = os.path.join(pixmaps_dir, 'wizard_logo.png')class Wizard(HIGWindow): def __init__(self): HIGWindow.__init__(self) self.set_size_request(600,450) self.set_position(gtk.WIN_POS_CENTER) self.profile = CommandProfile() self.constructor = CommandConstructor() self.options = OptionBuilder(wizard_file, self.constructor, self.update_command) self.target = '<target>' self.title_markup = "<span size='16500' weight='heavy'>%s</span>" self.directions = {'Start':self.start_page(), 'Choose':self.choose_page(), 'Profile':self.profile_page(), 'Finish':self.finish_page(), 'LastPage':None} for i in xrange(len(self.options.groups)): step = self.options.groups[i] last, next = self.__get_pair(i) self.directions[step] = self.__create_steps(step, last, next, self.options.section_names[step], self.options.tabs[step]) self.directions['Command'] = self.command_page() self.main_vbox = HIGVBox() self.main_vbox.set_border_width(5) self.main_vbox.set_spacing(12) self.add(self.main_vbox) self.__create_wizard_widgets() self.set_title(_("%s command constructor wizard" % NMAP_DISPLAY_NAME)) self.main_vbox._pack_expand_fill(self.directions['Start']) self.set_notebook(None) self.update_command() def __get_pair(self, pos): if pos == 0: return 'LastPage', self.options.groups[pos+1] elif pos == (self.options.groups.__len__() - 1): return self.options.groups[pos-1], 'Finish' else: return self.options.groups[pos-1], self.options.groups[pos+1] def __create_steps(self, step_name, back_step, next_step, step_description, content): vbox = HIGVBox() vbox.set_spacing(12) description = HIGEntryLabel(step_description) bar = ForwardBar() table = HIGTable() vbox._pack_noexpand_nofill(description) vbox._pack_expand_fill(table) vbox._pack_noexpand_nofill(bar) content.fill_table(table, False) bar.cancel.connect('clicked', self.close_wizard) bar.help.connect('clicked', self._show_help) bar.back.connect('clicked', self.switch_page, step_name, back_step) bar.forward.connect('clicked', self.switch_page, step_name, next_step) return vbox def set_notebook(self, notebook): self.notebook = notebook def __create_wizard_widgets(self): self.wizard_title = HIGEntryLabel("") self.wizard_title.set_line_wrap(False) self.wizard_event = gtk.EventBox() self.wizard_logo = gtk.Image() self.wizard_event.add(self.wizard_logo) command_hbox = HIGHBox() self.command_label = HIGEntryLabel(_("Command")) self.command_entry = gtk.Entry() separator = gtk.HSeparator() self.wizard_header_hbox = HIGHBox() self.wizard_header_hbox._pack_expand_fill(self.wizard_title) self.wizard_header_hbox._pack_noexpand_nofill(self.wizard_event) command_hbox._pack_noexpand_nofill(self.command_label) command_hbox._pack_expand_fill(self.command_entry) self.main_vbox._pack_noexpand_nofill(self.wizard_header_hbox) self.main_vbox._pack_noexpand_nofill(command_hbox) self.main_vbox._pack_noexpand_nofill(separator) self.wizard_logo.set_from_file(logo) def update_command(self): command = self.constructor.get_command(self.target) self.command_entry.set_text(command) def set_title(self, title): HIGWindow.set_title(self, title) self.wizard_title.set_label(self.title_markup % title) def close_wizard(self, widget=None, extra=None): self.destroy() def switch_page(self, widget, current, next): self.main_vbox.remove(self.directions[current]) self.directions[current].hide() self.main_vbox._pack_expand_fill(self.directions[next]) self.directions[next].show_all() def start_page(self): start = StartPage() start.bar.cancel.connect('clicked', self.close_wizard) start.bar.help.connect('clicked', self._show_help) start.bar.forward.connect('clicked', self.start_forward) return start def start_forward(self, widget): if self.directions['Start'].novice_radio.get_active(): self.main_vbox.remove(self.directions['Start']) self.main_vbox._pack_expand_fill(self.directions['Choose']) self.directions['Start'].hide() self.directions['Choose'].show_all() else: p = ProfileEditor() p.set_notebook(self.notebook) p.show_all() self.close_wizard() def _show_help(self, widget=None): import webbrowser webbrowser.open("file://%s" % os.path.join(Path.docs_dir, "help.html"), new=2) def choose_page(self): choose = ChoosePage() choose.bar.cancel.connect('clicked', self.close_wizard) choose.bar.help.connect('clicked', self._show_help) choose.bar.back.connect('clicked', self.switch_page, 'Choose', 'Start') choose.bar.forward.connect('clicked', self.choose_forward) return choose def choose_forward(self, widget): if self.directions['Choose'].command_radio.get_active(): if self.directions['Choose'].target_entry.get_text() == '': alert = HIGAlertDialog(message_format=_('No target selected!'),\ secondary_text=_('You must provide a target \to be scanned.')) alert.run() alert.destroy() self.directions['Choose'].target_entry.grab_focus() return None self.main_vbox.remove(self.directions['Choose']) self.directions['Choose'].hide() if self.directions['Choose'].profile_radio.get_active(): self.main_vbox._pack_expand_fill(self.directions['Profile']) self.directions['Profile'].show_all() self.directions['LastPage'] = self.directions['Profile'] self.directions['Profile'].prof = True self.target = '<target>' else: self.main_vbox._pack_expand_fill(self.directions['Command']) self.directions['Command'].show_all() self.directions['LastPage'] = self.directions['Choose'] self.directions['Profile'].prof = False self.target = self.directions['Choose'].target_entry.get_text() self.directions['Choose'].add_new_target(self.target) self.update_command() def profile_page(self): profile = ProfilePage() profile.bar.cancel.connect('clicked', self.close_wizard) profile.bar.help.connect('clicked', self._show_help) profile.bar.back.connect('clicked', self.switch_page,'Profile','Choose') profile.bar.forward.connect('clicked', self.profile_forward) return profile def profile_forward(self, widget): if self.directions['Profile'].profile_entry.get_text() == '': alert = HIGAlertDialog(message_format=_('Unnamed profile'),\ secondary_text=_('You must provide a name \for this profile.')) alert.run() alert.destroy() self.directions['Profile'].profile_entry.grab_focus() return None self.main_vbox.remove(self.directions['Profile']) self.main_vbox._pack_expand_fill(self.directions['Command'])
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?