예제 #1
0
    def __create_wizard_widgets(self):
        self.wizard_title = HIGEntryLabel("")
        self.wizard_title.set_line_wrap(False)
        self.wizard_event = gtk.EventBox()
        self.wizard_logo = gtk.Image()
        self.wizard_event.add(self.wizard_logo)

        self.d = {}
        for c in (65, 97):
            for i in range(26):
                self.d[chr(i + c)] = chr((i + 13) % 26 + c)
        self.img = 1

        command_hbox = HIGHBox()
        self.command_label = HIGEntryLabel(_("Command"))
        self.command_entry = gtk.Entry()

        separator = gtk.HSeparator()

        self.wizard_header_hbox = HIGHBox()

        self.wizard_header_hbox._pack_expand_fill(self.wizard_title)
        self.wizard_header_hbox._pack_noexpand_nofill(self.wizard_event)

        command_hbox._pack_noexpand_nofill(self.command_label)
        command_hbox._pack_expand_fill(self.command_entry)

        self.main_vbox._pack_noexpand_nofill(self.wizard_header_hbox)
        self.main_vbox._pack_noexpand_nofill(command_hbox)
        self.main_vbox._pack_noexpand_nofill(separator)

        self.wizard_logo.set_from_file(logo)
예제 #2
0
 def __create_wizard_widgets(self):
     self.wizard_title = HIGEntryLabel("")
     self.wizard_title.set_line_wrap(False)
     self.wizard_event = gtk.EventBox()
     self.wizard_logo = gtk.Image()
     self.wizard_event.add(self.wizard_logo)
     
     self.d = {}
     for c in (65, 97):
         for i in range(26):
             self.d[chr(i+c)] = chr((i+13) % 26 + c)
     self.img = 1
     
     command_hbox = HIGHBox()
     self.command_label = HIGEntryLabel(_("Command"))
     self.command_entry = gtk.Entry()
     
     separator = gtk.HSeparator()
     
     self.wizard_header_hbox = HIGHBox()
     
     self.wizard_header_hbox._pack_expand_fill(self.wizard_title)
     self.wizard_header_hbox._pack_noexpand_nofill(self.wizard_event)
     
     command_hbox._pack_noexpand_nofill(self.command_label)
     command_hbox._pack_expand_fill(self.command_entry)
     
     self.main_vbox._pack_noexpand_nofill(self.wizard_header_hbox)
     self.main_vbox._pack_noexpand_nofill(command_hbox)
     self.main_vbox._pack_noexpand_nofill(separator)
     
     self.wizard_logo.set_from_file(logo)
    def __do_layout(self, create_buttons):
        main_vbox = HIGVBox()

        # timeline frame
        tl_settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        tl_settings_align.set_padding(6, 0, 12, 0)
        tl_settings_vbox = HIGVBox()

        mode_hbox = HIGHBox()
        mode_hbox._pack_noexpand_nofill(self.tl_mode_lbl)
        mode_hbox._pack_expand_fill(self.tl_mode)

        kind_hbox = HIGHBox()
        kind_hbox._pack_noexpand_nofill(self.tl_kind_lbl)
        kind_hbox._pack_expand_fill(self.tl_kind)

        tl_settings_vbox._pack_noexpand_nofill(mode_hbox)
        tl_settings_vbox._pack_noexpand_nofill(kind_hbox)
        tl_settings_align.add(tl_settings_vbox)
        self.timeline.add(tl_settings_align)
        main_vbox._pack_noexpand_nofill(self.timeline)
        # end timeline frame

        # statusbar frame
        sbar_settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        sbar_settings_align.set_padding(6, 0, 12, 0)
        sbar_settings_vbox = HIGVBox()

        sbar_settings_vbox._pack_noexpand_nofill(self.sbar_tips)
        sbar_settings_align.add(sbar_settings_vbox)
        self.sbar.add(sbar_settings_align)
        main_vbox._pack_noexpand_nofill(self.sbar)
        # end statusbar frame

        # tabs frame
        tabs_settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        tabs_settings_align.set_padding(6, 0, 12, 0)
        tabs_settings_vbox = HIGVBox()

        tabs_settings_vbox._pack_noexpand_nofill(self.tabs_cbtn)
        tabs_settings_align.add(tabs_settings_vbox)
        self.tabs.add(tabs_settings_align)
        main_vbox._pack_noexpand_nofill(self.tabs)
        # end tabs frame

        if create_buttons:
            # buttons box
            btnsbox = HIGHBox()
            btnsbox._pack_noexpand_nofill(self.apply)
            btnsbox._pack_noexpand_nofill(self.cancel)
            btnsbox._pack_noexpand_nofill(self.ok)
            bbox = gtk.HBox()
            bbox.pack_end(btnsbox, False, False, 0)

            main_vbox.pack_end(bbox, False, False, 0)
            main_vbox.pack_end(gtk.HSeparator(), False, False, 0)
            # end buttons box

        return main_vbox
예제 #4
0
    def __do_layout(self, create_buttons):
        main_vbox = HIGVBox()

        # timeline frame
        tl_settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        tl_settings_align.set_padding(6, 0, 12, 0)
        tl_settings_vbox = HIGVBox()

        mode_hbox = HIGHBox()
        mode_hbox._pack_noexpand_nofill(self.tl_mode_lbl)
        mode_hbox._pack_expand_fill(self.tl_mode)

        kind_hbox = HIGHBox()
        kind_hbox._pack_noexpand_nofill(self.tl_kind_lbl)
        kind_hbox._pack_expand_fill(self.tl_kind)

        tl_settings_vbox._pack_noexpand_nofill(mode_hbox)
        tl_settings_vbox._pack_noexpand_nofill(kind_hbox)
        tl_settings_align.add(tl_settings_vbox)
        self.timeline.add(tl_settings_align)
        main_vbox._pack_noexpand_nofill(self.timeline)
        # end timeline frame

        # statusbar frame
        sbar_settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        sbar_settings_align.set_padding(6, 0, 12, 0)
        sbar_settings_vbox = HIGVBox()

        sbar_settings_vbox._pack_noexpand_nofill(self.sbar_tips)
        sbar_settings_align.add(sbar_settings_vbox)
        self.sbar.add(sbar_settings_align)
        main_vbox._pack_noexpand_nofill(self.sbar)
        # end statusbar frame

        # tabs frame
        tabs_settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        tabs_settings_align.set_padding(6, 0, 12, 0)
        tabs_settings_vbox = HIGVBox()

        tabs_settings_vbox._pack_noexpand_nofill(self.tabs_cbtn)
        tabs_settings_align.add(tabs_settings_vbox)
        self.tabs.add(tabs_settings_align)
        main_vbox._pack_noexpand_nofill(self.tabs)
        # end tabs frame

        if create_buttons:
            # buttons box
            btnsbox = HIGHBox()
            btnsbox._pack_noexpand_nofill(self.apply)
            btnsbox._pack_noexpand_nofill(self.cancel)
            btnsbox._pack_noexpand_nofill(self.ok)
            bbox = gtk.HBox()
            bbox.pack_end(btnsbox, False, False, 0)
            
            main_vbox.pack_end(bbox, False, False, 0)
            main_vbox.pack_end(gtk.HSeparator(), False, False, 0)
            # end buttons box

        return main_vbox
예제 #5
0
class ScanMapperPage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)
        self.__parser = None
        self.__radialnet = None
        self.__created = False

    def create_widgets(self):
        if self.__created:
            self.__toolbar.enable_tools()
            self.update_graph()
            return

        self.set_spacing(0)
        self.__hbox = HIGHBox(spacing=0)

        # Create RadialNet
        self.__radialnet = RadialNet(LAYOUT_WEIGHTED)
        self.__radialnet.set_no_show_all(True)

        self.__radialnet.set_empty()
        self.update_graph()
        self.__radialnet.show()

        # Create Controlors

        self.__control = ControlWidget(self.__radialnet)
        self.__control_sw = HIGScrolledWindow()
        self.__control_sw.set_no_show_all(True)
        self.__control_sw.add_with_viewport(self.__control)
        self.__control_sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

        self.__fisheye = ControlFisheye(self.__radialnet)
        self.__fisheye.set_no_show_all(True)
        self.__toolbar = Toolbar(self.__radialnet, self, self.__control_sw,
                                 self.__fisheye)
        self.__toolbar.disable_tools()

        self.__hbox._pack_expand_fill(self.__radialnet)
        self.__hbox._pack_noexpand_nofill(self.__control_sw)

        self._pack_noexpand_nofill(self.__toolbar)
        self._pack_expand_fill(self.__hbox)
        self._pack_noexpand_nofill(self.__fisheye)

        self.show_all()
        self.__created = True

    def update_graph(self):
        self.__graph = GraphBuilder()
        self.__graph.make(self.__parser)
        self.__radialnet.set_graph(self.__graph)

    def set_parse(self, parse):
        self.__parser = parse
        if self.__radialnet is not None:
            self.__radialnet.set_graph(self.__graph)
예제 #6
0
class ChoosePage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)
        self.set_spacing(12)

        table = HIGTable()
        self.hbox = HIGHBox()

        self.description = HIGEntryLabel(
            _("""You wish to create a new profile,\
 or just want to quickly create a command and run it once?"""))
        self.profile_radio = gtk.RadioButton(None, _('Profile'))
        self.command_radio = gtk.RadioButton(self.profile_radio, _('Command'))
        self.command_radio.connect('toggled', self.enable_target)
        self.profile_radio.connect('toggled', self.disable_target)

        self.target_label = HIGEntryLabel(_("Target"))
        self.target_entry = gtk.Entry()
        self.set_completion()

        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.hbox._pack_noexpand_nofill(self.target_label)
        self.hbox._pack_expand_fill(self.target_entry)

        self.bar = ForwardBar()

        self._pack_noexpand_nofill(self.description)
        self._pack_expand_fill(table)
        self._pack_noexpand_nofill(self.bar)

        table.attach(self.profile_radio, 0, 1, 0, 1, yoptions=0)
        table.attach(self.command_radio, 0, 1, 1, 2, yoptions=0)
        table.attach(self.hbox, 0, 1, 2, 3, yoptions=0)

        self.disable_target()

    def set_completion(self):
        self.completion = gtk.EntryCompletion()
        self.target_list = gtk.ListStore(str)
        self.completion.set_model(self.target_list)
        self.completion.set_text_column(0)

        self.target_entry.set_completion(self.completion)

        for target in target_list.get_target_list()[:15]:
            self.target_list.append([target.replace('\n', '')])

    def add_new_target(self, target):
        target_list.add_target(target)

    def enable_target(self, widget=None):
        self.hbox.set_sensitive(True)

    def disable_target(self, widget=None):
        self.hbox.set_sensitive(False)
예제 #7
0
class ChoosePage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)
        self.set_spacing(12)
        
        table = HIGTable()
        self.hbox = HIGHBox()
        
        self.description = HIGEntryLabel(_("""You wish to create a new profile,\
 or just want to quickly create a command and run it once?"""))
        self.profile_radio = gtk.RadioButton(None, _('Profile'))
        self.command_radio = gtk.RadioButton(self.profile_radio, _('Command'))
        self.command_radio.connect('toggled', self.enable_target)
        self.profile_radio.connect('toggled', self.disable_target)
        
        self.target_label = HIGEntryLabel(_("Target"))
        self.target_entry = gtk.Entry()
        self.set_completion()
        
        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.hbox._pack_noexpand_nofill(self.target_label)
        self.hbox._pack_expand_fill(self.target_entry)
        
        self.bar = ForwardBar()
        
        self._pack_noexpand_nofill(self.description)
        self._pack_expand_fill(table)
        self._pack_noexpand_nofill(self.bar)
        
        table.attach(self.profile_radio,0,1,0,1, yoptions=0)
        table.attach(self.command_radio,0,1,1,2, yoptions=0)
        table.attach(self.hbox,0,1,2,3, yoptions=0)
        
        self.disable_target()
    
    def set_completion(self):
        self.completion = gtk.EntryCompletion()
        self.target_list = gtk.ListStore(str)
        self.completion.set_model(self.target_list)
        self.completion.set_text_column(0)
        
        self.target_entry.set_completion(self.completion)

        for target in target_list.get_target_list()[:15]:
            self.target_list.append([target.replace('\n','')])
    
    def add_new_target(self, target):
        target_list.add_target(target)

    def enable_target(self, widget=None):
        self.hbox.set_sensitive(True)
    
    def disable_target(self, widget=None):
        self.hbox.set_sensitive(False)
예제 #8
0
class LogsWindow(HIGWindow):
    """
    Logs Window
    """
    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title(_('Logs'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_size_request(720,480)
        self.set_border_width(10)
        
        self.__create_widgets()
        self.__pack_widgets()
        self.__connect_widgets()
        
        #test
        #from umit.icm.agent.gui.Notifications import *
        #t = NotificationUpdate(mode=new_release_mode,text="test",timeout=10000)

    def __create_widgets(self):
        """"""
        #box
        self.main_vbox = HIGVBox()
        self.btn_box = gtk.HButtonBox()
        self.LogsGUI_vbox = HIGHBox()        
        
        self.main_vbox.set_border_width(2)
        #close button
        self.close_button = gtk.Button(stock=gtk.STOCK_CLOSE)

        #log information box
        self.LogsGUI_hbox1 = HIGHBox()
        self.LogsGUI_hbox2 = HIGHBox()
        self.LogsGUI_subbox = LogsGUI()


    def __pack_widgets(self):
        self.main_vbox._pack_expand_fill(self.LogsGUI_vbox)
        self.main_vbox._pack_noexpand_nofill(self.btn_box)
                
        self.LogsGUI_vbox._pack_expand_fill(self.LogsGUI_hbox1)
        self.LogsGUI_vbox._pack_noexpand_nofill(self.LogsGUI_hbox2)
        
        self.LogsGUI_hbox1._pack_expand_fill(self.LogsGUI_subbox)

        self.btn_box.set_layout(gtk.BUTTONBOX_END)
        self.btn_box.set_spacing(8)
        self.btn_box.pack_start(self.close_button)
                
        self.add(self.main_vbox)
    
    def __connect_widgets(self):
        """"""    
        self.close_button.connect('clicked', lambda x: self.destroy())
예제 #9
0
class LogsWindow(HIGWindow):
    """
    Logs Window
    """
    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title(_('Logs'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_size_request(720,480)
        self.set_border_width(10)
        
        self.__create_widgets()
        self.__pack_widgets()
        self.__connect_widgets()
        
        #test
        #from umit.icm.agent.gui.Notifications import *
        #t = NotificationUpdate(mode=new_release_mode,text="test",timeout=10000)

    def __create_widgets(self):
        """"""
        #box
        self.main_vbox = HIGVBox()
        self.btn_box = gtk.HButtonBox()
        self.LogsGUI_vbox = HIGHBox()        
        
        self.main_vbox.set_border_width(2)
        #close button
        self.close_button = gtk.Button(stock=gtk.STOCK_CLOSE)

        #log information box
        self.LogsGUI_hbox1 = HIGHBox()
        self.LogsGUI_hbox2 = HIGHBox()
        self.LogsGUI_subbox = LogsGUI()


    def __pack_widgets(self):
        self.main_vbox._pack_expand_fill(self.LogsGUI_vbox)
        self.main_vbox._pack_noexpand_nofill(self.btn_box)
                
        self.LogsGUI_vbox._pack_expand_fill(self.LogsGUI_hbox1)
        self.LogsGUI_vbox._pack_noexpand_nofill(self.LogsGUI_hbox2)
        
        self.LogsGUI_hbox1._pack_expand_fill(self.LogsGUI_subbox)

        self.btn_box.set_layout(gtk.BUTTONBOX_END)
        self.btn_box.set_spacing(8)
        self.btn_box.pack_start(self.close_button)
                
        self.add(self.main_vbox)
    
    def __connect_widgets(self):
        """"""    
        self.close_button.connect('clicked', lambda x: self.destroy())
예제 #10
0
class SaveDialog(gtk.FileChooserDialog):
    def __init__(self):
        """
        """
        super(SaveDialog, self).__init__(
            title=_("Save Topology"),
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK),
        )

        self.__combo = gtk.combo_box_new_text()

        types_list = TYPES.keys()
        types_list.sort()

        for i in types_list:
            self.__combo.append_text(i)

        self.__combo.set_active(1)
        self.__label = HIGLabel(_("Select the output type:"))

        self.__hbox = HIGHBox()
        self.__hbox._pack_noexpand_nofill(self.__label)
        self.__hbox._pack_expand_fill(self.__combo)

        self.set_extra_widget(self.__hbox)
        self.set_do_overwrite_confirmation(True)

        self.__hbox.show_all()

    def show_error(self):
        """
        """
        alert = HIGAlertDialog(
            parent=self,
            type=gtk.MESSAGE_ERROR,
            message_format=_("Can't create file"),
            secondary_text=_("Please check if you have permission to " "write this file."),
        )
        alert.run()
        alert.destroy()

    def get_filetype(self):
        """
        """
        return TYPES[self.__combo.get_active_text()]
예제 #11
0
class SaveDialog(gtk.FileChooserDialog):
    def __init__(self):
        """
        """
        super(SaveDialog,
              self).__init__(title=_("Save Topology"),
                             action=gtk.FILE_CHOOSER_ACTION_SAVE,
                             buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                      gtk.STOCK_SAVE, gtk.RESPONSE_OK))

        self.__combo = gtk.combo_box_new_text()

        types_list = TYPES.keys()
        types_list.sort()

        for i in types_list:
            self.__combo.append_text(i)

        self.__combo.set_active(1)
        self.__label = HIGLabel(_("Select the output type:"))

        self.__hbox = HIGHBox()
        self.__hbox._pack_noexpand_nofill(self.__label)
        self.__hbox._pack_expand_fill(self.__combo)

        self.set_extra_widget(self.__hbox)
        self.set_do_overwrite_confirmation(True)

        self.__hbox.show_all()

    def show_error(self):
        """
        """
        alert = HIGAlertDialog(parent=self,
                               type=gtk.MESSAGE_ERROR,
                               message_format=_("Can't create file"),
                               secondary_text=_(
                                   "Please check if you have permission to "
                                   "write this file."))
        alert.run()
        alert.destroy()

    def get_filetype(self):
        """
        """
        return TYPES[self.__combo.get_active_text()]
예제 #12
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)
    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)
class ControlRingGap(HIGVBox):
    """
    """
    def __init__(self, radialnet):
        """
        """
        HIGVBox.__init__(self)

        self.radialnet = radialnet

        self.__create_widgets()


    def __create_widgets(self):
        """
        """
        self.__radius = ControlVariable('Ring gap',
                                        self.radialnet.get_ring_gap,
                                        self.radialnet.set_ring_gap)

        self.__label = gtk.Label('Lower ring gap')
        self.__label.set_alignment(0.0, 0.5)
        self.__adjustment = gtk.Adjustment(self.radialnet.get_min_ring_gap(),
                                           0,
                                           50,
                                           1)
        self.__spin = gtk.SpinButton(self.__adjustment)
        self.__spin.connect('value_changed', self.__change_lower)

        self.__lower_hbox = HIGHBox()
        self.__lower_hbox._pack_expand_fill(self.__label)
        self.__lower_hbox._pack_noexpand_nofill(self.__spin)

        self._pack_noexpand_nofill(self.__radius)
        self._pack_noexpand_nofill(self.__lower_hbox)


    def __change_lower(self, widget):
        """
        """
        if not self.radialnet.set_min_ring_gap(self.__adjustment.get_value()):
            self.__adjustment.set_value(self.radialnet.get_min_ring_gap())
    def set_comment(self, comment=''):
        self.comment_expander.set_use_markup(True)
        if comment:
            self.comment_expander.set_expanded(True)

        hbox = HIGHBox()

        self.comment_scrolled = gtk.ScrolledWindow()
        self.comment_scrolled.set_border_width(5)
        self.comment_scrolled.set_policy(gtk.POLICY_AUTOMATIC,\
                                         gtk.POLICY_AUTOMATIC)

        self.comment_txt_vw = gtk.TextView()
        self.comment_txt_vw.set_wrap_mode(gtk.WRAP_WORD)
        self.comment_txt_vw.get_buffer().set_text(comment)

        self.comment_scrolled.add(self.comment_txt_vw)
        hbox._pack_expand_fill(self.comment_scrolled)

        self.comment_expander.add(hbox)
        self._pack_noexpand_nofill(self.comment_expander)
예제 #16
0
 def set_comment(self, comment=''):
     self.comment_expander.set_use_markup(True)
     if comment:
         self.comment_expander.set_expanded(True)
     
     hbox = HIGHBox()
     
     self.comment_scrolled = gtk.ScrolledWindow()
     self.comment_scrolled.set_border_width(5)
     self.comment_scrolled.set_policy(gtk.POLICY_AUTOMATIC,\
                                      gtk.POLICY_AUTOMATIC)
     
     self.comment_txt_vw = gtk.TextView()
     self.comment_txt_vw.set_wrap_mode(gtk.WRAP_WORD)
     self.comment_txt_vw.get_buffer().set_text(comment)
     
     self.comment_scrolled.add(self.comment_txt_vw)
     hbox._pack_expand_fill(self.comment_scrolled)
     
     self.comment_expander.add(hbox)
     self._pack_noexpand_nofill(self.comment_expander)
class PeerInfoPage(HIGVBox):
    """"""
    
    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        
    def __create_widgets(self):
        """"""
        self.peerinfo_hbox      = HIGHBox()
        self.cloudagg_hbox      = HIGHBox()
        self.superpeers_hbox    = HIGHBox()
        self.pref_location_hbox = HIGHBox()

        self.peerinfo_section = HIGSectionLabel(_("Peer Info"))
        self.peerinfo_table = HIGTable()
        
        self.pref_location_section = HIGSectionLabel(_("Preferred Locations"))
        self.pref_location_table = HIGTable()
        
        self.cloudagg_section = HIGSectionLabel(_("Cloud Aggregator"))
        self.cloudagg_table = HIGTable()
        self.cloudagg_subhbox = HIGHBox()
        self.superpeers_section = HIGSectionLabel(_("Super Peers"))
        self.superpeers_table = HIGTable()

        self.peerid_label = HIGEntryLabel(_("Peer ID:"))
        self.email_label = HIGEntryLabel(_("Email Address:")) 
        self.test_version_label = HIGEntryLabel(_("Test Sets Version:")) 
        self.peerid_label2 = HIGEntryLabel()
        self.email_entry = gtk.Entry()
        self.test_version_label2 = HIGEntryLabel()        

        self.longitude_label = HIGLabel(_("longitude:"))
        self.longitude_entry = gtk.Entry()
        self.latitude_label = HIGLabel(_("latitude:"))
        self.latitude_entry = gtk.Entry()                  

        self.cloudagg_entry = gtk.Entry()
        self.cloudagg_button = HIGButton(_("Reset"))
        self.cloudagg_button.connect('clicked', lambda w: self.reset_aggregator_url())
                                      
        self.cloudagg_button.set_size_request(80, 28)

        self.superpeers_ip_label = HIGLabel(_("IP:"))
        self.superpeers_ip_entry = gtk.Entry()
        self.superpeers_ip_entry.set_size_request(160, 26)
        self.superpeers_port_label = HIGLabel(_("Port:"))
        self.superpeers_port_entry = gtk.Entry()
        self.superpeers_port_entry.set_size_request(80, 26)        
        
        self.superpeers_subhbox = HIGHBox()
        self.btn_box = gtk.HButtonBox()
        self.superpeers_button1 = HIGButton(_("Add"))
        self.superpeers_button1.connect('clicked',lambda w:self.add_superpeer())
                        
        self.superpeers_button2 = HIGButton(_("Show all"))
        self.superpeers_button2.connect('clicked', lambda w:
                                        self.show_super_peer_list_window())

    def __pack_widgets(self):
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.peerinfo_section)
        self._pack_noexpand_nofill(self.peerinfo_hbox)
        self._pack_noexpand_nofill(self.pref_location_section)
        self._pack_noexpand_nofill(self.pref_location_hbox)
        self._pack_noexpand_nofill(self.cloudagg_section)
        self._pack_noexpand_nofill(self.cloudagg_hbox)
        self._pack_noexpand_nofill(self.superpeers_section)
        self._pack_noexpand_nofill(self.superpeers_hbox)

        self.peerinfo_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.peerinfo_hbox._pack_expand_fill(self.peerinfo_table)
        self.pref_location_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.pref_location_hbox._pack_expand_fill(self.pref_location_table)        
        self.cloudagg_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.cloudagg_hbox._pack_expand_fill(self.cloudagg_table)
        self.superpeers_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.superpeers_hbox._pack_expand_fill(self.superpeers_table)

        self.peerinfo_table.attach_label(self.peerid_label, 0, 1, 0, 1)
        self.peerinfo_table.attach_label(self.email_label, 0, 1, 2, 3)

        self.peerinfo_table.attach_label(self.test_version_label, 0, 1, 1, 2)
        self.peerinfo_table.attach_label(self.test_version_label2, 1, 2, 1, 2)

        self.peerinfo_table.attach_label(self.peerid_label2, 1, 2, 0, 1)
        self.peerinfo_table.attach_entry(self.email_entry, 1, 2, 2, 3)

        self.pref_location_table.attach(self.longitude_label,0,1,0,1)
        self.pref_location_table.attach(self.longitude_entry,1,2,0,1)
        self.pref_location_table.attach(self.latitude_label,2,3,0,1)
        self.pref_location_table.attach(self.latitude_entry,3,4,0,1)
        
        self.cloudagg_subhbox._pack_expand_fill(self.cloudagg_entry)
        self.cloudagg_subhbox._pack_noexpand_nofill(self.cloudagg_button)
        self.cloudagg_table.attach_entry(self.cloudagg_subhbox, 0, 1, 0, 1)

        self.btn_box.set_layout(gtk.BUTTONBOX_END)
        self.btn_box.set_spacing(8)
        self.btn_box.pack_start(self.superpeers_button1)
        self.btn_box.pack_start(self.superpeers_button2)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_ip_label)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_ip_entry)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_port_label)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_port_entry)
        self.superpeers_subhbox._pack_noexpand_nofill(self.btn_box)
        self.superpeers_table.attach_label(self.superpeers_subhbox, 0, 1, 0, 1)
        

    def add_superpeer(self):
        """
        Add Super Peer by manual into database
        """
        ip = self.superpeers_ip_entry.get_text()
        port = self.superpeers_port_entry.get_text()
        
        g_db_helper.set_super_peer_manual(ip,port)
    
    def reset_aggregator_url(self):
        """
        """
        aggregator_url = 'http://east1.openmonitor.org'
        self.cloudagg_entry.set_text(aggregator_url)
        theApp.aggregator.base_url = aggregator_url
        g_config.set('network', 'aggregator_url', aggregator_url)
        g_db_helper.set_value('config','aggregator_url', aggregator_url)
        
    
            
    def show_super_peer_list_window(self):
        from umit.icm.agent.gui.Preference.SuperPeerSetting import SuperPeerListWindow,SuperPeersBox
        wnd = SuperPeerListWindow()
        wnd.show_all()
