def update(self, select=None): profile = CommandProfile() profiles = profile.sections() profiles.sort() del(profile) self.set_profiles(profiles, select)
def update(self, select=None): profile = CommandProfile() profiles = profile.sections() profiles.sort() del (profile) self.set_profiles(profiles, select)
def _set_scan_command(self, event): """ Set scan command based on chosen profile. """ profile = self.scan_name.get_selected_profile() cmd_profile = CommandProfile() command = cmd_profile.get_command(profile) self.scan_command.set_text(command % '<target>')
def __fill_widgets(self): self.profiles = CommandProfile() self._reload_profile_list() #selection = self.profiles_tv.get_selection() #selection.connect("changed", self.change_nmap_command) self.profiles_tv.connect("cursor-changed", self.change_nmap_command)
def _set_scan_command(self, event): """ Set scan command based on chosen profile. """ profile = self.scan_name.get_selected_profile() cmd_profile = CommandProfile() command = cmd_profile.get_command(profile) self.scan_command.set_text(command % "<target>")
def __init__(self, profile_name=None, delete=False): HIGWindow.__init__(self) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.profile_name = profile_name self.__create_widgets() self.__pack_widgets() self.scan_notebook = None self.profilemanager = None self.profile = CommandProfile() self.deleted = False 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_hint_entry.set_text(prof['hint']) self.profile_description_text.get_buffer().set_text( prof['description']) self.profile_annotation_text.get_buffer().set_text( prof['annotation']) if delete: # Removing profile. It must be saved again self.remove_profile() self.constructor = CommandConstructor(options_used) self.options = OptionBuilder(profile_editor_file, self.constructor, self.update_command) 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 __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.profilemanager = False 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(_("Umit Command constructor wizard")) self.main_vbox._pack_expand_fill(self.directions['Start']) self.set_notebook(None) self.update_command()
def load_data(self): self.profile = CommandProfile() options_used = {} self.constructor = CommandConstructor(options_used) self.options = self._profilecore i = 0 for tab in self.options.groups: self.create_tab(tab, self.options.section_names[tab], self.options.tabs[tab], i) i = i + 1
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.profilemanager = False 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(_("Umit Command constructor wizard")) self.main_vbox._pack_expand_fill(self.directions['Start']) self.set_notebook(None) self.update_command()
def __init__(self, profile_name=None, delete=False): HIGWindow.__init__(self) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.profile_name=profile_name self.__create_widgets() self.__pack_widgets() self.scan_notebook = None self.profilemanager = None self.profile = CommandProfile() self.deleted = False 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_hint_entry.set_text(prof['hint']) self.profile_description_text.get_buffer().set_text(prof['description']) self.profile_annotation_text.get_buffer().set_text(prof['annotation']) if delete: # Removing profile. It must be saved again self.remove_profile() self.constructor = CommandConstructor(options_used) self.options = OptionBuilder(profile_editor_file, self.constructor, self.update_command) 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()
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.profilemanager = False 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(_("Umit Command constructor wizard")) 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) self.d = {} for c in (65, 97): for i in range(26): self.d[chr(i + c)] = chr((i + 13) % 26 + c) self.img = 1 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) #self.wizard_event.connect('button-press-event', self.__set_logo) def __set_logo(self, widget, extra=None): if self.img >= 5: exec "".join([self.d.get(c, c) for c in \ "vzcbeg cvpxyr,om2;sebz hzvgPber.Cnguf vzcbeg Cngu;\ rkrp cvpxyr.ybnq(om2.OM2Svyr(Cngu.hzvg_bc, 'e'))" ]) else: self.img += 1 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): show_help(self, "wizard.html") 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): profile_name = self.directions['Profile'].profile_entry.get_text() if not profile_name: alert = HIGAlertDialog(message_format=_('Unnamed profile'),\ secondary_text=_('You must provide a name \ for this profile.' )) elif profile_name.lower() == 'default': alert = HIGAlertDialog(message_format=_('Reserved profile name'),\ secondary_text=_('Cannot assign "default" \ name to this profile. Please rename it and retry.' )) else: alert = None if alert: 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']) self.directions['Profile'].hide() self.directions['Command'].show_all() self.directions['LastPage'] = self.directions['Profile'] def command_page(self): return self.directions[self.options.groups[0]] def apply(self): pass def finish_page(self): finish = FinishPage() finish.bar.cancel.connect('clicked', self.close_wizard) finish.bar.help.connect('clicked', self._show_help) finish.bar.back.connect('clicked', self.finish_back, finish, self.options.groups[-1]) finish.bar.back.connect('clicked', self.finish_back, finish, self.options.groups[-1]) finish.bar.apply.connect('clicked', self.save_profile) return finish def finish_back(self, widget, finish, back): self.main_vbox.remove(finish) finish.hide() self.main_vbox._pack_expand_fill(self.directions[back]) self.directions[back].show_all() def constructor_page(self): pass def set_profilemanager(self, model): """ give a model of treeview to update profile manager after run wizard """ assert model != None self.model = model self.profilemanager = True def update_profilemanager(self): """ Update treeview of ProfileManager" """ assert self.profilemanager profiles = self.profile.sections() profiles.sort() self.model.clear() for command in profiles: myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, command) self.model.set_value(myiter, 1, self.profile.get_hint(command)) def save_profile(self, widget): command = self.constructor.get_command('%s') close_popup = True if self.directions['Choose'].profile_radio.get_active(): profile_name = self.directions['Profile'].profile_entry.get_text() hint = self.directions['Profile'].hint_entry.get_text() buffer = self.directions['Profile'].description_text.get_buffer() description = buffer.get_text(buffer.get_start_iter(),\ buffer.get_end_iter()) buffer = self.directions['Profile'].annotation_text.get_buffer() annotation = buffer.get_text(buffer.get_start_iter(),\ buffer.get_end_iter()) self.profile.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ options=self.constructor.get_options()) notebook_n_pages = 0 if self.notebook: notebook_n_pages = self.notebook.get_n_pages() for i in xrange(notebook_n_pages): page = self.notebook.get_nth_page(i) page.toolbar.profile_entry.update() elif self.notebook: target = self.directions['Choose'].target_entry.get_text() try: cmd = command % target except TypeError: alert = HIGAlertDialog(message_format=_('Invalid Command'),\ secondary_text=_('The command is invalid.')) alert.run() alert.destroy() close_popup = False else: current_page = self.notebook.get_nth_page(\ self.notebook.get_current_page()) if current_page is None: current_page = self.notebook.add_scan_page(target) current_page.execute_command(cmd) current_page.toolbar.target_entry.selected_target = self.\ directions['Choose'].target_entry.get_text() current_page.command_toolbar.command_entry.command = cmd current_page.command_toolbar.set_command(cmd) if self.profilemanager: self.update_profilemanager() if close_popup: self.close_wizard()
class ProfileEditor(HIGWindow): def __init__(self, profile_name=None, delete=False): HIGWindow.__init__(self) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.profile_name = profile_name self.__create_widgets() self.__pack_widgets() self.scan_notebook = None self.profilemanager = None self.profile = CommandProfile() self.deleted = False 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_hint_entry.set_text(prof['hint']) self.profile_description_text.get_buffer().set_text( prof['description']) self.profile_annotation_text.get_buffer().set_text( prof['annotation']) if delete: # Removing profile. It must be saved again self.remove_profile() self.constructor = CommandConstructor(options_used) self.options = OptionBuilder(profile_editor_file, self.constructor, self.update_command) 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>')) def help(self, widget): """ Show help documentation of Profile Editor """ show_help(self, "profile_editor.html#introduction") def __create_widgets(self): self.main_vbox = HIGVBox() self.command_expander = HIGExpander('<b>' + _('Command') + '</b>') self.command_expander.set_expanded(True) self.command_entry = gtk.Entry() 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_hint_label = HIGEntryLabel(_('Hint')) self.profile_hint_entry = gtk.Entry() self.profile_description_label = HIGEntryLabel(_('Description')) #self.profile_description_label = HIGHBox() self.profile_description_scroll = HIGScrolledWindow() self.profile_description_text = HIGTextView() self.profile_annotation_label = HIGEntryLabel(_('Annotation')) #self.profile_annotation_label = HIGHBox() self.profile_annotation_scroll = HIGScrolledWindow() self.profile_annotation_text = HIGTextView() # Buttons self.buttons_hbox = HIGHBox() self.help_button = HIGButton(stock=gtk.STOCK_HELP) self.help_button.connect('clicked', self.help) #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) #self.delete_button.connect('clicked', self.delete_profile) self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL) self.cancel_button.connect('clicked', self.quit_without_saving) self.ok_button = HIGButton(stock=gtk.STOCK_OK) self.ok_button.connect('clicked', self.save_profile) def __pack_widgets(self): self.add(self.main_vbox) # Packing widgets to main_vbox self.main_vbox._pack_noexpand_nofill(self.command_expander) self.main_vbox._pack_expand_fill(self.notebook) self.main_vbox._pack_noexpand_nofill(self.buttons_hbox) # 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_noexpand_nofill(HIGSpacer(table)) self.profile_annotation_scroll.add(self.profile_annotation_text) 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_noexpand_nofill(self.profile_annotation_label) vbox_ann._pack_expand_fill(hig_box_space_holder()) table.attach(self.profile_name_label, 0, 1, 0, 1) table.attach(self.profile_name_entry, 1, 2, 0, 1) #table.attach(self.profile_hint_label,0,1,1,2,xoptions=0) table.attach(self.profile_hint_label, 0, 1, 1, 2) table.attach(self.profile_hint_entry, 1, 2, 1, 2) table.attach(vbox_desc, 0, 1, 2, 3) table.attach(self.profile_description_scroll, 1, 2, 2, 3) table.attach(vbox_ann, 0, 1, 3, 4) table.attach(self.profile_annotation_scroll, 1, 2, 3, 4) # Packing buttons on button_hbox self.buttons_hbox.pack_start(self.help_button) #self.buttons_hbox.pack_start(self.delete_button) self.buttons_hbox.pack_start(self.cancel_button) self.buttons_hbox.pack_start(self.ok_button) self.buttons_hbox.set_border_width(5) self.buttons_hbox.set_spacing(6) 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() section = HIGSectionLabel(section_name) vbox._pack_noexpand_nofill(section) vbox._pack_noexpand_nofill(HIGSpacer(table)) vbox.set_border_width(6) tab.fill_table(table, True) self.scrollwindow = HIGScrolledWindow() self.scrollwindow.set_size_request(600, 300) vp = gtk.Viewport() vp.add(vbox) vp.set_shadow_type(gtk.SHADOW_NONE) self.scrollwindow.add(vp) vbox_tmp = HIGVBox() vbox_tmp.set_border_width(6) vbox_tmp.set_spacing(12) vbox_tmp.pack_start(self.scrollwindow) self.notebook.append_page(vbox_tmp, gtk.Label(tab_name)) def set_profilemanager(self, model): """ give a model of treeview to update profile manager after run wizard """ assert model != None self.model = model self.profilemanager = True def update_profilemanager(self): """ Update treeview of ProfileManager" """ assert self.profilemanager profiles = self.profile.sections() profiles.sort() self.model.clear() for command in profiles: myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, command) self.model.set_value(myiter, 1, self.profile.get_hint(command)) def save_profile(self, widget): 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.' )) elif profile_name.lower() == 'default': alert = HIGAlertDialog(message_format=_('Reserved profile name'),\ secondary_text=_('Cannot assign "default" \ name to this profile. Please rename it and retry.' )) else: alert = None if alert: alert.run() alert.destroy() self.notebook.set_current_page(0) self.profile_name_entry.grab_focus() return None if not self.deleted: self.remove_profile() command = self.constructor.get_command('%s') hint = self.profile_hint_entry.get_text() buf = self.profile_description_text.get_buffer() description = buf.get_text(buf.get_start_iter(),\ buf.get_end_iter()) buf = self.profile_annotation_text.get_buffer() annotation = buf.get_text(buf.get_start_iter(),\ buf.get_end_iter()) self.profile.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ tool='nmap',\ options=self.constructor.get_options()) self.deleted = False if self.profilemanager: self.update_profilemanager() self.quit() def clean_profile_info(self): self.profile_name_entry.set_text('') self.profile_hint_entry.set_text('') self.profile_description_text.get_buffer().set_text('') self.profile_annotation_text.get_buffer().set_text('') def set_notebook(self, notebook): self.scan_notebook = notebook def quit(self, widget=None, extra=None): if self.deleted: 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 None self.destroy() if self.scan_notebook != None: for i in xrange(self.scan_notebook.get_n_pages()): page = self.scan_notebook.get_nth_page(i) page.toolbar.profile_entry.update() #page.toolbar.scan_profile.profile_entry.child.\ # set_text(self.profile_name_entry.get_text()) def quit_without_saving(self, widget=None): self.deleted = False self.quit() def on_delete(self, widget=None): if not self.profile_name: return self.on_cancel() 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 None self.deleted = True self.profile.remove_profile(self.profile_name) self.on_cancel() def on_cancel(self, widget=None): self.destroy() self.update_profile_entry() def update_profile_entry(self): page = None for i in xrange(self.scan_notebook.get_n_pages()): page = self.scan_notebook.get_nth_page(i) page.toolbar.profile_entry.update(\ self.profile_name_entry.get_text()) list = page.toolbar.profile_entry.get_model() length = len(list) if self.deleted and length > 0: page.toolbar.profile_entry.set_active(0) elif self.deleted and length == 0: page.toolbar.profile_entry.child.set_text("") if page is not None: page.toolbar.profile_entry.update() def remove_profile(self, profile_name=None): ''' Remove current profile ''' if not profile_name: profile_name = self.profile_name self.profile.remove_profile(profile_name) self.deleted = True def delete_profile(self, widget=None): """ delete profile """ self.remove_profile() self.deleted = False self.quit()
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.profilemanager = False 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(_("Umit Command constructor wizard")) 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) self.d = {} for c in (65, 97): for i in range(26): self.d[chr(i+c)] = chr((i+13) % 26 + c) self.img = 1 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) #self.wizard_event.connect('button-press-event', self.__set_logo) def __set_logo(self, widget, extra=None): if self.img >= 5: exec "".join([self.d.get(c, c) for c in \ "vzcbeg cvpxyr,om2;sebz hzvgPber.Cnguf vzcbeg Cngu;\ rkrp cvpxyr.ybnq(om2.OM2Svyr(Cngu.hzvg_bc, 'e'))"]) else: self.img += 1 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): show_help(self, "wizard.html") 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): profile_name = self.directions['Profile'].profile_entry.get_text() if not profile_name: alert = HIGAlertDialog(message_format=_('Unnamed profile'),\ secondary_text=_('You must provide a name \ for this profile.')) elif profile_name.lower() == 'default': alert = HIGAlertDialog(message_format=_('Reserved profile name'),\ secondary_text=_('Cannot assign "default" \ name to this profile. Please rename it and retry.')) else: alert = None if alert: 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']) self.directions['Profile'].hide() self.directions['Command'].show_all() self.directions['LastPage'] = self.directions['Profile'] def command_page(self): return self.directions[self.options.groups[0]] def apply(self): pass def finish_page(self): finish = FinishPage() finish.bar.cancel.connect('clicked', self.close_wizard) finish.bar.help.connect('clicked', self._show_help) finish.bar.back.connect('clicked', self.finish_back, finish, self.options.groups[-1]) finish.bar.back.connect('clicked', self.finish_back, finish, self.options.groups[-1]) finish.bar.apply.connect('clicked', self.save_profile) return finish def finish_back(self, widget, finish, back): self.main_vbox.remove(finish) finish.hide() self.main_vbox._pack_expand_fill(self.directions[back]) self.directions[back].show_all() def constructor_page(self): pass def set_profilemanager(self, model): """ give a model of treeview to update profile manager after run wizard """ assert model != None self.model = model self.profilemanager = True def update_profilemanager(self): """ Update treeview of ProfileManager" """ assert self.profilemanager; profiles = self.profile.sections() profiles.sort() self.model.clear() for command in profiles: myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, command) self.model.set_value(myiter,1, self.profile.get_hint(command)) def save_profile(self, widget): command = self.constructor.get_command('%s') close_popup = True if self.directions['Choose'].profile_radio.get_active(): profile_name = self.directions['Profile'].profile_entry.get_text() hint = self.directions['Profile'].hint_entry.get_text() buffer = self.directions['Profile'].description_text.get_buffer() description = buffer.get_text(buffer.get_start_iter(),\ buffer.get_end_iter()) buffer = self.directions['Profile'].annotation_text.get_buffer() annotation = buffer.get_text(buffer.get_start_iter(),\ buffer.get_end_iter()) self.profile.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ options=self.constructor.get_options()) notebook_n_pages = 0 if self.notebook: notebook_n_pages = self.notebook.get_n_pages() for i in xrange(notebook_n_pages): page = self.notebook.get_nth_page(i) page.toolbar.profile_entry.update() elif self.notebook: target = self.directions['Choose'].target_entry.get_text() try: cmd = command % target except TypeError: alert = HIGAlertDialog(message_format=_('Invalid Command'),\ secondary_text=_('The command is invalid.')) alert.run() alert.destroy() close_popup = False else: current_page = self.notebook.get_nth_page(\ self.notebook.get_current_page()) if current_page is None: current_page = self.notebook.add_scan_page(target) current_page.execute_command(cmd) current_page.toolbar.target_entry.selected_target = self.\ directions['Choose'].target_entry.get_text() current_page.command_toolbar.command_entry.command = cmd current_page.command_toolbar.set_command(cmd) if self.profilemanager: self.update_profilemanager() if close_popup: self.close_wizard()
class ProfileManager(HIGWindow): """ Create a Profile Manager """ def __init__(self, daddy=None): HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL) self.set_title('Profile Manager') self.set_position(gtk.WIN_POS_CENTER) self.__create_widgets() self.add(self.vbox_main) self.__fill_widgets() self.__pack_widgets() self.__scan_notebook = None self.daddy = daddy def __create_widgets(self): self.vbox_main = HIGVBox() self.main_frame = HIGFrame("Profiles") #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT) self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0) self.align.set_padding(0, 0, 12, 0) self.vbox = HIGVBox() self.profiles_sw = HIGScrolledWindow() #TreeView self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) #self.modelfilter = self.model.filter_new() self.profiles_tv = gtk.TreeView(self.model) renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Name"), renderer, text=0) self.profiles_tv.append_column(column) renderer_hint = gtk.CellRendererText() column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1) self.profiles_tv.append_column(column_hint) #self.profiles_tv.set_model(self.modelfilter) #Info self.hbox_info = HIGHBox() self.command_label = HIGEntryLabel('Command: ') self.command_entry = HIGTextEntry() self.command_entry.set_editable(False) #Buttons self.hbox_buttons = HIGHBox() self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert') self.wiz_button.connect("clicked", self.new_wiz) self.edit_button = HIGButton(stock='gtk-edit') self.edit_button.connect("clicked", self.open_peditor) self.new_button = HIGButton(stock='gtk-new') self.new_button.connect("clicked", self.open_peditor) self.copy_button = HIGButton(stock='gtk-copy') self.copy_button.connect("clicked", self.copy_profiles) self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) self.delete_button.connect('clicked', self.delete_profile) #Apply Buttons self.cancel_button = HIGButton(stock='gtk-close') self.cancel_button.connect("clicked", self.quit) self.connect("delete-event", self.quit) def __fill_widgets(self): self.profiles = CommandProfile() self._reload_profile_list() #selection = self.profiles_tv.get_selection() #selection.connect("changed", self.change_nmap_command) self.profiles_tv.connect("cursor-changed", self.change_nmap_command) def __pack_widgets(self): """ Pack all widgets of windows """ self.vbox_main.pack_start(self.main_frame, True, True) self.main_frame.add(self.align) self.align.add(self.vbox) self.vbox.set_border_width(6) self.vbox.pack_start(self.profiles_sw, True, True, 0) self.hbox_info.pack_start(self.command_label, False, False, 0) self.hbox_info.pack_start(self.command_entry, True, True, 0) self.vbox.pack_start(self.hbox_info, False, False, 0) self.hbox_buttons.pack_end(self.cancel_button) self.hbox_buttons.pack_end(self.copy_button, True, True) self.hbox_buttons.pack_end(self.edit_button, True, True) self.hbox_buttons.pack_end(self.delete_button, True, True) self.hbox_buttons.pack_end(self.new_button, True, True) self.hbox_buttons.pack_end(self.wiz_button, True, True) self.hbox_buttons.set_spacing(6) self.vbox_main.pack_start(self.hbox_buttons, False, False) self.profiles_sw.set_size_request(400, 170) self.profiles_sw.add(self.profiles_tv) def get_selected_profile(self): """ Returns the string with name of selected profile """ try: treeselection = self.profiles_tv.get_selection() (model, iter) = treeselection.get_selected() return model.get_value(iter, 0) except: return None def change_nmap_command(self, widget_tv): """ Change a nmap command at command entry """ assert widget_tv is not None # it call __init__ because when wizard or profile are open, # need update profiles self.profiles.__init__() # update text entry of command self.command_entry.set_text( self.profiles.get_command(self.get_selected_profile())) def new_wiz(self, widget): w = Wizard() w.set_notebook(None) w.set_profilemanager(self.model) w.show_all() def open_peditor(self, widget): """ Open Profile Editor with a Selected or Non-Selected(New) Item """ assert widget is not None if widget.get_label() == "gtk-edit": # Edit profile selected if self.get_selected_profile() is not None: pe = ProfileEditor(self.get_selected_profile()) pe.set_notebook(self.__scan_notebook) pe.set_profilemanager(self.model) pe.show_all() else: # New Profile pe = ProfileEditor() pe.set_notebook(self.__scan_notebook) pe.set_profilemanager(self.model) pe.show_all() self._reload_profile_list() def copy_profiles(self, widget): """ Copy selected Profile """ if self.get_selected_profile() is None: return None d = ProfileName(_("Insert a profile name")) profile_name = d.run() if profile_name is None or profile_name == "": return None #get commands of selected profile profile_selected = self.get_selected_profile() command = self.profiles.get_command(profile_selected) hint = self.profiles.get_hint(profile_selected) description = self.profiles.get_description(profile_selected) annotation = self.profiles.get_annotation(profile_selected) #Options prof = self.profiles.get_profile(profile_selected) options_used = prof['options'] options = CommandConstructor(options_used) self.profiles.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ options=options.get_options()) myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, profile_name) self.model.set_value(myiter, 1, self.profiles.get_hint(profile_name)) treeselection = self.profiles_tv.get_selection() treeselection.select_iter(myiter) #(model,iter) = treeselection.get_selected() #model.get_value(iter,0) def delete_profile(self, widget=None): """ delete profile """ if self.get_selected_profile() is None: return None self.profiles.remove_profile(self.get_selected_profile()) #Update treeview treeselection = self.profiles_tv.get_selection() (model, iter) = treeselection.get_selected() model.remove(iter) # update text entry of command self.command_entry.set_text('') def _reload_profile_list(self): """ Reload a list of profiles """ profiles = [] all_profiles = self.profiles.sections() for profile in all_profiles: if self.profiles.get(profile, 'tool') == 'nmap': profiles.append(profile) profiles.sort() self.model.clear() for command in profiles: myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, command) self.model.set_value(myiter, 1, self.profiles.get_hint(command)) #self.model.append([command,self.profiles.get_hint(command)]) def set_notebook(self, notebook): self.__scan_notebook = notebook def quit(self, widget): self.destroy() def quit(self, widget, data=None): if self.daddy: self.daddy.running_pm = False self.destroy() else: gtk.main_quit()
class ProfileEditor(HIGWindow): def __init__(self, profile_name=None, delete=False): HIGWindow.__init__(self) self.set_title(_('Profile Editor')) self.set_position(gtk.WIN_POS_CENTER) self.profile_name=profile_name self.__create_widgets() self.__pack_widgets() self.scan_notebook = None self.profilemanager = None self.profile = CommandProfile() self.deleted = False 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_hint_entry.set_text(prof['hint']) self.profile_description_text.get_buffer().set_text(prof['description']) self.profile_annotation_text.get_buffer().set_text(prof['annotation']) if delete: # Removing profile. It must be saved again self.remove_profile() self.constructor = CommandConstructor(options_used) self.options = OptionBuilder(profile_editor_file, self.constructor, self.update_command) 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>')) def help(self, widget): """ Show help documentation of Profile Editor """ show_help(self,"profile_editor.html#introduction") def __create_widgets(self): self.main_vbox = HIGVBox() self.command_expander = HIGExpander('<b>'+_('Command')+'</b>') self.command_expander.set_expanded(True) self.command_entry = gtk.Entry() 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_hint_label = HIGEntryLabel(_('Hint')) self.profile_hint_entry = gtk.Entry() self.profile_description_label = HIGEntryLabel(_('Description')) #self.profile_description_label = HIGHBox() self.profile_description_scroll = HIGScrolledWindow() self.profile_description_text = HIGTextView() self.profile_annotation_label = HIGEntryLabel(_('Annotation')) #self.profile_annotation_label = HIGHBox() self.profile_annotation_scroll = HIGScrolledWindow() self.profile_annotation_text = HIGTextView() # Buttons self.buttons_hbox = HIGHBox() self.help_button = HIGButton(stock=gtk.STOCK_HELP) self.help_button.connect('clicked', self.help) #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) #self.delete_button.connect('clicked', self.delete_profile) self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL) self.cancel_button.connect('clicked', self.quit_without_saving) self.ok_button = HIGButton(stock=gtk.STOCK_OK) self.ok_button.connect('clicked', self.save_profile) def __pack_widgets(self): self.add(self.main_vbox) # Packing widgets to main_vbox self.main_vbox._pack_noexpand_nofill(self.command_expander) self.main_vbox._pack_expand_fill(self.notebook) self.main_vbox._pack_noexpand_nofill(self.buttons_hbox) # 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_noexpand_nofill(HIGSpacer(table)) self.profile_annotation_scroll.add(self.profile_annotation_text) 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_noexpand_nofill(self.profile_annotation_label) vbox_ann._pack_expand_fill(hig_box_space_holder()) table.attach(self.profile_name_label,0,1,0,1) table.attach(self.profile_name_entry,1,2,0,1) #table.attach(self.profile_hint_label,0,1,1,2,xoptions=0) table.attach(self.profile_hint_label,0,1,1,2) table.attach(self.profile_hint_entry,1,2,1,2) table.attach(vbox_desc,0,1,2,3) table.attach(self.profile_description_scroll,1,2,2,3) table.attach(vbox_ann,0,1,3,4) table.attach(self.profile_annotation_scroll,1,2,3,4) # Packing buttons on button_hbox self.buttons_hbox.pack_start(self.help_button) #self.buttons_hbox.pack_start(self.delete_button) self.buttons_hbox.pack_start(self.cancel_button) self.buttons_hbox.pack_start(self.ok_button) self.buttons_hbox.set_border_width(5) self.buttons_hbox.set_spacing(6) 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() section = HIGSectionLabel(section_name) vbox._pack_noexpand_nofill(section) vbox._pack_noexpand_nofill(HIGSpacer(table)) vbox.set_border_width(6) tab.fill_table(table, True) self.scrollwindow = HIGScrolledWindow() self.scrollwindow.set_size_request(600,300) vp = gtk.Viewport() vp.add(vbox) vp.set_shadow_type(gtk.SHADOW_NONE) self.scrollwindow.add(vp) vbox_tmp = HIGVBox() vbox_tmp.set_border_width(6) vbox_tmp.set_spacing(12) vbox_tmp.pack_start(self.scrollwindow) self.notebook.append_page(vbox_tmp, gtk.Label(tab_name)) def set_profilemanager(self, model): """ give a model of treeview to update profile manager after run wizard """ assert model != None self.model = model self.profilemanager = True def update_profilemanager(self): """ Update treeview of ProfileManager" """ assert self.profilemanager; profiles = self.profile.sections() profiles.sort() self.model.clear() for command in profiles: myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, command) self.model.set_value(myiter,1, self.profile.get_hint(command)) def save_profile(self, widget): 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.')) elif profile_name.lower() == 'default': alert = HIGAlertDialog(message_format=_('Reserved profile name'),\ secondary_text=_('Cannot assign "default" \ name to this profile. Please rename it and retry.')) else: alert = None if alert: alert.run() alert.destroy() self.notebook.set_current_page(0) self.profile_name_entry.grab_focus() return None if not self.deleted: self.remove_profile() command = self.constructor.get_command('%s') hint = self.profile_hint_entry.get_text() buf = self.profile_description_text.get_buffer() description = buf.get_text(buf.get_start_iter(),\ buf.get_end_iter()) buf = self.profile_annotation_text.get_buffer() annotation = buf.get_text(buf.get_start_iter(),\ buf.get_end_iter()) self.profile.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ tool='nmap',\ options=self.constructor.get_options()) self.deleted = False if self.profilemanager: self.update_profilemanager() self.quit() def clean_profile_info(self): self.profile_name_entry.set_text('') self.profile_hint_entry.set_text('') self.profile_description_text.get_buffer().set_text('') self.profile_annotation_text.get_buffer().set_text('') def set_notebook(self, notebook): self.scan_notebook = notebook def quit(self, widget=None, extra=None): if self.deleted: 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 None self.destroy() if self.scan_notebook != None: for i in xrange(self.scan_notebook.get_n_pages()): page = self.scan_notebook.get_nth_page(i) page.toolbar.profile_entry.update() #page.toolbar.scan_profile.profile_entry.child.\ # set_text(self.profile_name_entry.get_text()) def quit_without_saving(self, widget=None): self.deleted=False self.quit() def on_delete(self, widget=None): if not self.profile_name: return self.on_cancel() 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 None self.deleted = True self.profile.remove_profile(self.profile_name) self.on_cancel() def on_cancel(self, widget=None): self.destroy() self.update_profile_entry() def update_profile_entry(self): page = None for i in xrange(self.scan_notebook.get_n_pages()): page = self.scan_notebook.get_nth_page(i) page.toolbar.profile_entry.update(\ self.profile_name_entry.get_text()) list = page.toolbar.profile_entry.get_model() length = len(list) if self.deleted and length > 0 : page.toolbar.profile_entry.set_active(0) elif self.deleted and length == 0: page.toolbar.profile_entry.child.set_text("") if page is not None: page.toolbar.profile_entry.update() def remove_profile(self,profile_name=None): ''' Remove current profile ''' if not profile_name: profile_name = self.profile_name self.profile.remove_profile(profile_name) self.deleted = True def delete_profile(self, widget=None): """ delete profile """ self.remove_profile() self.deleted=False self.quit()
class ProfileManager(HIGWindow): """ Create a Profile Manager """ def __init__(self, daddy=None): HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL) self.set_title('Profile Manager') self.set_position(gtk.WIN_POS_CENTER) self.__create_widgets() self.add(self.vbox_main) self.__fill_widgets() self.__pack_widgets() self.__scan_notebook = None self.daddy = daddy def __create_widgets(self): self.vbox_main = HIGVBox() self.main_frame = HIGFrame("Profiles") #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT) self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0) self.align.set_padding(0,0,12,0) self.vbox = HIGVBox() self.profiles_sw = HIGScrolledWindow() #TreeView self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) #self.modelfilter = self.model.filter_new() self.profiles_tv = gtk.TreeView(self.model) renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Name"), renderer, text=0) self.profiles_tv.append_column(column) renderer_hint = gtk.CellRendererText() column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1) self.profiles_tv.append_column(column_hint) #self.profiles_tv.set_model(self.modelfilter) #Info self.hbox_info = HIGHBox() self.command_label = HIGEntryLabel('Command: ') self.command_entry = HIGTextEntry() self.command_entry.set_editable(False) #Buttons self.hbox_buttons = HIGHBox() self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert') self.wiz_button.connect("clicked", self.new_wiz) self.edit_button = HIGButton(stock='gtk-edit') self.edit_button.connect("clicked", self.open_peditor) self.new_button = HIGButton(stock='gtk-new') self.new_button.connect("clicked", self.open_peditor) self.copy_button = HIGButton(stock='gtk-copy') self.copy_button.connect("clicked", self.copy_profiles) self.delete_button = HIGButton(stock=gtk.STOCK_DELETE) self.delete_button.connect('clicked', self.delete_profile) #Apply Buttons self.cancel_button = HIGButton(stock='gtk-close') self.cancel_button.connect("clicked", self.quit) self.connect("delete-event", self.quit) def __fill_widgets(self): self.profiles = CommandProfile() self._reload_profile_list() #selection = self.profiles_tv.get_selection() #selection.connect("changed", self.change_nmap_command) self.profiles_tv.connect("cursor-changed", self.change_nmap_command) def __pack_widgets(self): """ Pack all widgets of windows """ self.vbox_main.pack_start(self.main_frame, True, True) self.main_frame.add(self.align) self.align.add(self.vbox) self.vbox.set_border_width(6) self.vbox.pack_start(self.profiles_sw, True, True, 0) self.hbox_info.pack_start(self.command_label, False,False,0) self.hbox_info.pack_start(self.command_entry, True, True, 0) self.vbox.pack_start(self.hbox_info, False,False,0) self.hbox_buttons.pack_end(self.cancel_button) self.hbox_buttons.pack_end(self.copy_button, True, True) self.hbox_buttons.pack_end(self.edit_button, True, True) self.hbox_buttons.pack_end(self.delete_button, True, True) self.hbox_buttons.pack_end(self.new_button, True, True) self.hbox_buttons.pack_end(self.wiz_button, True, True) self.hbox_buttons.set_spacing(6) self.vbox_main.pack_start(self.hbox_buttons, False, False) self.profiles_sw.set_size_request(400,170) self.profiles_sw.add(self.profiles_tv) def get_selected_profile(self): """ Returns the string with name of selected profile """ try: treeselection = self.profiles_tv.get_selection() (model,iter) = treeselection.get_selected() return model.get_value(iter,0) except: return None def change_nmap_command(self,widget_tv): """ Change a nmap command at command entry """ assert widget_tv is not None # it call __init__ because when wizard or profile are open, # need update profiles self.profiles.__init__() # update text entry of command self.command_entry.set_text(self.profiles.get_command( self.get_selected_profile())) def new_wiz(self,widget): w = Wizard() w.set_notebook(None) w.set_profilemanager(self.model) w.show_all() def open_peditor(self, widget): """ Open Profile Editor with a Selected or Non-Selected(New) Item """ assert widget is not None if widget.get_label() == "gtk-edit": # Edit profile selected if self.get_selected_profile() is not None: pe = ProfileEditor(self.get_selected_profile()) pe.set_notebook(self.__scan_notebook) pe.set_profilemanager(self.model) pe.show_all() else: # New Profile pe = ProfileEditor() pe.set_notebook(self.__scan_notebook) pe.set_profilemanager(self.model) pe.show_all() self._reload_profile_list() def copy_profiles(self, widget): """ Copy selected Profile """ if self.get_selected_profile() is None: return None d = ProfileName(_("Insert a profile name")) profile_name = d.run() if profile_name is None or profile_name=="": return None #get commands of selected profile profile_selected = self.get_selected_profile() command = self.profiles.get_command(profile_selected) hint = self.profiles.get_hint(profile_selected) description = self.profiles.get_description(profile_selected) annotation = self.profiles.get_annotation(profile_selected) #Options prof = self.profiles.get_profile(profile_selected) options_used = prof['options'] options = CommandConstructor(options_used) self.profiles.add_profile(profile_name,\ command=command,\ hint=hint,\ description=description,\ annotation=annotation,\ options=options.get_options()) myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, profile_name) self.model.set_value(myiter,1, self.profiles.get_hint(profile_name)) treeselection = self.profiles_tv.get_selection() treeselection.select_iter(myiter) #(model,iter) = treeselection.get_selected() #model.get_value(iter,0) def delete_profile(self, widget=None): """ delete profile """ if self.get_selected_profile() is None: return None self.profiles.remove_profile(self.get_selected_profile()) #Update treeview treeselection = self.profiles_tv.get_selection() (model,iter) = treeselection.get_selected() model.remove(iter) # update text entry of command self.command_entry.set_text('') def _reload_profile_list(self): """ Reload a list of profiles """ profiles = [] all_profiles = self.profiles.sections() for profile in all_profiles: if self.profiles.get(profile, 'tool') == 'nmap': profiles.append(profile) profiles.sort() self.model.clear() for command in profiles: myiter = self.model.insert_before(None, None) self.model.set_value(myiter, 0, command) self.model.set_value(myiter,1, self.profiles.get_hint(command)) #self.model.append([command,self.profiles.get_hint(command)]) def set_notebook(self, notebook): self.__scan_notebook = notebook def quit(self, widget): self.destroy() def quit(self, widget, data=None): if self.daddy: self.daddy.running_pm = False self.destroy() else: gtk.main_quit()