Example #1
0
    def __init__(self, option=None):
        OptionDisplay.__init__(self)
        #Profile and Wizard core
        self._profilecore = None 
        self._wizardcore = None 
        self._notebook= None
        self._profile = None 
        self._wizard = None 
        self._changed = False

        hbox = HIGHBox()
        hbox.set_border_width(12)
        self.delete_button = HIGButton(stock='gtk-delete')
        self.delete_button.connect('clicked', self.delete_option)
        self.new_button = HIGButton(stock='gtk-new')
        self.new_button.connect('clicked', self.new_option)
        self.update_button = HIGButton(stock='gtk-refresh')
        self.update_button.connect('clicked', self.update_option)
        self.add_button = HIGButton(stock='gtk-add')
        self.add_button.connect('clicked', self.add_option)
        hbox.pack_end(self.delete_button,False,False)
        hbox.pack_end(self.update_button, False, False)
        hbox.pack_end(self.add_button, False, False)
        hbox.pack_end(self.new_button, False,False)
        self.attach(hbox, 1,2,6,7)

        self.optionlist = option
Example #2
0
    def __do_layout(self):
        """
        Layout window widgets.
        """
        main_vbox = HIGVBox()
        btns_box = HIGHBox()

        main_vbox.pack_start(self.logo_img)
        main_vbox.pack_start(self.lbl_program_version)
        main_vbox.pack_start(self.lbl_program_description)

        btns_box.pack_end(self.btn_close)
        main_vbox._pack_noexpand_nofill(btns_box)

        self.btn_close.grab_focus()

        self.add(main_vbox)
Example #3
0
    def __do_layout(self):
        """
        Layout window widgets.
        """
        main_vbox = HIGVBox()
        days_box = HIGHBox()
        btns_box = HIGHBox()

        days_box._pack_noexpand_nofill(self.data_lbl)
        days_box._pack_expand_fill(self.days)
        days_box._pack_noexpand_nofill(self.days_lbl)

        btns_box.pack_end(self.apply, False, False, 0)
        btns_box.pack_end(self.cancel, False, False, 0)

        main_vbox._pack_noexpand_nofill(days_box)
        main_vbox.pack_end(btns_box, False, False, 0)

        self.add(main_vbox)