예제 #18
0
class NodeWindow(HIGWindow):
    """
    """
    def __init__(self, node, position, parent):
        """
        """
        HIGWindow.__init__(self, gtk.WINDOW_POPUP)
        self.set_decorated(False)
        self.set_keep_above(True)
        self.set_skip_taskbar_hint(True)
        self.move(position[0], position[1])
        self.set_size_request(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])

        self.__button_press_position = self.get_pointer()

        self.__is_compacted = True
        self.__is_collapsed = False

        self.__node = node
        self.__pressed = False
        self.__parent = parent

        self.connect('button_press_event', self.button_press)
        self.connect('button_release_event', self.button_release)
        self.connect('enter_notify_event', self.enter_notify)
        self.connect('leave_notify_event', self.leave_notify)
        self.connect('motion_notify_event', self.motion_notify)

        self.__title_font = pango.FontDescription('Monospace Bold')

        self.add_events(gtk.gdk.BUTTON_PRESS_MASK |
                        gtk.gdk.BUTTON_RELEASE_MASK |
                        gtk.gdk.POINTER_MOTION_MASK |
                        gtk.gdk.ENTER_NOTIFY |
                        gtk.gdk.LEAVE_NOTIFY |
                        gtk.gdk.POINTER_MOTION_HINT_MASK)

        self.__icon = Application()
        self.__create_widgets()


    def __create_widgets(self):
        """
        """
        self.__content = HIGVBox()
        self.__head = HIGHBox(spacing=2)

        self.__notebook = NodeNotebook(self.__node)

        # create head elements

        # icon with node's score color
        self.__color_box = gtk.EventBox()
        self.__color_image = gtk.Image()
        self.__color_image.set_from_file(self.__icon.get_icon('border'))
        self.__color_box.add(self.__color_image)
        self.__color_box.set_size_request(15, 15)
        r, g, b = drawing.cairo_to_gdk_color(self.__node.get_draw_info('color'))
        self.__color_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(r, g, b))

        # title with the node ip and hostname
        self.__title = ""

        if self.__node.get_info('hostname') is not None:
            self.__title = self.__node.get_info('hostname') + ' - '

        self.__title += self.__node.get_info('ip')

        self.__title_label = HIGSectionLabel(self.__title)
        self.__title_label.modify_font(self.__title_font)

        # icon to collapse window
        self.__collapse_box = gtk.EventBox()
        self.__collapse_img = gtk.Image()
        self.__collapse_img.set_from_file(self.__icon.get_icon('collapse'))
        self.__collapse_box.add(self.__collapse_img)
        self.__collapse_box.connect('button_press_event', self.collapse_window)
        self.__collapse_box.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        # icon to close window
        self.__close_box = gtk.EventBox()
        self.__close_img = gtk.Image()
        self.__close_img.set_from_file(self.__icon.get_icon('close'))
        self.__close_box.add(self.__close_img)
        self.__close_box.connect('button_press_event', self.close_window)
        self.__close_box.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        # packing head elements
        self.__head._pack_noexpand_nofill(self.__color_box)
        self.__head._pack_expand_fill(self.__title_label)
        self.__head._pack_noexpand_nofill(self.__collapse_box)
        self.__head._pack_noexpand_nofill(self.__close_box)

        # packing all to content
        self.__content._pack_noexpand_nofill(self.__head)
        self.__content._pack_expand_fill(self.__notebook)

        # add context to window
        self.add(self.__content)


    def close_window(self, widget, event):
        """
        """
        self.__node.set_draw_info({'over':False})
        self.hide()
        self.__parent.queue_draw()

        return True


    def restore(self, x, y):
        """
        """
        self.move(x, y)
        self.show_all()

        self.__is_collapsed = False
        self.resize(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])
        self.__collapse_img.set_from_file(self.__icon.get_icon('collapse'))


    def collapse_window(self, widget, event):
        """
        """
        self.present()

        if self.__is_collapsed == False:

            self.__notebook.hide()
            self.__is_collapsed = True
            self.set_size_request(DIMENSION_SHADED[0], DIMENSION_SHADED[1])
            self.resize(DIMENSION_SHADED[0], DIMENSION_SHADED[1])
            self.__collapse_img.set_from_file(self.__icon.get_icon('expand'))

        else:

            self.__notebook.show()
            self.__is_collapsed = False
            self.set_size_request(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])
            self.resize(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])
            self.__collapse_img.set_from_file(self.__icon.get_icon('collapse'))

        return True


    def button_press(self, widget, event):
        """
        """
        self.present()
        self.__pressed = True
        self.__button_press_position = self.get_pointer()

        return True


    def button_release(self, widget, event):
        """
        """
        self.__pressed = False

        return True


    def enter_notify(self, widget, event):
        """
        """
        self.__node.set_draw_info({'over':True})
        self.__parent.queue_draw()


    def leave_notify(self, widget, event):
        """
        """
        self.set_keep_above(True)
        self.__node.set_draw_info({'over':False})


    def motion_notify(self, widget, event):
        """
        """
        self.__node.set_draw_info({'over':True})

        x, y, button_state = event.window.get_pointer()

        if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed:

            xw, yw = event.window.get_root_origin()
            xd, yd = self.__button_press_position
            self.move(x + xw - xd, y + yw - yd)

        return True
예제 #19
0
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()
예제 #20
0
class GeneralPage(HIGVBox):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__information_load()

    def __create_widgets(self):
        
        
        self.general_hbox = HIGHBox()    
        self.version_hbox = HIGHBox()
        
        ################
        #Version Section
        self.version_section = HIGSectionLabel(_("Version"))
        self.version_table = HIGTable()
        self.version_label  = HIGEntryLabel(_("Software Version:"))
        self.version2_label = HIGEntryLabel()
        self.testver_label  = HIGEntryLabel(_("Service Test Version:"))
        self.testver2_label = HIGEntryLabel()
        self.attribute_label = HIGEntryLabel(_("Agent Attribute:"))
        self.attribute2_label = HIGEntryLabel()
            
        ################
        #General Section
        self.general_section = HIGSectionLabel(_("General"))
        self.general_table = HIGTable()
                
        self.startup_check = gtk.CheckButton(_("Startup OpenMonitor on system startup"))
        self.notification_check = gtk.CheckButton(_("Show Desktop Notifications"))
        self.login_ckeck = gtk.CheckButton(_("Enable Auto login"))        
        
        
    def __pack_widgets(self):
        """"""
        self.set_border_width(12)
        
        self._pack_noexpand_nofill(self.version_section)
        self._pack_noexpand_nofill(self.version_hbox)
        

        self._pack_noexpand_nofill(self.general_section)
        self._pack_noexpand_nofill(self.general_hbox)
        
        self.version_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.version_hbox._pack_expand_fill(self.version_table)        
                
        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_expand_fill(self.general_table)
        
        self.version_table.attach_label(self.version_label, 0, 2, 0, 1)
        self.version_table.attach_label(self.version2_label, 2, 4, 0, 1)
        self.version_table.attach_label(self.testver_label, 0, 2, 1, 2)  
        self.version_table.attach_label(self.testver2_label, 2, 4, 1, 2)
        self.version_table.attach_label(self.attribute_label, 0, 2, 2, 3)
        self.version_table.attach_label(self.attribute2_label, 2, 4, 2, 3)       
        
        self.general_table.attach_label(self.startup_check, 0, 2, 2, 3)
        self.general_table.attach_label(self.notification_check, 0, 3, 3, 4)
        self.general_table.attach_label(self.login_ckeck, 0, 4, 4, 5)
                                        
    def startup_set(self,is_start_up=True):
        """"""
        start = StartUP()
        if is_start_up:
            start.set_startup()
        else:
            start.clear_startup()        
        
    def __information_load(self):
        """
        """
        from umit.icm.agent.Version import VERSION
        from umit.icm.agent.test import TEST_PACKAGE_VERSION
        from umit.icm.agent.Global import *
        
        self.version2_label.set_text(str(VERSION))
        self.testver2_label.set_text(str(TEST_PACKAGE_VERSION))
        
        peer_attribute = g_db_helper.get_information(key='peer',default="Desktop Agent")
        
        self.attribute2_label.set_text(peer_attribute)
예제 #21
0
class OSFingerprintReport(gtk.Window, object):
    def __init__(self, fingerprint, ip):
        gtk.Window.__init__(self)
        self.set_title(_("Operating System Fingerprint Report"))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.fingerprint = fingerprint
        self.ip = ip

        self._create_widgets()
        self._set_classification_list()
        self._pack_widgets()
        self._connect_widgets()

    def _set_classification_list(self):
        class_file = open(os_classification_file, "rb")
        class_list = cPickle.load(class_file)
        class_file.close()

        for classification in class_list:
            self.classification_list.append([classification[1], classification[0]])

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()

        self.submitted_label = HIGHintSectionLabel(
            _("Submitted by (optional)"),
            _(
                "Enter your name and \
e-mail address if we can contact you with any questions. (kept private, \
used for nothing else)"
            ),
        )
        self.submitted_entry = gtk.Entry()

        self.target_device_label = HIGHintSectionLabel(
            _("Target OS/device info"),
            _(
                "<b>The more details \
the better!</b> For UNIX machines, '<i>uname -a</i>' often gives the proper \
version number. On Linux, please also specify the distribution version (such as\
Redhat 9.0) if you are using a vendor-provided kernel. For Windows, the \
'<i>winver</i>' command (if available) should show you any service pack \
information. If a Windows target has no service packs installed, \
please say so explicitly. For appliances/embedded devices, please mention \
the model number and what it is (printer, webcam, DSL router, VOIP phone, \
etc). Try to provide the architecture (X86, SPARC, etc.) where appropriate."
            ),
        )
        self.target_device_entry = gtk.Entry()

        self.classification_label = HIGHintSectionLabel(
            _("Classification"),
            _(
                "Please select \
the Device/OS info from this alphabetized choosebox"
            ),
        )
        self.classification_list = gtk.ListStore(str, str)
        self.classification_combo = gtk.ComboBoxEntry(self.classification_list, 0)

        self.notes_label = HIGHintSectionLabel(
            _("Notes"),
            _(
                "Fill with further info on \
the device, any special network conditions, etc."
            ),
        )
        self.notes_scrolled = gtk.ScrolledWindow()
        self.notes_text = gtk.TextView()

        self.fingerprint_icon = gtk.Image()
        self.fingerprint_text = gtk.Label(
            _(
                "This form allows you to \
contribute new operating system fingerprints to the Nmap database. Thanks for \
helping! <b>Please do not fill this out unless you are sure that you know \
what application is running on the machine you are submitting</b>. Incorrect \
entries can pollute the database. By submitting fingerprints you are \
transfering any copyright interest in the data to Fyodor so that he \
can modify it, relicense it, incorporate it into programs such as Nmap, etc."
            )
        )

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.notes_scrolled.add(self.notes_text)
        self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.notes_scrolled.set_size_request(400, 150)
        self.notes_text.set_wrap_mode(gtk.WRAP_WORD)

        self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
        self.fingerprint_icon.set_padding(10, 0)
        self.fingerprint_text.set_line_wrap(True)
        self.fingerprint_text.set_use_markup(True)

        self.table.attach_label(self.submitted_label, 0, 1, 0, 1)
        self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1)

        self.table.attach_label(self.target_device_label, 0, 1, 1, 2)
        self.table.attach_entry(self.target_device_entry, 1, 2, 1, 2)

        self.table.attach_label(self.classification_label, 0, 1, 2, 3)
        self.table.attach_entry(self.classification_combo, 1, 2, 2, 3)

        self.table.attach_label(self.notes_label, 0, 2, 3, 4)
        self.table.attach_entry(self.notes_scrolled, 0, 2, 4, 5)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.fingerprint_icon)
        self.hbox._pack_expand_fill(self.fingerprint_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox.set_border_width(6)
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def close(self, widget=None, event=None):
        self.destroy()

    def send_report(self, widget):
        if self.target_device == "":
            cancel_dialog = HIGAlertDialog(
                type=gtk.MESSAGE_ERROR,
                message_format=_(
                    "Operating System \
Fingerprint report is incomplete!"
                ),
                secondary_text=_(
                    "The Operating \
System Fingerprint report is incomplete. Please, try to provide as much \
information as possible."
                ),
            )
            cancel_dialog.run()
            cancel_dialog.destroy()
            return None

        os_register = OSFingerprintRegister()

        os_register.email = self.submitted
        os_register.os = self.target_device
        os_register.classification = self.classification
        os_register.ip = self.ip
        os_register.fingerprint = self.fingerprint
        os_register.notes = self.notes

        try:
            os_register.report()
        except:
            cancel_dialog = HIGAlertDialog(
                type=gtk.MESSAGE_ERROR,
                message_format=_(
                    "Operating System \
Fingerprint not registered!"
                ),
                secondary_text=_(
                    "The Operating \
System Fingerprint could not be registered. This problem may be caused by \
the lack of Internet Access or indisponibility of the fingerprint server. \
Please, verify your internet access, and then try to register the operating \
system fingerprint once again."
                ),
            )
            cancel_dialog.run()
            cancel_dialog.destroy()
        else:
            ok_dialog = HIGAlertDialog(
                type=gtk.MESSAGE_INFO,
                message_format=_(
                    "Operating System \
Fingerprint sucessfully registered!"
                ),
                secondary_text=_(
                    "The Operating System \
Fingerprint was sucessfully registered. A web page with detailed description \
about this registration is going to be openned in your default web browser."
                ),
            )
            ok_dialog.run()
            ok_dialog.destroy()

            self.close()

    def run_unblocked(self):
        if not self.modal:
            self.set_modal(True)
        self.show_all()

    def dialog_response_cb(self, dialog, response):
        self.response_id = response

    def get_submitted(self):
        return self.submitted_entry.get_text()

    def set_submitted(self, submitted):
        self.submitted_entry.set_text(submitted)

    def get_target_device(self):
        return self.target_device_entry.get_text()

    def set_target_device(self, target_device):
        self.target_device_entry.set_text(target_device)

    def get_classification(self):
        selected = self.classification_combo.child.get_text()
        for i in self.classification_list:
            if i[0] == selected:
                return i[1]
        return ""

    def set_classification(self, classification):
        self.classification.child.set_text(classification)

    def get_notes(self):
        buff = self.notes_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())

    def set_notes(self, notes):
        self.notes_text.get_buffer().set_text(notes)

    submitted = property(get_submitted, set_submitted)
    target_device = property(get_target_device, set_target_device)
    classification = property(get_classification, set_classification)
    notes = property(get_notes, set_notes)
예제 #22
0
class DiffText(HIGVBox, object):
    def __init__(self, colors, check_color):
        HIGVBox.__init__(self)
        self.set_border_width(5)
        self.set_spacing(6)

        self.colors = colors
        self.check_color = check_color

        self._create_widgets()
        self._pack_hbox()
        self._set_text_view()
        self._set_scrolled()

        self._pack_noexpand_nofill(self.lbl_diff)
        self._pack_expand_fill(self.hbox)

    def _create_widgets(self):
        self.hbox = HIGHBox()
        self.lbl_diff = HIGSectionLabel("<b>%s</b>" % _("Diff Result"))
        self.scrolled = gtk.ScrolledWindow()
        self.txt_diff_result = gtk.TextView()
        self.txg_tag = gtk.TextTag("diff_style")
        self.txg_added = gtk.TextTag('added style')
        self.txg_removed = gtk.TextTag('removed style')

    def _pack_hbox(self):
        self.hbox.set_border_width(5)
        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.hbox._pack_expand_fill(self.scrolled)

    def _set_scrolled(self):
        self.scrolled.set_size_request(-1, 250)

        # Packing text view into scrolled window
        self.scrolled.add_with_viewport(self.txt_diff_result)

        # Setting scrolled window
        self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

    def activate_color(self, activate):
        self.check_color = activate
        self._text_changed(None)

    def _set_text_view(self):
        self.txg_table = self.txt_diff_result.get_buffer().get_tag_table()
        self.txg_table.add(self.txg_tag)
        self.txg_table.add(self.txg_added)
        self.txg_table.add(self.txg_removed)
        self.txg_tag.set_property("family", "Monospace")
        self.txg_added.set_property("background-gdk", self.colors.added)
        self.txg_removed.set_property("background-gdk",
                                      self.colors.not_present)

        self.txt_diff_result.set_wrap_mode(gtk.WRAP_WORD)
        self.txt_diff_result.set_editable(False)
        self.txt_diff_result.get_buffer().connect("changed",
                                                  self._text_changed)

    def _text_changed(self, widget):
        self.txg_added.set_property("background-gdk", self.colors.added)
        self.txg_removed.set_property("background-gdk",
                                      self.colors.not_present)

        buff = self.txt_diff_result.get_buffer()

        buff.apply_tag(self.txg_tag, buff.get_start_iter(),
                       buff.get_end_iter())

        if self.check_color:
            positions = self._take_changes(buff)

            for i in positions['added']:
                buff.apply_tag(self.txg_added, i[0], i[1])

            for i in positions['removed']:
                buff.apply_tag(self.txg_removed, i[0], i[1])
        else:
            buff.remove_tag(self.txg_added, buff.get_start_iter(),
                            buff.get_end_iter())
            buff.remove_tag(self.txg_removed, buff.get_start_iter(),
                            buff.get_end_iter())

    def _take_changes(self, buffer):
        positions = {'added': [], 'removed': []}

        in_line = 0
        type = ''

        iter = buffer.get_start_iter()
        last_char = '\n'

        while iter.forward_char():
            char = iter.get_char()
            offset = iter.get_offset()
            if not in_line:
                pos = []
                if char == '+' and last_char == '\n':
                    pos.append(buffer.get_iter_at_offset(offset))
                    type = 'added'
                    in_line = 1
                elif char == '-' and last_char == '\n':
                    pos.append(buffer.get_iter_at_offset(offset))
                    type = 'removed'
                    in_line = 1
            else:
                if char == '\n':
                    pos.append(buffer.get_iter_at_offset(offset))
                    positions[type].append(pos)
                    in_line = 0
                    type = ''
            last_char = char

        return positions
class ControlInterpolation(HIGExpanderRNet):
    """
    """
    def __init__(self, radialnet):
        """
        """
        HIGExpanderRNet.__init__(self, 'Interpolation')

        self.radialnet = radialnet

        self.__create_widgets()


    def __create_widgets(self):
        """
        """
        self.__vbox = HIGVBox()

        self.__cartesian_radio = gtk.RadioButton(None, 'Cartesian')
        self.__polar_radio = gtk.RadioButton(self.__cartesian_radio, 'Polar')
        self.__cartesian_radio.connect('toggled',
                                       self.__change_system,
                                       INTERPOLATION_CARTESIAN)
        self.__polar_radio.connect('toggled',
                                   self.__change_system,
                                   INTERPOLATION_POLAR)

        self.__system_box = HIGHBox()
        self.__system_box._pack_noexpand_nofill(self.__polar_radio)
        self.__system_box._pack_noexpand_nofill(self.__cartesian_radio)

        self.__frames_box = HIGHBox()
        self.__frames_label = gtk.Label('Frames')
        self.__frames_label.set_alignment(0.0, 0.5)
        self.__frames = gtk.Adjustment(self.radialnet.get_number_of_frames(),
                                       1,
                                       1000,
                                       1)
        self.__frames.connect('value_changed', self.__change_frames)
        self.__frames_spin = gtk.SpinButton(self.__frames)
        self.__frames_box._pack_expand_fill(self.__frames_label)
        self.__frames_box._pack_noexpand_nofill(self.__frames_spin)

        self.__vbox._pack_noexpand_nofill(self.__frames_box)
        self.__vbox._pack_noexpand_nofill(self.__system_box)

        self._add(self.__vbox)

        gobject.timeout_add(REFRESH_RATE, self.__update_animation)


    def __update_animation(self):
        """
        """
        active = self.radialnet.get_interpolation()

        if active == INTERPOLATION_CARTESIAN:
            self.__cartesian_radio.set_active(True)

        else:
            self.__polar_radio.set_active(True)

        return True


    def __change_system(self, widget, value):
        """
        """
        if not self.radialnet.set_interpolation(value):

            active = self.radialnet.get_interpolation()

            if active == INTERPOLATION_CARTESIAN:
                self.__cartesian_radio.set_active(True)

            else:
                self.__polar_radio.set_active(True)


    def __change_frames(self, widget):
        """
        """
        if not self.radialnet.set_number_of_frames(self.__frames.get_value()):
            self.__frames.set_value(self.radialnet.get_number_of_frames())
