def delete_profile(self, widget=None, extra=None): if self.deletable: dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>'+_("Deleting Profile")+'</b>') text = HIGEntryLabel(_('Your profile is going to be deleted! Click\ Ok to continue, or Cancel to go back to Profile Editor.')) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True self.profile.remove_profile(self.profile_name) self.update_profile_entry() self.destroy()
def delete_profile(self, widget=None, extra=None): if self.deletable: dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>'+_("Deleting Profile")+'</b>') text = HIGEntryLabel(_('Your profile is going to be deleted! Click\ Ok to continue, or Cancel to go back to Profile Editor.')) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True self.profile.remove_profile(self.profile_name) self.update_profile_entry() self.destroy()
class ProfileEditor(HIGWindow): def __init__(self, command=None, profile_name=None, deletable=True, overwrite=False): HIGWindow.__init__(self) self.connect("delete_event", self.exit) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.deletable = deletable self.profile_name = profile_name self.overwrite = overwrite # Used to block recursive updating of the command entry when the # command entry causes the OptionBuilder widgets to change. self.inhibit_command_update = False self.__create_widgets() self.__pack_widgets() self.profile = CommandProfile() self.ops = NmapOptions() if profile_name: log.debug("Showing profile %s" % profile_name) prof = self.profile.get_profile(profile_name) # Interface settings self.profile_name_entry.set_text(profile_name) self.profile_description_text.get_buffer().set_text( prof['description']) command_string = prof['command'] self.ops.parse_string(command_string) if command: self.ops.parse_string(command) self.option_builder = OptionBuilder( Path.profile_editor, self.ops, self.update_command, self.help_field.get_buffer()) log.debug("Option groups: %s" % str(self.option_builder.groups)) log.debug("Option section names: %s" % str( self.option_builder.section_names)) #log.debug("Option tabs: %s" % str(self.option_builder.tabs)) for tab in self.option_builder.groups: self.__create_tab( _(tab), _(self.option_builder.section_names[tab]), self.option_builder.tabs[tab]) self.update_command() def command_entry_changed_cb(self, widget): command_string = self.command_entry.get_text().decode("UTF-8") self.ops.parse_string(command_string) self.inhibit_command_update = True self.option_builder.update() self.inhibit_command_update = False def update_command(self): """Regenerate and display the command.""" if not self.inhibit_command_update: # Block recursive updating of the OptionBuilder widgets when they # cause a change in the command entry. self.command_entry.handler_block(self.command_entry_changed_cb_id) self.command_entry.set_text(self.ops.render_string()) self.command_entry.handler_unblock( self.command_entry_changed_cb_id) def update_help_name(self, widget, extra): self.help_field.get_buffer().set_text( "Profile name\n\nThis is how the profile will be identified " "in the drop-down combo box in the scan tab.") def update_help_desc(self, widget, extra): self.help_field.get_buffer().set_text( "Description\n\nThe description is a full description of what " "the scan does, which may be long.") def __create_widgets(self): ### # Vertical box to keep 3 boxes self.main_whole_box = HIGVBox() self.upper_box = HIGHBox() self.middle_box = HIGHBox() self.lower_box = HIGHBox() #self.main_vbox = HIGVBox() self.command_entry = gtk.Entry() self.command_entry_changed_cb_id = self.command_entry.connect( "changed", self.command_entry_changed_cb) self.scan_button = HIGButton(_("Scan")) self.scan_button.connect("clicked", self.run_scan) self.notebook = gtk.Notebook() # Profile info page self.profile_info_vbox = HIGVBox() self.profile_info_label = HIGSectionLabel(_('Profile Information')) self.profile_name_label = HIGEntryLabel(_('Profile name')) self.profile_name_entry = gtk.Entry() self.profile_name_entry.connect( 'enter-notify-event', self.update_help_name) self.profile_description_label = HIGEntryLabel(_('Description')) self.profile_description_scroll = HIGScrolledWindow() self.profile_description_scroll.set_border_width(0) self.profile_description_text = HIGTextView() self.profile_description_text.connect( 'motion-notify-event', self.update_help_desc) # Buttons self.buttons_hbox = HIGHBox() self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL) self.cancel_button.connect('clicked', self.exit) self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) self.delete_button.connect('clicked', self.delete_profile) self.save_button = HIGButton(_("Save Changes"), stock=gtk.STOCK_SAVE) self.save_button.connect('clicked', self.save_profile) ### self.help_vbox = HIGVBox() self.help_label = HIGSectionLabel(_('Help')) self.help_scroll = HIGScrolledWindow() self.help_scroll.set_border_width(0) self.help_field = HIGTextView() self.help_field.set_cursor_visible(False) self.help_field.set_left_margin(5) self.help_field.set_editable(False) self.help_vbox.set_size_request(200, -1) ### def __pack_widgets(self): ### self.add(self.main_whole_box) # Packing command entry to upper box self.upper_box._pack_expand_fill(self.command_entry) self.upper_box._pack_noexpand_nofill(self.scan_button) # Packing notebook (left) and help box (right) to middle box self.middle_box._pack_expand_fill(self.notebook) self.middle_box._pack_expand_fill(self.help_vbox) # Packing buttons to lower box self.lower_box.pack_end(self.buttons_hbox) # Packing the three vertical boxes to the main box self.main_whole_box._pack_noexpand_nofill(self.upper_box) self.main_whole_box._pack_expand_fill(self.middle_box) self.main_whole_box._pack_noexpand_nofill(self.lower_box) ### # Packing profile information tab on notebook self.notebook.append_page( self.profile_info_vbox, gtk.Label(_('Profile'))) self.profile_info_vbox.set_border_width(5) table = HIGTable() self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label) self.profile_info_vbox._pack_expand_fill(HIGSpacer(table)) self.profile_description_scroll.add(self.profile_description_text) vbox_desc = HIGVBox() vbox_desc._pack_noexpand_nofill(self.profile_description_label) vbox_desc._pack_expand_fill(hig_box_space_holder()) vbox_ann = HIGVBox() vbox_ann._pack_expand_fill(hig_box_space_holder()) table.attach( self.profile_name_label, 0, 1, 0, 1, xoptions=0, yoptions=0) table.attach(self.profile_name_entry, 1, 2, 0, 1, yoptions=0) table.attach(vbox_desc, 0, 1, 1, 2, xoptions=0) table.attach(self.profile_description_scroll, 1, 2, 1, 2) # Packing buttons on button_hbox self.buttons_hbox._pack_expand_fill(hig_box_space_holder()) if self.deletable: self.buttons_hbox._pack_noexpand_nofill(self.delete_button) self.buttons_hbox._pack_noexpand_nofill(self.cancel_button) self.buttons_hbox._pack_noexpand_nofill(self.save_button) self.buttons_hbox.set_border_width(5) self.buttons_hbox.set_spacing(6) ### self.help_vbox._pack_noexpand_nofill(self.help_label) self.help_vbox._pack_expand_fill(self.help_scroll) self.help_scroll.add(self.help_field) self.help_vbox.set_border_width(1) self.help_vbox.set_spacing(1) ### def __create_tab(self, tab_name, section_name, tab): log.debug(">>> Tab name: %s" % tab_name) log.debug(">>>Creating profile editor section: %s" % section_name) vbox = HIGVBox() if tab.notscripttab: # if notscripttab is set table = HIGTable() table.set_row_spacings(2) section = HIGSectionLabel(section_name) vbox._pack_noexpand_nofill(section) vbox._pack_noexpand_nofill(HIGSpacer(table)) vbox.set_border_width(5) tab.fill_table(table, True) else: hbox = tab.get_hmain_box() vbox.pack_start(hbox, True, True, 0) self.notebook.append_page(vbox, gtk.Label(tab_name)) def save_profile(self, widget): if self.overwrite: self.profile.remove_profile(self.profile_name) profile_name = self.profile_name_entry.get_text() if profile_name == '': alert = HIGAlertDialog( message_format=_('Unnamed profile'), secondary_text=_( 'You must provide a name for this profile.')) alert.run() alert.destroy() self.profile_name_entry.grab_focus() return None command = self.ops.render_string() buf = self.profile_description_text.get_buffer() description = buf.get_text( buf.get_start_iter(), buf.get_end_iter()) try: self.profile.add_profile( profile_name, command=command, description=description) except ValueError: alert = HIGAlertDialog( message_format=_('Disallowed profile name'), secondary_text=_('Sorry, the name "%s" is not allowed due ' 'to technical limitations. (The underlying ' 'ConfigParser used to store profiles does not allow ' 'it.) Choose a different name.' % profile_name)) alert.run() alert.destroy() return self.scan_interface.toolbar.profile_entry.update() self.destroy() def clean_profile_info(self): self.profile_name_entry.set_text('') self.profile_description_text.get_buffer().set_text('') def set_scan_interface(self, interface): self.scan_interface = interface def exit(self, *args): self.destroy() def delete_profile(self, widget=None, extra=None): if self.deletable: dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>' + _("Deleting Profile") + '</b>') text = HIGEntryLabel(_( 'Your profile is going to be deleted! ClickOk to continue, ' 'or Cancel to go back to Profile Editor.')) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock( gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True self.profile.remove_profile(self.profile_name) self.update_profile_entry() self.destroy() def run_scan(self, widget=None): command_string = self.command_entry.get_text().decode("UTF-8") self.scan_interface.command_toolbar.command = command_string self.scan_interface.start_scan_cb() self.exit() def update_profile_entry(self, widget=None, extra=None): self.scan_interface.toolbar.profile_entry.update() list = self.scan_interface.toolbar.profile_entry.get_model() length = len(list) if length > 0: self.scan_interface.toolbar.profile_entry.set_active(0)
class CrashReport(HIGWindow): def __init__(self, summary, description): HIGWindow.__init__(self) gtk.Window.__init__(self) self.set_title(_('Crash Report')) self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.response_id = False self._create_widgets() self._pack_widgets() self._connect_widgets() self.summary = summary self.description = "\n----\n" + description def _create_widgets(self): self.vbox = HIGVBox() self.button_box = gtk.HButtonBox() self.email_label = gtk.Label(_("""\ An email address is optional. Sometimes we use it to get more information. If \ you provide an email address your report will be marked private so only \ project developers can read it.\ """)) self.email_entry = gtk.Entry() self.summary_entry = gtk.Entry() self.description_label = gtk.Label(_("\ What were you doing when the crash happened?\ ")) self.description_scrolled = gtk.ScrolledWindow() self.description_text = gtk.TextView() self.bug_text = gtk.Label(_("""\ An unhandled exception has crashed Zenmap. This dialog allows you to tell us \ what you did to cause the crash and help us to fix it. Submitting the report \ will open a description of the new bug at the bug tracker. Feel free to edit \ the report to remove any identifying information such as your home directory.\ """)) self.btn_ok = gtk.Button(stock=gtk.STOCK_OK) self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.hbox = HIGHBox() self.table = HIGTable() def _pack_widgets(self): self.description_label.set_line_wrap(True) self.description_label.set_alignment(0.0, 0.5) self.description_scrolled.add(self.description_text) self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.description_scrolled.set_size_request(400, 150) self.description_text.set_wrap_mode(gtk.WRAP_WORD) self.email_label.set_line_wrap(True) self.email_label.set_alignment(0.0, 0.5) self.bug_text.set_line_wrap(True) self.hbox.set_border_width(12) self.vbox.set_border_width(6) self.table.attach_label(gtk.Label(_("Summary")), 0, 1, 0, 1) self.table.attach_entry(self.summary_entry, 1, 2, 0, 1) self.table.attach_entry(self.description_label, 0, 2, 1, 2) self.table.attach_entry(self.description_scrolled, 0, 2, 2, 3) self.table.attach(self.email_label, 0, 2, 3, 4) self.table.attach_label(gtk.Label(_("Email")), 0, 1, 4, 5) self.table.attach_entry(self.email_entry, 1, 2, 4, 5) self.hbox._pack_expand_fill(self.bug_text) self.button_box.set_layout(gtk.BUTTONBOX_END) self.button_box.pack_start(self.btn_ok) self.button_box.pack_start(self.btn_cancel) self.vbox._pack_noexpand_nofill(self.hbox) self.vbox._pack_expand_fill(self.table) self.vbox._pack_noexpand_nofill(self.button_box) self.add(self.vbox) def _connect_widgets(self): self.btn_ok.connect("clicked", self.send_report) self.btn_cancel.connect("clicked", self.close) self.connect("delete-event", self.close) def send_report(self, widget): bug_register = BugRegister() description_text = self.description private = False if self.email != "": description_text += "\n\n" + self.email private = True report_url = bug_register.get_report_url(self.summary, description_text, private = private) # First we try reporting the bug with a web browser because that gives # better feedback on what happened. If that doesn't work try with # urllib2. try: webbrowser.open(report_url) except webbrowser.Error: try: urllib2.urlopen(report_url) ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO, message_format=_("Bug reported"), secondary_text=_("The bug was successfully reported.")) ok_dialog.run() ok_dialog.destroy() except urllib2.URLError, e: cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, message_format=_("Bug not reported"), secondary_text=_("This error occurred while trying to report the bug:\n\n" + str(e))) cancel_dialog.run() cancel_dialog.destroy() self.close()
class ProfileEditor(HIGWindow): def __init__(self, command=None, profile_name=None, deletable=True, overwrite=False): HIGWindow.__init__(self) self.connect("delete_event", self.exit) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.deletable = deletable self.profile_name = profile_name self.overwrite = overwrite # Used to block recursive updating of the command entry when the command # entry causes the OptionBuilder widgets to change. self.inhibit_command_update = False self.__create_widgets() self.__pack_widgets() self.profile = CommandProfile() self.ops = NmapOptions() if profile_name: log.debug("Showing profile %s" % profile_name) prof = self.profile.get_profile(profile_name) # Interface settings self.profile_name_entry.set_text(profile_name) self.profile_description_text.get_buffer().set_text(prof['description']) command_string = prof['command'] self.ops.parse_string(command_string) if command: self.ops.parse_string(command) self.option_builder = OptionBuilder(Path.profile_editor, self.ops, self.update_command, self.help_field.get_buffer()) log.debug("Option groups: %s" % str(self.option_builder.groups)) log.debug("Option section names: %s" % str(self.option_builder.section_names)) #log.debug("Option tabs: %s" % str(self.option_builder.tabs)) for tab in self.option_builder.groups: self.__create_tab(_(tab), _(self.option_builder.section_names[tab]), self.option_builder.tabs[tab]) self.update_command() def command_entry_changed_cb(self, widget): command_string = self.command_entry.get_text().decode("UTF-8") self.ops.parse_string(command_string) self.inhibit_command_update = True self.option_builder.update() self.inhibit_command_update = False def update_command(self): """Regenerate and display the command.""" if not self.inhibit_command_update: # Block recursive updating of the OptionBuilder widgets when they # cause a change in the command entry. self.command_entry.handler_block(self.command_entry_changed_cb_id) self.command_entry.set_text(self.ops.render_string()) self.command_entry.handler_unblock(self.command_entry_changed_cb_id) def update_help_name(self, widget, extra): self.help_field.get_buffer().set_text("Profile name\n\nThis is how the" +" profile will be identified in the drop-down combo box in the" +" scan tab.") def update_help_desc(self, widget, extra): self.help_field.get_buffer().set_text("Description\n\nThe description is a" + " full description of what the scan does, which may be long.") def __create_widgets(self): ### # Vertical box to keep 3 boxes self.main_whole_box = HIGVBox() self.upper_box = HIGHBox() self.middle_box = HIGHBox() self.lower_box = HIGHBox() #self.main_vbox = HIGVBox() self.command_entry = gtk.Entry() self.command_entry_changed_cb_id = \ self.command_entry.connect("changed", self.command_entry_changed_cb) self.scan_button = HIGButton(_("Scan")) self.scan_button.connect("clicked", self.run_scan) self.notebook = gtk.Notebook() # Profile info page self.profile_info_vbox = HIGVBox() self.profile_info_label = HIGSectionLabel(_('Profile Information')) self.profile_name_label = HIGEntryLabel(_('Profile name')) self.profile_name_entry = gtk.Entry() self.profile_name_entry.connect('enter-notify-event', self.update_help_name) self.profile_description_label = HIGEntryLabel(_('Description')) self.profile_description_scroll = HIGScrolledWindow() self.profile_description_scroll.set_border_width(0) self.profile_description_text = HIGTextView() self.profile_description_text.connect('motion-notify-event', self.update_help_desc) # Buttons self.buttons_hbox = HIGHBox() self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL) self.cancel_button.connect('clicked', self.exit) self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) self.delete_button.connect('clicked', self.delete_profile) self.save_button = HIGButton(_("Save Changes"), stock=gtk.STOCK_SAVE) self.save_button.connect('clicked', self.save_profile) ### self.help_vbox = HIGVBox() self.help_label = HIGSectionLabel(_('Help')) self.help_scroll = HIGScrolledWindow() self.help_scroll.set_border_width(0) self.help_field = HIGTextView() self.help_field.set_cursor_visible(False) self.help_field.set_left_margin(5) self.help_field.set_editable(False) self.help_vbox.set_size_request(200,-1) ### def __pack_widgets(self): ### self.add(self.main_whole_box) # Packing command entry to upper box self.upper_box._pack_expand_fill(self.command_entry) self.upper_box._pack_noexpand_nofill(self.scan_button) # Packing notebook (left) and help box (right) to middle box self.middle_box._pack_expand_fill(self.notebook) self.middle_box._pack_expand_fill(self.help_vbox) # Packing buttons to lower box self.lower_box.pack_end(self.buttons_hbox) # Packing the three vertical boxes to the main box self.main_whole_box._pack_noexpand_nofill(self.upper_box) self.main_whole_box._pack_expand_fill(self.middle_box) self.main_whole_box._pack_noexpand_nofill(self.lower_box) ### # Packing profile information tab on notebook self.notebook.append_page(self.profile_info_vbox, gtk.Label(_('Profile'))) self.profile_info_vbox.set_border_width(5) table = HIGTable() self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label) self.profile_info_vbox._pack_expand_fill(HIGSpacer(table)) self.profile_description_scroll.add(self.profile_description_text) vbox_desc = HIGVBox() vbox_desc._pack_noexpand_nofill(self.profile_description_label) vbox_desc._pack_expand_fill(hig_box_space_holder()) vbox_ann = HIGVBox() vbox_ann._pack_expand_fill(hig_box_space_holder()) table.attach(self.profile_name_label,0,1,0,1,xoptions=0,yoptions=0) table.attach(self.profile_name_entry,1,2,0,1,yoptions=0) table.attach(vbox_desc,0,1,1,2,xoptions=0) table.attach(self.profile_description_scroll,1,2,1,2) # Packing buttons on button_hbox self.buttons_hbox._pack_expand_fill(hig_box_space_holder()) if self.deletable: self.buttons_hbox._pack_noexpand_nofill(self.delete_button) self.buttons_hbox._pack_noexpand_nofill(self.cancel_button) self.buttons_hbox._pack_noexpand_nofill(self.save_button) self.buttons_hbox.set_border_width(5) self.buttons_hbox.set_spacing(6) ### self.help_vbox._pack_noexpand_nofill(self.help_label) self.help_vbox._pack_expand_fill(self.help_scroll) self.help_scroll.add(self.help_field) self.help_vbox.set_border_width(1) self.help_vbox.set_spacing(1) ### def __create_tab(self, tab_name, section_name, tab): log.debug(">>> Tab name: %s" % tab_name) log.debug(">>>Creating profile editor section: %s" % section_name) vbox = HIGVBox() if tab.notscripttab: # if notscripttab is set table = HIGTable() table.set_row_spacings(2) section = HIGSectionLabel(section_name) vbox._pack_noexpand_nofill(section) vbox._pack_noexpand_nofill(HIGSpacer(table)) vbox.set_border_width(5) tab.fill_table(table, True) else: hbox = tab.get_hmain_box() vbox.pack_start(hbox,True,True,0) self.notebook.append_page(vbox, gtk.Label(tab_name)) def save_profile(self, widget): if self.overwrite: self.profile.remove_profile(self.profile_name) profile_name = self.profile_name_entry.get_text() if profile_name == '': alert = HIGAlertDialog(message_format=_('Unnamed profile'),\ secondary_text=_('You must provide a name \ for this profile.')) alert.run() alert.destroy() self.profile_name_entry.grab_focus() return None command = self.ops.render_string() buf = self.profile_description_text.get_buffer() description = buf.get_text(buf.get_start_iter(),\ buf.get_end_iter()) try: self.profile.add_profile(profile_name,\ command=command,\ description=description) except ValueError: alert = HIGAlertDialog(message_format=_('Disallowed profile name'),\ secondary_text=_('Sorry, the name "%s" \ is not allowed due to technical limitations. (The underlying ConfigParser \ used to store profiles does not allow it.) Choose a different \ name.' % profile_name)) alert.run() alert.destroy() return self.scan_interface.toolbar.profile_entry.update() self.destroy() def clean_profile_info(self): self.profile_name_entry.set_text('') self.profile_description_text.get_buffer().set_text('') def set_scan_interface(self, interface): self.scan_interface = interface def exit(self, *args): self.destroy() def delete_profile(self, widget=None, extra=None): if self.deletable: dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>'+_("Deleting Profile")+'</b>') text = HIGEntryLabel(_('Your profile is going to be deleted! Click\ Ok to continue, or Cancel to go back to Profile Editor.')) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True self.profile.remove_profile(self.profile_name) self.update_profile_entry() self.destroy() def run_scan(self, widget=None): command_string = self.command_entry.get_text().decode("UTF-8") self.scan_interface.command_toolbar.command = command_string self.scan_interface.start_scan_cb() self.exit() def update_profile_entry(self, widget=None, extra=None): self.scan_interface.toolbar.profile_entry.update() list = self.scan_interface.toolbar.profile_entry.get_model() length = len(list) if length >0 : self.scan_interface.toolbar.profile_entry.set_active(0)
class CrashReport(HIGDialog): def __init__(self, type, value, tb): HIGDialog.__init__(self) gtk.Window.__init__(self) self.set_title(_('Crash Report')) self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self._create_widgets() self._pack_widgets() self._connect_widgets() trace = "".join(traceback.format_exception(type, value, tb)) text = "Version: " + VERSION + "\n" + trace self.description_text.get_buffer().set_text(text) def _create_widgets(self): self.button_box = gtk.HButtonBox() self.button_box_ok = gtk.HButtonBox() self.description_scrolled = gtk.ScrolledWindow() self.description_text = gtk.TextView() self.description_text.set_editable(False) self.bug_text = gtk.Label() self.bug_text.set_markup(_("""\ An unexpected error has crashed %(app_name)s. Please copy the stack trace below and \ send it to the <a href="mailto:[email protected]">[email protected]</a> \ mailing list. (<a href="http://seclists.org/nmap-dev/">More about the list.</a>) \ The developers will see your report and try to fix the problem.""") % \ { "app_name": escape(APP_DISPLAY_NAME) }) self.email_frame = gtk.Frame() self.email_label = gtk.Label() self.email_label.set_markup(_("""\ <b>Copy and email to <a href="mailto:[email protected]">[email protected]</a>:</b>\ """)) self.btn_copy = gtk.Button(stock=gtk.STOCK_COPY) self.btn_ok = gtk.Button(stock=gtk.STOCK_OK) self.hbox = HIGHBox() def _pack_widgets(self): self.description_scrolled.add(self.description_text) self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.description_scrolled.set_size_request(400, 150) self.description_text.set_wrap_mode(gtk.WRAP_WORD) self.bug_text.set_line_wrap(True) self.email_label.set_line_wrap(True) self.email_frame.set_label_widget(self.email_label) self.email_frame.set_shadow_type(gtk.SHADOW_NONE) self.hbox.set_border_width(6) self.vbox.set_border_width(6) self.hbox._pack_expand_fill(self.bug_text) self.button_box.set_layout(gtk.BUTTONBOX_START) self.button_box_ok.set_layout(gtk.BUTTONBOX_END) self.button_box.pack_start(self.btn_copy) self.button_box_ok.pack_start(self.btn_ok) self.vbox.pack_start(self.hbox) self.vbox.pack_start(self.email_frame) self.vbox.pack_start(self.description_scrolled) self.vbox.pack_start(self.button_box) self.action_area.pack_start(self.button_box_ok) def _connect_widgets(self): self.btn_ok.connect("clicked", self.close) self.btn_copy.connect("clicked", self.copy) self.connect("delete-event", self.close) def get_description(self): buff = self.description_text.get_buffer() return buff.get_text(buff.get_start_iter(), buff.get_end_iter()) def copy(self, widget=None, event=None): clipboard = gtk.clipboard_get() clipboard.set_text(self.get_description()) clipboard.store() def close(self, widget=None, event=None): self.destroy() gtk.main_quit() sys.exit(0)
def _exit_cb(self, *args): """Closes the window, prompting for confirmation if necessary. If one of the tabs couldn't be closed, the function returns True and doesn't exit the application.""" if self.scan_interface.changed: log.debug("Found changes on closing window") dialog = HIGDialog( buttons=(_('Close anyway').encode('utf-8'), gtk.RESPONSE_CLOSE, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>%s</b>' % _("Unsaved changes")) text = HIGEntryLabel(_("The given scan has unsaved changes.\n" "What do you want to do?")) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock( gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True search_config = SearchConfig() if search_config.store_results: self.store_result(self.scan_interface) elif self.scan_interface.num_scans_running() > 0: log.debug("Trying to close a window with a running scan") dialog = HIGDialog( buttons=(_('Close anyway').encode('utf-8'), gtk.RESPONSE_CLOSE, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>%s</b>' % _("Trying to close")) text = HIGEntryLabel(_( "The window you are trying to close has a scan running in " "the background.\nWhat do you want to do?")) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock( gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CLOSE: self.scan_interface.kill_all_scans() elif response == gtk.RESPONSE_CANCEL: return True window = WindowConfig() window.x, window.y = self.get_position() window.width, window.height = self.get_size() window.save_changes() if config_parser.failed: alert = HIGAlertDialog( message_format=_("Can't save Zenmap configuration"), # newline before path to help avoid weird line wrapping secondary_text=_( 'An error occurred when saving to\n%s' '\nThe error was: %s.' ) % (Path.user_config_file, config_parser.failed)) alert.run() alert.destroy() self.destroy() return False
class CrashReport(HIGWindow): def __init__(self, summary, description): HIGWindow.__init__(self) gtk.Window.__init__(self) self.set_title(_('Crash Report')) self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.response_id = False self._create_widgets() self._pack_widgets() self._connect_widgets() self.summary = summary self.description = description def _create_widgets(self): self.vbox = HIGVBox() self.button_box = gtk.HButtonBox() self.email_label = HIGHintSectionLabel(_("Email"), _("\ Optional. We occasionally contact the reporters of crashes in order to get \ more information.")) self.email_entry = gtk.Entry() self.description_label = gtk.Label(_("\ At the top of this form please write what you were doing when the crash \ happened, as well as any other information you think is relevant.")) self.description_scrolled = gtk.ScrolledWindow() self.description_text = gtk.TextView() self.bug_icon = gtk.Image() self.bug_text = gtk.Label(_("""\ This Bug Report dialog allows you to easily tell us about a problem that you \ may have found in %s. Doing so, you help us to help you, by fixing and \ improving %s faster than usual. Submitting the report will open a description \ of the new bug at the bug tracker.\ """ % (APP_DISPLAY_NAME, APP_DISPLAY_NAME))) self.btn_ok = gtk.Button(stock=gtk.STOCK_OK) self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.hbox = HIGHBox() self.table = HIGTable() def _pack_widgets(self): self.description_label.set_line_wrap(True) self.description_label.set_alignment(0.0, 0.5) self.description_scrolled.add(self.description_text) self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.description_scrolled.set_size_request(400, 150) self.description_text.set_wrap_mode(gtk.WRAP_WORD) self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG) self.bug_icon.set_padding(10, 0) self.bug_text.set_line_wrap(True) self.hbox.set_border_width(12) self.vbox.set_border_width(6) self.table.attach_label(self.email_label, 0, 1, 0, 1) self.table.attach_entry(self.email_entry, 1, 2, 0, 1) self.table.attach_entry(self.description_label, 0, 2, 1, 2) self.table.attach_entry(self.description_scrolled, 0, 2, 2, 3) self.hbox._pack_noexpand_nofill(self.bug_icon) self.hbox._pack_expand_fill(self.bug_text) self.button_box.set_layout(gtk.BUTTONBOX_END) self.button_box.pack_start(self.btn_ok) self.button_box.pack_start(self.btn_cancel) self.vbox._pack_noexpand_nofill(self.hbox) self.vbox._pack_expand_fill(self.table) self.vbox._pack_noexpand_nofill(self.button_box) self.add(self.vbox) def _connect_widgets(self): self.btn_ok.connect("clicked", self.send_report) self.btn_cancel.connect("clicked", self.close) self.connect("delete-event", self.close) def send_report(self, widget): bug_register = BugRegister() report_url = bug_register.get_report_url(self.summary, "%s\n\nEmail: %s" % (self.description, self.email)) # First we try reporting the bug with a web browser because that gives # better feedback on what happened. If that doesn't work try with # urllib2. try: webbrowser.open(report_url) except webbrowser.Error: try: urllib2.urlopen(report_url) ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO, message_format=_("Bug reported"), secondary_text=_("The bug was successfully reported.")) ok_dialog.run() ok_dialog.destroy() except urllib2.URLError, e: cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, message_format=_("Bug not reported"), secondary_text=_("This error occurred while trying to report the bug:\n\n" + str(e))) cancel_dialog.run() cancel_dialog.destroy() self.close()
class ProfileEditor(HIGWindow): def __init__(self, profile_name=None, deletable=True, overwrite=False): HIGWindow.__init__(self) self.connect("delete_event", self.exit) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.deletable = deletable self.profile_name = profile_name self.overwrite = overwrite self.__create_widgets() self.__pack_widgets() self.profile = CommandProfile() options_used = {} if profile_name: log.debug("Showing profile %s" % profile_name) prof = self.profile.get_profile(profile_name) options_used = prof['options'] # Interface settings self.profile_name_entry.set_text(profile_name) self.profile_description_text.get_buffer().set_text( prof['description']) self.constructor = CommandConstructor(options_used) ### self.profilehelp = ProfileHelp(options_used) ### self.options = OptionBuilder(Path.profile_editor, self.constructor, self.update_command, self.profilehelp) log.debug("Option groups: %s" % str(self.options.groups)) log.debug("Option section names: %s" % str(self.options.section_names)) #log.debug("Option tabs: %s" % str(self.options.tabs)) for tab in self.options.groups: self.__create_tab(tab, self.options.section_names[tab], self.options.tabs[tab]) self.update_command() def update_command(self): """Regenerate command with target '<target>' and set the value for the command entry""" self.command_entry.set_text(self.constructor.get_command('<target>')) ### whenever the command would be updated, thats when we update the help self.update_help() def update_help(self, text=None): helpText = self.help_field.get_buffer() if text: helpText.set_text(text) else: tempText = "" if self.profilehelp.get_currentstate() == "Default": helpText.set_text(" ") else: tempText += self.profilehelp.get_label() tempText += "\n\n" tempText += self.profilehelp.get_shortdesc() if self.profilehelp.get_example(): tempText += "\n\nExample input:\n" tempText += self.profilehelp.get_example() helpText.set_text(tempText) def update_help_name(self, widget, extra): self.update_help( text="Profile name\n\nThis is how the" + " profile will be identified in the drop-down combo box in the" + " scan tab.") def update_help_desc(self, widget, extra): self.update_help( text="Description\n\nThe description is a" + " full description of what the scan does, which may be long.") def help(self, widget): d = HIGAlertDialog( parent=self, message_format=_("Help not implemented"), secondary_text=_("Profile editor help is not implemented yet.")) d.run() d.destroy() def __create_widgets(self): ### # Vertical box to keep 3 boxes self.main_whole_box = HIGVBox() self.upper_box = HIGVBox() self.middle_box = HIGHBox() self.lower_box = HIGHBox() #self.main_vbox = HIGVBox() self.command_expander = HIGExpander('<b>' + _('Command') + '</b>') self.command_expander.set_expanded(True) self.command_entry = gtk.Entry() self.command_entry.set_editable(False) self.notebook = gtk.Notebook() # Profile info page self.profile_info_vbox = HIGVBox() self.profile_info_label = HIGSectionLabel(_('Profile Information')) self.profile_name_label = HIGEntryLabel(_('Profile name')) self.profile_name_entry = gtk.Entry() self.profile_name_entry.connect('enter-notify-event', self.update_help_name) self.profile_description_label = HIGEntryLabel(_('Description')) self.profile_description_scroll = HIGScrolledWindow() self.profile_description_scroll.set_border_width(0) self.profile_description_text = HIGTextView() self.profile_description_text.connect('motion-notify-event', self.update_help_desc) # Buttons self.buttons_hbox = HIGHBox() self.help_button = HIGButton(stock=gtk.STOCK_HELP) self.help_button.connect('clicked', self.help) self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL) self.cancel_button.connect('clicked', self.exit) self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) self.delete_button.connect('clicked', self.delete_profile) self.ok_button = HIGButton(stock=gtk.STOCK_OK) self.ok_button.connect('clicked', self.save_profile) ### self.help_vbox = HIGVBox() self.help_label = HIGSectionLabel(_('Help')) self.help_scroll = HIGScrolledWindow() self.help_scroll.set_border_width(0) self.help_field = HIGTextView() self.help_field.set_cursor_visible(False) self.help_field.set_left_margin(5) self.help_field.set_editable(False) self.help_vbox.set_size_request(200, -1) ### def __pack_widgets(self): ### self.add(self.main_whole_box) # Packing command expander to upper box self.upper_box._pack_noexpand_nofill(self.command_expander) # Packing notebook (left) and help box (right) to middle box self.middle_box._pack_expand_fill(self.notebook) self.middle_box._pack_expand_fill(self.help_vbox) # Packing buttons to lower box self.lower_box.pack_end(self.buttons_hbox) # Packing the three vertical boxes to the main box self.main_whole_box._pack_noexpand_nofill(self.upper_box) self.main_whole_box._pack_noexpand_nofill(self.middle_box) self.main_whole_box._pack_noexpand_nofill(self.lower_box) ### # Packing command_entry on command_expander self.command_expander.hbox.pack_start(self.command_entry) # Packing profile information tab on notebook self.notebook.append_page(self.profile_info_vbox, gtk.Label(_('Profile'))) self.profile_info_vbox.set_border_width(5) table = HIGTable() self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label) self.profile_info_vbox._pack_expand_fill(HIGSpacer(table)) self.profile_description_scroll.add(self.profile_description_text) vbox_desc = HIGVBox() vbox_desc._pack_noexpand_nofill(self.profile_description_label) vbox_desc._pack_expand_fill(hig_box_space_holder()) vbox_ann = HIGVBox() vbox_ann._pack_expand_fill(hig_box_space_holder()) table.attach(self.profile_name_label, 0, 1, 0, 1, xoptions=0, yoptions=0) table.attach(self.profile_name_entry, 1, 2, 0, 1, yoptions=0) table.attach(vbox_desc, 0, 1, 1, 2, xoptions=0) table.attach(self.profile_description_scroll, 1, 2, 1, 2) # Packing buttons on button_hbox #self.buttons_hbox.pack_start(self.help_button) self.buttons_hbox._pack_expand_fill(hig_box_space_holder()) if self.deletable: self.buttons_hbox._pack_noexpand_nofill(self.delete_button) self.buttons_hbox._pack_noexpand_nofill(self.cancel_button) self.buttons_hbox._pack_noexpand_nofill(self.ok_button) self.buttons_hbox.set_border_width(5) self.buttons_hbox.set_spacing(6) ### self.help_vbox._pack_noexpand_nofill(self.help_label) self.help_vbox._pack_expand_fill(self.help_scroll) self.help_scroll.add(self.help_field) self.help_vbox.set_border_width(1) self.help_vbox.set_spacing(1) ### def __create_tab(self, tab_name, section_name, tab): log.debug(">>> Tab name: %s" % tab_name) log.debug(">>>Creating profile editor section: %s" % section_name) vbox = HIGVBox() table = HIGTable() table.set_row_spacings(2) section = HIGSectionLabel(section_name) vbox._pack_noexpand_nofill(section) vbox._pack_noexpand_nofill(HIGSpacer(table)) vbox.set_border_width(5) tab.fill_table(table, True) self.notebook.append_page(vbox, gtk.Label(tab_name)) def save_profile(self, widget): if self.overwrite: self.profile.remove_profile(self.profile_name) profile_name = self.profile_name_entry.get_text() if profile_name == '': alert = HIGAlertDialog(message_format=_('Unnamed profile'),\ secondary_text=_('You must provide a name \ for this profile.' )) alert.run() alert.destroy() self.profile_name_entry.grab_focus() return None command = self.constructor.get_command('%s') buf = self.profile_description_text.get_buffer() description = buf.get_text(buf.get_start_iter(),\ buf.get_end_iter()) self.profile.add_profile(profile_name,\ command=command,\ description=description,\ options=self.constructor.get_options()) self.scan_interface.toolbar.profile_entry.update() self.scan_interface.refresh_command(None) self.destroy() def clean_profile_info(self): self.profile_name_entry.set_text('') self.profile_description_text.get_buffer().set_text('') def set_scan_interface(self, interface): self.scan_interface = interface def exit(self, *args): self.destroy() def delete_profile(self, widget=None, extra=None): if self.deletable: dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) alert = HIGEntryLabel('<b>' + _("Deleting Profile") + '</b>') text = HIGEntryLabel( _('Your profile is going to be deleted! Click\ Ok to continue, or Cancel to go back to Profile Editor.')) hbox = HIGHBox() hbox.set_border_width(5) hbox.set_spacing(12) vbox = HIGVBox() vbox.set_border_width(5) vbox.set_spacing(12) image = gtk.Image() image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) vbox.pack_start(alert) vbox.pack_start(text) hbox.pack_start(image) hbox.pack_start(vbox) dialog.vbox.pack_start(hbox) dialog.vbox.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_CANCEL: return True self.profile.remove_profile(self.profile_name) self.update_profile_entry() self.destroy() def update_profile_entry(self, widget=None, extra=None): self.scan_interface.toolbar.profile_entry.update() list = self.scan_interface.toolbar.profile_entry.get_model() length = len(list) if length > 0: self.scan_interface.toolbar.profile_entry.set_active(0)
class DiffText(HIGVBox, object): def __init__ (self, colors, check_color): HIGVBox.__init__(self) self.set_border_width(5) self.set_spacing(6) self.colors = colors self.check_color = check_color self._create_widgets() self._pack_hbox() self._set_text_view() self._set_scrolled() self._pack_noexpand_nofill(self.lbl_diff) self._pack_expand_fill(self.hbox) def _create_widgets (self): self.hbox = HIGHBox () self.lbl_diff = HIGSectionLabel ("<b>%s</b>" % _("Diff Result")) self.scrolled = gtk.ScrolledWindow() self.txt_diff_result = gtk.TextView() self.txg_tag = gtk.TextTag ("diff_style") self.txg_added = gtk.TextTag ('added style') self.txg_removed = gtk.TextTag ('removed style') def _pack_hbox (self): self.hbox.set_border_width(5) self.hbox._pack_noexpand_nofill (hig_box_space_holder()) self.hbox._pack_expand_fill(self.scrolled) def _set_scrolled (self): self.scrolled.set_size_request(-1, 250) # Packing text view into scrolled window self.scrolled.add_with_viewport(self.txt_diff_result) # Setting scrolled window self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) def set_text(self, text): """Set the raw diff text of this diff view.""" self.txt_diff_result.get_buffer().set_text(text) def clear(self): """Make this diff view empty.""" self.set_text("") def activate_color(self, activate): self.check_color = activate self._refresh() def _set_text_view(self): self.txg_table = self.txt_diff_result.get_buffer().get_tag_table() self.txg_table.add(self.txg_tag) self.txg_table.add(self.txg_added) self.txg_table.add(self.txg_removed) self.txg_tag.set_property("family", "Monospace") self.txg_added.set_property("background-gdk", self.colors.added) self.txg_removed.set_property("background-gdk", self.colors.not_present) self.txt_diff_result.set_wrap_mode(gtk.WRAP_WORD) self.txt_diff_result.set_editable(False) self.txt_diff_result.get_buffer().connect("changed", self._refresh) def _refresh(self, *args): self.txg_added.set_property("background-gdk", self.colors.added) self.txg_removed.set_property("background-gdk", self.colors.not_present) buff = self.txt_diff_result.get_buffer() buff.apply_tag(self.txg_tag, buff.get_start_iter(), buff.get_end_iter()) if self.check_color: positions = self._take_changes(buff) for i in positions['added']: buff.apply_tag(self.txg_added, i[0],i[1]) for i in positions['removed']: buff.apply_tag(self.txg_removed, i[0], i[1]) else: buff.remove_tag(self.txg_added, buff.get_start_iter (), buff.get_end_iter()) buff.remove_tag(self.txg_removed, buff.get_start_iter (), buff.get_end_iter()) def _take_changes (self, buffer): positions = {'added':[], 'removed':[]} in_line = 0 type = '' iter = buffer.get_start_iter () last_char = '\n' while iter.forward_char(): char = iter.get_char () offset = iter.get_offset() if not in_line: pos = [] if char == '+' and last_char == '\n': pos.append (buffer.get_iter_at_offset(offset)) type = 'added' in_line = 1 elif char == '-' and last_char == '\n': pos.append (buffer.get_iter_at_offset(offset)) type = 'removed' in_line = 1 else: if char == '\n': pos.append (buffer.get_iter_at_offset(offset)) positions [type].append (pos) in_line = 0 type = '' last_char = char return positions