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 _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
def _save_scan_results_cb(self, widget): """'Save Scan' callback function. If it's OK to save the scan, it displays a 'Save File' dialog and saves the scan. If not, it displays an appropriate alert dialog.""" num_scans = len(self.scan_interface.inventory.get_scans()) if num_scans == 0: alert = HIGAlertDialog( message_format=_('Nothing to save'), secondary_text=_( 'There are no scans with results to be saved. ' 'Run a scan with the "Scan" button first.')) alert.run() alert.destroy() return num_scans_running = self.scan_interface.num_scans_running() if num_scans_running > 0: if num_scans_running == 1: text = _("There is a scan still running. " "Wait until it finishes and then save.") else: text = _("There are %u scans still running. Wait until they " "finish and then save.") % num_scans_running alert = HIGAlertDialog(message_format=_('Scan is running'), secondary_text=text) alert.run() alert.destroy() return # If there's more than one scan in the inventory, display a warning # dialog saying that only the most recent scan will be saved selected = 0 if num_scans > 1: #text = _("You have %u scans loaded in the current view. " # "Only the most recent scan will be saved." % num_scans) #alert = HIGAlertDialog( # message_format=_("More than one scan loaded"), # secondary_text=text) #alert.run() #alert.destroy() dlg = HIGDialog( title="Choose a scan to save", parent=self, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) dlg.vbox.pack_start(gtk.Label( "You have %u scans loaded in the current view.\n" "Select the scan which you would like to save." % num_scans), False) scan_combo = gtk.combo_box_new_text() for scan in self.scan_interface.inventory.get_scans(): scan_combo.append_text(scan.nmap_command) scan_combo.set_active(0) dlg.vbox.pack_start(scan_combo, False) dlg.vbox.show_all() if dlg.run() == gtk.RESPONSE_OK: selected = scan_combo.get_active() dlg.destroy() else: dlg.destroy() return # Show the dialog to choose the path to save scan result self._save_results_filechooser_dialog = \ SaveResultsFileChooserDialog(title=_('Save Scan')) # Supply a default file name if this scan was previously saved. if self.scan_interface.saved_filename: self._save_results_filechooser_dialog.set_filename( self.scan_interface.saved_filename) response = self._save_results_filechooser_dialog.run() filename = None if (response == gtk.RESPONSE_OK): filename = self._save_results_filechooser_dialog.get_filename() format = self._save_results_filechooser_dialog.get_format() # add .xml to filename if there is no other extension if filename.find('.') == -1: filename += ".xml" self._save(self.scan_interface, filename, selected, format) self._save_results_filechooser_dialog.destroy() self._save_results_filechooser_dialog = None