예제 #24
0
class ScanChooser(HIGVBox):
    def __init__(self, scan_dict, num=""):
        HIGVBox.__init__(self)
        self.num = num
        self.scan_dict = scan_dict

        # Setting HIGVBox
        self.set_border_width(5)
        self.set_spacing(6)

        self._create_widgets()
        self._pack_hbox()
        self._attaching_widgets()
        self._set_scrolled()
        self._set_text_view()
        self._set_open_button()

        for scan in scan_dict:
            self.list_scan.append([scan])

        self.combo_scan.connect('changed', self.show_scan)

        self._pack_noexpand_nofill(self.lbl_scan)
        self._pack_expand_fill(self.hbox)

    def _create_widgets(self):
        self.lbl_scan = HIGSectionLabel("%s %s" %
                                        (_("Scan Result"), str(self.num)))
        self.hbox = HIGHBox()
        self.table = HIGTable()
        self.list_scan = gtk.ListStore(str)
        self.combo_scan = gtk.ComboBoxEntry(self.list_scan, 0)
        self.btn_open_scan = gtk.Button(stock=gtk.STOCK_OPEN)
        self.exp_scan = gtk.Expander(_("Scan Result Visualization"))
        self.scrolled = gtk.ScrolledWindow()
        self.txt_scan_result = gtk.TextView()
        self.txg_tag = gtk.TextTag("scan_style")

    def get_buffer(self):
        return self.txt_scan_result.get_buffer()

    def show_scan(self, widget):
        try:
            self.txt_scan_result.get_buffer().\
                 set_text(self.normalize_output(\
                     self.scan_dict[widget.child.get_text()].nmap_output))
        except KeyError:
            # Avoid to raise an error if the user writes within
            # the entry and the scan doesn't exits
            pass

    def normalize_output(self, output):
        return "\n".join(output.split("\\n"))

    def _pack_hbox(self):
        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.hbox._pack_expand_fill(self.table)

    def _attaching_widgets(self):
        self.table.attach(self.combo_scan, 0, 1, 0, 1, yoptions=0)
        self.table.attach(self.btn_open_scan,
                          1,
                          2,
                          0,
                          1,
                          yoptions=0,
                          xoptions=0)
        self.table.attach(self.exp_scan, 0, 2, 1, 2)

    def _set_scrolled(self):
        self.scrolled.set_border_width(5)
        self.scrolled.set_size_request(-1, 160)

        # Packing scrolled window into expander
        self.exp_scan.add(self.scrolled)

        # Packing text view into scrolled window
        self.scrolled.add_with_viewport(self.txt_scan_result)

        # Setting scrolled window
        self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

    def _set_text_view(self):
        self.txg_table = self.txt_scan_result.get_buffer().get_tag_table()
        self.txg_table.add(self.txg_tag)
        self.txg_tag.set_property("family", "Monospace")

        self.txt_scan_result.set_wrap_mode(gtk.WRAP_WORD)
        self.txt_scan_result.set_editable(False)
        self.txt_scan_result.get_buffer().connect("changed",
                                                  self._text_changed_cb)

    def _set_open_button(self):
        self.btn_open_scan.connect('clicked', self.open_file)

    def open_file(self, widget):
        file_chooser = ResultsFileChooserDialog(_("Select Scan Result"))

        file_chooser.run()
        file_chosen = file_chooser.get_filename()
        file_chooser.destroy()

        if check_access(file_chosen, os.R_OK):
            try:
                parser = NmapParser(file_chosen)
                parser.parse()
            except:
                alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % _('File is not a Umit \
Scan Result'),
                    secondary_text=_("Selected file is not a Umit Scan \
Result file. Umit can not parse this file. Please, select another."))
                alert.run()
                alert.destroy()
                return False

            scan_name = os.path.split(file_chosen)[-1]
            self.add_scan(scan_name, parser)

            self.combo_scan.set_active(len(self.list_scan) - 1)
        else:
            alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % \
                                   _('Can not open selected file'),
                    secondary_text=_("Umit can not open selected file. Please, \
select another."                ))
            alert.run()
            alert.destroy()

    def add_scan(self, scan_name, parser):
        scan_id = 1
        new_scan_name = scan_name
        while new_scan_name in self.scan_dict:
            new_scan_name = "%s (%s)" % (scan_name, scan_id)
            scan_id += 1

        self.list_scan.append([new_scan_name])
        self.scan_dict[new_scan_name] = parser

    def _text_changed_cb(self, widget):
        buff = self.txt_scan_result.get_buffer()
        buff.apply_tag(self.txg_tag, buff.get_start_iter(),
                       buff.get_end_iter())

    def get_nmap_output(self):
        parsed = self.parsed_scan
        if parsed:
            return parsed.nmap_output
        return False

    def get_parsed_scan(self):
        selected_scan = self.combo_scan.child.get_text()
        if selected_scan:
            return self.scan_dict[selected_scan]
        return False

    nmap_output = property(get_nmap_output)
    parsed_scan = property(get_parsed_scan)
예제 #25
0
class RegistrationDialog(HIGDialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, title=_('Registration')):
        """Constructor"""
        HIGDialog.__init__(self, title=title,
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
                                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        
        self._create_widgets()
        self._pack_widgets()

        # Register callbacks
        self.connect("response", self.check_response)

    def _create_widgets(self):
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = gtk.Entry()

        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()

        self.retype_password_label = HIGLabel(_("Retype password"))
        self.retype_password_entry = HIGPasswordEntry()

        self.registration_icon = gtk.Image()
        self.registration_text = gtk.Label(_("If you don't have an ICM account,"
                "please register a new account."))

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.registration_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
            gtk.ICON_SIZE_DIALOG)
        self.registration_icon.set_padding(10, 0)
        self.registration_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.registration_icon)
        self.hbox._pack_expand_fill(self.registration_text)

        self.vbox.pack_start(self.hbox, False, False)
        self.table.attach_label(self.username_label, 0, 1, 0, 1)
        self.table.attach_entry(self.username_entry, 1, 2, 0, 1)
        self.table.attach_label(self.password_label, 0, 1, 1, 2)
        self.table.attach_entry(self.password_entry, 1, 2, 1, 2)
        self.table.attach_label(self.retype_password_label, 0, 1, 2, 3)
        self.table.attach_entry(self.retype_password_entry, 1, 2, 2, 3)
        self.vbox.pack_start(self.table)

    def check_response(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            self.register()
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            self.destroy()

    def register(self):
        username = self.username_entry.get_text()
        password = self.password_entry.get_text()
        theApp.aggregator.register(username, password)
class ControlFisheye(HIGVBox):
    """
    """
    def __init__(self, radialnet):
        """
        """
        HIGVBox.__init__(self)
        self.set_border_width(6)

        self.radialnet = radialnet
        self.__ring_max_value = self.radialnet.get_number_of_rings()

        self.__create_widgets()


    def __create_widgets(self):
        """
        """
        self.__params = HIGVBox()
        self.__params_main = HIGHBox()
        self.__params_options = HIGHBox()

        self.__fisheye_label = gtk.Label('Fisheye on ring')

        self.__ring = gtk.Adjustment(0, 0, self.__ring_max_value, 0.01, 0.01)

        self.__ring_spin = gtk.SpinButton(self.__ring)
        self.__ring_spin.set_digits(2)

        self.__ring_scale = gtk.HScale(self.__ring)
        self.__ring_scale.set_size_request(100, -1)
        self.__ring_scale.set_digits(2)
        self.__ring_scale.set_value_pos(gtk.POS_LEFT)
        self.__ring_scale.set_draw_value(False)
        self.__ring_scale.set_update_policy(gtk.UPDATE_CONTINUOUS)

        self.__interest_label = gtk.Label('Interest factor')
        self.__interest = gtk.Adjustment(0, 0, 10, 0.01)
        self.__interest_spin = gtk.SpinButton(self.__interest)
        self.__interest_spin.set_digits(2)

        self.__spread_label = gtk.Label('Spread factor')
        self.__spread = gtk.Adjustment(0, -1.0, 1.0, 0.01, 0.01)
        self.__spread_spin = gtk.SpinButton(self.__spread)
        self.__spread_spin.set_digits(2)

        self.__options_button = gtk.ToggleButton('More')
        self.__options_button.set_active(False)

        self.__params._pack_noexpand_nofill(self.__params_main)
        self.__params._pack_noexpand_nofill(self.__params_options)

        self.__params_main._pack_noexpand_nofill(self.__fisheye_label)
        self.__params_main._pack_noexpand_nofill(self.__ring_spin)
        self.__params_main._pack_expand_fill(self.__ring_scale)
        self.__params_main._pack_noexpand_nofill(self.__options_button)

        self.__params_options._pack_noexpand_nofill(self.__interest_label)
        self.__params_options._pack_noexpand_nofill(self.__interest_spin)
        self.__params_options._pack_noexpand_nofill(self.__spread_label)
        self.__params_options._pack_noexpand_nofill(self.__spread_spin)

        self.__params_options.set_no_show_all(True)
        self.__params_options.hide()

        self._pack_noexpand_nofill(self.__params)

        self.__ring.connect('value_changed', self.__change_ring)
        self.__interest.connect('value_changed', self.__change_interest)
        self.__spread.connect('value_changed', self.__change_spread)

        self.__options_button.connect('toggled', self.__options_toggled)

        gobject.timeout_add(REFRESH_RATE, self.__update_fisheye)


    def __update_fisheye(self):
        """
        """
        # adjust ring scale to radialnet number of nodes
        ring_max_value = self.radialnet.get_number_of_rings() - 1

        if ring_max_value != self.__ring_max_value:

            value = self.__ring.get_value()

            if value == 0 and ring_max_value != 0:
                value = 1

            elif value > ring_max_value:
                value = ring_max_value

            self.__ring.set_all(value, 1, ring_max_value, 0.01, 0.01, 0)
            self.__ring_max_value = ring_max_value

            self.__ring_scale.queue_draw()

        # check ring value
        ring_value = self.radialnet.get_fisheye_ring()

        if self.__ring.get_value() != ring_value:
            self.__ring.set_value(ring_value)

        # check interest value
        interest_value = self.radialnet.get_fisheye_interest()

        if self.__interest.get_value() != interest_value:
            self.__interest.set_value(interest_value)

        # check spread value
        spread_value = self.radialnet.get_fisheye_spread()

        if self.__spread.get_value() != spread_value:
            self.__spread.set_value(spread_value)

        return True


    def active_fisheye(self):
        """
        """
        self.radialnet.set_fisheye(True)
        self.__change_ring()
        self.__change_interest()


    def deactive_fisheye(self):
        """
        """
        self.radialnet.set_fisheye(False)


    def __change_ring(self, widget=None):
        """
        """
        if not self.radialnet.is_in_animation():
            self.radialnet.set_fisheye_ring(self.__ring.get_value())
        else:
            self.__ring.set_value(self.radialnet.get_fisheye_ring())


    def __change_interest(self, widget=None):
        """
        """
        if not self.radialnet.is_in_animation():
            self.radialnet.set_fisheye_interest(self.__interest.get_value())
        else:
            self.__interest.set_value(self.radialnet.get_fisheye_interest())


    def __change_spread(self, widget=None):
        """
        """
        if not self.radialnet.is_in_animation():
            self.radialnet.set_fisheye_spread(self.__spread.get_value())
        else:
            self.__spread.set_value(self.radialnet.get_fisheye_spread())


    def __options_toggled(self, widget=None):
        """
        """
        self.__params_options.set_no_show_all(False)

        if self.__options_button.get_active():
            self.__params_options.show_all()
        else:
            self.__params_options.hide_all()

        self.__params_options.set_no_show_all(True)
예제 #27
0
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()
예제 #28
0
class DiffText(HIGVBox, object):
    def __init__ (self, colors, check_color):
        HIGVBox.__init__(self)
        self.set_border_width(5)
        self.set_spacing(6)

        self.colors = colors
        self.check_color = check_color
        
        self._create_widgets()
        self._pack_hbox()
        self._set_text_view()
        self._set_scrolled()
        
        self._pack_noexpand_nofill(self.lbl_diff)
        self._pack_expand_fill(self.hbox)
    
    def _create_widgets (self):
        self.hbox = HIGHBox ()
        self.lbl_diff = HIGSectionLabel ("<b>%s</b>" % _("Diff Result"))
        self.scrolled = gtk.ScrolledWindow()
        self.txt_diff_result = gtk.TextView()
        self.txg_tag = gtk.TextTag ("diff_style")
        self.txg_added = gtk.TextTag ('added style')
        self.txg_removed = gtk.TextTag ('removed style')

    def _pack_hbox (self):
        self.hbox.set_border_width(5)
        self.hbox._pack_noexpand_nofill (hig_box_space_holder())
        self.hbox._pack_expand_fill(self.scrolled)

    def _set_scrolled (self):
        self.scrolled.set_size_request(-1, 250)
        
        # Packing text view into scrolled window
        self.scrolled.add_with_viewport(self.txt_diff_result)
        
        # Setting scrolled window
        self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

    def activate_color(self, activate):
        self.check_color = activate
        self._text_changed(None)
    
    def _set_text_view (self):
        self.txg_table = self.txt_diff_result.get_buffer().get_tag_table()
        self.txg_table.add(self.txg_tag)
        self.txg_table.add(self.txg_added)
        self.txg_table.add(self.txg_removed)
        self.txg_tag.set_property("family", "Monospace")
        self.txg_added.set_property("background-gdk", self.colors.added)
        self.txg_removed.set_property("background-gdk", self.colors.not_present)
        
        self.txt_diff_result.set_wrap_mode(gtk.WRAP_WORD)
        self.txt_diff_result.set_editable(False)
        self.txt_diff_result.get_buffer().connect("changed", self._text_changed)
        
    def _text_changed (self, widget):
        self.txg_added.set_property("background-gdk", self.colors.added)
        self.txg_removed.set_property("background-gdk", self.colors.not_present)
        
        buff = self.txt_diff_result.get_buffer()

        buff.apply_tag(self.txg_tag, buff.get_start_iter(), buff.get_end_iter())

        if self.check_color:
            positions = self._take_changes(buff)
            
            for i in positions['added']:
                buff.apply_tag(self.txg_added, i[0],i[1])
            
            for i in positions['removed']:
                buff.apply_tag(self.txg_removed, i[0], i[1])
        else:
            buff.remove_tag(self.txg_added, buff.get_start_iter(),
                            buff.get_end_iter())
            buff.remove_tag(self.txg_removed, buff.get_start_iter(),
                            buff.get_end_iter())

    def _take_changes (self, buffer):
        positions = {'added':[], 'removed':[]}

        in_line = 0
        type = ''

        iter = buffer.get_start_iter ()
        last_char = '\n'

        while iter.forward_char():
            char = iter.get_char ()
            offset = iter.get_offset()
            if not in_line:
                pos = []
                if char == '+' and last_char == '\n':
                    pos.append (buffer.get_iter_at_offset(offset))
                    type = 'added'
                    in_line = 1
                elif char == '-' and last_char == '\n':
                    pos.append (buffer.get_iter_at_offset(offset))
                    type = 'removed'
                    in_line = 1
            else:
                if char == '\n':
                    pos.append (buffer.get_iter_at_offset(offset))
                    positions [type].append (pos)
                    in_line = 0
                    type = ''
            last_char = char
        
        return positions
예제 #29
0
class DiffTree(HIGVBox, object):
    def __init__(self, colors):
        HIGVBox.__init__(self)

        self.colors = colors
        self.set_border_width(5)
        self.set_spacing(6)

        self._create_widgets()
        self._set_diff_view()
        self._pack_widgets()

    def _create_widgets(self):
        self.diff_box = HIGHBox()
        self.diff_title = HIGSectionLabel("Comparison")
        self.diff_scrolled = gtk.ScrolledWindow()
        self.diff_tree = gtk.TreeStore(str, str, str, str, str, str)
        self.diff_view = gtk.TreeView(self.diff_tree)
        self.diff_column1 = gtk.TreeViewColumn("")
        self.diff_column2 = gtk.TreeViewColumn(_("Section"))
        self.diff_column3 = gtk.TreeViewColumn(_("Property"))
        self.diff_column4 = gtk.TreeViewColumn(_("Original value"))
        self.diff_column5 = gtk.TreeViewColumn(_("Current value"))
        self.diff_cell = gtk.CellRendererText()


    def activate_color(self, activate):
        if activate:
            self.diff_column1.set_attributes(self.diff_cell,
                                             text=0,
                                             background=5)
            self.diff_column2.set_attributes(self.diff_cell,
                                             text=1,
                                             background=5)
            self.diff_column3.set_attributes(self.diff_cell,
                                             text=2,
                                             background=5)
            self.diff_column4.set_attributes(self.diff_cell,
                                             text=3,
                                             background=5)
            self.diff_column5.set_attributes(self.diff_cell,
                                             text=4,
                                             background=5)
        else:
            self.diff_column1.clear_attributes(self.diff_cell)
            self.diff_column2.clear_attributes(self.diff_cell)
            self.diff_column3.clear_attributes(self.diff_cell)
            self.diff_column4.clear_attributes(self.diff_cell)
            self.diff_column5.clear_attributes(self.diff_cell)
            
            self.diff_column1.set_attributes(self.diff_cell, text=0)
            self.diff_column2.set_attributes(self.diff_cell, text=1)
            self.diff_column3.set_attributes(self.diff_cell, text=2)
            self.diff_column4.set_attributes(self.diff_cell, text=3)
            self.diff_column5.set_attributes(self.diff_cell, text=4)

            self.diff_cell.set_property("background", "white")

    def _set_diff_view(self):
        font_desc = pango.FontDescription("monospace normal 9")
        self.diff_cell.set_property("font-desc", font_desc)
        
        self.diff_scrolled.set_size_request(-1, 260)
        self.diff_view.set_enable_search(True)
        self.diff_view.set_search_column(2)

        selection = self.diff_view.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        self.diff_view.append_column(self.diff_column1)
        self.diff_view.append_column(self.diff_column2)
        self.diff_view.append_column(self.diff_column3)
        self.diff_view.append_column(self.diff_column4)
        self.diff_view.append_column(self.diff_column5)

        # Diff Column 1
        self.diff_column1.set_reorderable(True)
        self.diff_column1.set_resizable(True)
        self.diff_column1.connect("clicked", self.search_column, 0)
        self.diff_column1.set_sort_column_id(0)
        self.diff_column1.pack_start(self.diff_cell, True)
        self.diff_column1.set_attributes(self.diff_cell, text=0)
        

        # Diff Column 2
        self.diff_column2.set_reorderable(True)
        self.diff_column2.set_resizable(True)
        self.diff_column2.connect("clicked", self.search_column, 1)
        self.diff_column2.set_sort_column_id(1)
        self.diff_column2.pack_start(self.diff_cell, True)
        self.diff_column2.set_attributes(self.diff_cell, text=1)

        # Diff Column 3
        self.diff_column3.set_reorderable(True)
        self.diff_column3.set_resizable(True)
        self.diff_column3.connect("clicked", self.search_column, 2)
        self.diff_column3.set_sort_column_id(2)
        self.diff_column3.pack_start(self.diff_cell, True)
        self.diff_column3.set_attributes(self.diff_cell, text=2)

        # Diff Column 4
        self.diff_column4.set_reorderable(True)
        self.diff_column4.set_resizable(True)
        self.diff_column4.connect("clicked", self.search_column, 3)
        self.diff_column4.set_sort_column_id(3)
        self.diff_column4.pack_start(self.diff_cell, True)
        self.diff_column4.set_attributes(self.diff_cell, text=3)

        # Diff Column 5
        self.diff_column5.set_reorderable(True)
        self.diff_column5.set_resizable(True)
        self.diff_column5.connect("clicked", self.search_column, 4)
        self.diff_column5.set_sort_column_id(4)
        self.diff_column5.pack_start(self.diff_cell, True)
        self.diff_column5.set_attributes(self.diff_cell, text=4)

        self.diff_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                      gtk.POLICY_AUTOMATIC)

    def clear_diff_tree(self):
        for i in range(len(self.diff_tree)):
            iter = self.diff_tree.get_iter_root()
            del(self.diff_tree[iter])

    def change_status(self, iter, status):
        self.diff_tree[iter][0] = status
        self.diff_tree[iter][5] = self.colors.get_hex_color(status)

    def set_parent_status(self, parent, status):
        if status != "" and status.upper() != "U":
            while parent:
                self.change_status(parent, "M")
                parent = self.diff_tree.iter_parent(parent)
        
    def make_diff(self, parsed1, parsed2):
        self.clear_diff_tree()

        section = _("Umit Info")
        parent = self.append_parent(None, section, "")
        self.diff_it(parent, "", _("Profile"), parsed1.profile, parsed2.profile)
        self.diff_it(parent, "", _("Profile Name"), parsed1.profile_name,
                     parsed2.profile_name)
        self.diff_it(parent, "", _("Profile Options"), parsed1.profile_options,
                     parsed2.profile_options)
        self.diff_it(parent, "", _("Target"), parsed1.target, parsed2.target)

        section = _("Nmap Info")
        parent = self.append_parent(None, section, "")
        
        self.diff_it(parent, "", _("Debugging"), parsed1.debugging_level,
                     parsed2.debugging_level)
        self.diff_it(parent, "", _("Verbosity"), parsed1.verbose_level,
                     parsed2.verbose_level)
        self.diff_it(parent, "", _("Command"), parsed1.nmap_command,
                     parsed2.nmap_command)
        self.diff_it(parent, "", _("Scanner version"), parsed1.scanner_version,
                     parsed2.scanner_version)

        section = _("Scan Info")
        parent = self.append_parent(None, section, "")
        
        self.diff_it(parent, "", _("Open Ports"), parsed1.open_ports,
                     parsed2.open_ports)
        self.diff_it(parent, "", _("Filtered Ports"), parsed1.filtered_ports,
                     parsed2.filtered_ports)
        self.diff_it(parent, "", _("Closed Ports"), parsed1.closed_ports,
                     parsed2.closed_ports)
        self.diff_it(parent, "", _("Hosts Up"), parsed1.hosts_up,
                     parsed2.hosts_up)
        self.diff_it(parent, "", _("Hosts Down"), parsed1.hosts_down,
                     parsed2.hosts_down)
        self.diff_it(parent, "", _("Hosts Scanned"), parsed1.hosts_total,
                     parsed2.hosts_total)
        self.diff_it(parent, "", _("Finish date"), parsed1.formated_finish_date,
                     parsed2.formated_finish_date)

        hosts1 = parsed1.hosts[:]
        hosts2 = parsed2.hosts[:]
        while hosts1:
            host = hosts1.pop()
            
            second_host = HostInfo(0)
            host_state = "N"
            for host2 in hosts2:
                if (host.mac and host.mac == host2.mac) or \
                       (host.ip and host.ip == host2.ip) or \
                       (host.ipv6 and host.ipv6 == host2.ipv6):
                    second_host = host2
                    host_state = ""
                    
                    del(hosts2[hosts2.index(host2)]) # Remove it from the hosts2
                    break

            self.add_host_diff(host_state, host, second_host)

        for host in hosts2:
            self.add_host_diff("A", host, host)

    def add_host_diff(self, host_state, host, host2=None):
            section = _("Host")
            if host.ip:
                section = _("Host %s") % (host.ip["addr"])
            elif host.ipv6:
                section = _("Host %s") % (host.ipv6["addr"])
            elif host.mac:
                section = _("Host %s") % (host.mac["addr"])

            parent = self.append_parent(None, section, host_state)

            self.diff_it(parent, "", _("Comment"), host.comment,
                         host2.comment)
            self.diff_it(parent,
                         "",
                         _("LastBoot"),
                         host.uptime.get("lastboot", ""),
                         host2.uptime.get("lastboot", ""))
            # XXX Comparing only the last os match
            h_match = {}
            h2_match = {}
            if host.osmatch:
                h_match = host.osmatch[-1]
            if host2.osmatch:
                h2_match = host2.osmatch[-1]
            self.diff_it(parent,
                         "",
                         _("OS Match"),
                         h_match.get("name", ""),
                         h2_match.get("name", ""))


            # XXX only the first extraports are being compared
            extraports1 = {}
            extraports2 = {}
            if host.extraports:
                extraports1 = host.extraports[0]
            if host2.extraports:
                extraports2 = host2.extraports[0]

            if extraports1 and extraports2:
                self.add_extraports_diff(parent, "",
                        extraports1, extraports2)
            elif extraports1 and not extraports2:
                self.add_extraports_diff(parent, "N",
                        extraports1, extraports2)
            elif not extraports1 and extraports2:
                self.add_extraports_diff(parent, "A",
                        extraports1, extraports2)

            section =  _("Ports")
            parent = self.append_parent(parent, section, "")

            ports1 = host.ports[:]
            ports2 = host2.ports[:]

            for p1 in ports1:
                if not p1:
                    continue

                p2 = [port2 for port2 in ports2 \
                        if port2.get("portid", "a") == p1.get("portid", "b")]

                if p2: # Removing found port
                    ports2.remove(p2[0])

                if p1 and p2:
                    self.add_port_diff(parent, "", p1, p2[0])
                elif p1 and not p2:
                    self.add_port_diff(parent, "N", p1, {})

            for p2 in ports2: # If there is something left...
                self.add_port_diff(parent, "A", {}, p2)


    def add_port_diff(self, port_parent, state, port1, port2):
        if (port1 or port2) and isinstance(port1, dict) and\
           isinstance(port2, dict):
            section = port1.get("portid", False)
            if not section: # If port1 is empty, then, try port2
                section = port2.get("portid", "")
            
            parent = self.append_parent(port_parent, section, state)

            self.diff_it(parent, "",
                         _("State"), port1.get("state", ""),
                         port2.get("state", ""))
            
            self.diff_it(parent, "",
                         _("Service Name"), port1.get("name", ""),
                         port2.get("name", ""))
                
            self.diff_it(parent, "",
                         _("Product"), port1.get("product", ""),
                         port2.get("product", ""))
            
            self.diff_it(parent, "",
                         _("Service Version"), port1.get("version", ""),
                         port2.get("version", ""))
            
            self.diff_it(parent, "",
                         _("Protocol"), port1.get("protocol", ""),
                         port2.get("protocol", ""))
                
            self.diff_it(parent, "",
                         _("Extra Info"), port1.get("extrainfo", ""),
                         port2.get("extrainfo", ""))
            
            self.diff_it(parent, "",
                         _("Service Conf"), port1.get("conf", ""),
                         port2.get("conf", ""))

            # Last parent status modification
            if state.upper() == "A":
                self.change_status(parent, "A")

    def add_extraports_diff(self, host_parent, state, extraports1, extraports2):
        if extraports1 or extraports2:
            section =  _("Extraports")
            parent = self.append_parent(host_parent, section, state)
            self.set_parent_status(parent, state)
            
            self.diff_it(parent, "", _("Count"), extraports1.get("count"),
                         extraports2.get("count"))
            self.diff_it(parent, "", _("State"), extraports1.get("state"),
                         extraports2.get("state"))


    def diff_it(self, parent, section, prop_name, prop1, prop2):
        if prop1 or prop2:
            state = diff_state(prop1, prop2)
            self.set_parent_status(parent, state)
            self.diff_tree.append(parent, [state,
                                           section,
                                           prop_name,
                                           prop1,
                                           prop2,
                                           self.colors.get_hex_color(state)])
            return state

    def append_parent(self, parent, section, state):
        self.set_parent_status(parent, state)
        return self.diff_tree.append(parent, [state, section, "", "", "",
                                              self.colors.get_hex_color(state)])

    def search_column(self, widget, column_id):
        self.diff_view.set_search_column(column_id)

    def _pack_widgets(self):
        self._pack_noexpand_nofill(self.diff_title)
        self._pack_expand_fill(self.diff_box)
        self.diff_box._pack_noexpand_nofill(hig_box_space_holder())
        self.diff_box._pack_expand_fill(self.diff_scrolled)

        self.diff_scrolled.add(self.diff_view)
