def create_widgets(self): vboxmain = gtk.VBox() sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.store = gtk.ListStore(str) self.update_model() self.treeView = gtk.TreeView(self.store) #treeView.connect("row-activated", self.on_activated) #treeView.set_rules_hint(True) self.create_columns(self.treeView) sw.add(self.treeView) # buttons vbox = HIGVBox() btn = HIGButton(_("Edit..."), gtk.STOCK_EDIT) vbox.pack_start(btn, False, False) btn.connect("clicked", self._edit_template) btn = HIGButton(_("Remove"), gtk.STOCK_REMOVE) vbox.pack_start(btn, False, False) btn.connect("clicked", self._remove_template) hbox = HIGHBox() hbox.pack_start(sw, True, True) hbox.pack_start(vbox, False, False) vboxmain.pack_start(hbox, True, True, 0) self.add(vboxmain) self.show_all()
def __init__(self, parent = None): HIGDialog.__init__(self, _("Find"), parent, gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_FIND, gtk.RESPONSE_OK)) self.set_default_response(gtk.RESPONSE_OK) hbox = HIGHBox() hbox.pack_start(gtk.Label(_("Search:"))) self.entry = HIGTextEntry() self.entry.set_activates_default(True) hbox.pack_start(self.entry) self.vbox.add(hbox) self.show_all()
def create_widgets(self): hbox = HIGHBox() hbox.pack_start(self.create_columns_list(), True, True) # buttons vbox = HIGVBox() btn = HIGButton(_("Move Up"), gtk.STOCK_GO_UP) vbox.pack_start(btn, False, False) btn.connect("clicked", self._move_up_down, -1) btn = HIGButton(_("Move Down"), gtk.STOCK_GO_DOWN) vbox.pack_start(btn, False, False) btn.connect("clicked", self._move_up_down, 1) hbox.pack_start(vbox, False, False) self.pack_start(hbox)
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()
def __init__(self, type_ = None, path = None): if type_ and path: title = _("Edit Source") else: type_ = "FILE" path = "" title = _("Add Source") HIGDialog.__init__(self, title, None, gtk.DIALOG_MODAL, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) hbox = HIGHBox() self.combo = gtk.combo_box_new_text() types = sorted(self.types.keys()) for t in types: self.combo.append_text(t) self.combo.set_active(types.index(type_)) self.combo.connect("changed", self._changed_cb) hbox.pack_start(self.combo, False, False) self.entry = HIGTextEntry() self.entry.set_text(path) hbox.pack_start(self.entry) self.btn = HIGButton(_("Browse..."), stock=gtk.STOCK_OPEN) self.btn.connect("clicked", self._clicked_cb) hbox.pack_start(self.btn, False, False) self.vbox.add(hbox) self.show_all() self.update()
def create_widgets(self): hbox = HIGHBox() hbox.pack_start(self.create_src_list(), True, True) # buttons vbox = HIGVBox() btn = HIGButton(_("Add Source..."), gtk.STOCK_ADD) vbox.pack_start(btn, False, False) btn.connect("clicked", self._add_source_cb) btn = HIGButton(_("Edit..."), gtk.STOCK_EDIT) vbox.pack_start(btn, False, False) btn.connect("clicked", self._edit_source_cb) btn = HIGButton(_("Remove"), gtk.STOCK_REMOVE) vbox.pack_start(btn, False, False) btn.connect("clicked", self._remove_cb) hbox.pack_start(vbox, False, False) self.pack_start(hbox)
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 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()
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()
class DiffWindow(gtk.Window): def __init__(self, scans): """scans in the format: {"scan_title":parsed_scan} """ gtk.Window.__init__(self) self.set_title(_("Compare Results")) self.scans = scans self.umit_conf = UmitConf() self.colors = Colors() # Diff views self.text_view = DiffText(self.colors, self.umit_conf.colored_diff) self.compare_view = DiffTree(self.colors) self._create_widgets() self._pack_widgets() self._connect_widgets() # Settings if self.umit_conf.diff_mode == "text": self.text_mode.set_active(True) else: self.compare_mode.set_active(True) self.check_color.set_active(self.umit_conf.colored_diff) # Initial Size Request self.initial_size = self.size_request() def _show_help(self, action): show_help(self, "index.html") def _create_widgets(self): self.main_vbox = HIGVBox() self.hbox_mode = HIGHBox() self.hbox_settings = HIGHBox() self.hbox_buttons = HIGHBox() self.hbox_result = HIGHBox() self.btn_open_browser = HIGButton(_("Open in Browser"), stock=gtk.STOCK_EXECUTE) self.btn_help = HIGButton(stock=gtk.STOCK_HELP) self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE) self.check_color = gtk.CheckButton(_("Enable colored diffies")) self.btn_legend = HIGButton(_("Color Descriptions"), stock=gtk.STOCK_SELECT_COLOR) self.text_mode = gtk.ToggleButton(_("Text Mode")) self.compare_mode = gtk.ToggleButton(_("Compare Mode")) self.vpaned = gtk.VPaned() self.hpaned = gtk.HPaned() self.scan_chooser1 = ScanChooser(self.scans, "1") self.scan_chooser2 = ScanChooser(self.scans, "2") self.scan_buffer1 = self.scan_chooser1.get_buffer() self.scan_buffer2 = self.scan_chooser2.get_buffer() def _pack_widgets(self): self.main_vbox.set_border_width(6) self.vpaned.pack1(self.hpaned, True, False) self.vpaned.pack2(self.hbox_result) self.hpaned.pack1(self.scan_chooser1, True, False) self.hpaned.pack2(self.scan_chooser2, True, False) self.hbox_buttons._pack_expand_fill(self.btn_help) self.hbox_buttons._pack_expand_fill(self.btn_legend) self.hbox_buttons._pack_expand_fill(self.btn_open_browser) self.hbox_buttons._pack_expand_fill(self.btn_close) self.hbox_buttons.set_homogeneous(True) self.hbox_mode.set_homogeneous(True) self.hbox_mode.pack_start(self.text_mode) self.hbox_mode.pack_start(self.compare_mode) self.hbox_settings._pack_noexpand_nofill(self.hbox_mode) self.hbox_settings._pack_expand_fill(self.check_color) self.main_vbox._pack_expand_fill(self.vpaned) self.main_vbox._pack_noexpand_nofill(self.hbox_settings) self.main_vbox._pack_noexpand_nofill(self.hbox_buttons) self.add(self.main_vbox) def _connect_widgets(self): self.connect("delete-event", self.close) self.btn_legend.connect("clicked", self.show_legend_window) self.btn_help.connect("clicked", self._show_help) self.btn_close.connect("clicked", self.close) self.btn_open_browser.connect("clicked", self.open_browser) self.check_color.connect("toggled", self._set_color) self.text_mode.connect("clicked", self._change_to_text) self.compare_mode.connect("clicked", self._change_to_compare) self.scan_chooser1.exp_scan.connect('activate', self.resize_vpane) self.scan_chooser2.exp_scan.connect('activate', self.resize_vpane) self.scan_buffer1.connect('changed', self.text_changed) self.scan_buffer2.connect('changed', self.text_changed) def open_browser(self, widget): text1=self.scan_buffer1.get_text(self.scan_buffer1.get_start_iter(),\ self.scan_buffer1.get_end_iter()) text2=self.scan_buffer2.get_text(self.scan_buffer2.get_start_iter(),\ self.scan_buffer2.get_end_iter()) if not text1 or not text2: alert = HIGAlertDialog( message_format='<b>' + _('Select Scan') + '</b>', secondary_text=_("You must select two different scans to \ generate diff.")) alert.run() alert.destroy() return False text1 = text1.split('\n') text2 = text2.split('\n') self.temp_view = mktemp('.html') text1 = [text + '\n' for text in text1] text2 = [text + '\n' for text in text2] if use_html: diff = DiffHtml(text1, text2) diff = diff.generate() file_desc = open(self.temp_view, 'w') file_desc.write(''.join(diff)) # Closing file to avoid problems with file descriptors file_desc.close() else: diff = Diff(text1, text2) diff = diff.generate() diff.insert( 0, '''<pre>(This diff is been shown in pure text \ because you dont have Python 2.4 or higher.)\n''') diff.append('</pre>') file_desc = open(self.temp_view, 'w') file_desc.writelines(diff) # Closing file to avoid problems with file descriptors file_desc.close() webbrowser.open("file://" + self.temp_view, autoraise=1) def show_legend_window(self, widget): legend_window = DiffLegendWindow(self.colors) legend_window.run() legend_window.destroy() self.text_changed(None) def text_changed(self, widget): text1 = self.scan_buffer1.get_text(self.scan_buffer1.get_start_iter(),\ self.scan_buffer1.get_end_iter()) text2 = self.scan_buffer2.get_text(self.scan_buffer2.get_start_iter(),\ self.scan_buffer2.get_end_iter()) if text1 != '' and text2 != '': if self.compare_mode.get_active(): self.compare_view.make_diff(self.scan_chooser1.parsed_scan, self.scan_chooser2.parsed_scan) self.compare_view.activate_color(self.check_color.get_active()) else: self.text1 = text1.split('\n') self.text2 = text2.split('\n') self.diff = Diff(self.text1, self.text2) self.text_view.txt_diff_result.get_buffer().set_text\ ('\n'.join(self.diff.generate_without_banner())) self.text_view.activate_color(self.check_color.get_active()) self.text_view._text_changed(None) def resize_vpane(self, widget): exp1 = not widget.get_expanded() if widget == self.scan_chooser1.exp_scan: exp2 = self.scan_chooser2.exp_scan.get_expanded() else: exp2 = self.scan_chooser1.exp_scan.get_expanded() if not exp1 and not exp2: self.vpaned.compute_position(-1, 0, 500) self.size_allocate( gtk.gdk.Rectangle(width=self.initial_size[0], height=self.initial_size[1])) self.queue_resize() def _change_to_text(self, widget): if not widget.get_active(): return self.umit_conf.diff_mode = "text" children = self.hbox_result.get_children() if children: self.hbox_result.remove(children[0]) self.compare_view.hide() self.hbox_result._pack_expand_fill(self.text_view) self.text_view.show_all() self.compare_mode.set_active(False) self.text_changed(None) def _change_to_compare(self, widget): if not widget.get_active(): return self.umit_conf.diff_mode = "compare" children = self.hbox_result.get_children() if children: self.hbox_result.remove(children[0]) self.text_view.hide() self.hbox_result._pack_expand_fill(self.compare_view) self.compare_view.show_all() self.text_mode.set_active(False) self.text_changed(None) def _set_color(self, widget): activate = widget.get_active() self.umit_conf.colored_diff = activate self.compare_view.activate_color(activate) self.text_view.activate_color(activate) def close(self, widget=None, extra=None): self.destroy()
class PreferencesWindow(HIGMainWindow): def __init__(self): HIGMainWindow.__init__(self) self.set_title("Preferences") self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.resize(950,500) self.set_border_width(10) self.__pixmap_d = Path.pixmaps_dir self.__list = { 'General settings':'general.svg', 'Fonts':'fonts.svg', 'Expose/Interface':'expose.svg', 'Network':'network.svg' } self.__list_bw = { 'General settings':'general-bw.svg', 'Fonts':'fonts-bw.svg', 'Expose/Interface':'expose-bw.svg', 'Network':'network-bw.svg' } # FIXME ### Replace two list above self.__dic_tabs = { 'Expose/Interface':['expose.svg','expose-bw.svg', ExposeGeneral], #'Network':['network.svg', 'network-bw.svg', NetworkTab], '.General settings':['general.svg','general-bw.svg',\ GeneralSettings], 'Interface Details':['fonts.svg','fonts-bw.svg', InterfaceDetails], } self.__create() self.__pack() self.__frame = None #self.connect("destroy", lambda w: gtk.main_quit()) self.connect("delete_event", lambda w, e: self.close()) self._create_frame("General Settings", GeneralSettings) # Add button Close and Help Button self.__closeb = HIGButton(stock=gtk.STOCK_CANCEL) self.__helpb = HIGButton(stock=gtk.STOCK_HELP) self.__applyb = HIGButton(stock = gtk.STOCK_APPLY) self.__okb = HIGButton(stock = gtk.STOCK_OK) self.__buttons_box = HIGHBox() self.__alignb_c = gtk.Alignment(0,0,0,0) self.__alignb_h = gtk.Alignment(0,0,0,0) self.__alignb_y = gtk.Alignment(0,0,0,0) self.__alignb_k = gtk.Alignment(0,0,0,0) self.__alignb_c.add(self.__closeb) self.__alignb_h.add(self.__helpb) self.__alignb_y.add(self.__applyb) self.__alignb_k.add(self.__okb) self.__alignb_y.set_padding(0,0, 1,1) self.__alignb_c.set_padding(0,0, 1,1) self.__alignb_h.set_padding(0,0, 1,1) self.__alignb_k.set_padding(0,0, 1,1) self.__buttons_box.pack_end(self.__alignb_k, False, False) self.__buttons_box.pack_end(self.__alignb_y, False, False) self.__buttons_box.pack_end(self.__alignb_c, False, False) self.__buttons_box.pack_start(self.__alignb_h, False, False) self.__box.pack_end(self.__buttons_box, False, True) self.__closeb.connect("clicked", lambda e: self.close()) self.__applyb.connect("clicked", self.save_changes) self.__okb.connect("clicked", self._save_close) self.connect("key-press-event", self.cb_keypress) self.show_all() # Callbacks def cb_keypress(self, widget, event): ''' handle the "key-press-event" signal ''' n = ord(event.string) if len(event.string) > 0 else '' kv = event.keyval print 'n: %s, keyval: %s' % (n, hex(kv)) def test1(): print "test" string_dict = { 12 : test1 # ctrl-L } keyval_dict = { gtk.keysyms.space : self.ac } # TODO: do return values propagate correctly? if n in string_dict: string_dict[n]() return True # event handled elif kv in keyval_dict: keyval_dict[kv]() return True def ac(self): print "action" def _save_close(self, widget): self.save_changes(None) self.close() def save_changes(self, widget): log.info('>>> Saving preferences changes') general_settings.save_changes() expose_conf.save_changes() network_conf.save_changes() nse_conf.save_changes() # save changes of registered pages self.__vt.save_changes() def on_change(self, widget, text): #get classname classname = self.__dic_tabs.get(text)[2] self._create_frame(text, classname) #DELME ### Old school def on_select(self,icon_view, model=None, current=None): selected = icon_view.get_selected_items() # Frame changes if len(selected) == 0: return i = selected[0][0] # Put Black and White the last selected item if (current[0] != None and current[0] != i ): cat = category = model[current[0]][0] model.remove(model.get_iter(current[0])) if (current[0]>model.get_n_columns()): current[0]=current[0]-1 iter_bw = None else: iter_bw = model.get_iter(current[0]) self.__t.add_item(category, self.__list_bw.get(category), \ iter_bw) current[0] = i category = model[i][0] #get classname classname = self.__dic_tabs.get(category)[2] self._create_frame(category, classname) model.remove(model.get_iter(i)) if (i>model.get_n_columns()): i=i-1 iter = None else: iter = model.get_iter(i) self.__t.add_item(category, self.__list.get(category), \ iter) def __create(self): """ Create mainly widgets""" # TabsWidget - Create self.__t = TabWidget() self.__vt = VTabManager() #self.__t.add_item("General settings", "general.svg") #self.__t.add_item("Fonts", "fonts-bw.svg") #self.__t.add_item("Expose/Interface", "expose-bw.svg") #self.__t.add_item("Network", "network-bw.svg") for i in self.__dic_tabs.items(): pixmap = os.path.join(self.__pixmap_d, "Preferences" ,i[1][0]) pixmap_bw = os.path.join(self.__pixmap_d, "Preferences" ,i[1][1]) self.__t.add_item(i[0], pixmap, pixmap_bw) self.__t.connect('changed',self.on_change) self.__mbox = HIGHBox() self.__box = HIGVBox() # Used for Vertical : def change_page(self, page): if self.__frame is not None: self.__box.remove(self.__frame) self.__frame.destroy() self.__frame = page self.__frame.show_all() self.__box.pack_start(self.__frame, True, True) self.__frame.set_border_width(10) def _create_frame(self, name, classname): if self.__frame is not None: self.__box.remove(self.__frame) self.__frame.destroy() self.__frame = classname(name) self.__frame.show_all() self.__box.pack_start(self.__frame, True, True) self.__frame.set_border_width(10) def __pack(self): """ Organize widgets """ self.__mbox.pack_start(self.__vt, False, False) self.__mbox.pack_start(self.__box, True, True) self.add(self.__mbox) def close(self): """ Close the window """ self.hide() ## Save Information needed self.destroy()
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()
class FeedbackPage(HIGVBox): """""" #---------------------------------------------------------------------- def __init__(self): """Constructor""" HIGVBox.__init__(self) self.__create_widgets() self.__pack_widgets() self.__set_values() def __create_widgets(self): self.suggestion_hbox = HIGHBox() self.report_hbox = HIGHBox() self.suggestion_section = HIGSectionLabel(_("Test Suggestion")) self.suggestion_table = HIGTable() self.report_section = HIGSectionLabel(_("Bug Report")) self.report_table = HIGTable() # Website Suggestion self.website_suggestion_table = HIGTable() self.website_suggestion_slabel = HIGSectionLabel(_("Website Suggestion")) self.website_url_subhbox = HIGHBox() self.website_url_label = HIGEntryLabel(_("URL:")) self.website_url_entry = gtk.Entry() self.website_suggestion_sendbtn = HIGButton(_('Send')) self.website_suggestion_sendbtn.set_size_request(60, 25) self.website_suggestion_sendbtn.connect( 'clicked', lambda x: self.send_website_suggestion()) # Service Suggestion self.service_suggestion_table = HIGTable() self.service_suggestion_slabel = HIGSectionLabel(_("Service Suggestion")) self.service_name_subhbox = HIGHBox() self.service_name_label = HIGEntryLabel(_("Name:")) self.service_list_store = gtk.ListStore(str) self.service_name_entry = gtk.ComboBoxEntry(self.service_list_store, 0) self.service_host_subhbox = HIGHBox() self.service_host_label = HIGEntryLabel(_("Hostname:")) self.service_host_entry = gtk.Entry() self.service_ip_subhbox = HIGHBox() self.service_ip_label = HIGEntryLabel(_("IP:")) self.service_ip_entry = gtk.Entry() self.service_port_label = HIGEntryLabel(_("PORT:")) self.service_port_entry = gtk.Entry() self.service_suggestion_sendbtn = HIGButton(_('Send')) self.service_suggestion_sendbtn.set_size_request(60, 25) self.service_suggestion_sendbtn.connect( 'clicked', lambda x: self.send_service_suggestion()) self.report_namelabel = HIGEntryLabel(_("Your Name:")) self.report_nameentry = gtk.Entry() #self.report_nameentry.set_has_frame(True) self.report_nameentry.set_size_request(100, 26) self.report_emaillabel = HIGEntryLabel(_("Email:")) self.report_emailentry = gtk.Entry() self.report_emailentry.set_size_request(198, 26) self.report_subhbox1 = HIGHBox() self.report_sw = gtk.ScrolledWindow() self.report_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.report_textview = gtk.TextView() self.report_textbuffer = self.report_textview.get_buffer() self.report_textview.set_editable(True) self.report_textview.set_wrap_mode(True) self.report_textview.set_border_width(2) self.report_sw.add(self.report_textview) self.report_sw.show() self.report_textview.show() self.report_subhbox2 = HIGHBox() self.report_sendbtn = HIGButton(_('Send')) self.report_sendbtn.set_size_request(60, 25) self.report_sendbtn.connect('clicked', lambda x: self.send_bug_report()) self.report_subhbox3 = HIGHBox() def __pack_widgets(self): self.set_border_width(12) self._pack_noexpand_nofill(self.suggestion_section) self._pack_noexpand_nofill(self.suggestion_hbox) self._pack_noexpand_nofill(self.report_section) self._pack_noexpand_nofill(self.report_hbox) #self.suggestion_hbox._pack_noexpand_nofill(hig_box_space_holder()) #self.suggestion_hbox._pack_expand_fill(self.suggestion_table) #self.report_hbox._pack_noexpand_nofill(hig_box_space_holder()) self.report_hbox._pack_expand_fill(self.report_table) self.suggestion_hbox._pack_expand_fill(self.suggestion_table) #self.suggestion_hbox._pack_expand_fill(self.service_suggestion_table) self.suggestion_table.attach_label(self.website_suggestion_slabel, 0, 2, 0, 1) self.suggestion_table.attach_label(self.website_url_label, 0, 1, 1, 2) self.suggestion_table.attach_entry(self.website_url_entry, 1, 2, 1, 2) self.suggestion_table.attach(self.website_suggestion_sendbtn, 0, 2, 2, 3, gtk.PACK_START) self.suggestion_table.attach_label(self.service_suggestion_slabel, 2, 4, 0, 1) self.suggestion_table.attach_label(self.service_name_label, 2, 3, 1, 2) self.suggestion_table.attach_entry(self.service_name_entry, 3, 4, 1, 2) self.suggestion_table.attach_label(self.service_host_label, 2, 3, 2, 3) self.suggestion_table.attach_entry(self.service_host_entry, 3, 4, 2, 3) self.suggestion_table.attach_label(self.service_ip_label, 2, 3, 3, 4) self.suggestion_table.attach_entry(self.service_ip_entry, 3, 4, 3, 4) self.suggestion_table.attach_label(self.service_port_label, 2, 3, 4, 5) self.suggestion_table.attach_entry(self.service_port_entry, 3, 4, 4, 5) self.suggestion_table.attach(self.service_suggestion_sendbtn, 2, 4, 5, 6, gtk.PACK_START) self.report_subhbox1.pack_start(self.report_namelabel, True, True, 0) self.report_subhbox1.pack_start(self.report_nameentry, True, True, 0) self.report_subhbox1.pack_start(self.report_emaillabel, True, True, 0) self.report_subhbox1.pack_start(self.report_emailentry) self.report_table.attach(self.report_subhbox1, 0, 1, 0, 1) self.report_subhbox2.pack_start(self.report_sw) self.report_table.attach(self.report_subhbox2, 0, 1, 1, 2) self.report_subhbox3.pack_start(self.report_sendbtn) self.report_table.attach(self.report_subhbox3, 0, 1, 2, 3, gtk.PACK_START) def __set_values(self): from umit.icm.agent.test import SUPPORTED_SERVICES for each in SUPPORTED_SERVICES: self.service_list_store.append([each]) def send_website_suggestion(self): website_url = self.website_url_entry.get_text() if website_url == '': alert = HIGAlertDialog(message_format=_("Missing fields."), secondary_text=_("Please input all fields " "for website suggestion.")) alert.run() alert.destroy() return d = theApp.aggregator.send_website_suggestion(website_url) d.addCallback(self.show_success) d.addErrback(self.show_failed) def send_service_suggestion(self): service_name = self.service_name_entry.child.get_text() host_name = self.service_host_entry.get_text() ip = self.service_ip_entry.get_text() port = int(self.service_port_entry.get_text()) if service_name == '' or host_name == '' or ip == '' or port == "": alert = HIGAlertDialog(message_format=_("Missing fields."), secondary_text=_("Please input all fields "\ "for service suggestion.")) alert.run() alert.destroy() return d = theApp.aggregator.send_service_suggestion(service_name, host_name, ip,port) d.addCallback(self.show_success) d.addErrback(self.show_failed) def send_bug_report(self): pass def show_failed(self,result): """ """ alert = HIGAlertDialog(message_format=_("Error."), secondary_text=_("Send to aggregaetor failed.")) alert.run() alert.destroy() def show_success(self, result): """ """ if result is not None: alert = HIGAlertDialog(message_format=_("Succuss."), secondary_text=_("Send to aggregaetor successfully.")) alert.run() alert.destroy() else: alert = HIGAlertDialog(message_format=_("Error."), secondary_text=_("Send to aggregaetor failed.")) alert.run() alert.destroy()
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 DiffWindow(gtk.Window): def __init__(self, scans): """scans in the format: {"scan_title":parsed_scan} """ gtk.Window.__init__(self) self.set_title(_("Compare Results")) self.scans = scans self.umit_conf = UmitConf() self.colors = Colors() # Diff views self.text_view = DiffText(self.colors, self.umit_conf.colored_diff) self.compare_view = DiffTree(self.colors) self._create_widgets() self._pack_widgets() self._connect_widgets() # Settings if self.umit_conf.diff_mode == "text": self.text_mode.set_active(True) else: self.compare_mode.set_active(True) self.check_color.set_active(self.umit_conf.colored_diff) # Initial Size Request self.initial_size = self.size_request() def _show_help(self, action): show_help(self, "index.html") def _create_widgets(self): self.main_vbox = HIGVBox() self.hbox_mode = HIGHBox() self.hbox_settings = HIGHBox() self.hbox_buttons = HIGHBox() self.hbox_result = HIGHBox() self.btn_open_browser = HIGButton(_("Open in Browser"), stock=gtk.STOCK_EXECUTE) self.btn_help = HIGButton(stock=gtk.STOCK_HELP) self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE) self.check_color = gtk.CheckButton(_("Enable colored diffies")) self.btn_legend = HIGButton(_("Color Descriptions"), stock=gtk.STOCK_SELECT_COLOR) self.text_mode = gtk.ToggleButton(_("Text Mode")) self.compare_mode = gtk.ToggleButton(_("Compare Mode")) self.vpaned = gtk.VPaned() self.hpaned = gtk.HPaned() self.scan_chooser1 = ScanChooser(self.scans, "1") self.scan_chooser2 = ScanChooser(self.scans, "2") self.scan_buffer1 = self.scan_chooser1.get_buffer() self.scan_buffer2 = self.scan_chooser2.get_buffer() def _pack_widgets(self): self.main_vbox.set_border_width(6) self.vpaned.pack1(self.hpaned, True, False) self.vpaned.pack2(self.hbox_result) self.hpaned.pack1(self.scan_chooser1, True, False) self.hpaned.pack2(self.scan_chooser2, True, False) self.hbox_buttons._pack_expand_fill(self.btn_help) self.hbox_buttons._pack_expand_fill(self.btn_legend) self.hbox_buttons._pack_expand_fill(self.btn_open_browser) self.hbox_buttons._pack_expand_fill(self.btn_close) self.hbox_buttons.set_homogeneous(True) self.hbox_mode.set_homogeneous(True) self.hbox_mode.pack_start(self.text_mode) self.hbox_mode.pack_start(self.compare_mode) self.hbox_settings._pack_noexpand_nofill(self.hbox_mode) self.hbox_settings._pack_expand_fill(self.check_color) self.main_vbox._pack_expand_fill(self.vpaned) self.main_vbox._pack_noexpand_nofill(self.hbox_settings) self.main_vbox._pack_noexpand_nofill(self.hbox_buttons) self.add(self.main_vbox) def _connect_widgets(self): self.connect("delete-event", self.close) self.btn_legend.connect("clicked", self.show_legend_window) self.btn_help.connect("clicked", self._show_help) self.btn_close.connect("clicked", self.close) self.btn_open_browser.connect("clicked", self.open_browser) self.check_color.connect("toggled", self._set_color) self.text_mode.connect("clicked", self._change_to_text) self.compare_mode.connect("clicked", self._change_to_compare) self.scan_chooser1.exp_scan.connect('activate', self.resize_vpane) self.scan_chooser2.exp_scan.connect('activate', self.resize_vpane) self.scan_buffer1.connect('changed', self.text_changed) self.scan_buffer2.connect('changed', self.text_changed) def open_browser(self, widget): text1=self.scan_buffer1.get_text(self.scan_buffer1.get_start_iter(),\ self.scan_buffer1.get_end_iter()) text2=self.scan_buffer2.get_text(self.scan_buffer2.get_start_iter(),\ self.scan_buffer2.get_end_iter()) if not text1 or not text2: alert = HIGAlertDialog( message_format='<b>'+_('Select Scan')+'</b>', secondary_text=_("You must select two different scans to \ generate diff.")) alert.run() alert.destroy() return False text1 = text1.split('\n') text2 = text2.split('\n') self.temp_view = mktemp('.html') text1 = [text+'\n' for text in text1] text2 = [text+'\n' for text in text2] if use_html: diff = DiffHtml(text1, text2) diff = diff.generate() file_desc = open(self.temp_view, 'w') file_desc.write(''.join(diff)) # Closing file to avoid problems with file descriptors file_desc.close() else: diff = Diff(text1, text2) diff = diff.generate () diff.insert(0, '''<pre>(This diff is been shown in pure text \ because you dont have Python 2.4 or higher.)\n''') diff.append('</pre>') file_desc = open(self.temp_view, 'w') file_desc.writelines(diff) # Closing file to avoid problems with file descriptors file_desc.close() webbrowser.open("file://" + self.temp_view, autoraise=1) def show_legend_window(self, widget): legend_window = DiffLegendWindow(self.colors) legend_window.run() legend_window.destroy() self.text_changed(None) def text_changed (self, widget): text1 = self.scan_buffer1.get_text(self.scan_buffer1.get_start_iter(),\ self.scan_buffer1.get_end_iter()) text2 = self.scan_buffer2.get_text(self.scan_buffer2.get_start_iter(),\ self.scan_buffer2.get_end_iter()) if text1 != '' and text2 != '': if self.compare_mode.get_active(): self.compare_view.make_diff(self.scan_chooser1.parsed_scan, self.scan_chooser2.parsed_scan) self.compare_view.activate_color(self.check_color.get_active()) else: self.text1 = text1.split ('\n') self.text2 = text2.split ('\n') self.diff = Diff(self.text1, self.text2) self.text_view.txt_diff_result.get_buffer().set_text\ ('\n'.join(self.diff.generate_without_banner())) self.text_view.activate_color(self.check_color.get_active()) self.text_view._text_changed(None) def resize_vpane(self, widget): exp1 = not widget.get_expanded() if widget == self.scan_chooser1.exp_scan: exp2 = self.scan_chooser2.exp_scan.get_expanded() else: exp2 = self.scan_chooser1.exp_scan.get_expanded() if not exp1 and not exp2: self.vpaned.compute_position(-1, 0, 500) self.size_allocate(gtk.gdk.Rectangle(width=self.initial_size[0], height=self.initial_size[1])) self.queue_resize() def _change_to_text(self, widget): if not widget.get_active(): return self.umit_conf.diff_mode = "text" children = self.hbox_result.get_children() if children: self.hbox_result.remove(children[0]) self.compare_view.hide() self.hbox_result._pack_expand_fill(self.text_view) self.text_view.show_all() self.compare_mode.set_active(False) self.text_changed(None) def _change_to_compare(self, widget): if not widget.get_active(): return self.umit_conf.diff_mode = "compare" children = self.hbox_result.get_children() if children: self.hbox_result.remove(children[0]) self.text_view.hide() self.hbox_result._pack_expand_fill(self.compare_view) self.compare_view.show_all() self.text_mode.set_active(False) self.text_changed(None) def _set_color(self, widget): activate = widget.get_active() self.umit_conf.colored_diff = activate self.compare_view.activate_color(activate) self.text_view.activate_color(activate) def close(self, widget=None, extra=None): self.destroy()
class PreferencesWindow(HIGMainWindow): def __init__(self): HIGMainWindow.__init__(self) self.set_title("Preferences") self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.resize(950, 500) self.set_border_width(10) self.__pixmap_d = Path.pixmaps_dir self.__list = { 'General settings': 'general.svg', 'Fonts': 'fonts.svg', 'Expose/Interface': 'expose.svg', 'Network': 'network.svg' } self.__list_bw = { 'General settings': 'general-bw.svg', 'Fonts': 'fonts-bw.svg', 'Expose/Interface': 'expose-bw.svg', 'Network': 'network-bw.svg' } # FIXME ### Replace two list above self.__dic_tabs = { 'Expose/Interface':['expose.svg','expose-bw.svg', ExposeGeneral], #'Network':['network.svg', 'network-bw.svg', NetworkTab], '.General settings':['general.svg','general-bw.svg',\ GeneralSettings], 'Interface Details':['fonts.svg','fonts-bw.svg', InterfaceDetails], } self.__create() self.__pack() self.__frame = None #self.connect("destroy", lambda w: gtk.main_quit()) self.connect("delete_event", lambda w, e: self.close()) self._create_frame("General Settings", GeneralSettings) # Add button Close and Help Button self.__closeb = HIGButton(stock=gtk.STOCK_CANCEL) self.__helpb = HIGButton(stock=gtk.STOCK_HELP) self.__applyb = HIGButton(stock=gtk.STOCK_APPLY) self.__okb = HIGButton(stock=gtk.STOCK_OK) self.__buttons_box = HIGHBox() self.__alignb_c = gtk.Alignment(0, 0, 0, 0) self.__alignb_h = gtk.Alignment(0, 0, 0, 0) self.__alignb_y = gtk.Alignment(0, 0, 0, 0) self.__alignb_k = gtk.Alignment(0, 0, 0, 0) self.__alignb_c.add(self.__closeb) self.__alignb_h.add(self.__helpb) self.__alignb_y.add(self.__applyb) self.__alignb_k.add(self.__okb) self.__alignb_y.set_padding(0, 0, 1, 1) self.__alignb_c.set_padding(0, 0, 1, 1) self.__alignb_h.set_padding(0, 0, 1, 1) self.__alignb_k.set_padding(0, 0, 1, 1) self.__buttons_box.pack_end(self.__alignb_k, False, False) self.__buttons_box.pack_end(self.__alignb_y, False, False) self.__buttons_box.pack_end(self.__alignb_c, False, False) self.__buttons_box.pack_start(self.__alignb_h, False, False) self.__box.pack_end(self.__buttons_box, False, True) self.__closeb.connect("clicked", lambda e: self.close()) self.__applyb.connect("clicked", self.save_changes) self.__okb.connect("clicked", self._save_close) self.connect("key-press-event", self.cb_keypress) self.show_all() # Callbacks def cb_keypress(self, widget, event): ''' handle the "key-press-event" signal ''' n = ord(event.string) if len(event.string) > 0 else '' kv = event.keyval print 'n: %s, keyval: %s' % (n, hex(kv)) def test1(): print "test" string_dict = { 12: test1 # ctrl-L } keyval_dict = {gtk.keysyms.space: self.ac} # TODO: do return values propagate correctly? if n in string_dict: string_dict[n]() return True # event handled elif kv in keyval_dict: keyval_dict[kv]() return True def ac(self): print "action" def _save_close(self, widget): self.save_changes(None) self.close() def save_changes(self, widget): log.info('>>> Saving preferences changes') general_settings.save_changes() expose_conf.save_changes() network_conf.save_changes() nse_conf.save_changes() # save changes of registered pages self.__vt.save_changes() def on_change(self, widget, text): #get classname classname = self.__dic_tabs.get(text)[2] self._create_frame(text, classname) #DELME ### Old school def on_select(self, icon_view, model=None, current=None): selected = icon_view.get_selected_items() # Frame changes if len(selected) == 0: return i = selected[0][0] # Put Black and White the last selected item if (current[0] != None and current[0] != i): cat = category = model[current[0]][0] model.remove(model.get_iter(current[0])) if (current[0] > model.get_n_columns()): current[0] = current[0] - 1 iter_bw = None else: iter_bw = model.get_iter(current[0]) self.__t.add_item(category, self.__list_bw.get(category), \ iter_bw) current[0] = i category = model[i][0] #get classname classname = self.__dic_tabs.get(category)[2] self._create_frame(category, classname) model.remove(model.get_iter(i)) if (i > model.get_n_columns()): i = i - 1 iter = None else: iter = model.get_iter(i) self.__t.add_item(category, self.__list.get(category), \ iter) def __create(self): """ Create mainly widgets""" # TabsWidget - Create self.__t = TabWidget() self.__vt = VTabManager() #self.__t.add_item("General settings", "general.svg") #self.__t.add_item("Fonts", "fonts-bw.svg") #self.__t.add_item("Expose/Interface", "expose-bw.svg") #self.__t.add_item("Network", "network-bw.svg") for i in self.__dic_tabs.items(): pixmap = os.path.join(self.__pixmap_d, "Preferences", i[1][0]) pixmap_bw = os.path.join(self.__pixmap_d, "Preferences", i[1][1]) self.__t.add_item(i[0], pixmap, pixmap_bw) self.__t.connect('changed', self.on_change) self.__mbox = HIGHBox() self.__box = HIGVBox() # Used for Vertical : def change_page(self, page): if self.__frame is not None: self.__box.remove(self.__frame) self.__frame.destroy() self.__frame = page self.__frame.show_all() self.__box.pack_start(self.__frame, True, True) self.__frame.set_border_width(10) def _create_frame(self, name, classname): if self.__frame is not None: self.__box.remove(self.__frame) self.__frame.destroy() self.__frame = classname(name) self.__frame.show_all() self.__box.pack_start(self.__frame, True, True) self.__frame.set_border_width(10) def __pack(self): """ Organize widgets """ self.__mbox.pack_start(self.__vt, False, False) self.__mbox.pack_start(self.__box, True, True) self.add(self.__mbox) def close(self): """ Close the window """ self.hide() ## Save Information needed self.destroy()
class FeedbackPage(HIGVBox): """""" #---------------------------------------------------------------------- def __init__(self): """Constructor""" HIGVBox.__init__(self) self.__create_widgets() self.__pack_widgets() self.__set_values() def __create_widgets(self): self.suggestion_hbox = HIGHBox() self.report_hbox = HIGHBox() self.suggestion_section = HIGSectionLabel(_("Test Suggestion")) self.suggestion_table = HIGTable() self.report_section = HIGSectionLabel(_("Bug Report")) self.report_table = HIGTable() # Website Suggestion self.website_suggestion_table = HIGTable() self.website_suggestion_slabel = HIGSectionLabel( _("Website Suggestion")) self.website_url_subhbox = HIGHBox() self.website_url_label = HIGEntryLabel(_("URL:")) self.website_url_entry = gtk.Entry() self.website_suggestion_sendbtn = HIGButton(_('Send')) self.website_suggestion_sendbtn.set_size_request(60, 25) self.website_suggestion_sendbtn.connect( 'clicked', lambda x: self.send_website_suggestion()) # Service Suggestion self.service_suggestion_table = HIGTable() self.service_suggestion_slabel = HIGSectionLabel( _("Service Suggestion")) self.service_name_subhbox = HIGHBox() self.service_name_label = HIGEntryLabel(_("Name:")) self.service_list_store = gtk.ListStore(str) self.service_name_entry = gtk.ComboBoxEntry(self.service_list_store, 0) self.service_host_subhbox = HIGHBox() self.service_host_label = HIGEntryLabel(_("Hostname:")) self.service_host_entry = gtk.Entry() self.service_ip_subhbox = HIGHBox() self.service_ip_label = HIGEntryLabel(_("IP:")) self.service_ip_entry = gtk.Entry() self.service_port_label = HIGEntryLabel(_("PORT:")) self.service_port_entry = gtk.Entry() self.service_suggestion_sendbtn = HIGButton(_('Send')) self.service_suggestion_sendbtn.set_size_request(60, 25) self.service_suggestion_sendbtn.connect( 'clicked', lambda x: self.send_service_suggestion()) self.report_namelabel = HIGEntryLabel(_("Your Name:")) self.report_nameentry = gtk.Entry() #self.report_nameentry.set_has_frame(True) self.report_nameentry.set_size_request(100, 26) self.report_emaillabel = HIGEntryLabel(_("Email:")) self.report_emailentry = gtk.Entry() self.report_emailentry.set_size_request(198, 26) self.report_subhbox1 = HIGHBox() self.report_sw = gtk.ScrolledWindow() self.report_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.report_textview = gtk.TextView() self.report_textbuffer = self.report_textview.get_buffer() self.report_textview.set_editable(True) self.report_textview.set_wrap_mode(True) self.report_textview.set_border_width(2) self.report_sw.add(self.report_textview) self.report_sw.show() self.report_textview.show() self.report_subhbox2 = HIGHBox() self.report_sendbtn = HIGButton(_('Send')) self.report_sendbtn.set_size_request(60, 25) self.report_sendbtn.connect('clicked', lambda x: self.send_bug_report()) self.report_subhbox3 = HIGHBox() def __pack_widgets(self): self.set_border_width(12) self._pack_noexpand_nofill(self.suggestion_section) self._pack_noexpand_nofill(self.suggestion_hbox) self._pack_noexpand_nofill(self.report_section) self._pack_noexpand_nofill(self.report_hbox) #self.suggestion_hbox._pack_noexpand_nofill(hig_box_space_holder()) #self.suggestion_hbox._pack_expand_fill(self.suggestion_table) #self.report_hbox._pack_noexpand_nofill(hig_box_space_holder()) self.report_hbox._pack_expand_fill(self.report_table) self.suggestion_hbox._pack_expand_fill(self.suggestion_table) #self.suggestion_hbox._pack_expand_fill(self.service_suggestion_table) self.suggestion_table.attach_label(self.website_suggestion_slabel, 0, 2, 0, 1) self.suggestion_table.attach_label(self.website_url_label, 0, 1, 1, 2) self.suggestion_table.attach_entry(self.website_url_entry, 1, 2, 1, 2) self.suggestion_table.attach(self.website_suggestion_sendbtn, 0, 2, 2, 3, gtk.PACK_START) self.suggestion_table.attach_label(self.service_suggestion_slabel, 2, 4, 0, 1) self.suggestion_table.attach_label(self.service_name_label, 2, 3, 1, 2) self.suggestion_table.attach_entry(self.service_name_entry, 3, 4, 1, 2) self.suggestion_table.attach_label(self.service_host_label, 2, 3, 2, 3) self.suggestion_table.attach_entry(self.service_host_entry, 3, 4, 2, 3) self.suggestion_table.attach_label(self.service_ip_label, 2, 3, 3, 4) self.suggestion_table.attach_entry(self.service_ip_entry, 3, 4, 3, 4) self.suggestion_table.attach_label(self.service_port_label, 2, 3, 4, 5) self.suggestion_table.attach_entry(self.service_port_entry, 3, 4, 4, 5) self.suggestion_table.attach(self.service_suggestion_sendbtn, 2, 4, 5, 6, gtk.PACK_START) self.report_subhbox1.pack_start(self.report_namelabel, True, True, 0) self.report_subhbox1.pack_start(self.report_nameentry, True, True, 0) self.report_subhbox1.pack_start(self.report_emaillabel, True, True, 0) self.report_subhbox1.pack_start(self.report_emailentry) self.report_table.attach(self.report_subhbox1, 0, 1, 0, 1) self.report_subhbox2.pack_start(self.report_sw) self.report_table.attach(self.report_subhbox2, 0, 1, 1, 2) self.report_subhbox3.pack_start(self.report_sendbtn) self.report_table.attach(self.report_subhbox3, 0, 1, 2, 3, gtk.PACK_START) def __set_values(self): from umit.icm.agent.test import SUPPORTED_SERVICES for each in SUPPORTED_SERVICES: self.service_list_store.append([each]) def send_website_suggestion(self): website_url = self.website_url_entry.get_text() if website_url == '': alert = HIGAlertDialog(message_format=_("Missing fields."), secondary_text=_("Please input all fields " "for website suggestion.")) alert.run() alert.destroy() return d = theApp.aggregator.send_website_suggestion(website_url) d.addCallback(self.show_success) d.addErrback(self.show_failed) def send_service_suggestion(self): service_name = self.service_name_entry.child.get_text() host_name = self.service_host_entry.get_text() ip = self.service_ip_entry.get_text() port = int(self.service_port_entry.get_text()) if service_name == '' or host_name == '' or ip == '' or port == "": alert = HIGAlertDialog(message_format=_("Missing fields."), secondary_text=_("Please input all fields "\ "for service suggestion.")) alert.run() alert.destroy() return d = theApp.aggregator.send_service_suggestion(service_name, host_name, ip, port) d.addCallback(self.show_success) d.addErrback(self.show_failed) def send_bug_report(self): pass def show_failed(self, result): """ """ alert = HIGAlertDialog(message_format=_("Error."), secondary_text=_("Send to aggregaetor failed.")) alert.run() alert.destroy() def show_success(self, result): """ """ if result is not None: alert = HIGAlertDialog( message_format=_("Succuss."), secondary_text=_("Send to aggregaetor successfully.")) alert.run() alert.destroy() else: alert = HIGAlertDialog( message_format=_("Error."), secondary_text=_("Send to aggregaetor failed.")) alert.run() alert.destroy()
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()