Example #4
0
    def __do_layout(self):
        """
        Layout widgets.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        invname_hbox = HIGHBox()
        scan_hbox = HIGHBox()
        scanadv_hbox = HIGHBox()
        scantarget_hbox = HIGHBox()
        sched_box = HIGHBox()
        btns_hbox = HIGHBox()

        # header
        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)
        # inventory's name
        invname_hbox._pack_noexpand_nofill(self.invname_lbl)
        invname_hbox._pack_expand_fill(self.invname)
        invname_hbox._pack_noexpand_nofill(self.invname_inuse)
        invname_hbox._pack_noexpand_nofill(self.invenabled)
        # scan command
        scan_hbox._pack_noexpand_nofill(self.scandefault)
        scan_hbox._pack_noexpand_nofill(self.scandefault_tip)
        scanadv_hbox._pack_expand_fill(self.scanadv)

        adv_box = HIGVBox()
        scanadv_align = gtk.Alignment(0.5, 0.5, 1, 1)
        scanadv_align.set_padding(6, 0, 12, 0)
        scanname_box = HIGHBox()
        scanname_box._pack_noexpand_nofill(self.scan_name_lbl)
        scanname_box._pack_expand_fill(self.scan_name)
        scanname_box._pack_noexpand_nofill(self.cmd_wizard)
        adv_box.add(scanname_box)
        scancmd_box = HIGHBox()
        scancmd_box._pack_noexpand_nofill(self.scan_command_lbl)
        scancmd_box._pack_expand_fill(self.scan_command)
        adv_box.add(scancmd_box)

        scanadv_align.add(adv_box)
        self.scanadv.add(scanadv_align)
        # scan target
        scantarget_hbox._pack_noexpand_nofill(self.scantarget_lbl)
        scantarget_hbox._pack_expand_fill(self.scantarget)
        scantarget_hbox._pack_noexpand_nofill(self.scantarget_discovery)
        # scheduling profiles
        sched_box._pack_noexpand_nofill(self.sched_name_lbl)
        sched_box._pack_expand_fill(self.sched_name)
        sched_box._pack_noexpand_nofill(self.sched_name_edit)
        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.ok)

        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(invname_hbox)
        main_vbox._pack_noexpand_nofill(scan_hbox)
        main_vbox._pack_noexpand_nofill(scanadv_hbox)
        main_vbox._pack_noexpand_nofill(scantarget_hbox)

        if self.loaded_command and self.edit_mode:
            view_cmd_box = HIGHBox()
            view_cmd_box._pack_noexpand_nofill(gtk.Label(_("Command")))
            # XXX Why don't reuse scan_command?
            self.cmd_entry = gtk.Entry()
            self.cmd_entry.set_text(self.loaded_command)
            view_cmd_box._pack_expand_fill(self.cmd_entry)
            img_info = gtk.Image()
            img_info.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_MENU)
            eb = gtk.EventBox()
            eb.add(img_info)
            self.tooltips.set_tip(eb, _("Changes in command won't be saved!"))
            view_cmd_box.pack_end(eb, False, False, 0)
            main_vbox._pack_noexpand_nofill(view_cmd_box)

        main_vbox._pack_noexpand_nofill(sched_box)
        main_vbox.pack_end(btns_hbox, False, False, 0)
        main_vbox.pack_end(gtk.HSeparator(), False, False, 0)

        self.add(main_vbox)
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()
Example #6
0
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()
Example #7
0
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()
Example #8
0
    def __do_layout(self):
        """
        Layout widgets.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        invname_hbox = HIGHBox()
        scan_hbox = HIGHBox()
        scanadv_hbox = HIGHBox()
        scantarget_hbox = HIGHBox()
        sched_box = HIGHBox()
        btns_hbox = HIGHBox()

        # header
        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)
        # inventory's name
        invname_hbox._pack_noexpand_nofill(self.invname_lbl)
        invname_hbox._pack_expand_fill(self.invname)
        invname_hbox._pack_noexpand_nofill(self.invname_inuse)
        invname_hbox._pack_noexpand_nofill(self.invenabled)
        # scan command
        scan_hbox._pack_noexpand_nofill(self.scandefault)
        scan_hbox._pack_noexpand_nofill(self.scandefault_tip)
        scanadv_hbox._pack_expand_fill(self.scanadv)

        adv_box = HIGVBox()
        scanadv_align = gtk.Alignment(0.5, 0.5, 1, 1)
        scanadv_align.set_padding(6, 0, 12, 0)
        scanname_box = HIGHBox()
        scanname_box._pack_noexpand_nofill(self.scan_name_lbl)
        scanname_box._pack_expand_fill(self.scan_name)
        scanname_box._pack_noexpand_nofill(self.cmd_wizard)
        adv_box.add(scanname_box)
        scancmd_box = HIGHBox()
        scancmd_box._pack_noexpand_nofill(self.scan_command_lbl)
        scancmd_box._pack_expand_fill(self.scan_command)
        adv_box.add(scancmd_box)

        scanadv_align.add(adv_box)
        self.scanadv.add(scanadv_align)
        # scan target
        scantarget_hbox._pack_noexpand_nofill(self.scantarget_lbl)
        scantarget_hbox._pack_expand_fill(self.scantarget)
        scantarget_hbox._pack_noexpand_nofill(self.scantarget_discovery)
        # scheduling profiles
        sched_box._pack_noexpand_nofill(self.sched_name_lbl)
        sched_box._pack_expand_fill(self.sched_name)
        sched_box._pack_noexpand_nofill(self.sched_name_edit)
        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.ok)


        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(invname_hbox)
        main_vbox._pack_noexpand_nofill(scan_hbox)
        main_vbox._pack_noexpand_nofill(scanadv_hbox)
        main_vbox._pack_noexpand_nofill(scantarget_hbox)
        
        if self.loaded_command and self.edit_mode:
            view_cmd_box = HIGHBox()
            view_cmd_box._pack_noexpand_nofill(gtk.Label(_("Command")))
            # XXX Why don't reuse scan_command?
            self.cmd_entry = gtk.Entry()
            self.cmd_entry.set_text(self.loaded_command)
            view_cmd_box._pack_expand_fill(self.cmd_entry)
            img_info = gtk.Image()
            img_info.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_MENU)
            eb = gtk.EventBox()
            eb.add(img_info)
            self.tooltips.set_tip(eb, _("Changes in command won't be saved!"))
            view_cmd_box.pack_end(eb, False, False, 0)
            main_vbox._pack_noexpand_nofill(view_cmd_box)

        main_vbox._pack_noexpand_nofill(sched_box)
        main_vbox.pack_end(btns_hbox, False, False, 0)
        main_vbox.pack_end(gtk.HSeparator(), False, False, 0)

        self.add(main_vbox)
    def __layout(self):
        """
        Layout widgets
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        main_hpaned = gtk.HPaned()
        btns_hbox = HIGHBox()
        left_box = HIGVBox()
        right_box = gtk.VBox()

        header_hbox = HIGHBox()
        hostdetect_hbox = HIGHBox()
        targetl_hbox = HIGHBox()
        targetv_hbox = HIGHBox()
        targetr_hbox = HIGHBox()

        # header
        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)
        # network list
        netframe = HIGFrame(_("Network list"))
        settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        settings_align.set_padding(6, 0, 12, 0)
        nbox = HIGVBox()
        entry = gtk.Entry()
        entry.set_text(_("Sample 192.168.254.0/24"))
        nbox._pack_noexpand_nofill(entry)
        addnw_hbox = HIGHBox()
        addnw_hbox._pack_noexpand_nofill(self.addnetworks)
        nbox.pack_end(addnw_hbox, False, False, 0)
        self.networks_box = nbox
        settings_align.add(nbox)
        netframe.add(settings_align)
        # detection
        hostdetect_hbox._pack_noexpand_nofill(self.netdetect_btn)
        hostdetect_hbox._pack_noexpand_nofill(self.hostdetect_btn)

        # target list
        targetl_hbox._pack_noexpand_nofill(self.target_lbl)
        targetv_hbox._pack_expand_fill(self.tview)
        targetr_hbox.pack_end(self.target_remove, False, False, 0)

        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.apply)
        # change apply button stock text
        lbl = self.apply.get_children()[0].get_children()[0].get_children()[1]
        lbl.set_text(_("Use target list"))

        left_box._pack_noexpand_nofill(netframe)
        left_box.pack_end(hostdetect_hbox, False, False, 0)
        right_box.pack_start(targetl_hbox, False, False, 0)
        right_box.pack_start(targetv_hbox, True, True, 6)
        right_box.pack_start(targetr_hbox, False, False, 0)

        left_align = gtk.Alignment(0.5, 0.5, 1, 1)
        left_align.set_padding(0, 0, 0, 6)
        left_align.add(left_box)
        right_align = gtk.Alignment(0.5, 0.5, 1, 1)
        right_align.set_padding(0, 0, 6, 0)
        right_align.add(right_box)

        main_hpaned.add1(left_align)
        main_hpaned.add2(right_align)

        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_expand_fill(main_hpaned)
        main_vbox.pack_end(btns_hbox, False, False, 0)

        self.add(main_vbox)
Example #10
0
    def __layout(self):
        """
        Layout widgets
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        main_hpaned = gtk.HPaned()
        btns_hbox = HIGHBox()
        left_box = HIGVBox()
        right_box = gtk.VBox()

        header_hbox = HIGHBox()
        hostdetect_hbox = HIGHBox()
        targetl_hbox = HIGHBox()
        targetv_hbox = HIGHBox()
        targetr_hbox = HIGHBox()

        # header
        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)
        # network list
        netframe = HIGFrame(_("Network list"))
        settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        settings_align.set_padding(6, 0, 12, 0)
        nbox = HIGVBox()
        entry = gtk.Entry()
        entry.set_text(_("Sample 192.168.254.0/24"))
        nbox._pack_noexpand_nofill(entry)
        addnw_hbox = HIGHBox()
        addnw_hbox._pack_noexpand_nofill(self.addnetworks)
        nbox.pack_end(addnw_hbox, False, False, 0)
        self.networks_box = nbox
        settings_align.add(nbox)
        netframe.add(settings_align)
        # detection
        hostdetect_hbox._pack_noexpand_nofill(self.netdetect_btn)
        hostdetect_hbox._pack_noexpand_nofill(self.hostdetect_btn)

        # target list
        targetl_hbox._pack_noexpand_nofill(self.target_lbl)
        targetv_hbox._pack_expand_fill(self.tview)
        targetr_hbox.pack_end(self.target_remove, False, False, 0)

        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.apply)
        # change apply button stock text
        lbl = self.apply.get_children()[0].get_children()[0].get_children()[1]
        lbl.set_text(_("Use target list"))


        left_box._pack_noexpand_nofill(netframe)
        left_box.pack_end(hostdetect_hbox, False, False, 0)
        right_box.pack_start(targetl_hbox, False, False, 0)
        right_box.pack_start(targetv_hbox, True, True, 6)
        right_box.pack_start(targetr_hbox, False, False, 0)

        left_align = gtk.Alignment(0.5, 0.5, 1, 1)
        left_align.set_padding(0, 0, 0, 6)
        left_align.add(left_box)
        right_align = gtk.Alignment(0.5, 0.5, 1, 1)
        right_align.set_padding(0, 0, 6, 0)
        right_align.add(right_box)

        main_hpaned.add1(left_align)
        main_hpaned.add2(right_align)

        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_expand_fill(main_hpaned)
        main_vbox.pack_end(btns_hbox, False, False, 0)

        self.add(main_vbox)
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()