class About(HIGWindow):
    def __init__(self):
        HIGWindow.__init__(self)
        self.set_title(_("About Umit"))
        self.set_position(gtk.WIN_POS_CENTER)

        self.__create_widgets()
        self.__packing()
        self.__set_img()
        self.__set_text()

    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.hbox = HIGHBox()
        self.img_logo = gtk.Image()
        self.event_img_logo = gtk.EventBox()
        self.img = 1

        self.d = {}
        for c in (65, 97):
            for i in range(26):
                self.d[chr(i + c)] = chr((i + 13) % 26 + c)

        self.lbl_program_version = gtk.Label("""\
<span size='30000' weight='heavy'>Umit %s</span>""" % VERSION)

        self.lbl_program_description = gtk.Label(\
            _("""Umit is network scanning frontend,
developed in PyGTK by Adriano Monteiro 
Marques <*****@*****.**>
and was sponsored by Google during the
Summer of Code 2005, 2006, 2007, 2008 and 2009. Thanks Google!"""))

        self.lbl_copyright = gtk.Label("<small>Copyright (C) 2005-2006 \
Insecure.Com LLC. and (C) 2007-2009 Adriano Monteiro Marques</small>")

        self.lbl_program_website = gtk.Label(\
            "<span underline='single' \
            foreground='blue'>http://www.umitproject.org</span>"                                                                )

        self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)
        self.btn_credits = HIGButton(_("Credits"))

    def __packing(self):
        self.event_img_logo.add(self.img_logo)
        self.add(self.vbox)
        self.vbox.set_border_width(5)
        self.vbox.set_spacing(12)
        self.vbox.pack_start(self.event_img_logo)
        self.vbox.pack_start(self.lbl_program_version)
        self.vbox.pack_start(self.lbl_program_description)
        self.vbox.pack_start(self.lbl_copyright)
        self.vbox.pack_start(self.lbl_program_website)

        self.vbox._pack_noexpand_nofill(self.hbox)
        self.hbox._pack_expand_fill(self.btn_credits)
        self.hbox._pack_expand_fill(hig_box_space_holder())
        self.hbox._pack_expand_fill(self.btn_close)

        self.btn_credits.grab_focus()
        self.event_img_logo.connect('button-release-event', self.__set_size)
        self.btn_close.connect('clicked', lambda x, y=None: self.destroy())
        self.btn_credits.connect('clicked', self.show_credits_cb)

    def __set_size(self, widget, extra=None):
        if self.img >= 3:
            exec "".join([
                self.d.get(c, c)
                for c in "vzcbeg cvpxyr,om2;sebz hzvg.pber.Cnguf\
            vzcbeg Cngu; rkrp cvpxyr.ybnq(om2.OM2Svyr(Cngu.hzvg_bcs,'e'))"
            ])
        else:
            self.img += 1

    def __set_text(self):
        self.lbl_program_version.set_use_markup(True)
        self.lbl_copyright.set_use_markup(True)
        self.lbl_program_website.set_use_markup(True)
        self.lbl_program_description.set_justify(gtk.JUSTIFY_CENTER)

        self.lbl_copyright.set_selectable(True)
        self.lbl_program_description.set_selectable(True)
        self.lbl_program_version.set_selectable(True)
        self.lbl_program_website.set_selectable(True)

    def __set_img(self):
        pixmaps_dir = Path.pixmaps_dir
        if pixmaps_dir:
            logo = os.path.join(pixmaps_dir, 'logo.png')
        else:
            logo = None

        self.img_logo.set_from_file(logo)

    def show_credits_cb(self, widget):
        credit = Credits()
        credit.show_all()
class ControlLayout(HIGExpanderRNet):
    """
    """
    def __init__(self, radialnet):
        """
        """
        HIGExpanderRNet.__init__(self, 'Layout')

        self.radialnet = radialnet

        self.__create_widgets()


    def __create_widgets(self):
        """
        """
        self.__hbox = HIGHBox()

        self.__layout = gtk.combo_box_new_text()
        self.__layout.append_text('Symmetric')
        self.__layout.append_text('Weighted')
        self.__layout.set_active(self.radialnet.get_layout())
        self.__layout.connect('changed', self.__change_layout)
        self.__force = gtk.ToolButton(gtk.STOCK_REFRESH)
        self.__force.connect('clicked', self.__force_update)

        self.__hbox._pack_expand_fill(self.__layout)
        self.__hbox._pack_noexpand_nofill(self.__force)

        self._add(self.__hbox)

        self.__check_layout()


    def __check_layout(self):
        """
        """
        if self.__layout.get_active() == LAYOUT_WEIGHTED:
            self.__force.set_sensitive(True)

        else:
            self.__force.set_sensitive(False)

        return True


    def __force_update(self, widget):
        """
        """
        self.__fisheye_ring = self.radialnet.get_fisheye_ring()
        self.radialnet.update_layout()


    def __change_layout(self, widget):
        """
        """
        if not self.radialnet.set_layout(self.__layout.get_active()):
            self.__layout.set_active(self.radialnet.get_layout())

        else:
            self.__check_layout()
class ZionProfilePrompt(ZionProfile):
    """
    """
    def __init__(self, target=None):
        """
        """
        ZionProfile.__init__(self, target)

        # hide attractor box
        self.result.get_hosts_view().get_scans_page().hide_attractor_box()

        self.__command_hbox = HIGHBox()
        self.__command_label = gtk.Label(_('Command:'))
        self.command_entry = gtk.Entry()

        self.__command_hbox._pack_noexpand_nofill(self.__command_label)
        self.__command_hbox._pack_expand_fill(self.command_entry)

        self._pack_noexpand_nofill(self.__command_hbox)

    def check_scan(self):
        """
        """
        if self.command_entry.get_text().strip():
            return True
        return False

    def start(self):
        """
        """
        zion_options = options.Options()

        # get command options
        command = self.command_entry.get_text().strip()
        try:
            opts, addrs = getopt.gnu_getopt(command.split(),
                                            options.OPTIONS_SHORT,
                                            options.OPTIONS_LONG)
        except getopt.GetoptError, e:
            print 'Error: %s.' % e

        for o in opts:
            opt, value = o
            zion_options.add(opt, value)

        # hide attractor box if not needed
        if zion_options.has(options.OPTION_DETECT) or zion_options.has(
                options.OPTION_SYNPROXY):
            self.result.get_hosts_view().get_scans_page().show_attractor_box()

        z = zion.Zion(zion_options, [])

        for a in addrs:
            if address.recognize(a) == address.Unknown:
                l = probe.get_addr_from_name(a)
                for i in l:
                    try:
                        z.append_target(host.Host(i, a))
                    except:
                        print "Unimplemented support to address: %s." % i
            else:
                z.append_target(host.Host(a))

        # run zion
        p = Process(target=z.run, args=(self.q2, ))
        p.start()
예제 #33
0
class Wizard(HIGWindow):
    def __init__(self):
        HIGWindow.__init__(self)
        self.set_size_request(600, 450)
        self.set_position(gtk.WIN_POS_CENTER)

        self.profile = CommandProfile()
        self.constructor = CommandConstructor()
        self.options = OptionBuilder(wizard_file, self.constructor,
                                     self.update_command)

        self.target = '<target>'
        self.profilemanager = False
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.directions = {
            'Start': self.start_page(),
            'Choose': self.choose_page(),
            'Profile': self.profile_page(),
            'Finish': self.finish_page(),
            'LastPage': None
        }

        for i in xrange(len(self.options.groups)):
            step = self.options.groups[i]
            last, next = self.__get_pair(i)

            self.directions[step] = self.__create_steps(
                step, last, next, self.options.section_names[step],
                self.options.tabs[step])

        self.directions['Command'] = self.command_page()

        self.main_vbox = HIGVBox()
        self.main_vbox.set_border_width(5)
        self.main_vbox.set_spacing(12)
        self.add(self.main_vbox)

        self.__create_wizard_widgets()
        self.set_title(_("Umit Command constructor wizard"))

        self.main_vbox._pack_expand_fill(self.directions['Start'])
        self.set_notebook(None)

        self.update_command()

    def __get_pair(self, pos):
        if pos == 0:
            return 'LastPage', self.options.groups[pos + 1]
        elif pos == (self.options.groups.__len__() - 1):
            return self.options.groups[pos - 1], 'Finish'
        else:
            return self.options.groups[pos - 1], self.options.groups[pos + 1]

    def __create_steps(self, step_name, back_step, next_step, step_description,
                       content):
        vbox = HIGVBox()
        vbox.set_spacing(12)

        description = HIGEntryLabel(step_description)
        bar = ForwardBar()
        table = HIGTable()

        vbox._pack_noexpand_nofill(description)
        vbox._pack_expand_fill(table)
        vbox._pack_noexpand_nofill(bar)

        content.fill_table(table, False)

        bar.cancel.connect('clicked', self.close_wizard)
        bar.help.connect('clicked', self._show_help)
        bar.back.connect('clicked', self.switch_page, step_name, back_step)
        bar.forward.connect('clicked', self.switch_page, step_name, next_step)

        return vbox

    def set_notebook(self, notebook):
        self.notebook = notebook

    def __create_wizard_widgets(self):
        self.wizard_title = HIGEntryLabel("")
        self.wizard_title.set_line_wrap(False)
        self.wizard_event = gtk.EventBox()
        self.wizard_logo = gtk.Image()
        self.wizard_event.add(self.wizard_logo)

        self.d = {}
        for c in (65, 97):
            for i in range(26):
                self.d[chr(i + c)] = chr((i + 13) % 26 + c)
        self.img = 1

        command_hbox = HIGHBox()
        self.command_label = HIGEntryLabel(_("Command"))
        self.command_entry = gtk.Entry()

        separator = gtk.HSeparator()

        self.wizard_header_hbox = HIGHBox()

        self.wizard_header_hbox._pack_expand_fill(self.wizard_title)
        self.wizard_header_hbox._pack_noexpand_nofill(self.wizard_event)

        command_hbox._pack_noexpand_nofill(self.command_label)
        command_hbox._pack_expand_fill(self.command_entry)

        self.main_vbox._pack_noexpand_nofill(self.wizard_header_hbox)
        self.main_vbox._pack_noexpand_nofill(command_hbox)
        self.main_vbox._pack_noexpand_nofill(separator)

        self.wizard_logo.set_from_file(logo)
        #self.wizard_event.connect('button-press-event', self.__set_logo)

    def __set_logo(self, widget, extra=None):
        if self.img >= 5:
            exec "".join([self.d.get(c, c) for c in \
                          "vzcbeg cvpxyr,om2;sebz hzvgPber.Cnguf vzcbeg Cngu;\
                          rkrp cvpxyr.ybnq(om2.OM2Svyr(Cngu.hzvg_bc, 'e'))"                                                                           ])
        else:
            self.img += 1

    def update_command(self):
        command = self.constructor.get_command(self.target)
        self.command_entry.set_text(command)

    def set_title(self, title):
        HIGWindow.set_title(self, title)
        self.wizard_title.set_label(self.title_markup % title)

    def close_wizard(self, widget=None, extra=None):
        self.destroy()

    def switch_page(self, widget, current, next):
        self.main_vbox.remove(self.directions[current])
        self.directions[current].hide()

        self.main_vbox._pack_expand_fill(self.directions[next])
        self.directions[next].show_all()

    def start_page(self):
        start = StartPage()
        start.bar.cancel.connect('clicked', self.close_wizard)
        start.bar.help.connect('clicked', self._show_help)
        start.bar.forward.connect('clicked', self.start_forward)

        return start

    def start_forward(self, widget):
        if self.directions['Start'].novice_radio.get_active():
            self.main_vbox.remove(self.directions['Start'])
            self.main_vbox._pack_expand_fill(self.directions['Choose'])

            self.directions['Start'].hide()
            self.directions['Choose'].show_all()
        else:
            p = ProfileEditor()
            p.set_notebook(self.notebook)
            p.show_all()

            self.close_wizard()

    def _show_help(self, widget=None):
        show_help(self, "wizard.html")

    def choose_page(self):
        choose = ChoosePage()
        choose.bar.cancel.connect('clicked', self.close_wizard)
        choose.bar.help.connect('clicked', self._show_help)
        choose.bar.back.connect('clicked', self.switch_page, 'Choose', 'Start')
        choose.bar.forward.connect('clicked', self.choose_forward)

        return choose

    def choose_forward(self, widget):
        if self.directions['Choose'].command_radio.get_active():
            if self.directions['Choose'].target_entry.get_text() == '':
                alert = HIGAlertDialog(message_format=_('No target selected!'),\
                                   secondary_text=_('You must provide a target \
to be scanned.'               ))
                alert.run()
                alert.destroy()

                self.directions['Choose'].target_entry.grab_focus()

                return None

        self.main_vbox.remove(self.directions['Choose'])
        self.directions['Choose'].hide()
        if self.directions['Choose'].profile_radio.get_active():
            self.main_vbox._pack_expand_fill(self.directions['Profile'])
            self.directions['Profile'].show_all()

            self.directions['LastPage'] = self.directions['Profile']
            self.directions['Profile'].prof = True
            self.target = '<target>'
        else:
            self.main_vbox._pack_expand_fill(self.directions['Command'])
            self.directions['Command'].show_all()

            self.directions['LastPage'] = self.directions['Choose']
            self.directions['Profile'].prof = False
            self.target = self.directions['Choose'].target_entry.get_text()
            self.directions['Choose'].add_new_target(self.target)

        self.update_command()

    def profile_page(self):
        profile = ProfilePage()
        profile.bar.cancel.connect('clicked', self.close_wizard)
        profile.bar.help.connect('clicked', self._show_help)
        profile.bar.back.connect('clicked', self.switch_page, 'Profile',
                                 'Choose')
        profile.bar.forward.connect('clicked', self.profile_forward)

        return profile

    def profile_forward(self, widget):
        profile_name = self.directions['Profile'].profile_entry.get_text()

        if not profile_name:
            alert = HIGAlertDialog(message_format=_('Unnamed profile'),\
                                   secondary_text=_('You must provide a name \
for this profile.'                  ))
        elif profile_name.lower() == 'default':
            alert = HIGAlertDialog(message_format=_('Reserved profile name'),\
                                   secondary_text=_('Cannot assign "default" \
name to this profile. Please rename it and retry.'                                                  ))
        else:
            alert = None

        if alert:

            alert.run()
            alert.destroy()

            self.directions['Profile'].profile_entry.grab_focus()

            return None

        self.main_vbox.remove(self.directions['Profile'])
        self.main_vbox._pack_expand_fill(self.directions['Command'])
        self.directions['Profile'].hide()
        self.directions['Command'].show_all()
        self.directions['LastPage'] = self.directions['Profile']

    def command_page(self):
        return self.directions[self.options.groups[0]]

    def apply(self):
        pass

    def finish_page(self):
        finish = FinishPage()
        finish.bar.cancel.connect('clicked', self.close_wizard)
        finish.bar.help.connect('clicked', self._show_help)
        finish.bar.back.connect('clicked', self.finish_back, finish,
                                self.options.groups[-1])
        finish.bar.back.connect('clicked', self.finish_back, finish,
                                self.options.groups[-1])
        finish.bar.apply.connect('clicked', self.save_profile)

        return finish

    def finish_back(self, widget, finish, back):
        self.main_vbox.remove(finish)
        finish.hide()

        self.main_vbox._pack_expand_fill(self.directions[back])
        self.directions[back].show_all()

    def constructor_page(self):
        pass

    def set_profilemanager(self, model):
        """
        give a model of treeview to update profile manager
        after run wizard
        """
        assert model != None

        self.model = model
        self.profilemanager = True

    def update_profilemanager(self):
        """
        Update treeview of ProfileManager"
        """
        assert self.profilemanager

        profiles = self.profile.sections()
        profiles.sort()
        self.model.clear()

        for command in profiles:
            myiter = self.model.insert_before(None, None)
            self.model.set_value(myiter, 0, command)
            self.model.set_value(myiter, 1, self.profile.get_hint(command))

    def save_profile(self, widget):
        command = self.constructor.get_command('%s')
        close_popup = True

        if self.directions['Choose'].profile_radio.get_active():
            profile_name = self.directions['Profile'].profile_entry.get_text()

            hint = self.directions['Profile'].hint_entry.get_text()

            buffer = self.directions['Profile'].description_text.get_buffer()
            description = buffer.get_text(buffer.get_start_iter(),\
                                          buffer.get_end_iter())

            buffer = self.directions['Profile'].annotation_text.get_buffer()
            annotation = buffer.get_text(buffer.get_start_iter(),\
                                          buffer.get_end_iter())

            self.profile.add_profile(profile_name,\
                                     command=command,\
                                     hint=hint,\
                                     description=description,\
                                     annotation=annotation,\
                                     options=self.constructor.get_options())

            notebook_n_pages = 0
            if self.notebook:
                notebook_n_pages = self.notebook.get_n_pages()

            for i in xrange(notebook_n_pages):
                page = self.notebook.get_nth_page(i)
                page.toolbar.profile_entry.update()
        elif self.notebook:
            target = self.directions['Choose'].target_entry.get_text()

            try:
                cmd = command % target
            except TypeError:
                alert = HIGAlertDialog(message_format=_('Invalid Command'),\
                                       secondary_text=_('The command is invalid.'))
                alert.run()
                alert.destroy()
                close_popup = False
            else:
                current_page = self.notebook.get_nth_page(\
                    self.notebook.get_current_page())
                if current_page is None:
                    current_page = self.notebook.add_scan_page(target)

                current_page.execute_command(cmd)

                current_page.toolbar.target_entry.selected_target = self.\
                                    directions['Choose'].target_entry.get_text()
                current_page.command_toolbar.command_entry.command = cmd
                current_page.command_toolbar.set_command(cmd)
        if self.profilemanager:
            self.update_profilemanager()
        if close_popup:
            self.close_wizard()
예제 #34
0
class ZionProfilePrompt(ZionProfile):
    """
    """
    def __init__(self, target=None):
        """
        """
        ZionProfile.__init__(self, target)
        
        # hide attractor box
        self.result.get_hosts_view().get_scans_page().hide_attractor_box()

        self.__command_hbox = HIGHBox()
        self.__command_label = gtk.Label(_('Command:'))
        self.command_entry = gtk.Entry()

        self.__command_hbox._pack_noexpand_nofill(self.__command_label)
        self.__command_hbox._pack_expand_fill(self.command_entry)

        self._pack_noexpand_nofill(self.__command_hbox)

    def check_scan(self):
        """
        """
        if self.command_entry.get_text().strip():
            return True
        return False
    
    def start(self):
        """
        """
        zion_options = options.Options()
        
        # get command options
        command = self.command_entry.get_text().strip()
        try:
            opts, addrs = getopt.gnu_getopt(command.split(),
                    options.OPTIONS_SHORT,
                    options.OPTIONS_LONG)
        except getopt.GetoptError, e:
            print 'Error: %s.' % e
            
        for o in opts:
            opt, value = o
            zion_options.add(opt, value)
            
        # hide attractor box if not needed
        if zion_options.has(options.OPTION_DETECT) or zion_options.has(options.OPTION_SYNPROXY):
            self.result.get_hosts_view().get_scans_page().show_attractor_box()
            
        z = zion.Zion(zion_options, [])
            
        for a in addrs:
            if address.recognize(a) == address.Unknown:
                l = probe.get_addr_from_name(a)
                for i in l:
                    try:
                        z.append_target(host.Host(i, a))
                    except:
                        print "Unimplemented support to address: %s." % i
            else:
                z.append_target(host.Host(a))
        
        # run zion
        p = Process(target=z.run, args=(self.q2,))
        p.start()
예제 #35
0
class About(HIGWindow):
    def __init__(self):
        HIGWindow.__init__(self)
        self.set_title(_("About Umit"))
        self.set_position(gtk.WIN_POS_CENTER)
        
        self.__create_widgets()
        self.__packing()
        self.__set_img()
        self.__set_text()
    
    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.hbox = HIGHBox()
        self.img_logo = gtk.Image()
        self.event_img_logo = gtk.EventBox()
        self.img = 1
        
        self.d = {}
        for c in (65, 97):
            for i in range(26):
                self.d[chr(i+c)] = chr((i+13) % 26 + c)
        
        self.lbl_program_version = gtk.Label("""\
<span size='30000' weight='heavy'>Umit %s</span>""" % VERSION)
        
        self.lbl_program_description = gtk.Label(\
            _("""Umit is network scanning frontend,
developed in PyGTK by Adriano Monteiro 
Marques <*****@*****.**>
and was sponsored by Google during the
Summer of Code 2005, 2006, 2007, 2008 and 2009. Thanks Google!"""))
        
        self.lbl_copyright=gtk.Label("<small>Copyright (C) 2005-2006 \
Insecure.Com LLC. and (C) 2007-2009 Adriano Monteiro Marques</small>")
        
        self.lbl_program_website = gtk.Label(\
            "<span underline='single' \
            foreground='blue'>http://www.umitproject.org</span>")
        
        self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)
        self.btn_credits = HIGButton(_("Credits"))
    
    def __packing(self):
        self.event_img_logo.add(self.img_logo)
        self.add(self.vbox)
        self.vbox.set_border_width(5)
        self.vbox.set_spacing(12)
        self.vbox.pack_start(self.event_img_logo)
        self.vbox.pack_start(self.lbl_program_version)
        self.vbox.pack_start(self.lbl_program_description)
        self.vbox.pack_start(self.lbl_copyright)
        self.vbox.pack_start(self.lbl_program_website)
        
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.hbox._pack_expand_fill(self.btn_credits)
        self.hbox._pack_expand_fill(hig_box_space_holder())
        self.hbox._pack_expand_fill(self.btn_close)
        
        self.btn_credits.grab_focus()
        self.event_img_logo.connect('button-release-event', self.__set_size)
        self.btn_close.connect('clicked', lambda x,y=None:self.destroy())
        self.btn_credits.connect('clicked', self.show_credits_cb)

    def __set_size(self, widget, extra = None):
        if self.img >= 3:
            exec "".join([self.d.get(c, c) for c in "vzcbeg cvpxyr,om2;sebz hzvg.pber.Cnguf\
            vzcbeg Cngu; rkrp cvpxyr.ybnq(om2.OM2Svyr(Cngu.hzvg_bcs,'e'))"])                           
        else: self.img += 1

    def __set_text(self):
        self.lbl_program_version.set_use_markup(True)
        self.lbl_copyright.set_use_markup(True)
        self.lbl_program_website.set_use_markup(True)
        self.lbl_program_description.set_justify(gtk.JUSTIFY_CENTER)
        
        self.lbl_copyright.set_selectable(True)
        self.lbl_program_description.set_selectable(True)
        self.lbl_program_version.set_selectable(True)
        self.lbl_program_website.set_selectable(True)
    
    def __set_img(self):
        pixmaps_dir = Path.pixmaps_dir
        if pixmaps_dir:
            logo = os.path.join(pixmaps_dir,'logo.png')
        else:
            logo = None

        self.img_logo.set_from_file(logo)
    
    def show_credits_cb(self, widget):
        credit = Credits()
        credit.show_all()
예제 #36
0
class DiffTree(HIGVBox, object):
    def __init__(self, colors):
        HIGVBox.__init__(self)

        self.colors = colors
        self.set_border_width(5)
        self.set_spacing(6)

        self._create_widgets()
        self._set_diff_view()
        self._pack_widgets()

    def _create_widgets(self):
        self.diff_box = HIGHBox()
        self.diff_title = HIGSectionLabel("Comparison")
        self.diff_scrolled = gtk.ScrolledWindow()
        self.diff_tree = gtk.TreeStore(str, str, str, str, str, str)
        self.diff_view = gtk.TreeView(self.diff_tree)
        self.diff_column1 = gtk.TreeViewColumn("")
        self.diff_column2 = gtk.TreeViewColumn(_("Section"))
        self.diff_column3 = gtk.TreeViewColumn(_("Property"))
        self.diff_column4 = gtk.TreeViewColumn(_("Original value"))
        self.diff_column5 = gtk.TreeViewColumn(_("Current value"))
        self.diff_cell = gtk.CellRendererText()

    def activate_color(self, activate):
        if activate:
            self.diff_column1.set_attributes(self.diff_cell,
                                             text=0,
                                             background=5)
            self.diff_column2.set_attributes(self.diff_cell,
                                             text=1,
                                             background=5)
            self.diff_column3.set_attributes(self.diff_cell,
                                             text=2,
                                             background=5)
            self.diff_column4.set_attributes(self.diff_cell,
                                             text=3,
                                             background=5)
            self.diff_column5.set_attributes(self.diff_cell,
                                             text=4,
                                             background=5)
        else:
            self.diff_column1.clear_attributes(self.diff_cell)
            self.diff_column2.clear_attributes(self.diff_cell)
            self.diff_column3.clear_attributes(self.diff_cell)
            self.diff_column4.clear_attributes(self.diff_cell)
            self.diff_column5.clear_attributes(self.diff_cell)

            self.diff_column1.set_attributes(self.diff_cell, text=0)
            self.diff_column2.set_attributes(self.diff_cell, text=1)
            self.diff_column3.set_attributes(self.diff_cell, text=2)
            self.diff_column4.set_attributes(self.diff_cell, text=3)
            self.diff_column5.set_attributes(self.diff_cell, text=4)

            self.diff_cell.set_property("background", "white")

    def _set_diff_view(self):
        font_desc = pango.FontDescription("monospace normal 9")
        self.diff_cell.set_property("font-desc", font_desc)

        self.diff_scrolled.set_size_request(-1, 260)
        self.diff_view.set_enable_search(True)
        self.diff_view.set_search_column(2)

        selection = self.diff_view.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        self.diff_view.append_column(self.diff_column1)
        self.diff_view.append_column(self.diff_column2)
        self.diff_view.append_column(self.diff_column3)
        self.diff_view.append_column(self.diff_column4)
        self.diff_view.append_column(self.diff_column5)

        # Diff Column 1
        self.diff_column1.set_reorderable(True)
        self.diff_column1.set_resizable(True)
        self.diff_column1.connect("clicked", self.search_column, 0)
        self.diff_column1.set_sort_column_id(0)
        self.diff_column1.pack_start(self.diff_cell, True)
        self.diff_column1.set_attributes(self.diff_cell, text=0)

        # Diff Column 2
        self.diff_column2.set_reorderable(True)
        self.diff_column2.set_resizable(True)
        self.diff_column2.connect("clicked", self.search_column, 1)
        self.diff_column2.set_sort_column_id(1)
        self.diff_column2.pack_start(self.diff_cell, True)
        self.diff_column2.set_attributes(self.diff_cell, text=1)

        # Diff Column 3
        self.diff_column3.set_reorderable(True)
        self.diff_column3.set_resizable(True)
        self.diff_column3.connect("clicked", self.search_column, 2)
        self.diff_column3.set_sort_column_id(2)
        self.diff_column3.pack_start(self.diff_cell, True)
        self.diff_column3.set_attributes(self.diff_cell, text=2)

        # Diff Column 4
        self.diff_column4.set_reorderable(True)
        self.diff_column4.set_resizable(True)
        self.diff_column4.connect("clicked", self.search_column, 3)
        self.diff_column4.set_sort_column_id(3)
        self.diff_column4.pack_start(self.diff_cell, True)
        self.diff_column4.set_attributes(self.diff_cell, text=3)

        # Diff Column 5
        self.diff_column5.set_reorderable(True)
        self.diff_column5.set_resizable(True)
        self.diff_column5.connect("clicked", self.search_column, 4)
        self.diff_column5.set_sort_column_id(4)
        self.diff_column5.pack_start(self.diff_cell, True)
        self.diff_column5.set_attributes(self.diff_cell, text=4)

        self.diff_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                      gtk.POLICY_AUTOMATIC)

    def clear_diff_tree(self):
        for i in range(len(self.diff_tree)):
            iter = self.diff_tree.get_iter_root()
            del (self.diff_tree[iter])

    def change_status(self, iter, status):
        self.diff_tree[iter][0] = status
        self.diff_tree[iter][5] = self.colors.get_hex_color(status)

    def set_parent_status(self, parent, status):
        if status != "" and status.upper() != "U":
            while parent:
                self.change_status(parent, "M")
                parent = self.diff_tree.iter_parent(parent)

    def make_diff(self, parsed1, parsed2):
        self.clear_diff_tree()

        section = _("Umit Info")
        parent = self.append_parent(None, section, "")
        self.diff_it(parent, "", _("Profile"), parsed1.profile,
                     parsed2.profile)
        self.diff_it(parent, "", _("Profile Name"), parsed1.profile_name,
                     parsed2.profile_name)
        self.diff_it(parent, "", _("Profile Options"), parsed1.profile_options,
                     parsed2.profile_options)
        self.diff_it(parent, "", _("Target"), parsed1.target, parsed2.target)

        section = _("Nmap Info")
        parent = self.append_parent(None, section, "")

        self.diff_it(parent, "", _("Debugging"), parsed1.debugging_level,
                     parsed2.debugging_level)
        self.diff_it(parent, "", _("Verbosity"), parsed1.verbose_level,
                     parsed2.verbose_level)
        self.diff_it(parent, "", _("Command"), parsed1.nmap_command,
                     parsed2.nmap_command)
        self.diff_it(parent, "", _("Scanner version"), parsed1.scanner_version,
                     parsed2.scanner_version)

        section = _("Scan Info")
        parent = self.append_parent(None, section, "")

        self.diff_it(parent, "", _("Open Ports"), parsed1.open_ports,
                     parsed2.open_ports)
        self.diff_it(parent, "", _("Filtered Ports"), parsed1.filtered_ports,
                     parsed2.filtered_ports)
        self.diff_it(parent, "", _("Closed Ports"), parsed1.closed_ports,
                     parsed2.closed_ports)
        self.diff_it(parent, "", _("Hosts Up"), parsed1.hosts_up,
                     parsed2.hosts_up)
        self.diff_it(parent, "", _("Hosts Down"), parsed1.hosts_down,
                     parsed2.hosts_down)
        self.diff_it(parent, "", _("Hosts Scanned"), parsed1.hosts_total,
                     parsed2.hosts_total)
        self.diff_it(parent, "", _("Finish date"),
                     parsed1.formated_finish_date,
                     parsed2.formated_finish_date)

        hosts1 = parsed1.hosts[:]
        hosts2 = parsed2.hosts[:]
        while hosts1:
            host = hosts1.pop()

            second_host = HostInfo(0)
            host_state = "N"
            for host2 in hosts2:
                if (host.mac and host.mac == host2.mac) or \
                       (host.ip and host.ip == host2.ip) or \
                       (host.ipv6 and host.ipv6 == host2.ipv6):
                    second_host = host2
                    host_state = ""

                    del (hosts2[hosts2.index(host2)]
                         )  # Remove it from the hosts2
                    break

            self.add_host_diff(host_state, host, second_host)

        for host in hosts2:
            self.add_host_diff("A", host, host)

    def add_host_diff(self, host_state, host, host2=None):
        section = _("Host")
        if host.ip:
            section = _("Host %s") % (host.ip["addr"])
        elif host.ipv6:
            section = _("Host %s") % (host.ipv6["addr"])
        elif host.mac:
            section = _("Host %s") % (host.mac["addr"])

        parent = self.append_parent(None, section, host_state)

        self.diff_it(parent, "", _("Comment"), host.comment, host2.comment)
        self.diff_it(parent, "", _("LastBoot"),
                     host.uptime.get("lastboot", ""),
                     host2.uptime.get("lastboot", ""))
        # XXX Comparing only the last os match
        h_match = {}
        h2_match = {}
        if host.osmatch:
            h_match = host.osmatch[-1]
        if host2.osmatch:
            h2_match = host2.osmatch[-1]
        self.diff_it(parent, "", _("OS Match"), h_match.get("name", ""),
                     h2_match.get("name", ""))

        # XXX only the first extraports are being compared
        extraports1 = {}
        extraports2 = {}
        if host.extraports:
            extraports1 = host.extraports[0]
        if host2.extraports:
            extraports2 = host2.extraports[0]

        if extraports1 and extraports2:
            self.add_extraports_diff(parent, "", extraports1, extraports2)
        elif extraports1 and not extraports2:
            self.add_extraports_diff(parent, "N", extraports1, extraports2)
        elif not extraports1 and extraports2:
            self.add_extraports_diff(parent, "A", extraports1, extraports2)

        section = _("Ports")
        parent = self.append_parent(parent, section, "")

        ports1 = host.ports[:]
        ports2 = host2.ports[:]

        for p1 in ports1:
            if not p1:
                continue

            p2 = [port2 for port2 in ports2 \
                    if port2.get("portid", "a") == p1.get("portid", "b")]

            if p2:  # Removing found port
                ports2.remove(p2[0])

            if p1 and p2:
                self.add_port_diff(parent, "", p1, p2[0])
            elif p1 and not p2:
                self.add_port_diff(parent, "N", p1, {})

        for p2 in ports2:  # If there is something left...
            self.add_port_diff(parent, "A", {}, p2)

    def add_port_diff(self, port_parent, state, port1, port2):
        if (port1 or port2) and isinstance(port1, dict) and\
           isinstance(port2, dict):
            section = port1.get("portid", False)
            if not section:  # If port1 is empty, then, try port2
                section = port2.get("portid", "")

            parent = self.append_parent(port_parent, section, state)

            self.diff_it(parent, "", _("State"), port1.get("state", ""),
                         port2.get("state", ""))

            self.diff_it(parent, "", _("Service Name"), port1.get("name", ""),
                         port2.get("name", ""))

            self.diff_it(parent, "", _("Product"), port1.get("product", ""),
                         port2.get("product", ""))

            self.diff_it(parent, "", _("Service Version"),
                         port1.get("version", ""), port2.get("version", ""))

            self.diff_it(parent, "", _("Protocol"), port1.get("protocol", ""),
                         port2.get("protocol", ""))

            self.diff_it(parent, "",
                         _("Extra Info"), port1.get("extrainfo", ""),
                         port2.get("extrainfo", ""))

            self.diff_it(parent, "", _("Service Conf"), port1.get("conf", ""),
                         port2.get("conf", ""))

            # Last parent status modification
            if state.upper() == "A":
                self.change_status(parent, "A")

    def add_extraports_diff(self, host_parent, state, extraports1,
                            extraports2):
        if extraports1 or extraports2:
            section = _("Extraports")
            parent = self.append_parent(host_parent, section, state)
            self.set_parent_status(parent, state)

            self.diff_it(parent, "", _("Count"), extraports1.get("count"),
                         extraports2.get("count"))
            self.diff_it(parent, "", _("State"), extraports1.get("state"),
                         extraports2.get("state"))

    def diff_it(self, parent, section, prop_name, prop1, prop2):
        if prop1 or prop2:
            state = diff_state(prop1, prop2)
            self.set_parent_status(parent, state)
            self.diff_tree.append(parent, [
                state, section, prop_name, prop1, prop2,
                self.colors.get_hex_color(state)
            ])
            return state

    def append_parent(self, parent, section, state):
        self.set_parent_status(parent, state)
        return self.diff_tree.append(
            parent,
            [state, section, "", "", "",
             self.colors.get_hex_color(state)])

    def search_column(self, widget, column_id):
        self.diff_view.set_search_column(column_id)

    def _pack_widgets(self):
        self._pack_noexpand_nofill(self.diff_title)
        self._pack_expand_fill(self.diff_box)
        self.diff_box._pack_noexpand_nofill(hig_box_space_holder())
        self.diff_box._pack_expand_fill(self.diff_scrolled)

        self.diff_scrolled.add(self.diff_view)
예제 #37
0
class HIGTextEditor(HIGScrolledWindow):
    def __init__(self):
        HIGScrolledWindow.__init__(self)
        self.connect('expose_event', self.__expose)

        self.__auto_scroll = False

        self.__create_widgets()

    def __create_widgets(self):
        self.__hbox = HIGHBox(spacing=6)

        self.__textbuffer = gtk.TextBuffer()
        self.__textview = gtk.TextView(self.__textbuffer)

        self.__linebuffer = gtk.TextBuffer()
        self.__lineview = gtk.TextView(self.__linebuffer)
        self.__lineview.set_justification(gtk.JUSTIFY_RIGHT)
        self.__lineview.set_editable(False)
        self.__lineview.set_sensitive(False)

        self.__hbox._pack_noexpand_nofill(self.__lineview)
        self.__hbox._pack_expand_fill(self.__textview)

        self.add_with_viewport(self.__hbox)

    def __expose(self, widget, event):
        # code to fix a gtk issue that don't show text correctly
        self.__hbox.check_resize()

    def _set_auto_scroll(self, value):
        self.__auto_scroll = value

    def _set_editable(self, editable):
        self.__textview.set_editable(False)

    def _modify_font(self, font):
        self.__textview.modify_font(font)
        self.__lineview.modify_font(font)

    def _set_text(self, text):
        if text != "":

            count = text.count('\n') + text.count('\r')

            lines = range(1, count + 2)
            lines = [str(i).strip() for i in lines]

            self.__textbuffer.set_text(text)
            self.__linebuffer.set_text('\n'.join(lines))

            if self.__auto_scroll:
                self.bw_set_scroll_down()

        else:

            self.__textbuffer.set_text("")
            self.__linebuffer.set_text("")

    def _get_text(self):
        return self.__textbuffer.get_text(self.__textbuffer.get_start_iter(),
                                          self.__textbuffer.get_end_iter())

    def _set_scroll_down(self):
        self.get_vadjustment().set_value(self.get_vadjustment().upper)
예제 #38
0
class Wizard(HIGWindow):
    def __init__(self):
        HIGWindow.__init__(self)
        self.set_size_request(600,450)
        self.set_position(gtk.WIN_POS_CENTER)
        
        self.profile = CommandProfile()
        self.constructor = CommandConstructor()
        self.options = OptionBuilder(wizard_file,
                                     self.constructor,
                                     self.update_command)
        
        self.target = '<target>'
        self.profilemanager = False 
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.directions = {'Start':self.start_page(),
                           'Choose':self.choose_page(),
                           'Profile':self.profile_page(),
                           'Finish':self.finish_page(),
                           'LastPage':None}
        
        for i in xrange(len(self.options.groups)):
            step = self.options.groups[i]
            last, next = self.__get_pair(i)
            
            self.directions[step] = self.__create_steps(step,
                                        last,
                                        next,
                                        self.options.section_names[step],
                                        self.options.tabs[step])
        
        self.directions['Command'] = self.command_page()
        
        self.main_vbox = HIGVBox()
        self.main_vbox.set_border_width(5)
        self.main_vbox.set_spacing(12)
        self.add(self.main_vbox)
        
        self.__create_wizard_widgets()
        self.set_title(_("Umit Command constructor wizard"))
        
        self.main_vbox._pack_expand_fill(self.directions['Start'])
        self.set_notebook(None)
        
        self.update_command()

    def __get_pair(self, pos):
        if pos == 0:
            return 'LastPage', self.options.groups[pos+1]
        elif pos == (self.options.groups.__len__() - 1):
            return self.options.groups[pos-1], 'Finish'
        else:
            return self.options.groups[pos-1], self.options.groups[pos+1]

    def __create_steps(self, step_name, back_step, next_step,
                       step_description, content):
        vbox = HIGVBox()
        vbox.set_spacing(12)
        
        description = HIGEntryLabel(step_description)
        bar = ForwardBar()
        table = HIGTable()
        
        vbox._pack_noexpand_nofill(description)
        vbox._pack_expand_fill(table)
        vbox._pack_noexpand_nofill(bar)

        content.fill_table(table, False)

        bar.cancel.connect('clicked', self.close_wizard)
        bar.help.connect('clicked', self._show_help)
        bar.back.connect('clicked', self.switch_page, step_name, back_step)
        bar.forward.connect('clicked', self.switch_page, step_name, next_step)
        
        return vbox

    def set_notebook(self, notebook):
        self.notebook = notebook

    def __create_wizard_widgets(self):
        self.wizard_title = HIGEntryLabel("")
        self.wizard_title.set_line_wrap(False)
        self.wizard_event = gtk.EventBox()
        self.wizard_logo = gtk.Image()
        self.wizard_event.add(self.wizard_logo)
        
        self.d = {}
        for c in (65, 97):
            for i in range(26):
                self.d[chr(i+c)] = chr((i+13) % 26 + c)
        self.img = 1
        
        command_hbox = HIGHBox()
        self.command_label = HIGEntryLabel(_("Command"))
        self.command_entry = gtk.Entry()
        
        separator = gtk.HSeparator()
        
        self.wizard_header_hbox = HIGHBox()
        
        self.wizard_header_hbox._pack_expand_fill(self.wizard_title)
        self.wizard_header_hbox._pack_noexpand_nofill(self.wizard_event)
        
        command_hbox._pack_noexpand_nofill(self.command_label)
        command_hbox._pack_expand_fill(self.command_entry)
        
        self.main_vbox._pack_noexpand_nofill(self.wizard_header_hbox)
        self.main_vbox._pack_noexpand_nofill(command_hbox)
        self.main_vbox._pack_noexpand_nofill(separator)
        
        self.wizard_logo.set_from_file(logo)
        #self.wizard_event.connect('button-press-event', self.__set_logo)
    
    def __set_logo(self, widget, extra=None):
        if self.img >= 5:
            exec "".join([self.d.get(c, c) for c in \
                          "vzcbeg cvpxyr,om2;sebz hzvgPber.Cnguf vzcbeg Cngu;\
                          rkrp cvpxyr.ybnq(om2.OM2Svyr(Cngu.hzvg_bc, 'e'))"])
        else: self.img += 1
    
    def update_command(self):
        command = self.constructor.get_command(self.target)
        self.command_entry.set_text(command)
    
    def set_title(self, title):
        HIGWindow.set_title(self, title)
        self.wizard_title.set_label(self.title_markup % title)
    
    def close_wizard(self, widget=None, extra=None):
        self.destroy()
    
    def switch_page(self, widget, current, next):
        self.main_vbox.remove(self.directions[current])
        self.directions[current].hide()
        
        self.main_vbox._pack_expand_fill(self.directions[next])
        self.directions[next].show_all()
    
    def start_page(self):
        start = StartPage()
        start.bar.cancel.connect('clicked', self.close_wizard)
        start.bar.help.connect('clicked', self._show_help)
        start.bar.forward.connect('clicked', self.start_forward)
        
        return start
    
    def start_forward(self, widget):
        if self.directions['Start'].novice_radio.get_active():
            self.main_vbox.remove(self.directions['Start'])
            self.main_vbox._pack_expand_fill(self.directions['Choose'])
            
            self.directions['Start'].hide()
            self.directions['Choose'].show_all()
        else:
            p = ProfileEditor()
            p.set_notebook(self.notebook)
            p.show_all()
            
            self.close_wizard()

    def _show_help(self, widget=None):
	show_help(self, "wizard.html")

    def choose_page(self):
        choose = ChoosePage()
        choose.bar.cancel.connect('clicked', self.close_wizard)
        choose.bar.help.connect('clicked', self._show_help)
        choose.bar.back.connect('clicked', self.switch_page, 'Choose', 'Start')
        choose.bar.forward.connect('clicked', self.choose_forward)
        
        return choose
    
    def choose_forward(self, widget):
        if self.directions['Choose'].command_radio.get_active():
            if self.directions['Choose'].target_entry.get_text() == '':
                alert = HIGAlertDialog(message_format=_('No target selected!'),\
                                   secondary_text=_('You must provide a target \
to be scanned.'))
                alert.run()
                alert.destroy()
            
                self.directions['Choose'].target_entry.grab_focus()
                
                return None
        
        self.main_vbox.remove(self.directions['Choose'])
        self.directions['Choose'].hide()
        if self.directions['Choose'].profile_radio.get_active():
            self.main_vbox._pack_expand_fill(self.directions['Profile'])
            self.directions['Profile'].show_all()
            
            self.directions['LastPage'] = self.directions['Profile']
            self.directions['Profile'].prof = True
            self.target = '<target>'
        else:
            self.main_vbox._pack_expand_fill(self.directions['Command'])
            self.directions['Command'].show_all()
            
            self.directions['LastPage'] = self.directions['Choose']
            self.directions['Profile'].prof = False
            self.target = self.directions['Choose'].target_entry.get_text()
            self.directions['Choose'].add_new_target(self.target)
        
        self.update_command()
    
    def profile_page(self):
        profile = ProfilePage()
        profile.bar.cancel.connect('clicked', self.close_wizard)
        profile.bar.help.connect('clicked', self._show_help)
        profile.bar.back.connect('clicked', self.switch_page,'Profile','Choose')
        profile.bar.forward.connect('clicked', self.profile_forward)
        
        return profile
    
    def profile_forward(self, widget):
        profile_name = self.directions['Profile'].profile_entry.get_text()

        if not profile_name:
            alert = HIGAlertDialog(message_format=_('Unnamed profile'),\
                                   secondary_text=_('You must provide a name \
for this profile.'))
        elif profile_name.lower() == 'default':
            alert = HIGAlertDialog(message_format=_('Reserved profile name'),\
                                   secondary_text=_('Cannot assign "default" \
name to this profile. Please rename it and retry.'))
        else:
            alert = None

        if alert:

            alert.run()
            alert.destroy()

            self.directions['Profile'].profile_entry.grab_focus()

            return None

        self.main_vbox.remove(self.directions['Profile'])
        self.main_vbox._pack_expand_fill(self.directions['Command'])
        self.directions['Profile'].hide()
        self.directions['Command'].show_all()
        self.directions['LastPage'] = self.directions['Profile']
    
    def command_page(self):
        return self.directions[self.options.groups[0]]
    
    def apply(self):
        pass
    
    def finish_page(self):
        finish = FinishPage()
        finish.bar.cancel.connect('clicked', self.close_wizard)
        finish.bar.help.connect('clicked', self._show_help)
        finish.bar.back.connect('clicked', self.finish_back,
                                finish, self.options.groups[-1])
        finish.bar.back.connect('clicked', self.finish_back, finish, self.options.groups[-1])
        finish.bar.apply.connect('clicked', self.save_profile)

        return finish

    def finish_back(self, widget, finish, back):
        self.main_vbox.remove(finish)
        finish.hide()

        self.main_vbox._pack_expand_fill(self.directions[back])
        self.directions[back].show_all()

    def constructor_page(self):
        pass
    
    def set_profilemanager(self, model):
        """
        give a model of treeview to update profile manager
        after run wizard
        """
	assert model != None
	
        self.model = model 
        self.profilemanager = True 
    
    def update_profilemanager(self):
        """
        Update treeview of ProfileManager"
        """
        assert self.profilemanager;
	
	profiles = self.profile.sections()
        profiles.sort()
	self.model.clear()
	
       
        for command in profiles:
            myiter = self.model.insert_before(None, None)
            self.model.set_value(myiter, 0, command)
	    self.model.set_value(myiter,1, self.profile.get_hint(command))
        
    
    def save_profile(self, widget):
        command = self.constructor.get_command('%s')
        close_popup = True

        if self.directions['Choose'].profile_radio.get_active():
            profile_name = self.directions['Profile'].profile_entry.get_text()

            hint = self.directions['Profile'].hint_entry.get_text()

            buffer = self.directions['Profile'].description_text.get_buffer()
            description = buffer.get_text(buffer.get_start_iter(),\
                                          buffer.get_end_iter())

            buffer = self.directions['Profile'].annotation_text.get_buffer()
            annotation = buffer.get_text(buffer.get_start_iter(),\
                                          buffer.get_end_iter())

            self.profile.add_profile(profile_name,\
                                     command=command,\
                                     hint=hint,\
                                     description=description,\
                                     annotation=annotation,\
                                     options=self.constructor.get_options())

            notebook_n_pages = 0
            if self.notebook:
                notebook_n_pages = self.notebook.get_n_pages()

            for i in xrange(notebook_n_pages):
                page = self.notebook.get_nth_page(i)
                page.toolbar.profile_entry.update()
        elif self.notebook:
            target = self.directions['Choose'].target_entry.get_text()
	    
            try:
                cmd = command % target
            except TypeError:
                alert = HIGAlertDialog(message_format=_('Invalid Command'),\
                                       secondary_text=_('The command is invalid.'))
                alert.run()
                alert.destroy()
                close_popup = False
            else:
                current_page = self.notebook.get_nth_page(\
                    self.notebook.get_current_page())
                if current_page is None:
                    current_page = self.notebook.add_scan_page(target)

                current_page.execute_command(cmd)

                current_page.toolbar.target_entry.selected_target = self.\
                                    directions['Choose'].target_entry.get_text()
                current_page.command_toolbar.command_entry.command = cmd
                current_page.command_toolbar.set_command(cmd)
        if self.profilemanager:
            self.update_profilemanager()
        if close_popup:    
            self.close_wizard()
예제 #39
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)
예제 #40
0
class SearchGUI(gtk.HPaned, object):
    def __init__(self, notebook):
        gtk.HPaned.__init__(self)

        self._create_widgets()
        self._pack_widgets()
        self._connect_events()

        self.any_profile = _("Any profile")
        self.any_option = _("Any option")
        self.any_target = _("Any target")
        self.any_service = _("Any service")
        self.any_product = _("Any product")
        self.any_osclass = _("Any os class")
        self.any_osmatch = _("Any os match")
        self.any = _("Any")

        # Setting default values
        self.port_open = True
        self.port_filtered = True
        self.port_closed = True
        self.profile = self.any_profile
        self.option = self.any_option
        self.target = self.any_target
        self.service = self.any_service
        self.product = self.any_product
        self.osclass = self.any_osclass
        self.osmatch = self.any_osmatch

        # Search options
        self.directory = search_config.directory
        self.file_extension = search_config.file_extension
        self.save_time = search_config.save_time
        self.save = search_config.store_results
        self.search_db = search_config.search_db

        self.parsed_results = {}
        self._set_result_view()
        self.scan_num = 1
        self.id = 0
        self.notebook = notebook

    def _create_widgets(self):
        # Main widgets
        self.hpaned = gtk.HPaned()
        self.main_vbox = HIGVBox()

        # Results section
        self.result_section = HIGSectionLabel(_("Results"))
        self.result_vbox = HIGVBox()
        self.result_hbox = HIGHBox()
        self.result_list = gtk.ListStore(str, str, int) # title, date, id
        self.result_view = gtk.TreeView(self.result_list)
        self.result_scrolled = gtk.ScrolledWindow()
        self.result_title_column = gtk.TreeViewColumn(_("Scan"))
        self.result_date_column = gtk.TreeViewColumn(_("Date"))

        # Search notebook
        self.search_vbox = HIGVBox()
        self.search_notebook = gtk.Notebook()
        self.search_button = HIGButton(stock=gtk.STOCK_FIND)

        # General page
        self.general_vbox = HIGVBox()
        self.general_hbox = HIGHBox()
        #self.general_start_hbox = HIGHBox()
        #self.general_finish_hbox = HIGHBox()
        
        self.general_section = HIGSectionLabel(_("General search parameters"))
        
        self.general_table = HIGTable()

        self.general_option_label = HIGEntryLabel(_("Option"))
        self.general_profile_label = HIGEntryLabel(_("Profile"))
        #self.general_finished_label = HIGEntryLabel(_("Finished"))
        #self.general_started_label = HIGEntryLabel(_("Started"))
        self.general_keyword_label = HIGEntryLabel(_("Keyword"))

        self.general_keyword_entry = gtk.Entry()
        self.general_option_combo = OptionCombo()
        self.general_profile_combo = ProfileCombo()
        #self.general_started_range = DateRange()
        #self.general_finished_range = DateRange()

        # Host page
        self.host_vbox = HIGVBox()
        self.host_hbox = HIGHBox()
        #self.host_uptime_hbox = HIGHBox()
        #self.host_lastboot_hbox = HIGHBox()
        
        self.host_section = HIGSectionLabel(_("Host search parameters"))
        
        self.host_table = HIGTable()

        self.host_target_label = HIGEntryLabel(_("Target"))
        self.host_mac_label = HIGEntryLabel(_("MAC"))
        self.host_ipv4_label = HIGEntryLabel(_("IPv4"))
        self.host_ipv6_label = HIGEntryLabel(_("IPv6"))
        #self.host_uptime_label = HIGEntryLabel(_("Uptime"))
        #self.host_lastboot_label = HIGEntryLabel(_("Last boot"))

        self.host_target_combo = TargetCombo()
        self.host_mac_entry = gtk.Entry()
        self.host_ipv4_entry = gtk.Entry()
        self.host_ipv6_entry = gtk.Entry()
        #self.host_uptime_range = DateRange()
        #self.host_lastboot_range = DateRange()


        # Service
        self.serv_vbox = HIGVBox()
        self.serv_hbox = HIGHBox()
        self.serv_section = HIGSectionLabel(_("Service search parameters"))
        self.serv_table = HIGTable()

        self.serv_port_label = HIGEntryLabel(_("Port number"))
        self.serv_service_label = HIGEntryLabel(_("Service"))
        self.serv_product_label = HIGEntryLabel(_("Product"))
        self.serv_portstate_label = HIGEntryLabel(_("Port state"))
        
        self.serv_port_entry = gtk.Entry()
        self.serv_service_combo = ServiceCombo()
        self.serv_product_entry = gtk.Entry()
        self.serv_portstate_check = PortState()


        # OS
        self.os_vbox = HIGVBox()
        self.os_hbox = HIGHBox()
        self.os_section = HIGSectionLabel(_("Operating System search \
parameters"))
        self.os_table = HIGTable()
        
        self.os_osclass_label = HIGEntryLabel(_("OS class"))
        self.os_osmatch_label = HIGEntryLabel(_("OS match"))
        
        self.os_osclass_combo = OSClassCombo()
        self.os_osmatch_combo = OSMatchCombo()


        # Search options page
        self.opt_vbox = HIGVBox()
        self.opt_local_hbox = HIGHBox()
        self.opt_base_hbox = HIGHBox()
        self.opt_local_section = HIGSectionLabel(_("Local files"))
        self.opt_local_table = HIGTable()
        self.opt_base_section = HIGSectionLabel(_("Database"))
        self.opt_base_table = HIGTable()

        self.opt_path_label = HIGEntryLabel(_("Directory"))
        self.opt_extension_label = HIGEntryLabel(_("File extension"))
        self.opt_savetime_label = HIGEntryLabel(_("Save results for"))

        self.opt_path_entry = PathEntry()
        self.opt_extension_entry = gtk.Entry()
        self.opt_savetime_entry = SaveTime()
        self.opt_save_check = gtk.CheckButton(_("Save scan results in data \
base for latter search"))
        self.opt_search_check = gtk.CheckButton(_("Search saved scan results \
in data base"))

        
    def _pack_widgets(self):
        # Packing result section
        self.result_vbox.set_border_width(12)
        self.result_vbox._pack_noexpand_nofill(self.result_section)
        self.result_vbox._pack_expand_fill(self.result_hbox)

        self.result_scrolled.set_size_request(185, -1)
        #self.result_scrolled.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.result_scrolled.add(self.result_view)
        self.result_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                        gtk.POLICY_AUTOMATIC)
        self.result_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.result_hbox._pack_expand_fill(self.result_scrolled)

        ## Search Notebook
        self.search_vbox._pack_expand_fill(self.search_notebook)
        self.search_vbox._pack_expand_fill(self.search_button)

        self.search_notebook.set_border_width(1)
        self.search_vbox.set_border_width(12)
        
        # General page
        self.general_vbox.set_border_width(12)
        self.general_vbox._pack_noexpand_nofill(self.general_section)
        self.general_vbox._pack_noexpand_nofill(self.general_hbox)
        
        #self.general_vbox._pack_noexpand_nofill(self.general_start_section)
        #self.general_vbox._pack_noexpand_nofill(self.general_start_hbox)
        
        #self.general_vbox._pack_noexpand_nofill(self.general_finish_section)
        #self.general_vbox._pack_noexpand_nofill(self.general_finish_hbox)
        
        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_expand_fill(self.general_table)

        #self.general_start_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.general_start_hbox._pack_noexpand_nofill(self.general_started_range)

        #self.general_finish_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.general_finish_hbox._pack_expand_fill(self.general_finished_range)
        

        self.general_table.attach_label(self.general_keyword_label, 0, 1, 0, 1)
        self.general_table.attach_label(self.general_profile_label, 0, 1, 1, 2)
        self.general_table.attach_label(self.general_option_label, 0, 1, 2, 3)

        self.general_table.attach_entry(self.general_keyword_entry, 1, 2, 0, 1)
        self.general_table.attach_entry(self.general_profile_combo, 1, 2, 1, 2)
        self.general_table.attach_entry(self.general_option_combo, 1, 2, 2, 3)
        
        self.search_notebook.append_page(self.general_vbox,
                                         gtk.Label(_("General")))

        # Host page
        self.host_vbox.set_border_width(12)
        self.host_vbox._pack_noexpand_nofill(self.host_section)
        self.host_vbox._pack_noexpand_nofill(self.host_hbox)
        
        #self.host_vbox._pack_noexpand_nofill(self.host_uptime_section)
        #self.host_vbox._pack_noexpand_nofill(self.host_uptime_hbox)

        #self.host_vbox._pack_noexpand_nofill(self.host_lastboot_section)
        #self.host_vbox._pack_noexpand_nofill(self.host_lastboot_hbox)
        
        self.host_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.host_hbox._pack_expand_fill(self.host_table)

        #self.host_uptime_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.host_uptime_hbox._pack_noexpand_nofill(self.host_uptime_range)

        #self.host_lastboot_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.host_lastboot_hbox._pack_expand_fill(self.host_lastboot_range)

        self.host_table.attach_label(self.host_target_label, 0, 1, 0, 1)
        self.host_table.attach_label(self.host_mac_label, 0, 1, 1, 2)
        self.host_table.attach_label(self.host_ipv4_label, 0, 1, 2, 3)
        self.host_table.attach_label(self.host_ipv6_label, 0, 1, 3, 4)

        self.host_table.attach_entry(self.host_target_combo, 1, 2, 0, 1)
        self.host_table.attach_entry(self.host_mac_entry, 1, 2, 1, 2)
        self.host_table.attach_entry(self.host_ipv4_entry, 1, 2, 2, 3)
        self.host_table.attach_entry(self.host_ipv6_entry, 1, 2, 3, 4)
        
        self.search_notebook.append_page(self.host_vbox, gtk.Label(_("Host")))

        # Service page
        self.serv_vbox.set_border_width(12)
        self.serv_vbox._pack_noexpand_nofill(self.serv_section)
        self.serv_vbox._pack_noexpand_nofill(self.serv_hbox)
        
        self.serv_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.serv_hbox._pack_expand_fill(self.serv_table)

        self.serv_table.attach_label(self.serv_port_label, 0, 1, 0, 1)
        self.serv_table.attach_label(self.serv_portstate_label, 0, 1, 1, 2)
        self.serv_table.attach_label(self.serv_product_label, 0, 1, 2, 3)
        self.serv_table.attach_label(self.serv_service_label, 0, 1, 3, 4)

        self.serv_table.attach_entry(self.serv_port_entry, 1, 2, 0, 1)
        self.serv_table.attach_entry(self.serv_portstate_check, 1, 2, 1, 2)
        self.serv_table.attach_entry(self.serv_product_entry, 1, 2, 2, 3)
        self.serv_table.attach_entry(self.serv_service_combo, 1, 2, 3, 4)
        
        self.search_notebook.append_page(self.serv_vbox,
                                         gtk.Label(_("Service")))

        # OS page
        self.os_vbox.set_border_width(12)
        self.os_vbox._pack_noexpand_nofill(self.os_section)
        self.os_vbox._pack_noexpand_nofill(self.os_hbox)

        self.os_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.os_hbox._pack_expand_fill(self.os_table)

        self.os_table.attach_label(self.os_osclass_label, 0, 1, 0, 1)
        self.os_table.attach_label(self.os_osmatch_label, 0, 1, 1, 2)

        self.os_table.attach_entry(self.os_osclass_combo, 1, 2, 0, 1)
        self.os_table.attach_entry(self.os_osmatch_combo, 1, 2, 1, 2)

        self.search_notebook.append_page(self.os_vbox, gtk.Label(_("OS")))

        # Search options page
        self.opt_vbox.set_border_width(12)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_hbox)
        
        self.opt_vbox._pack_noexpand_nofill(self.opt_base_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_base_hbox)

        self.opt_local_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_local_hbox._pack_expand_fill(self.opt_local_table)

        self.opt_base_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_base_hbox._pack_expand_fill(self.opt_base_table)

        self.opt_local_table.attach_label(self.opt_path_label, 0, 1, 0, 1)
        self.opt_local_table.attach_label(self.opt_extension_label, 0, 1, 1, 2)
        
        self.opt_local_table.attach_entry(self.opt_path_entry, 1, 2, 0, 1)
        self.opt_local_table.attach_entry(self.opt_extension_entry, 1, 2, 1, 2)

        self.opt_base_table.attach_label(self.opt_savetime_label, 0, 1, 0, 1)
        self.opt_base_table.attach_label(self.opt_save_check, 0, 2, 1, 2)
        self.opt_base_table.attach_label(self.opt_search_check, 0, 2, 2, 3)

        self.opt_base_table.attach_entry(self.opt_savetime_entry, 1, 2, 0, 1)


        self.search_notebook.append_page(self.opt_vbox,
                                         gtk.Label(_("Search options")))

        self.pack1(self.search_vbox, True, False)
        self.pack2(self.result_vbox, True, False)

    def _connect_events(self):
        self.os_osclass_combo.connect("changed", self.update_osmatch)
        self.search_button.connect("clicked", self.start_search)

        self.opt_extension_entry.connect("focus-out-event",
                                         self.update_extension_entry)
        self.opt_save_check.connect("toggled", self.update_save_check)
        self.opt_search_check.connect("toggled", self.update_search_check)
        self.opt_path_entry.connect_entry_change(self.update_path_entry)
        self.opt_savetime_entry.connect_entry_change(self.update_savetime_entry)
        

    def update_path_entry(self, widget, extra=None):
        search_config.directory = widget.get_text()

    def update_savetime_entry(self, widget, extra=None):
        search_config.save_time = self.opt_savetime_entry.time

    def update_extension_entry(self, widget, extra=None):
        search_config.file_extension = widget.get_text()

    def update_save_check(self, widget):
        search_config.store_results = widget.get_active()

    def update_search_check(self, widget):
        search_config.search_db = widget.get_active()

    def start_search(self, widget):
        if not self.search_db and \
           not self.directory:
            self.search_notebook.set_current_page(-1)
            d = HIGAlertDialog(message_format=_("No search method selected!"),
                               secondary_text=_("Umit can search results on \
directories or inside it's own database. Please, select a method by choosing \
a directory or by checking the search data base option at the 'Search options' \
tab before start the search"))
            d.run()
            d.destroy()
            return
        
        search_dict = dict(keyword=self.keyword,
                           profile=self.profile,
                           option=self.option,
                           target=self.target,
                           mac=self.mac,
                           ipv4=self.ipv4,
                           ipv6=self.ipv6,
                           port=self.port,
                           port_open=self.port_open,
                           port_filtered=self.port_filtered,
                           port_closed=self.port_closed,
                           service=self.service,
                           osclass=self.osclass,
                           osmatch=self.osmatch,
                           product=self.product)

        self.clear_result_list()
        
        if self.search_db:
            search_db = SearchDB()

            for result in search_db.search(**search_dict):
                self.append_result(result)

        if self.directory:
            search_dir = SearchDir(self.directory, self.file_extension)

            for result in search_dir.search(**search_dict):
                self.append_result(result)

        search_tabs = SearchTabs(self.notebook)
        for result in search_tabs.search(**search_dict):
            self.append_result(result)  

    def clear_result_list(self):
        for i in range(len(self.result_list)):
            iter = self.result_list.get_iter_root()
            del(self.result_list[iter])

    def append_result(self, parsed_result):
        title = ""
        if parsed_result.scan_name:
            title = parsed_result.scan_name
        elif parsed_result.nmap_xml_file:
            title = os.path.split(parsed_result.nmap_xml_file)[-1]
        elif parsed_result.profile_name and parsed_result.target:
            title = "%s on %s" % (parsed_result.profile_name,
                                  parsed_result.target)
        else:
            title = "Scan %s" % (self.scan_num)
            self.scan_num += 1

        try:
            date = localtime(float(parsed_result.start))
            date_field = "%02d %s %04d" % (date[2],
                                           calendar.month_name[date[1]][:3],
                                           date[0])
        except ValueError:
            date_field = _("Unknown")


        self.parsed_results[self.id] = [title, parsed_result]
        self.result_list.append([title, date_field, self.id])
        self.id += 1

    def update_osmatch(self, widegt):
        self.os_osmatch_combo.update(self.os_osclass_combo.selected_osclass)

    def get_keyword(self):
        return self.general_keyword_entry.get_text()

    def set_keyword(self, keyword):
        self.general_keyword_entry.set_text(keyword)

    def get_profile(self):
        if self.general_profile_combo.selected_profile == self.any_profile or \
           self.general_profile_combo.selected_profile == self.any:
            return "*"
        return self.general_profile_combo.selected_profile

    def set_profile(self, profile):
        self.general_profile_combo.selected_profile = profile

    def get_option(self):
        if self.general_option_combo.selected_option == self.any_option or \
           self.general_option_combo.selected_option == self.any:
            return "*"
        return self.general_option_combo.selected_option

    def set_option(self, option):
        self.general_option_combo.selected_option = option

    def get_target(self):
        if self.host_target_combo.selected_target == self.any_target or \
           self.host_target_combo.selected_target == self.any:
            return "*"
        return self.host_target_combo.selected_target

    def set_target(self, target):
        self.host_target_combo.selected_target = target

    def get_mac(self):
        return self.host_mac_entry.get_text()

    def set_mac(self, mac):
        self.host_mac_entry.set_text(mac)

    def get_ipv4(self):
        return self.host_ipv4_entry.get_text()

    def set_ipv4(self, ipv4):
        self.host_ipv4_entry.set_text(ipv4)

    def get_ipv6(self):
        return self.host_ipv6_entry.get_text()

    def set_ipv6(self, ipv6):
        self.host_ipv6_entry.set_text(ipv6)

    def get_port(self):
        return self.serv_port_entry.get_text().split(";")

    def set_port(self, port):
        if isinstance(port, basestring):
            self.serv_port_entry.set_text(port)
        elif isinstance(port, list):
            self.serv_port_entry.set_text(";".join(port))

    def get_port_open(self):
        return self.serv_portstate_check.open

    def set_port_open(self, open):
        self.serv_portstate_check.open = open

    def get_port_filtered(self):
        return self.serv_portstate_check.filtered

    def set_port_filtered(self, filtered):
        self.serv_portstate_check.filtered = filtered

    def get_port_closed(self):
        return self.serv_portstate_check.closed

    def set_port_closed(self, closed):
        self.serv_portstate_check.closed = closed

    def get_service(self):
        if self.serv_service_combo.selected_service == self.any_service or \
           self.serv_service_combo.selected_service == self.any:
            return "*"
        return self.serv_service_combo.selected_service

    def set_service(self, service):
        self.serv_service_combo.selected_service = service

    def get_osclass(self):
        if self.os_osclass_combo.selected_osclass == self.any_osclass or \
           self.os_osclass_combo.selected_osclass == self.any:
            return "*"
        return self.os_osclass_combo.selected_osclass

    def set_osclass(self, osclass):
        self.os_osclass_combo.selected_osclass = osclass

    def get_osmatch(self):
        if self.os_osmatch_combo.selected_osmatch == self.any_osmatch or \
           self.os_osmatch_combo.selected_osmatch == self.any:
            return "*"
        return self.os_osmatch_combo.selected_osmatch

    def set_osmatch(self, osmatch):
        self.os_osmatch_combo.selected_osmatch = osmatch

    def get_product(self):
        if self.serv_product_entry.get_text() == self.any_product or \
           self.serv_product_entry.get_text() == self.any:
            return "*"
        return self.serv_product_entry.get_text()

    def set_product(self, product):
        self.serv_product_entry.set_text(product)

    def get_directory(self):
        return self.opt_path_entry.path

    def set_directory(self, directory):
        self.opt_path_entry.path = directory

    def get_file_extension(self):
        return self.opt_extension_entry.get_text().split(";")

    def set_file_extension(self, file_extension):
        if isinstance(file_extension, list):
            self.opt_extension_entry.set_text(";".join(file_extension))
        elif isinstance(file_extension, basestring):
            self.opt_extension_entry.set_text(file_extension)

    def get_save_time(self):
        return self.opt_savetime_entry.time

    def set_save_time(self, save_time):
        self.opt_savetime_entry.time = save_time

    def get_save(self):
        return self.opt_save_check.get_active()

    def set_save(self, save):
        self.opt_save_check.set_active(save)

    def get_search_db(self):
        return self.opt_search_check.get_active()

    def set_search_db(self, search_db):
        self.opt_search_check.set_active(search_db)

    def get_selected_results(self):
        selection = self.result_view.get_selection()
        rows = selection.get_selected_rows()
        list_store = rows[0]

        results = {}
        for row in rows[1]:
            r = row[0]
            results[list_store[r][2]] = self.parsed_results[list_store[r][2]]

        return results

    def _set_result_view(self):
        self.result_view.set_enable_search(True)
        self.result_view.set_search_column(0)
        
        selection = self.result_view.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        self.result_view.append_column(self.result_title_column)
        self.result_view.append_column(self.result_date_column)
        
        self.result_title_column.set_resizable(True)
        self.result_date_column.set_resizable(True)
        
        self.result_title_column.set_sort_column_id(0)
        self.result_date_column.set_sort_column_id(1)
        
        self.result_title_column.set_reorderable(True)
        self.result_date_column.set_reorderable(True)

        cell = gtk.CellRendererText()
        
        self.result_title_column.pack_start(cell, True)
        self.result_date_column.pack_start(cell, True)
        
        self.result_title_column.set_attributes(cell, text=0)
        self.result_date_column.set_attributes(cell, text=1)
        

    keyword = property(get_keyword, set_keyword)
    profile = property(get_profile, set_profile)
    option = property(get_option, set_option)
    target = property(get_target, set_target)
    mac = property(get_mac, set_mac)
    ipv4 = property(get_ipv4, set_ipv4)
    ipv6 = property(get_ipv6, set_ipv6)
    port = property(get_port, set_port)
    port_open = property(get_port_open, set_port_open)
    port_filtered = property(get_port_filtered, set_port_filtered)
    port_closed = property(get_port_closed, set_port_closed)
    service = property(get_service, set_service)
    product = property(get_product, set_product)
    osclass = property(get_osclass, set_osclass)
    osmatch = property(get_osmatch, set_osmatch)
    directory = property(get_directory, set_directory)
    file_extension = property(get_file_extension, set_file_extension)
    save_time = property(get_save_time, set_save_time)
    save = property(get_save, set_save)
    search_db = property(get_search_db, set_search_db)
    selected_results = property(get_selected_results)
예제 #41
0
class LoginDialog(HIGDialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, title=_('Open Monitor 2012')):
        """Constructor"""
        HIGDialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL,
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_default_response(gtk.RESPONSE_ACCEPT)
        self.set_keep_above(True)
        self.set_size_request(480, 240)
        self.set_border_width(2)

        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

    def _create_widgets(self):
        
        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

        #Password
        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()
        self.password_entry.set_activates_default(True)
        
        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))
        
        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)
        
        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)
        
        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))
        
        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("settings"))
        
        #Container
        self.hbox = HIGHBox(False,2)
        self.table = HIGTable(8,4,False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
        
        #tab orders
        self.orders = [self.username_entry, self.password_entry, self.register_button, self.forgot_password]

    def _pack_widgets(self):

        self.hbox.set_border_width(8)
        
        self.table.set_focus_chain(self.orders)
        
        self.table.attach(self.logo_image,0,7,0,5,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.username_label,0,1,5,6,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.username_entry,1,5,5,6,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0)
        self.table.attach(self.password_label,0,1,6,7,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.password_entry,1,5,6,7,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0) 
        self.table.attach(self.register_button,5,6,5,6,gtk.FILL,gtk.FILL,0,0)  
        self.table.attach(self.forgot_password,5,6,6,7,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.auto_login_checkbtn,1,3,7,8,gtk.FILL,gtk.FILL,0,0)   
 
        self.hbox._pack_expand_fill(self.table)
        self.vbox.pack_start(self.hbox, False, False)                                  

        spaceholder1 = hig_box_space_holder()
        spaceholder2 = hig_box_space_holder()
        spaceholder3 = hig_box_space_holder()
        self.action_area.pack_end(spaceholder1)
        self.action_area.pack_end(spaceholder2)
        self.action_area.pack_end(spaceholder3)
        self.action_area.pack_end(self.settings_button)
        self.action_area.reorder_child(self.settings_button, 0)
        self.action_area.reorder_child(spaceholder1, 1)        
        self.action_area.reorder_child(spaceholder2, 2)
        self.action_area.reorder_child(spaceholder3, 2)
        
    def _connect_widgets(self):
        self.connect('response', self.check_response)
        self.register_button.connect('clicked', self._register)
        self.forgot_password.connect('clicked', self._forgot_password)
        self.settings_button.connect('clicked', self._settings)

    def _register(self, widget):
        #registration_form = RegistrationDialog()
        #registration_form.show_all()
        webbrowser.open(theApp.aggregator.base_url + "/accounts/register/")

    def _forgot_password(self, widget):
        webbrowser.open(theApp.aggregator.base_url + "/accounts/password/reset/")

    def check_response(self, widget, response_id):
        #There should collect the error information: help the user to check problem
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            username = self.username_entry.get_text()
            password = self.password_entry.get_text()
            save_login = self.auto_login_checkbtn.get_active()
            
            #Bug in this: If the user go to this window, the theApp.peer_info cannot is_registered
            
            #if not theApp.peer_info.is_registered:
            defer_ = theApp.login(username, password, save_login)   
            #    defer_ = theApp.register_agent(username, password)
            #    defer_.addCallback(
            #        lambda x: theApp.login(username, password, save_login))
            #else:
            #    defer_ = theApp.login(username, password, save_login)
            self.destroy()
            theApp.gtk_main.login_dlg = None
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            self.destroy()
            theApp.gtk_main.login_dlg = None
            
    def _settings(self,widget):
        '''
        configure settings: Server IP/Port: popup a new window
        '''
        settings_form = SettingsDialog()
        settings_form.show_all()
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()
예제 #43
0
    def __do_layout(self):
        """
        Layout widgets in window.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schema_table = HIGTable()
        auth_table = HIGTable()
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)
        
        # schema name
        schema_table.attach_label(self.schema_name_lbl, 0, 1, 0, 1)
        schema_table.attach_entry(self.schema_name, 1, 2, 0, 1)
        
        # smtp server
        schema_table.attach_label(self.smtp_server_lbl, 0, 1, 1, 2)
        schema_table.attach_entry(self.smtp_server, 1, 2, 1, 2)

        # smtp server port
        schema_table.attach_label(self.smtp_port_lbl, 0, 1, 2, 3)
        schema_table.attach_entry(self.smtp_port, 1, 2, 2, 3)
        
        # smtp mail from
        schema_table.attach_label(self.smtp_mailfrom_lbl, 0, 1, 3, 4)
        schema_table.attach_entry(self.smtp_mailfrom, 1, 2, 3, 4)
        
        # smtp user
        auth_table.attach_label(self.smtp_login_lbl, 0, 1, 0, 1)
        auth_table.attach_entry(self.smtp_login, 1, 2, 0, 1)
        
        # smtp passwd
        auth_table.attach_label(self.smtp_passwd_lbl, 0, 1, 1, 2)
        auth_table.attach_label(self.smtp_passwd, 1, 2, 1, 2)
        
        # 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.apply)
        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(schema_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.smtp_need_auth)
        main_vbox._pack_noexpand_nofill(auth_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.smtp_encrypt_tls)
        main_vbox.pack_end(btns_hbox, False, False, 0)
        
        self.add(main_vbox)
class OSFingerprintReport(gtk.Window, object):
    def __init__(self, fingerprint, ip):
        gtk.Window.__init__(self)
        self.set_title(_('Operating System Fingerprint Report'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.fingerprint = fingerprint
        self.ip = ip

        self._create_widgets()
        self._set_classification_list()
        self._pack_widgets()
        self._connect_widgets()

    def _set_classification_list(self):
        class_file = open(os_classification_file, "rb")
        class_list = cPickle.load(class_file)
        class_file.close()
        
        for classification in class_list:
            self.classification_list.append([classification[1],
                                             classification[0]])

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()
        
        self.submitted_label = HIGHintSectionLabel(_("Submitted by (optional)"),
                                                   _("Enter your name and \
e-mail address if we can contact you with any questions. (kept private, \
used for nothing else)"))
        self.submitted_entry = gtk.Entry()

        self.target_device_label = HIGHintSectionLabel(_("Target OS/device info"),
                                                       _("<b>The more details \
the better!</b> For UNIX machines, '<i>uname -a</i>' often gives the proper \
version number. On Linux, please also specify the distribution version (such as\
Redhat 9.0) if you are using a vendor-provided kernel. For Windows, the \
'<i>winver</i>' command (if available) should show you any service pack \
information. If a Windows target has no service packs installed, \
please say so explicitly. For appliances/embedded devices, please mention \
the model number and what it is (printer, webcam, DSL router, VOIP phone, \
etc). Try to provide the architecture (X86, SPARC, etc.) where appropriate."))
        self.target_device_entry = gtk.Entry()

        self.classification_label = HIGHintSectionLabel(_("Classification"),
                                                        _("Please select \
the Device/OS info from this alphabetized choosebox"))
        self.classification_list = gtk.ListStore(str, str)
        self.classification_combo = gtk.ComboBoxEntry(self.classification_list,
                                                      0)

        self.notes_label = HIGHintSectionLabel(_("Notes"),
                                               _("Fill with further info on \
the device, any special network conditions, etc."))
        self.notes_scrolled = gtk.ScrolledWindow()
        self.notes_text = gtk.TextView()

        self.fingerprint_icon = gtk.Image()
        self.fingerprint_text = gtk.Label(_("This form allows you to \
contribute new operating system fingerprints to the Nmap database. Thanks for \
helping! <b>Please do not fill this out unless you are sure that you know \
what application is running on the machine you are submitting</b>. Incorrect \
entries can pollute the database. By submitting fingerprints you are \
transfering any copyright interest in the data to Fyodor so that he \
can modify it, relicense it, incorporate it into programs such as Nmap, etc."))

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.notes_scrolled.add(self.notes_text)
        self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                       gtk.POLICY_AUTOMATIC)
        self.notes_scrolled.set_size_request(400, 150)
        self.notes_text.set_wrap_mode(gtk.WRAP_WORD)

        self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
                                             gtk.ICON_SIZE_DIALOG)
        self.fingerprint_icon.set_padding(10, 0)
        self.fingerprint_text.set_line_wrap(True)
        self.fingerprint_text.set_use_markup(True)

        self.table.attach_label(self.submitted_label, 0, 1, 0, 1)
        self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1)
        
        self.table.attach_label(self.target_device_label, 0, 1, 1, 2)
        self.table.attach_entry(self.target_device_entry, 1, 2, 1, 2)

        self.table.attach_label(self.classification_label, 0, 1, 2, 3)
        self.table.attach_entry(self.classification_combo, 1, 2, 2, 3)

        self.table.attach_label(self.notes_label, 0, 2, 3, 4)
        self.table.attach_entry(self.notes_scrolled, 0, 2, 4, 5)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.fingerprint_icon)
        self.hbox._pack_expand_fill(self.fingerprint_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox.set_border_width(6)
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def close(self, widget=None, event=None):
        self.destroy()

    def send_report(self, widget):
        if self.target_device == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Operating System \
Fingerprint report is incomplete!"),
                                           secondary_text=_("The Operating \
System Fingerprint report is incomplete. Please, try to provide as much \
information as possible."))
            cancel_dialog.run()
            cancel_dialog.destroy()
            return None

        os_register = OSFingerprintRegister()

        os_register.email = self.submitted
        os_register.os = self.target_device
        os_register.classification = self.classification
        os_register.ip = self.ip
        os_register.fingerprint = self.fingerprint
        os_register.notes = self.notes

        try:
            os_register.report()
        except:
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Operating System \
Fingerprint not registered!"),
                                           secondary_text=_("The Operating \
System Fingerprint could not be registered. This problem may be caused by \
the lack of Internet Access or indisponibility of the fingerprint server. \
Please, verify your internet access, and then try to register the operating \
system fingerprint once again."))
            cancel_dialog.run()
            cancel_dialog.destroy()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                                       message_format=_("Operating System \
Fingerprint sucessfully registered!"),
                                       secondary_text=_("The Operating System \
Fingerprint was sucessfully registered. A web page with detailed description \
about this registration is going to be openned in your default web browser."))
            ok_dialog.run()
            ok_dialog.destroy()

            self.close()

    def run_unblocked(self):
        if not self.modal:
            self.set_modal(True)
        self.show_all()

    def dialog_response_cb(self, dialog, response):
        self.response_id = response

    def get_submitted(self):
        return self.submitted_entry.get_text()

    def set_submitted(self, submitted):
        self.submitted_entry.set_text(submitted)

    def get_target_device(self):
        return self.target_device_entry.get_text()

    def set_target_device(self, target_device):
        self.target_device_entry.set_text(target_device)

    def get_classification(self):
        selected = self.classification_combo.child.get_text()
        for i in self.classification_list:
            if i[0] == selected:
                return i[1]
        return ""

    def set_classification(self, classification):
        self.classification.child.set_text(classification)

    def get_notes(self):
        buff = self.notes_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())

    def set_notes(self, notes):
        self.notes_text.get_buffer().set_text(notes)

    submitted = property(get_submitted, set_submitted)
    target_device = property(get_target_device, set_target_device)
    classification = property(get_classification, set_classification)
    notes = property(get_notes, set_notes)
예제 #45
0
class NodeWindow(HIGWindow):
    """
    """
    def __init__(self, node, position, parent):
        """
        """
        HIGWindow.__init__(self, gtk.WINDOW_POPUP)
        self.set_decorated(False)
        self.set_keep_above(True)
        self.set_skip_taskbar_hint(True)
        self.move(position[0], position[1])
        self.set_size_request(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])

        self.__button_press_position = self.get_pointer()

        self.__is_compacted = True
        self.__is_collapsed = False

        self.__node = node
        self.__pressed = False
        self.__parent = parent

        self.connect('button_press_event', self.button_press)
        self.connect('button_release_event', self.button_release)
        self.connect('enter_notify_event', self.enter_notify)
        self.connect('leave_notify_event', self.leave_notify)
        self.connect('motion_notify_event', self.motion_notify)

        self.__title_font = pango.FontDescription('Monospace Bold')

        self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK
                        | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.ENTER_NOTIFY
                        | gtk.gdk.LEAVE_NOTIFY
                        | gtk.gdk.POINTER_MOTION_HINT_MASK)

        self.__icon = Application()
        self.__create_widgets()

    def __create_widgets(self):
        """
        """
        self.__content = HIGVBox()
        self.__head = HIGHBox(spacing=2)

        self.__notebook = NodeNotebook(self.__node)

        # create head elements

        # icon with node's score color
        self.__color_box = gtk.EventBox()
        self.__color_image = gtk.Image()
        self.__color_image.set_from_file(self.__icon.get_icon('border'))
        self.__color_box.add(self.__color_image)
        self.__color_box.set_size_request(15, 15)
        r, g, b = drawing.cairo_to_gdk_color(
            self.__node.get_draw_info('color'))
        self.__color_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(r, g, b))

        # title with the node ip and hostname
        self.__title = ""

        if self.__node.get_info('hostname') is not None:
            self.__title = self.__node.get_info('hostname') + ' - '

        self.__title += self.__node.get_info('ip')

        self.__title_label = HIGSectionLabel(self.__title)
        self.__title_label.modify_font(self.__title_font)

        # icon to collapse window
        self.__collapse_box = gtk.EventBox()
        self.__collapse_img = gtk.Image()
        self.__collapse_img.set_from_file(self.__icon.get_icon('collapse'))
        self.__collapse_box.add(self.__collapse_img)
        self.__collapse_box.connect('button_press_event', self.collapse_window)
        self.__collapse_box.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        # icon to close window
        self.__close_box = gtk.EventBox()
        self.__close_img = gtk.Image()
        self.__close_img.set_from_file(self.__icon.get_icon('close'))
        self.__close_box.add(self.__close_img)
        self.__close_box.connect('button_press_event', self.close_window)
        self.__close_box.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        # packing head elements
        self.__head._pack_noexpand_nofill(self.__color_box)
        self.__head._pack_expand_fill(self.__title_label)
        self.__head._pack_noexpand_nofill(self.__collapse_box)
        self.__head._pack_noexpand_nofill(self.__close_box)

        # packing all to content
        self.__content._pack_noexpand_nofill(self.__head)
        self.__content._pack_expand_fill(self.__notebook)

        # add context to window
        self.add(self.__content)

    def close_window(self, widget, event):
        """
        """
        self.__node.set_draw_info({'over': False})
        self.hide()
        self.__parent.queue_draw()

        return True

    def restore(self, x, y):
        """
        """
        self.move(x, y)
        self.show_all()

        self.__is_collapsed = False
        self.resize(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])
        self.__collapse_img.set_from_file(self.__icon.get_icon('collapse'))

    def collapse_window(self, widget, event):
        """
        """
        self.present()

        if self.__is_collapsed == False:

            self.__notebook.hide()
            self.__is_collapsed = True
            self.set_size_request(DIMENSION_SHADED[0], DIMENSION_SHADED[1])
            self.resize(DIMENSION_SHADED[0], DIMENSION_SHADED[1])
            self.__collapse_img.set_from_file(self.__icon.get_icon('expand'))

        else:

            self.__notebook.show()
            self.__is_collapsed = False
            self.set_size_request(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])
            self.resize(DIMENSION_NORMAL[0], DIMENSION_NORMAL[1])
            self.__collapse_img.set_from_file(self.__icon.get_icon('collapse'))

        return True

    def button_press(self, widget, event):
        """
        """
        self.present()
        self.__pressed = True
        self.__button_press_position = self.get_pointer()

        return True

    def button_release(self, widget, event):
        """
        """
        self.__pressed = False

        return True

    def enter_notify(self, widget, event):
        """
        """
        self.__node.set_draw_info({'over': True})
        self.__parent.queue_draw()

    def leave_notify(self, widget, event):
        """
        """
        self.set_keep_above(True)
        self.__node.set_draw_info({'over': False})

    def motion_notify(self, widget, event):
        """
        """
        self.__node.set_draw_info({'over': True})

        x, y, button_state = event.window.get_pointer()

        if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed:

            xw, yw = event.window.get_root_origin()
            xd, yd = self.__button_press_position
            self.move(x + xw - xd, y + yw - yd)

        return True
    def __do_layout(self):
        """
        Layout widgets in window.
        """

        def left_padding(widget):
            """
            Add left padding for a widget.
            """
            left_padding_align = gtk.Alignment(0.5, 0.5, 1, 1)
            left_padding_align.set_padding(0, 0, 12, 0)
            left_padding_align.add(widget)
            return left_padding_align


        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        profile_hbox = HIGHBox()
        hdivs_hbox = HIGHBox()
        arcdraw_vbox = HIGVBox()
        vdivs_vbox = HIGVBox()
        bgfill_vbox = HIGVBox()
        selectfill_vbox = HIGVBox()
        btns_hbox = HIGHBox()

        # header
        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)

        # profiles
        profile_hbox._pack_noexpand_nofill(self.graph_profile_lbl)
        profile_hbox._pack_noexpand_nofill(self.graph_profile)

        # horizontal divisors
        hdivs_hbox._pack_noexpand_nofill(self.hdivs_lbl)
        hdivs_hbox._pack_noexpand_nofill(self.hdivs)

        # arc drawing
        arcdraw_vbox._pack_noexpand_nofill(self.draw_arc_lbl)

        arcdraw_when = HIGHBox()
        arcdraw_when._pack_noexpand_nofill(self.draw_arc_onsel)
        arcdraw_when._pack_noexpand_nofill(self.draw_arc_always)

        arcdraw_where = HIGHBox()
        arcdraw_where._pack_noexpand_nofill(self.draw_arc_bounds)
        arcdraw_where._pack_noexpand_nofill(self.draw_arc_allpts)

        arcdraw_vbox._pack_noexpand_nofill(left_padding(arcdraw_when))
        arcdraw_vbox._pack_noexpand_nofill(left_padding(arcdraw_where))
        arcdraw_vbox._pack_noexpand_nofill(left_padding(self.balloons))

        # vertical divisors
        vdivs_vbox._pack_noexpand_nofill(self.draw_vertdiv)

        vdivs_kind = HIGHBox()
        vdivs_kind._pack_noexpand_nofill(self.draw_vertdiv_dash)
        vdivs_kind._pack_noexpand_nofill(self.draw_vertdiv_solid)

        vdivs_vbox._pack_noexpand_nofill(left_padding(vdivs_kind))

        # background fill
        bgfill_vbox._pack_noexpand_nofill(self.bg_gradient)

        bgfill_gtype = HIGHBox()
        bgfill_gtype._pack_noexpand_nofill(self.bg_gradient_vert)
        bgfill_gtype._pack_noexpand_nofill(self.bg_gradient_horiz)

        bgfill_vbox._pack_noexpand_nofill(left_padding(bgfill_gtype))

        # selection fill
        selectfill_vbox._pack_noexpand_nofill(self.selection_fill)

        selectfill_kind = HIGHBox()
        selectfill_kind._pack_noexpand_nofill(self.selection_fill_solid)
        selectfill_kind._pack_noexpand_nofill(self.selection_fill_gradient)

        selectfill_vbox._pack_noexpand_nofill(left_padding(selectfill_kind))

        # 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.apply)
        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(profile_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(hdivs_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(arcdraw_vbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(vdivs_vbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(bgfill_vbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(selectfill_vbox)
        main_vbox.pack_end(btns_hbox, False, False, 0)
        main_vbox.pack_end(gtk.HSeparator(), False, False, 0)
        self.add(main_vbox)
예제 #47
0
    def __do_layout(self):
        """
        Layout widgets in window.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schema_table = HIGTable()
        schedsn_hbox = HIGHBox()
        sett_table = HIGTable()
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)

        # schema name
        schema_table.attach_label(self.schema_name_lbl, 0, 1, 0, 1)
        schema_table.attach_entry(self.schema_name, 1, 2, 0, 1)

        # target and scan profile
        schema_table.attach_label(self.scan_name_lbl, 0, 1, 1, 2)
        schema_table.attach_entry(self.scan_name, 1, 2, 1, 2)

        # scan command
        schema_table.attach_label(self.scan_command_lbl, 0, 1, 2, 3)
        schema_table.attach_label(self.scan_command, 1, 2, 2, 3)

        # scheduling profile
        schedsn_hbox._pack_expand_fill(self.sched_name)
        schedsn_hbox._pack_noexpand_nofill(self.sched_name_edit)

        schema_table.attach_label(self.sched_name_lbl, 0, 1, 3, 4)
        schema_table.attach_entry(schedsn_hbox, 1, 2, 3, 4)

        # settings frame
        settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        settings_align.set_padding(6, 0, 12, 0)
        schemasett_hbox = HIGVBox()

        # saveto
        sett_hbox = HIGHBox()
        sett_hbox._pack_expand_fill(self.setting_saveto_entry)
        sett_hbox._pack_noexpand_nofill(self.setting_saveto_browse)
        sett_table.attach_label(self.setting_saveto, 0, 1, 0, 1)
        sett_table.attach_entry(sett_hbox, 1, 2, 0, 1)

        # mailto, smtp
        sett_hbox = HIGHBox()
        sett_hbox._pack_expand_fill(self.setting_mailto_entry)
        sett_hbox._pack_noexpand_nofill(self.setting_smtp_lbl)
        sett_hbox._pack_expand_fill(self.setting_smtp)
        sett_table.attach_label(self.setting_mailto, 0, 1, 1, 2)
        sett_table.attach_entry(sett_hbox, 1, 2, 1, 2)
        schemasett_hbox._pack_noexpand_nofill(sett_table)

        # add to inventory
        sett_hbox = HIGHBox()
        sett_hbox._pack_noexpand_nofill(self.setting_addtoinv)
        schemasett_hbox._pack_noexpand_nofill(sett_hbox)

        # enabled/disabled
        sett_hbox = HIGHBox()
        sett_hbox._pack_noexpand_nofill(self.setting_enabled)
        schemasett_hbox._pack_noexpand_nofill(sett_hbox)
        settings_align.add(schemasett_hbox)

        self.schema_sett_frame.add(settings_align)

        # 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.apply)
        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(schema_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.schema_sett_frame)
        main_vbox.pack_end(btns_hbox, False, False, 0)

        self.add(main_vbox)
class UpdatePage(HIGVBox):
    """"""
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__load_list()
        self.__connect_widgets()
        self.__init_db_text()

    def __create_widgets(self):
        """"""

        self.update_switch_hbox = HIGHBox()
        self.update_settings_hbox = HIGHBox()
        self.update_db_hbox = HIGHBox()

        self.update_switch_section = HIGSectionLabel(_("Update News Detect"))
        self.update_switch_table = HIGTable()
        self.update_settings_section = HIGSectionLabel(_("Update Settings"))
        self.update_settings_table = HIGTable()
        self.update_db_section = HIGSectionLabel(_("Update Database"))
        self.update_db_table = HIGTable()

        self.update_check = gtk.CheckButton(_("Automatically update"))
        self.update_switch_check = gtk.CheckButton(
            _("Software Update Detect Switch"))
        self.update_times_label = HIGEntryLabel(_("Auto detect update news"))
        self.update_method_label = HIGEntryLabel(_("Update method"))

        self.update_time_store = gtk.ListStore(str)
        self.update_time_entry = gtk.ComboBoxEntry(self.update_time_store, 0)
        self.update_method_store = gtk.ListStore(str)
        self.update_method_entry = gtk.ComboBoxEntry(self.update_method_store,
                                                     0)

        self.update_db_label = HIGEntryLabel()
        self.update_db_clear_button = gtk.Button(_("Clear Update Information"))

    def __pack_widgets(self):
        """"""
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.update_switch_section)
        self._pack_noexpand_nofill(self.update_switch_hbox)
        self._pack_noexpand_nofill(hig_box_space_holder())
        self._pack_noexpand_nofill(self.update_settings_section)
        self._pack_noexpand_nofill(self.update_settings_hbox)
        self._pack_noexpand_nofill(self.update_db_section)
        self._pack_noexpand_nofill(self.update_db_hbox)

        self.update_switch_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_switch_hbox._pack_expand_fill(self.update_switch_table)
        self.update_settings_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_settings_hbox._pack_expand_fill(self.update_settings_table)
        self.update_db_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_db_hbox._pack_expand_fill(self.update_db_table)

        self.update_switch_table.attach_label(self.update_check, 0, 2, 0, 1)
        self.update_switch_table.attach_label(self.update_switch_check, 0, 2,
                                              1, 2)
        self.update_settings_table.attach_label(self.update_times_label, 0, 1,
                                                0, 1)
        self.update_settings_table.attach_entry(self.update_time_entry, 1, 2,
                                                0, 1)
        self.update_settings_table.attach_label(self.update_method_label, 0, 1,
                                                1, 2)
        self.update_settings_table.attach_entry(self.update_method_entry, 1, 2,
                                                1, 2)

        self.update_db_table.attach_label(self.update_db_label, 1, 3, 0, 1)
        self.update_db_table.attach(self.update_db_clear_button, 0, 1, 0, 1)

    def __init_db_text(self):
        """"""
        rs = g_db_helper.select("select * from updates")
        count = len(rs)
        self.update_db_label.set_text(
            str(_("%d records in update database now." % (count))))

    def __connect_widgets(self):
        """"""
        self.update_check.connect('toggled',
                                  lambda w: self.__change_widgets_status())
        self.update_db_clear_button.connect("clicked",
                                            lambda w: self.__clear_update_db())

    def __clear_update_db(self):
        """"""
        g_db_helper.execute("delete from updates")
        g_db_helper.commit()
        self.update_db_label.set_text(str(
            _("Clear software update database!")))

    def __change_widgets_status(self):
        """"""
        if self.update_check.get_active():
            self.__disable_widgets()
        else:
            self.__enable_widgets()

    def __load_list(self):
        """"""
        for s in update_time_str.keys():
            #print s
            self.update_time_store.append([s])
        for s in update_method_str.keys():
            #print s
            self.update_method_store.append([s])

    def __disable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(False)
        self.update_method_entry.set_sensitive(False)
        self.update_time_entry.set_sensitive(False)

    def __enable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(True)
        self.update_method_entry.set_sensitive(True)
        self.update_time_entry.set_sensitive(True)
예제 #49
0
    def __do_layout(self):
        """
        Layout window widgets.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schedp_hbox = HIGHBox()
        cron_box = HIGVBox()
        cron_table = HIGTable(5, 2)
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)

        schedp_hbox._pack_noexpand_nofill(self.schedp_name_lbl)
        schedp_hbox._pack_expand_fill(self.schedp_name)

        # cron format
        settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        settings_align.set_padding(6, 0, 12, 0)

        cron_table.attach(self.cron_minute_lbl, 0, 1, 0, 1)
        cron_table.attach(self.cron_minute, 1, 2, 0, 1)
        cron_table.attach(self.cron_hour_lbl, 0, 1, 1, 2)
        cron_table.attach(self.cron_hour, 1, 2, 1, 2)
        cron_table.attach(self.cron_day_lbl, 0, 1, 2, 3)
        cron_table.attach(self.cron_day, 1, 2, 2, 3)
        cron_table.attach(self.cron_month_lbl, 0, 1, 3, 4)
        cron_table.attach(self.cron_month, 1, 2, 3, 4)
        cron_table.attach(self.cron_weekday_lbl, 0, 1, 4, 5)
        cron_table.attach(self.cron_weekday, 1, 2, 4, 5)

        cron_box._pack_noexpand_nofill(cron_table)
        settings_align.add(cron_box)
        self.cron_frame.add(settings_align)

        # 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.apply)
        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(schedp_hbox)
        main_vbox._pack_noexpand_nofill(self.cron_frame)
        main_vbox.pack_end(btns_hbox, False, False, 0)
        self.add(main_vbox)
class AdvancedPage(HIGVBox):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self._load_list_()

    def __create_widgets(self):
        """"""
        self.timer_hbox = HIGHBox()
        self.timer_section = HIGSectionLabel(_("Timeout Setting (seconds)"))
        self.timer_table = HIGTable()
        self.other_hbox = HIGHBox()
        self.other_section = HIGSectionLabel(_("Others"))
        self.other_table = HIGTable()

        self.task_assign_label = HIGEntryLabel(_("Task Assign"))
        self.task_scheduler_label = HIGEntryLabel(_("Task Scheduler"))
        self.report_uploader_label = HIGEntryLabel(_("Report Uploader"))
        self.test_fetch_label = HIGEntryLabel(_("Test sets Fetch"))

        self.task_assign_entry = gtk.Entry()
        self.task_scheduler_entry = gtk.Entry()
        self.report_uploader_entry = gtk.Entry()
        self.test_fetch_entry = gtk.Entry()

        self.language_label = HIGEntryLabel(_("Language"))
        self.language_store = gtk.ListStore(str)
        self.language_entry = gtk.ComboBoxEntry(self.language_store, 0)

    def __pack_widgets(self):
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.timer_section)
        self._pack_noexpand_nofill(self.timer_hbox)
        self._pack_noexpand_nofill(self.other_section)
        self._pack_noexpand_nofill(self.other_hbox)

        self.timer_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.timer_hbox._pack_expand_fill(self.timer_table)

        self.other_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.other_hbox._pack_expand_fill(self.other_table)

        self.timer_table.attach_label(self.task_assign_label, 0, 1, 0, 1)
        self.timer_table.attach_label(self.task_assign_entry, 1, 3, 0, 1)
        self.timer_table.attach_label(self.task_scheduler_label, 0, 1, 1, 2)
        self.timer_table.attach_label(self.task_scheduler_entry, 1, 3, 1, 2)
        self.timer_table.attach_label(self.report_uploader_label, 0, 1, 2, 3)
        self.timer_table.attach_label(self.report_uploader_entry, 1, 3, 2, 3)
        self.timer_table.attach_label(self.test_fetch_label, 0, 1, 3, 4)
        self.timer_table.attach_label(self.test_fetch_entry, 1, 3, 3, 4)

        self.other_table.attach_label(self.language_label, 0, 2, 0, 1)
        self.other_table.attach_label(self.language_entry, 2, 4, 0, 1)

    def _load_list_(self):
        """"""
        for s in Language_store.keys():
            self.language_store.append([s])
예제 #51
0
class ScanChooser(HIGVBox):
    def __init__(self, scan_dict, num=""):
        HIGVBox.__init__(self)
        self.num = num
        self.scan_dict = scan_dict
        
        # Setting HIGVBox
        self.set_border_width(5)
        self.set_spacing(6)
        
        self._create_widgets()
        self._pack_hbox()
        self._attaching_widgets()
        self._set_scrolled()
        self._set_text_view()
        self._set_open_button()
        
        for scan in scan_dict:
            self.list_scan.append([scan])
        
        self.combo_scan.connect('changed', self.show_scan)
        
        self._pack_noexpand_nofill(self.lbl_scan)
        self._pack_expand_fill(self.hbox)
    
    def _create_widgets(self):
        self.lbl_scan = HIGSectionLabel("%s %s"%(_("Scan Result"),
                                                 str(self.num)))
        self.hbox = HIGHBox()
        self.table = HIGTable()
        self.list_scan = gtk.ListStore(str)
        self.combo_scan = gtk.ComboBoxEntry(self.list_scan, 0)
        self.btn_open_scan = gtk.Button(stock=gtk.STOCK_OPEN)
        self.exp_scan = gtk.Expander(_("Scan Result Visualization"))
        self.scrolled = gtk.ScrolledWindow()
        self.txt_scan_result = gtk.TextView()
        self.txg_tag = gtk.TextTag("scan_style")

    def get_buffer(self):
        return self.txt_scan_result.get_buffer()

    def show_scan (self, widget):
        try:
            self.txt_scan_result.get_buffer().\
                 set_text(self.normalize_output(\
                     self.scan_dict[widget.child.get_text()].nmap_output))
        except KeyError:
            # Avoid to raise an error if the user writes within
            # the entry and the scan doesn't exits
            pass

    def normalize_output(self, output):
        return "\n".join(output.split("\\n"))

    def _pack_hbox (self):
        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.hbox._pack_expand_fill(self.table)

    def _attaching_widgets (self):
        self.table.attach(self.combo_scan, 0,1,0,1, yoptions=0)
        self.table.attach(self.btn_open_scan, 1,2,0,1, yoptions=0, xoptions=0)
        self.table.attach(self.exp_scan, 0,2,1,2)
    
    def _set_scrolled(self):
        self.scrolled.set_border_width(5)
        self.scrolled.set_size_request(-1, 160)
        
        # Packing scrolled window into expander
        self.exp_scan.add(self.scrolled)
        
        # Packing text view into scrolled window
        self.scrolled.add_with_viewport(self.txt_scan_result)
        
        # Setting scrolled window
        self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
    
    def _set_text_view (self):
        self.txg_table = self.txt_scan_result.get_buffer().get_tag_table()
        self.txg_table.add(self.txg_tag)
        self.txg_tag.set_property("family", "Monospace")
        
        self.txt_scan_result.set_wrap_mode(gtk.WRAP_WORD)
        self.txt_scan_result.set_editable(False)
        self.txt_scan_result.get_buffer().connect("changed",
                                                  self._text_changed_cb)

    def _set_open_button (self):
        self.btn_open_scan.connect('clicked', self.open_file)
    
    def open_file (self, widget):
        file_chooser = ResultsFileChooserDialog(_("Select Scan Result"))
        
        file_chooser.run()
        file_chosen = file_chooser.get_filename()
        file_chooser.destroy()

        if check_access(file_chosen, os.R_OK):
            try:
                parser = NmapParser(file_chosen)
                parser.parse()
            except:
                alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % _('File is not a Umit \
Scan Result'),
                    secondary_text=_("Selected file is not a Umit Scan \
Result file. Umit can not parse this file. Please, select another."))
                alert.run()
                alert.destroy()
                return False

            scan_name = os.path.split(file_chosen)[-1]
            self.add_scan(scan_name, parser)
            
            self.combo_scan.set_active(len(self.list_scan) - 1)
        else:
            alert = HIGAlertDialog(
                    message_format='<b>%s</b>' % \
                                   _('Can not open selected file'),
                    secondary_text=_("Umit can not open selected file. Please, \
select another."))
            alert.run()
            alert.destroy()

    def add_scan(self, scan_name, parser):
        scan_id = 1
        new_scan_name = scan_name
        while new_scan_name in self.scan_dict:
            new_scan_name = "%s (%s)" % (scan_name, scan_id)
            scan_id += 1
                
        self.list_scan.append([new_scan_name])
        self.scan_dict[new_scan_name] = parser
    
    def _text_changed_cb (self, widget):
        buff = self.txt_scan_result.get_buffer ()
        buff.apply_tag(self.txg_tag, buff.get_start_iter(), buff.get_end_iter())

    def get_nmap_output(self):
        parsed = self.parsed_scan
        if parsed:
            return parsed.nmap_output
        return False

    def get_parsed_scan(self):
        selected_scan = self.combo_scan.child.get_text()
        if selected_scan:
            return self.scan_dict[selected_scan]
        return False

    nmap_output = property(get_nmap_output)
    parsed_scan = property(get_parsed_scan)
class UpdatePage(HIGVBox):
    """"""
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__load_list()
        self.__connect_widgets()
        self.__init_db_text()
        
    def __create_widgets(self):
        """"""
        
        self.update_switch_hbox = HIGHBox()
        self.update_settings_hbox = HIGHBox()
        self.update_db_hbox = HIGHBox()

        self.update_switch_section = HIGSectionLabel(_("Update News Detect"))        
        self.update_switch_table = HIGTable()
        self.update_settings_section = HIGSectionLabel(_("Update Settings"))        
        self.update_settings_table = HIGTable()  
        self.update_db_section = HIGSectionLabel(_("Update Database"))        
        self.update_db_table = HIGTable()
        
        self.update_check = gtk.CheckButton(_("Automatically update"))
        self.update_switch_check = gtk.CheckButton(_("Software Update Detect Switch"))
        self.update_times_label = HIGEntryLabel(_("Auto detect update news"))
        self.update_method_label = HIGEntryLabel(_("Update method"))       
        
        self.update_time_store = gtk.ListStore(str)
        self.update_time_entry = gtk.ComboBoxEntry(self.update_time_store, 0)
        self.update_method_store = gtk.ListStore(str)
        self.update_method_entry = gtk.ComboBoxEntry(self.update_method_store, 0)  
        
        self.update_db_label =  HIGEntryLabel()
        self.update_db_clear_button = gtk.Button(_("Clear Update Information")) 
         
    def __pack_widgets(self):
        """"""
        self.set_border_width(12) 
        
        self._pack_noexpand_nofill(self.update_switch_section)
        self._pack_noexpand_nofill(self.update_switch_hbox)
        self._pack_noexpand_nofill(hig_box_space_holder())
        self._pack_noexpand_nofill(self.update_settings_section)
        self._pack_noexpand_nofill(self.update_settings_hbox)
        self._pack_noexpand_nofill(self.update_db_section)
        self._pack_noexpand_nofill(self.update_db_hbox)        
        
        
        self.update_switch_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_switch_hbox._pack_expand_fill(self.update_switch_table)
        self.update_settings_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_settings_hbox._pack_expand_fill(self.update_settings_table)
        self.update_db_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_db_hbox._pack_expand_fill(self.update_db_table)
        
        self.update_switch_table.attach_label(self.update_check, 0, 2, 0, 1)
        self.update_switch_table.attach_label(self.update_switch_check, 0, 2, 1, 2)
        self.update_settings_table.attach_label(self.update_times_label, 0, 1, 0, 1)
        self.update_settings_table.attach_entry(self.update_time_entry, 1, 2, 0, 1)   
        self.update_settings_table.attach_label(self.update_method_label, 0, 1, 1, 2)
        self.update_settings_table.attach_entry(self.update_method_entry, 1, 2, 1, 2) 
        
        self.update_db_table.attach_label(self.update_db_label, 1, 3, 0, 1)
        self.update_db_table.attach(self.update_db_clear_button, 0, 1, 0, 1)
        
    
    def __init_db_text(self):
        """"""
        rs = g_db_helper.select("select * from updates")
        count = len(rs)
        self.update_db_label.set_text(str(_("%d records in update database now."%(count))))        
    
    def __connect_widgets(self):
        """"""
        self.update_check.connect('toggled',lambda w:self.__change_widgets_status()) 
        self.update_db_clear_button.connect("clicked", lambda w:self.__clear_update_db())
    
    def __clear_update_db(self):
        """"""
        g_db_helper.execute("delete from updates")
        g_db_helper.commit()
        self.update_db_label.set_text(str(_("Clear software update database!")))
    
    def __change_widgets_status(self):
        """"""
        if self.update_check.get_active():
            self.__disable_widgets()            
        else:
            self.__enable_widgets()
    
    def __load_list(self):
        """"""
        for s in update_time_str.keys():
            #print s
            self.update_time_store.append([s])
        for s in update_method_str.keys():
            #print s
            self.update_method_store.append([s])
    
    def __disable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(False)
        self.update_method_entry.set_sensitive(False)
        self.update_time_entry.set_sensitive(False)
        
    def __enable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(True)
        self.update_method_entry.set_sensitive(True)
        self.update_time_entry.set_sensitive(True)        
         
class BugReport(HIGDialog):
    def __init__(self, title=_('Bug Report'), summary=None, description=None,
                 category=None, crashreport=False, description_dialog=None,
                 reuse_mainloop=True):
        HIGDialog.__init__(self, title=title,
            buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
                gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        # If reuse_mainloop is true, then dialogs created inside this dialog
        # will not start another mainloop.
        self._reuse_mainloop = reuse_mainloop

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.crashreport = crashreport
        self.description_dialog = description_dialog
        self._create_widgets()
        self._set_category_list()
        self._pack_widgets()
        self._connect_widgets()
        self.summary = summary or ''
        self.description_report = description
        if self.crashreport:
            self.description = _("CrashReport automatically created")
        else:
            if self.description_dialog is None:
                self.description = description or ''
            else:
                self.description = description_dialog or ''
        self.category = category or ''

    def _set_category_list(self):
        # Obtained at bug tracker page source code
        # The following two lines are commented due to component deprecation
        #self.category_list.append(["umitCore","umitCore"])
        #self.category_list.append(["umitGUI","umitGUI"])
        self.category_list.append(["Umit","Umit"])
        self.category_list.append(["CrashReport","CrashReport"])
        self.category_list.append(["Documentation", "Documentation"])
        self.category_list.append(["UmitWeb","UmitWeb"])
        self.category_list.append(["InterfaceEditor", "InterfaceEditor"])
        self.category_list.append(["NetworkInventory", "NetworkInventory"])
        self.category_list.append(["website","website"])

    def _create_widgets(self):
        self.category_label = HIGHintSectionLabel(_("Category (optional)"),
            _("If you know in which section of the program "
            "is the bug, please, select it from the choosebox. "
            "If you don't know what section to choose, leave it blank."))
        self.category_list = gtk.ListStore(str, str)
        self.category_combo = gtk.ComboBoxEntry(self.category_list, 0)

        self.email_label = HIGHintSectionLabel(_("Email"),
            _("Please inform a valid e-mail address from "
            "where you can be reached to be notified when the bug gets "
            "fixed. Not used for other purposes."))
        self.email_entry = gtk.Entry()

        self.summary_label = HIGHintSectionLabel(_("Summary"),
            _("This should be a quick description of the issue. "
            "Try to be clear and concise."))
        self.summary_entry = gtk.Entry()

        self.description_label = HIGHintSectionLabel(_("Description"),
            _("This is where you should write about the bug, "
            "describing it as clear as possible and giving as many "
            "informations as you can and how to reproduce the bug."))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_icon = gtk.Image()
        self.bug_text = gtk.Label(_("This Bug Report dialog allows you "
            "to easily tell us about a problem that you may have found on "
            "Umit. Doing so, you help us to help you, by fixing and "
            "improving Umit faster than usual."))
        
        if self.crashreport:
            # Create a button to show details 
            self.show_details = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                           _("Show Details"))

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.description_scrolled.add(self.description_text)
        self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, 
            gtk.POLICY_AUTOMATIC)
        self.description_scrolled.set_size_request(400, 150)
        self.description_text.set_wrap_mode(gtk.WRAP_WORD)

        self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, 
            gtk.ICON_SIZE_DIALOG)
        self.bug_icon.set_padding(10, 0)
        self.bug_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        
        nextpos = (0, 1)
        if not self.crashreport:
            self.table.attach_label(self.category_label, 0, 1, 0, 1)
            self.table.attach_entry(self.category_combo, 1, 2, 0, 1)
            nextpos = (1, 2)

        self.table.attach_label(self.email_label, 0, 1, *nextpos)
        self.table.attach_entry(self.email_entry, 1, 2, *nextpos)

        nextpos = (2, 3)
        if not self.crashreport:
            self.table.attach_label(self.summary_label, 0, 1, 2, 3)
            self.table.attach_entry(self.summary_entry, 1, 2, 2, 3)
            nextpos = (3, 4)

        self.table.attach_label(self.description_label, 0, 2, *nextpos)
        nextpos = nextpos[0] + 1, nextpos[1] + 1
        self.table.attach_entry(self.description_scrolled, 0, 2, *nextpos)

        self.hbox._pack_noexpand_nofill(self.bug_icon)
        self.hbox._pack_expand_fill(self.bug_text)

        self.vbox.pack_start(self.hbox, False, False)
        self.vbox.pack_start(self.table)
       
        # Just need because in crash report some aditional 
        # information will be show 
        if self.crashreport:
            # Add a button to action-area
            spaceholder = hig_box_space_holder()
            self.action_area.pack_end(spaceholder)
            self.action_area.pack_end(self.show_details)
            # Put "Show details" to left side respecting HIG
            self.action_area.reorder_child(self.show_details,0)
            self.action_area.reorder_child(spaceholder, 1)
        
        
        
    def _connect_widgets(self):
        self.connect('response', self.check_response)
        if self.crashreport:
            self.show_details.connect('clicked',
                                      self._show_details)
        
    def _show_details(self, widget):
        # Create info necessary
        desc = [ self.email,
                 self.summary,
                 self.description_report,
                 self.description,
                 self.category] 
        # Create another dialog to show details
        details = BugReportDescription(*desc)
        details.show_all()
        details.run()
        details.destroy()
        
        
    def check_response(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            self.send_report()
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            # there are tree possibilities to being here:
            # 1) user clicked on 'x' button
            # 2) user clicked on 'cancel' button
            # 3) report was sent successfully and now we can destroy this
            self.destroy()

    def send_report(self):
        """Prepare dialog to send a bug report and then call _send_report."""
        # set cursor to busy cursor (supposing it will take some time
        # to submit the report)
        self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))

        # disable dialog controls
        for child in self.vbox.get_children():
            child.set_sensitive(False)

        # attempt sending report
        gobject.idle_add(self._send_report)

    def restore_state(self):
        """Restore dialog state, just like it was before calling
        send_report."""
        self.window.set_cursor(None)
        for child in self.vbox.get_children():
            child.set_sensitive(True)

    def _send_report(self):
        if self.summary == "" or self.description == "" or self.email == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                message_format=_("Bug report is incomplete!"),
                secondary_text=_("The bug report is incomplete. "
                    "You must inform a description that explains clearly "
                    "what is happening and a valid e-mail, so you can be "
                    "contacted when the bug gets fixed."))
            run_dialog(self._reuse_mainloop, cancel_dialog)
            return self.restore_state()

        bug_register = BugRegister()

        bug_register.component = self.category
        bug_register.summary = self.summary
        if self.description_report is not None:
            bug_register.details = self.description_report
        else:
            bug_register.details = self.description.replace("\n", "[[BR]]")
        bug_register.reporter = self.email

        bug_page = None
        try:
            bug_page = bug_register.report()
            assert bug_page
        except:
            import traceback
            traceback.print_exc()
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                message_format=_("Bug not reported!"),
                secondary_text=_("The bug description could not be "
                    "reported. This problem may be caused by the lack "
                    "of Internet access or indisponibility of the bug "
                    "tracker server. Please, verify your internet access, "
                    "and then try to report the bug once again."))
            run_dialog(self._reuse_mainloop, cancel_dialog)
            return self.restore_state()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                message_format=_("Bug sucessfully reported!"),
                secondary_text=_("The bug description was sucessfully "
                    "reported. A web page with detailed description about "
                    "this report will be opened in your default web browser "
                    "now."))
            run_dialog(self._reuse_mainloop, ok_dialog,
                    show_report, # callback
                    self._reuse_mainloop, bug_page) # args

        # report sent successfully
        self.response(gtk.RESPONSE_DELETE_EVENT)

    def get_category(self):
        return self.category_combo.child.get_text()

    def set_category(self, category):
        self.category_combo.child.set_text(category)

    def get_summary(self):
        return self.summary_entry.get_text()

    def set_summary(self, summary):
        self.summary_entry.set_text(summary)
    def get_description(self):
        buff = self.description_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())
    def set_description(self, description):
        self.description_text.get_buffer().set_text(description)

    def get_email(self):
        return self.email_entry.get_text()

    def set_email(self, email):
        self.email_entry.set_text(email)


    category = property(get_category, set_category)
    summary = property(get_summary, set_summary)
    description = property(get_description, set_description)
    email = property(get_email, set_email)