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 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 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)
Exemple #4
0
class SearchWindow(HIGWindow, object):
    """Search Window. Shows informations about the search while it's running
    """
    def __init__(self):
        HIGWindow.__init__(self)

        self.__create_widgets()
        self.__pack_widgets()
        self.__set_widgets()

    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.button_box = gtk.HButtonBox()
        self.search_file_label = HIGEntryLabel()
        self.progress = gtk.ProgressBar()

    def __pack_widgets(self):
        self.add(self.vbox)
        self.vbox.pack_start(self.search_file_label)
        self.vbox.pack_start(self.progress)
        self.vbox.pack_start(self.button_box)
        self.button_box.pack_start(self.cancel_button)

    def __set_widgets(self):
        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.set_title('Searching...')
        self.set_size_request(350, -1)
        self.set_position(gtk.WIN_POS_CENTER)

    def set_filename(self, filename):
        self.__filename = filename
        self.search_file_label.set_text(_("File: %s") % filename)

    def get_filename(self):
        return self.__filename

    def set_path(self, path):
        self.__path = path
        self.forward_progress_status()
        self.progress.set_text(_("Searching inside '%s'") % path)

    def get_path(self):
        return self.__path

    def set_fraction(self, fraction):
        self.__fraction = fraction

    def get_fraction(self):
        return self.__fraction

    def forward_progress_status(self):
        try:
            self.fraction
        except:
            self.fraction = 0.2
        self.progress.set_fraction(self.fraction + self.progress.get_fraction())


    filename = property(get_filename,
                        set_filename,
                        doc=_("File's name being searched"))
    path = property(get_path,
                    set_path,
                    doc=_("Path being scanned"))
    fraction = property(get_fraction,
                        set_fraction,
                        doc=_("Fraction of the progress bar"))
class HighlightProperty(object):
    def __init__(self, property_name, property):
        self.__create_widgets()

        self.property_name = property_name
        
        self.property_label = property[0].capitalize()
        self.example = property[1]
        self.bold = property[2]
        self.italic = property[3]
        self.underline = property[4]
        
        self.text_color = property[5]
        self.highlight_color = property[6]

        self.__connect_buttons()

    def __create_widgets(self):
        self.property_name_label = HIGEntryLabel("")
        self.example_label = HIGEntryLabel("")
        self.bold_tg_button = HIGToggleButton(" ", gtk.STOCK_BOLD)
        self.italic_tg_button = HIGToggleButton(" ", gtk.STOCK_ITALIC)
        self.underline_tg_button = HIGToggleButton(" ", gtk.STOCK_UNDERLINE)
        self.text_color_button = HIGButton(_("Text"),
                                           stock=gtk.STOCK_SELECT_COLOR)
        self.highlight_color_button = HIGButton(_("Highlight"),
                                                stock=gtk.STOCK_SELECT_COLOR)

    def __connect_buttons(self):
        self.bold_tg_button.connect("toggled", self.update_example)
        self.italic_tg_button.connect("toggled", self.update_example)
        self.underline_tg_button.connect("toggled", self.update_example)

        self.text_color_button.connect("clicked",
                                       self.text_color_dialog)
        self.highlight_color_button.connect("clicked",
                                            self.highlight_color_dialog)


    ####################################
    # Text color dialog
    
    def text_color_dialog(self, widget):
        color_dialog = gtk.ColorSelectionDialog("%s %s" % (self.label,
                                                           _("text color")))
        color_dialog.colorsel.set_current_color(self.text_color)
        
        color_dialog.ok_button.connect("clicked",
                                       self.text_color_dialog_ok,
                                       color_dialog)
        color_dialog.cancel_button.connect("clicked",
                                           self.text_color_dialog_cancel,
                                           color_dialog)
        color_dialog.connect("delete-event",
                             self.text_color_dialog_close,
                             color_dialog)
        
        color_dialog.run()

    def text_color_dialog_ok(self, widget, color_dialog):
        self.text_color = color_dialog.colorsel.get_current_color()
        color_dialog.destroy()
        self.update_example()

    def text_color_dialog_cancel(self, widget, color_dialog):
        color_dialog.destroy()

    def text_color_dialog_close(self, widget, extra, color_dialog):
        color_dialog.destroy()


    #########################################
    # Highlight color dialog
    def highlight_color_dialog(self, widget):
        color_dialog = gtk.ColorSelectionDialog("%s %s" % (self.property_name,
                                                        _("highlight color")))
        color_dialog.colorsel.set_current_color(self.highlight_color)

        color_dialog.ok_button.connect("clicked",
                                       self.highlight_color_dialog_ok,
                                       color_dialog)
        color_dialog.cancel_button.connect("clicked",
                                           self.highlight_color_dialog_cancel,
                                           color_dialog)
        color_dialog.connect("delete-event",
                             self.highlight_color_dialog_close,
                             color_dialog)
        
        color_dialog.run()

    def highlight_color_dialog_ok(self, widget, color_dialog):
        self.highlight_color = color_dialog.colorsel.get_current_color()
        color_dialog.destroy()
        self.update_example()

    def highlight_color_dialog_cancel(self, widget, color_dialog):
        color_dialog.destroy()

    def highlight_color_dialog_close(self, widget, extra, color_dialog):
        color_dialog.destroy()

    def update_example(self, widget=None):
        start = 0
        end = len(self.example)
        
        attributes = pango.AttrList()

        attributes.insert(pango.AttrForeground(self.text_color.red,
                                               self.text_color.green,
                                               self.text_color.blue,
                                               start, end))
        attributes.insert(pango.AttrBackground(self.highlight_color.red,
                                               self.highlight_color.green,
                                               self.highlight_color.blue,
                                               start, end))

        # Bold verification
        if self.bold_tg_button.get_active():
            attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, start, end))
        else:
            attributes.insert(pango.AttrWeight(pango.WEIGHT_NORMAL, start, end))

        # Italic verification
        if self.italic_tg_button.get_active():
            attributes.insert(pango.AttrStyle(pango.STYLE_ITALIC, start, end))
        else:
            attributes.insert(pango.AttrStyle(pango.STYLE_NORMAL, start, end))

        # Underline verification
        if self.underline_tg_button.get_active():
            attributes.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE,
                                                  start, end))
        else:
            attributes.insert(pango.AttrUnderline(pango.UNDERLINE_NONE,
                                                  start, end))

        self.example_label.set_attributes(attributes)


    def show_bold(self, widget):
        self.example_label.set_markup("<>")

    def get_example(self):
        return self.example_label.get_text()

    def set_example(self, example):
        self.example_label.set_text(example)

    def get_bold(self):
        if self.bold_tg_button.get_active():
            return 1
        return 0

    def set_bold(self, bold):
        self.bold_tg_button.set_active(bold)

    def get_italic(self):
        if self.italic_tg_button.get_active():
            return 1
        return 0

    def set_italic(self, italic):
        self.italic_tg_button.set_active(italic)

    def get_underline(self):
        if self.underline_tg_button.get_active():
            return 1
        return 0

    def set_underline(self, underline):
        self.underline_tg_button.set_active(underline)

    def get_label(self):
        return self.property_name_label.get_text()

    def set_label(self, label):
        self.property_name_label.set_text(label)

    label = property(get_label, set_label)
    example = property(get_example, set_example)
    bold = property(get_bold, set_bold)
    italic = property(get_italic, set_italic)
    underline = property(get_underline, set_underline)
class HostDetails(HIGVBox):
    os_table = None
    os_hbox = None

    def __init__(self):
        HIGVBox.__init__(self)

        self.__create_widgets()

    def __create_widgets(self):
        self.host_status_expander = gtk.Expander('<b>' + _('Host Status') +
                                                 '</b>')
        self.address_expander = gtk.Expander('<b>' + _('Addresses') + '</b>')
        self.hostnames_expander = gtk.Expander('<b>' + _('Hostnames') + '</b>')
        self.os_expander = gtk.Expander('<b>' + _('Operating System') + '</b>')
        self.portsused_expander = gtk.Expander('<b>' + _('Ports used') +
                                               '</b>')
        self.osclass_expander = gtk.Expander('<b>' + _('OS Class') + '</b>')
        self.tcp_expander = gtk.Expander('<b>' + _('TCP Sequence') + '</b>')
        self.ip_expander = gtk.Expander('<b>' + _('IP ID Sequence') + '</b>')
        self.tcpts_expander = gtk.Expander('<b>' + _('TCP TS Sequence') +
                                           '</b>')
        self.comment_expander = gtk.Expander('<b>' + _('Comments') + '</b>')
        self.os_image = gtk.Image()
        self.vulnerability_image = gtk.Image()

        # Host Status expander
        self.host_state_label = HIGEntryLabel(_('State:'))
        self.info_host_state_label = HIGEntryLabel(na)

        self.open_label = HIGEntryLabel(_('Open ports:'))
        self.info_open_ports = HIGEntryLabel(na)

        self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
        self.info_filtered_label = HIGEntryLabel(na)

        self.closed_label = HIGEntryLabel(_('Closed ports:'))
        self.info_closed_ports = HIGEntryLabel(na)

        self.scanned_label = HIGEntryLabel(_('Scanned ports:'))
        self.info_scanned_label = HIGEntryLabel(na)

        self.uptime_label = HIGEntryLabel(_('Up time:'))
        self.info_uptime_label = HIGEntryLabel(na)

        self.lastboot_label = HIGEntryLabel(_('Last boot:'))
        self.info_lastboot_label = HIGEntryLabel(na)

        # Addresses expander
        self.ipv4_label = HIGEntryLabel(_('IPv4:'))
        self.info_ipv4_label = HIGEntryLabel(na)

        self.ipv6_label = HIGEntryLabel(_('IPv6:'))
        self.info_ipv6_label = HIGEntryLabel(na)

        self.mac_label = HIGEntryLabel(_('MAC:'))
        self.info_mac_label = HIGEntryLabel(na)

        self.vendor_label = HIGEntryLabel(_('Vendor:'))
        self.info_vendor_label = HIGEntryLabel(na)

    def create_table_hbox(self):
        table = HIGTable()
        hbox = HIGHBox()

        hbox._pack_noexpand_nofill(hig_box_space_holder())
        hbox._pack_noexpand_nofill(table)

        return table, hbox

    def set_host_status(self, status):
        self.host_status_expander.set_use_markup(True)
        self.host_status_expander.set_expanded(True)
        table, hbox = self.create_table_hbox()

        try:
            if status['state'] == '': raise Exception
            self.info_host_state_label.set_text(status['state'])
        except:
            pass

        try:
            if status['open'] == '': raise Exception
            self.info_open_ports.set_text(status['open'])
        except:
            pass

        try:
            if status['filtered'] == '': raise Exception
            self.info_filtered_label.set_text(status['filtered'])
        except:
            pass

        try:
            if status['closed'] == '': raise Exception
            self.info_closed_ports.set_text(status['closed'])
        except:
            pass

        try:
            if status['scanned'] == '': raise Exception
            self.info_scanned_label.set_text(status['scanned'])
        except:
            pass

        try:
            if status['uptime'] == '': raise Exception
            self.info_uptime_label.set_text(status['uptime'])
        except:
            pass

        try:
            if status['lastboot'] == '': raise Exception
            self.info_lastboot_label.set_text(status['lastboot'])
        except:
            pass

        table.attach(self.host_state_label, 0, 1, 0, 1)
        table.attach(self.info_host_state_label, 1, 2, 0, 1)

        table.attach(self.open_label, 0, 1, 1, 2)
        table.attach(self.info_open_ports, 1, 2, 1, 2)

        table.attach(self.filtered_label, 0, 1, 2, 3)
        table.attach(self.info_filtered_label, 1, 2, 2, 3)

        table.attach(self.closed_label, 0, 1, 3, 4)
        table.attach(self.info_closed_ports, 1, 2, 3, 4)

        table.attach(self.scanned_label, 0, 1, 4, 5)
        table.attach(self.info_scanned_label, 1, 2, 4, 5)

        table.attach(self.uptime_label, 0, 1, 5, 6)
        table.attach(self.info_uptime_label, 1, 2, 5, 6)

        table.attach(self.lastboot_label, 0, 1, 6, 7)
        table.attach(self.info_lastboot_label, 1, 2, 6, 7)

        table.attach(self.os_image, 2, 4, 0, 3, xoptions=1, yoptions=0)
        table.attach(self.vulnerability_image,
                     2,
                     4,
                     4,
                     7,
                     xoptions=1,
                     yoptions=0)

        table.set_col_spacing(1, 50)

        self.host_status_expander.add(hbox)
        self._pack_noexpand_nofill(self.host_status_expander)

    def set_os_image(self, image):
        self.os_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG)

    def set_vulnerability_image(self, image):
        self.vulnerability_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG)

    def set_addresses(self, address):
        self.address_expander.set_use_markup(True)
        table, hbox = self.create_table_hbox()
        self.address_expander.set_expanded(True)

        #print '>>> Address:', address
        try:
            if address['ipv4'] == 1: raise Exception
            self.info_ipv4_label.set_text(address['ipv4'])
        except:
            pass

        try:
            if address['ipv6'] == 1: raise Exception
            self.info_ipv6_label.set_text(address['ipv6'])
        except:
            pass

        try:
            if address['mac'] == 1: raise Exception
            self.info_mac_label.set_text(address['mac'])
        except:
            pass

        table.attach(self.ipv4_label, 0, 1, 0, 1)
        table.attach(self.info_ipv4_label, 1, 2, 0, 1)

        table.attach(self.ipv6_label, 0, 1, 1, 2)
        table.attach(self.info_ipv6_label, 1, 2, 1, 2)

        table.attach(self.mac_label, 0, 1, 2, 3)
        table.attach(self.info_mac_label, 1, 2, 2, 3)

        self.address_expander.add(hbox)
        self._pack_noexpand_nofill(self.address_expander)

    def set_hostnames(self, hostname):
        if hostname:
            self.hostnames_expander.set_use_markup(True)
            self.hostnames_expander.set_expanded(True)
            table, hbox = self.create_table_hbox()

            y1 = 1
            y2 = 2

            for h in hostname:
                name = na
                try:
                    name = h['hostname']
                except:
                    pass

                type = na
                try:
                    type = h['hostname_type']
                except:
                    pass

                table.attach(HIGEntryLabel(_('Name - Type:')), 0, 1, y1, y2)
                table.attach(HIGEntryLabel(name+' - '+\
                                           type),1,2,y1,y2)
                y1 += 1
                y2 += 1

            self.hostnames_expander.add(hbox)
            self._pack_noexpand_nofill(self.hostnames_expander)

    def os_selection_changed(self, widget):
        current_selection = widget.get_active_text()
        self.set_os_image(get_os_logo(current_selection))

        for os_match in self.current_os_list:
            if isinstance(os_match, dict) and \
               current_selection == os_match.get('name', None):
                self.os_progress.set_fraction(
                    float(os_match['accuracy']) / 100.0)
                self.os_progress.set_text(os_match['accuracy'] + "%")
                self.os_progress.set_sensitive(True)
                break
        else:
            self.os_progress.set_fraction(0.0)
            self.os_progress.set_text(_("Not Available"))
            self.os_progress.set_sensitive(False)

    def set_os_list(self, os_list, os_match):
        # Creating the main widgets for this section
        self.os_expander.set_use_markup(True)
        self.os_expander.set_expanded(True)
        self.os_table, self.os_hbox = self.create_table_hbox()
        self.os_progress = gtk.ProgressBar()

        # Setting the current match's details in the widgets
        if len(os_list) > 1:
            self.os_list = gtk.combo_box_new_text()

            model = self.os_list.get_model()
            [
                model.append([os['name']]) for os in os_list
                if os.has_key("name")
            ]
            self.os_list.set_active(0)

            # In case we have the os selection changed, we need to change the
            # icon and the current accuracy. Also, we need to save the selection
            # in the usr result.
            self.os_list.connect("changed", self.os_selection_changed)
        else:
            self.os_list = HIGEntryLabel(os_match.get("name", "Not Available"))

        self.os_table.attach(HIGEntryLabel(_('Name:')), 0, 1, 0, 1)
        self.os_table.attach(self.os_list, 1, 2, 0, 1)

        # Setting current os_match accuracy
        if os_match.get("accuracy", ''):
            self.os_progress.set_fraction(float(os_match['accuracy']) / 100.0)
            self.os_progress.set_text(os_match['accuracy'] + '%')
            self.os_progress.set_sensitive(True)
        else:
            self.os_progress.set_sensitive(False)
            self.os_progress.set_text(_('Not Available'))

        self.os_table.attach(HIGEntryLabel(_('Accuracy:')), 0, 1, 1, 2)
        self.os_table.attach(self.os_progress, 1, 2, 1, 2)

        ###################
        ## Setting the list of matches and the list of ports used in the scan
        if os_match.has_key("portsused"):
            self.set_ports_used(os_match["portsused"])
            self.portsused_expander.set_sensitive(True)
        else:
            # In case we don't have any port, we still show the expander widget
            # but in a non-sensitive manner
            self.portsused_expander.set_sensitive(False)
        self.portsused_expander.set_use_markup(True)
        self.os_table.attach(self.portsused_expander, 0, 2, 2, 3)

        if os_match.has_key('osclass'):
            self.set_osclass(os_match['osclass'])
            self.osclass_expander.set_sensitive(True)
        else:
            self.osclass_expander.set_sensitive(False)
        self.osclass_expander.set_use_markup(True)
        self.os_table.attach(self.osclass_expander, 0, 2, 3, 4)

        self.os_expander.add(self.os_hbox)
        self._pack_noexpand_nofill(self.os_expander)

        # Saving os_list and os_match for latter access
        self.current_os_list = os_list
        self.current_os_match = os_match

    def set_ports_used(self, ports=None):
        # Removing old childs
        child = self.portsused_expander.get_child()
        if child is not None:
            self.portsused_expander.remove(child)

        if ports is None:
            self.portsused_expander.set_sensitive(False)
            return
        else:
            self.portsused_expander.set_sensitive(True)

        self.portsused_expander.set_use_markup(True)
        table, hbox = self.create_table_hbox()

        y1 = 0
        y2 = 1

        for p in ports:
            table.attach(HIGEntryLabel(_('Port-Protocol-State:')), 0, 1, y1,
                         y2)
            table.attach(HIGEntryLabel(p['portid']+' - '+p['proto']+' - '+\
                                       p['state']), 1, 2, y1, y2)
            y1 += 1
            y2 += 1

        self.portsused_expander.add(hbox)

    def set_osclass(self, osclass=None):
        child = self.osclass_expander.get_child()
        if child is not None:
            self.osclass_expander.remove(child)

        if osclass is None:
            self.osclass_expander.set_sensitive(False)
            return
        else:
            self.osclass_expander.set_sensitive(True)
            self.osclass_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            table.attach(HIGEntryLabel(_('Type')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(_('Vendor')), 1, 2, 0, 1)
            table.attach(HIGEntryLabel(_('OS Family')), 2, 3, 0, 1)
            table.attach(HIGEntryLabel(_('OS Generation')), 3, 4, 0, 1)
            table.attach(HIGEntryLabel(_('Accuracy')), 4, 5, 0, 1)

            y1 = 1
            y2 = 2

            for o in osclass:
                table.attach(HIGEntryLabel(o['type']), 0, 1, y1, y2)
                table.attach(HIGEntryLabel(o['vendor']), 1, 2, y1, y2)
                table.attach(HIGEntryLabel(o['osfamily']), 2, 3, y1, y2)
                table.attach(HIGEntryLabel(o.get('osgen', '')), 3, 4, y1, y2)

                progress = gtk.ProgressBar()
                progress.set_text(o['accuracy'] + '%')
                progress.set_fraction(float(o['accuracy']) / 100.0)
                table.attach(progress, 4, 5, y1, y2)
                y1 += 1
                y2 += 1

            self.osclass_expander.add(hbox)

    def set_tcpseq(self, tcpseq):
        if tcpseq:
            self.tcp_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            combo = gtk.combo_box_new_text()
            for v in tcpseq['values'].split(','):
                combo.append_text(v)

            table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(tcpseq.get('class', '')), 1, 2, 0, 1)

            table.attach(HIGEntryLabel(_('Difficulty:')), 0, 1, 1, 2)
            table.attach(HIGEntryLabel(tcpseq['difficulty']), 1, 2, 1, 2)

            table.attach(HIGEntryLabel(_('Index:')), 0, 1, 2, 3)
            table.attach(HIGEntryLabel(tcpseq['index']), 1, 2, 2, 3)

            table.attach(HIGEntryLabel(_('Values:')), 0, 1, 3, 4)
            table.attach(combo, 1, 2, 3, 4)

            self.tcp_expander.add(hbox)
            self._pack_noexpand_nofill(self.tcp_expander)

    def set_ipseq(self, ipseq):
        if ipseq:
            self.ip_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            combo = gtk.combo_box_new_text()

            for i in ipseq['values'].split(','):
                combo.append_text(i)

            table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(ipseq['class']), 1, 2, 0, 1)

            table.attach(HIGEntryLabel(_('Values:')), 0, 1, 1, 2)
            table.attach(combo, 1, 2, 1, 2)

            self.ip_expander.add(hbox)
            self._pack_noexpand_nofill(self.ip_expander)

    def set_tcptsseq(self, tcptsseq):
        if tcptsseq:
            self.tcpts_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            combo = gtk.combo_box_new_text()

            for i in tcptsseq.get('values', '').split(','):
                combo.append_text(i)

            table.attach(HIGEntryLabel(_('Class:')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(tcptsseq['class']), 1, 2, 0, 1)

            table.attach(HIGEntryLabel(_('Values:')), 0, 1, 1, 2)
            table.attach(combo, 1, 2, 1, 2)

            self.tcpts_expander.add(hbox)
            self._pack_noexpand_nofill(self.tcpts_expander)

    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)

    def get_comment(self):
        buffer = self.comment_txt_vw.get_buffer()
        return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
Exemple #7
0
class ScanRunDetailsPage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)

        self.__create_widgets()

    def __create_widgets(self):
        na = _('Not available')
        self.command_expander = gtk.Expander("<b>" + _("Command Info") +
                                             "</b>")
        self.general_expander = gtk.Expander("<b>" + _("General Info") +
                                             "</b>")

        # Command info
        self.command_label = HIGEntryLabel(_('Command:'))
        self.info_command_label = HIGEntryLabel(na)

        self.nmap_version_label = HIGEntryLabel(_('Nmap Version:'))
        self.info_nmap_version_label = HIGEntryLabel(na)

        self.verbose_label = HIGEntryLabel(_('Verbosity level:'))
        self.info_verbose_label = HIGEntryLabel(na)

        self.debug_label = HIGEntryLabel(_('Debug level:'))
        self.info_debug_label = HIGEntryLabel(na)

        self.command_table = HIGTable()
        self.command_hbox = HIGHBox()

        # General info:
        self.start_label = HIGEntryLabel(_('Started on:'))
        self.info_start_label = HIGEntryLabel(na)

        self.finished_label = HIGEntryLabel(_('Finished on:'))
        self.info_finished_label = HIGEntryLabel(na)

        self.host_up_label = HIGEntryLabel(_('Hosts up:'))
        self.info_hosts_up_label = HIGEntryLabel(na)

        self.host_down_label = HIGEntryLabel(_('Hosts down:'))
        self.info_hosts_down_label = HIGEntryLabel(na)

        self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:'))
        self.info_hosts_scanned_label = HIGEntryLabel(na)

        self.open_label = HIGEntryLabel(_('Open ports:'))
        self.info_open_label = HIGEntryLabel(na)

        self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
        self.info_filtered_label = HIGEntryLabel(na)

        self.closed_label = HIGEntryLabel(_('Closed ports:'))
        self.info_closed_label = HIGEntryLabel(na)

        self.general_table = HIGTable()
        self.general_hbox = HIGHBox()

    def set_command_info(self, info):
        # Fix aligment!
        self.command_expander.set_use_markup(True)
        self.command_table.set_border_width(5)
        self.command_table.set_row_spacings(6)
        self.command_table.set_col_spacings(6)

        try:
            self.info_command_label.set_text(info['command'])
        except:
            pass

        try:
            self.info_nmap_version_label.set_text(info['version'])
        except:
            pass

        try:
            self.info_verbose_label.set_text(info['verbose'])
        except:
            pass

        try:
            self.info_debug_label.set_text(info['debug'])
        except:
            pass

        self.command_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.command_hbox._pack_noexpand_nofill(self.command_table)

        self.command_table.attach(self.command_label, 0, 1, 0, 1)
        self.command_table.attach(self.info_command_label, 1, 2, 0, 1)

        self.command_table.attach(self.nmap_version_label, 0, 1, 1, 2)
        self.command_table.attach(self.info_nmap_version_label, 1, 2, 1, 2)

        self.command_table.attach(self.verbose_label, 0, 1, 2, 3)
        self.command_table.attach(self.info_verbose_label, 1, 2, 2, 3)

        self.command_table.attach(self.debug_label, 0, 1, 3, 4)
        self.command_table.attach(self.info_debug_label, 1, 2, 3, 4)

        self.command_expander.add(self.command_hbox)
        self._pack_noexpand_nofill(self.command_expander)
        self.command_expander.set_expanded(True)

    def set_general_info(self, info):
        # Fix aligment!
        self.general_expander.set_use_markup(True)
        self.general_table.set_border_width(5)
        self.general_table.set_row_spacings(6)
        self.general_table.set_col_spacings(6)

        try:
            self.info_start_label.set_text(info['start'])
        except:
            pass

        try:
            self.info_finished_label.set_text(info['finish'])
        except:
            pass

        try:
            self.info_hosts_up_label.set_text(info['hosts_up'])
        except:
            pass

        try:
            self.info_hosts_down_label.set_text(info['hosts_down'])
        except:
            pass

        try:
            self.info_hosts_scanned_label.set_text(info['hosts_scanned'])
        except:
            pass

        #try:
        self.info_open_label.set_text(info['open_ports'])
        #except:pass

        #try:
        self.info_filtered_label.set_text(info['filtered_ports'])
        #except:pass

        #try:
        self.info_closed_label.set_text(info['closed_ports'])
        #except:pass

        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_noexpand_nofill(self.general_table)

        self.general_table.attach(self.start_label, 0, 1, 0, 1)
        self.general_table.attach(self.info_start_label, 1, 2, 0, 1)

        self.general_table.attach(self.finished_label, 0, 1, 1, 2)
        self.general_table.attach(self.info_finished_label, 1, 2, 1, 2)

        self.general_table.attach(self.host_up_label, 0, 1, 2, 3)
        self.general_table.attach(self.info_hosts_up_label, 1, 2, 2, 3)

        self.general_table.attach(self.host_down_label, 0, 1, 3, 4)
        self.general_table.attach(self.info_hosts_down_label, 1, 2, 3, 4)

        self.general_table.attach(self.host_scanned_label, 0, 1, 4, 5)
        self.general_table.attach(self.info_hosts_scanned_label, 1, 2, 4, 5)

        self.general_table.attach(self.open_label, 0, 1, 5, 6)
        self.general_table.attach(self.info_open_label, 1, 2, 5, 6)

        self.general_table.attach(self.filtered_label, 0, 1, 6, 7)
        self.general_table.attach(self.info_filtered_label, 1, 2, 6, 7)

        self.general_table.attach(self.closed_label, 0, 1, 7, 8)
        self.general_table.attach(self.info_closed_label, 1, 2, 7, 8)

        self.general_expander.add(self.general_hbox)
        self._pack_noexpand_nofill(self.general_expander)
        self.general_expander.set_expanded(True)

    def set_scan_infos(self, scan_info):
        for scan in scan_info:
            exp = gtk.Expander('<b>%s - %s</b>' %
                               (_('Scan Info'), scan['type'].capitalize()))
            exp.set_use_markup(True)
            hbox = HIGHBox()
            table = HIGTable()
            table.set_border_width(5)
            table.set_row_spacings(6)
            table.set_col_spacings(6)

            table.attach(HIGEntryLabel(_('Scan type:')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(scan['type']), 1, 2, 0, 1)

            table.attach(HIGEntryLabel(_('Protocol:')), 0, 1, 1, 2)
            table.attach(HIGEntryLabel(scan['protocol']), 1, 2, 1, 2)

            table.attach(HIGEntryLabel(_('# scanned ports:')), 0, 1, 2, 3)
            table.attach(HIGEntryLabel(scan['numservices']), 1, 2, 2, 3)

            table.attach(HIGEntryLabel(_('Services:')), 0, 1, 3, 4)
            table.attach(self.get_service_view(scan['services'].split(',')),\
                                               1,2,3,4)

            hbox._pack_noexpand_nofill(hig_box_space_holder())
            hbox._pack_noexpand_nofill(table)

            exp.add(hbox)
            self._pack_noexpand_nofill(exp)

    def get_service_view(self, services):
        combo = gtk.combo_box_new_text()

        for i in services:
            combo.append_text(i)

        return combo
class ScanRunDetailsPage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)
        
        self.__create_widgets()
    
    def __create_widgets(self):
        na = _('Not available')
        self.command_expander = gtk.Expander("<b>"+_("Command Info")+"</b>")
        self.general_expander = gtk.Expander("<b>"+_("General Info")+"</b>")
        
        # Command info
        self.command_label = HIGEntryLabel(_('Command:'))
        self.info_command_label = HIGEntryLabel(na)
        
        self.nmap_version_label = HIGEntryLabel(_('Nmap Version:'))
        self.info_nmap_version_label = HIGEntryLabel(na)
        
        self.verbose_label = HIGEntryLabel(_('Verbosity level:'))
        self.info_verbose_label = HIGEntryLabel(na)
        
        self.debug_label = HIGEntryLabel(_('Debug level:'))
        self.info_debug_label = HIGEntryLabel(na)
        
        self.command_table = HIGTable()
        self.command_hbox = HIGHBox()
        
        # General info:
        self.start_label = HIGEntryLabel(_('Started on:'))
        self.info_start_label = HIGEntryLabel(na)
        
        self.finished_label = HIGEntryLabel(_('Finished on:'))
        self.info_finished_label = HIGEntryLabel(na)
        
        self.host_up_label = HIGEntryLabel(_('Hosts up:'))
        self.info_hosts_up_label = HIGEntryLabel(na)
        
        self.host_down_label = HIGEntryLabel(_('Hosts down:'))
        self.info_hosts_down_label = HIGEntryLabel(na)
        
        self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:'))
        self.info_hosts_scanned_label = HIGEntryLabel(na)
        
        self.open_label = HIGEntryLabel(_('Open ports:'))
        self.info_open_label = HIGEntryLabel(na)
        
        self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
        self.info_filtered_label = HIGEntryLabel(na)
        
        self.closed_label = HIGEntryLabel(_('Closed ports:'))
        self.info_closed_label = HIGEntryLabel(na)
        
        self.general_table = HIGTable()
        self.general_hbox = HIGHBox()
    
    def set_command_info(self, info):
        # Fix aligment!
        self.command_expander.set_use_markup(True)
        self.command_table.set_border_width(5)
        self.command_table.set_row_spacings(6)
        self.command_table.set_col_spacings(6)
        
        try:self.info_command_label.set_text(info['command'])
        except:pass
        
        try:self.info_nmap_version_label.set_text(info['version'])
        except:pass
        
        try:self.info_verbose_label.set_text(info['verbose'])
        except:pass
        
        try:self.info_debug_label.set_text(info['debug'])
        except:pass
        
        self.command_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.command_hbox._pack_noexpand_nofill(self.command_table)
        
        self.command_table.attach(self.command_label,0,1,0,1)
        self.command_table.attach(self.info_command_label,1,2,0,1)
        
        self.command_table.attach(self.nmap_version_label,0,1,1,2)
        self.command_table.attach(self.info_nmap_version_label,1,2,1,2)
        
        self.command_table.attach(self.verbose_label,0,1,2,3)
        self.command_table.attach(self.info_verbose_label,1,2,2,3)
        
        self.command_table.attach(self.debug_label,0,1,3,4)
        self.command_table.attach(self.info_debug_label,1,2,3,4)
        
        self.command_expander.add(self.command_hbox)
        self._pack_noexpand_nofill(self.command_expander)
        self.command_expander.set_expanded(True)
    
    def set_general_info(self, info):
        # Fix aligment!
        self.general_expander.set_use_markup(True)
        self.general_table.set_border_width(5)
        self.general_table.set_row_spacings(6)
        self.general_table.set_col_spacings(6)
        
        try:self.info_start_label.set_text(info['start'])
        except:pass
        
        try:self.info_finished_label.set_text(info['finish'])
        except:pass
        
        try:self.info_hosts_up_label.set_text(info['hosts_up'])
        except:pass
        
        try:self.info_hosts_down_label.set_text(info['hosts_down'])
        except:pass
        
        try:self.info_hosts_scanned_label.set_text(info['hosts_scanned'])
        except:pass
        
        #try:
        self.info_open_label.set_text(info['open_ports'])
        #except:pass
        
        #try:
        self.info_filtered_label.set_text(info['filtered_ports'])
        #except:pass
        
        #try:
        self.info_closed_label.set_text(info['closed_ports'])
        #except:pass
        
        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_noexpand_nofill(self.general_table)
        
        self.general_table.attach(self.start_label,0,1,0,1)
        self.general_table.attach(self.info_start_label,1,2,0,1)
        
        self.general_table.attach(self.finished_label,0,1,1,2)
        self.general_table.attach(self.info_finished_label,1,2,1,2)
        
        self.general_table.attach(self.host_up_label,0,1,2,3)
        self.general_table.attach(self.info_hosts_up_label,1,2,2,3)
        
        self.general_table.attach(self.host_down_label,0,1,3,4)
        self.general_table.attach(self.info_hosts_down_label,1,2,3,4)
        
        self.general_table.attach(self.host_scanned_label,0,1,4,5)
        self.general_table.attach(self.info_hosts_scanned_label,1,2,4,5)
        
        self.general_table.attach(self.open_label,0,1,5,6)
        self.general_table.attach(self.info_open_label,1,2,5,6)
        
        self.general_table.attach(self.filtered_label,0,1,6,7)
        self.general_table.attach(self.info_filtered_label,1,2,6,7)
        
        self.general_table.attach(self.closed_label,0,1,7,8)
        self.general_table.attach(self.info_closed_label,1,2,7,8)
        
        self.general_expander.add(self.general_hbox)
        self._pack_noexpand_nofill(self.general_expander)
        self.general_expander.set_expanded(True)

    def set_scan_infos(self, scan_info):
        for scan in scan_info:
            exp = gtk.Expander('<b>%s - %s</b>' % (_('Scan Info'),
                                                   scan['type'].capitalize()))
            exp.set_use_markup(True)
            hbox = HIGHBox()
            table = HIGTable()
            table.set_border_width(5)
            table.set_row_spacings(6)
            table.set_col_spacings(6)
            
            table.attach(HIGEntryLabel(_('Scan type:')),0,1,0,1)
            table.attach(HIGEntryLabel(scan['type']),1,2,0,1)
            
            table.attach(HIGEntryLabel(_('Protocol:')),0,1,1,2)
            table.attach(HIGEntryLabel(scan['protocol']),1,2,1,2)
            
            table.attach(HIGEntryLabel(_('# scanned ports:')),0,1,2,3)
            table.attach(HIGEntryLabel(scan['numservices']),1,2,2,3)
            
            table.attach(HIGEntryLabel(_('Services:')),0,1,3,4)
            table.attach(self.get_service_view(scan['services'].split(',')),\
                                               1,2,3,4)
            
            hbox._pack_noexpand_nofill(hig_box_space_holder())
            hbox._pack_noexpand_nofill(table)
            
            exp.add (hbox)
            self._pack_noexpand_nofill(exp)
    
    def get_service_view(self, services):
        combo = gtk.combo_box_new_text()
        
        for i in services:
            combo.append_text(i)
        
        return combo
Exemple #9
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)
class SearchWindow(HIGWindow, object):
    """Search Window. Shows informations about the search while it's running
    """
    def __init__(self):
        HIGWindow.__init__(self)

        self.__create_widgets()
        self.__pack_widgets()
        self.__set_widgets()

    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.button_box = gtk.HButtonBox()
        self.search_file_label = HIGEntryLabel()
        self.progress = gtk.ProgressBar()

    def __pack_widgets(self):
        self.add(self.vbox)
        self.vbox.pack_start(self.search_file_label)
        self.vbox.pack_start(self.progress)
        self.vbox.pack_start(self.button_box)
        self.button_box.pack_start(self.cancel_button)

    def __set_widgets(self):
        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.set_title('Searching...')
        self.set_size_request(350, -1)
        self.set_position(gtk.WIN_POS_CENTER)

    def set_filename(self, filename):
        self.__filename = filename
        self.search_file_label.set_text(_("File: %s") % filename)

    def get_filename(self):
        return self.__filename

    def set_path(self, path):
        self.__path = path
        self.forward_progress_status()
        self.progress.set_text(_("Searching inside '%s'") % path)

    def get_path(self):
        return self.__path

    def set_fraction(self, fraction):
        self.__fraction = fraction

    def get_fraction(self):
        return self.__fraction

    def forward_progress_status(self):
        try:
            self.fraction
        except:
            self.fraction = 0.2
        self.progress.set_fraction(self.fraction +
                                   self.progress.get_fraction())

    filename = property(get_filename,
                        set_filename,
                        doc=_("File's name being searched"))
    path = property(get_path, set_path, doc=_("Path being scanned"))
    fraction = property(get_fraction,
                        set_fraction,
                        doc=_("Fraction of the progress bar"))
class HostDetails(HIGVBox):
    os_table = None
    os_hbox = None

    def __init__(self):
        HIGVBox.__init__(self)
        
        self.__create_widgets()
    
    def __create_widgets(self):
        self.host_status_expander = gtk.Expander('<b>'+_('Host Status')+'</b>')
        self.address_expander = gtk.Expander('<b>'+_('Addresses')+'</b>')
        self.hostnames_expander = gtk.Expander('<b>'+_('Hostnames')+'</b>')
        self.os_expander = gtk.Expander('<b>'+_('Operating System')+'</b>')
        self.portsused_expander = gtk.Expander('<b>'+_('Ports used')+'</b>')
        self.osclass_expander = gtk.Expander('<b>'+_('OS Class')+'</b>')
        self.tcp_expander = gtk.Expander('<b>'+_('TCP Sequence')+'</b>')
        self.ip_expander = gtk.Expander('<b>'+_('IP ID Sequence')+'</b>')
        self.tcpts_expander = gtk.Expander('<b>'+_('TCP TS Sequence')+'</b>')
        self.comment_expander = gtk.Expander('<b>'+_('Comments')+'</b>')
        self.os_image = gtk.Image()
        self.vulnerability_image = gtk.Image()
        
        # Host Status expander
        self.host_state_label = HIGEntryLabel(_('State:'))
        self.info_host_state_label = HIGEntryLabel(na)
        
        self.open_label = HIGEntryLabel(_('Open ports:'))
        self.info_open_ports = HIGEntryLabel(na)
        
        self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
        self.info_filtered_label = HIGEntryLabel(na)
        
        self.closed_label = HIGEntryLabel(_('Closed ports:'))
        self.info_closed_ports = HIGEntryLabel(na)
        
        self.scanned_label = HIGEntryLabel(_('Scanned ports:'))
        self.info_scanned_label = HIGEntryLabel(na)
        
        self.uptime_label = HIGEntryLabel(_('Up time:'))
        self.info_uptime_label = HIGEntryLabel(na)
        
        self.lastboot_label = HIGEntryLabel(_('Last boot:'))
        self.info_lastboot_label = HIGEntryLabel(na)
        
        
        # Addresses expander
        self.ipv4_label = HIGEntryLabel(_('IPv4:'))
        self.info_ipv4_label = HIGEntryLabel(na)
        
        self.ipv6_label = HIGEntryLabel(_('IPv6:'))
        self.info_ipv6_label = HIGEntryLabel(na)
        
        self.mac_label = HIGEntryLabel(_('MAC:'))
        self.info_mac_label = HIGEntryLabel(na)
        
        self.vendor_label = HIGEntryLabel(_('Vendor:'))
        self.info_vendor_label = HIGEntryLabel(na)
    
    def create_table_hbox(self):
        table = HIGTable()
        hbox = HIGHBox()
        
        hbox._pack_noexpand_nofill(hig_box_space_holder())
        hbox._pack_noexpand_nofill(table)
        
        return table, hbox
    
    def set_host_status(self, status):
        self.host_status_expander.set_use_markup(True)
        self.host_status_expander.set_expanded(True)
        table, hbox = self.create_table_hbox()
        
        try:
            if status['state'] == '': raise Exception
            self.info_host_state_label.set_text(status['state'])
        except:pass
        
        try:
            if status['open'] == '': raise Exception
            self.info_open_ports.set_text(status['open'])
        except:pass
        
        try:
            if status['filtered'] == '': raise Exception
            self.info_filtered_label.set_text(status['filtered'])
        except:pass
        
        try:
            if status['closed'] == '': raise Exception
            self.info_closed_ports.set_text(status['closed'])
        except:pass
        
        try:
            if status['scanned'] == '': raise Exception
            self.info_scanned_label.set_text(status['scanned'])
        except:pass
        
        try:
            if status['uptime'] == '': raise Exception
            self.info_uptime_label.set_text(status['uptime'])
        except:pass
        
        try:
            if status['lastboot'] == '': raise Exception
            self.info_lastboot_label.set_text(status['lastboot'])
        except:pass
        
        table.attach(self.host_state_label,0,1,0,1)
        table.attach(self.info_host_state_label,1,2,0,1)
        
        table.attach(self.open_label,0,1,1,2)
        table.attach(self.info_open_ports,1,2,1,2)
        
        table.attach(self.filtered_label,0,1,2,3)
        table.attach(self.info_filtered_label,1,2,2,3)
        
        table.attach(self.closed_label,0,1,3,4)
        table.attach(self.info_closed_ports,1,2,3,4)
        
        table.attach(self.scanned_label,0,1,4,5)
        table.attach(self.info_scanned_label,1,2,4,5)
        
        table.attach(self.uptime_label,0,1,5,6)
        table.attach(self.info_uptime_label,1,2,5,6)
        
        table.attach(self.lastboot_label,0,1,6,7)
        table.attach(self.info_lastboot_label,1,2,6,7)
        
        table.attach(self.os_image,2,4,0,3,xoptions=1,yoptions=0)
        table.attach(self.vulnerability_image,2,4,4,7,xoptions=1,yoptions=0)
        
        table.set_col_spacing(1, 50)
        
        self.host_status_expander.add(hbox)
        self._pack_noexpand_nofill(self.host_status_expander)

    def set_os_image(self, image):
        self.os_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG)
    
    def set_vulnerability_image(self, image):
        self.vulnerability_image.set_from_stock(image, gtk.ICON_SIZE_DIALOG)

    def set_addresses(self, address):
        self.address_expander.set_use_markup(True)
        table, hbox = self.create_table_hbox()
        self.address_expander.set_expanded(True)
        
        #print '>>> Address:', address
        try:
            if address['ipv4'] == 1: raise Exception
            self.info_ipv4_label.set_text(address['ipv4'])
        except:pass
        
        try:
            if address['ipv6'] == 1: raise Exception
            self.info_ipv6_label.set_text(address['ipv6'])
        except:pass
        
        try:
            if address['mac'] == 1: raise Exception
            self.info_mac_label.set_text(address['mac'])
        except:pass
        
        table.attach(self.ipv4_label,0,1,0,1)
        table.attach(self.info_ipv4_label,1,2,0,1)
        
        table.attach(self.ipv6_label,0,1,1,2)
        table.attach(self.info_ipv6_label,1,2,1,2)
        
        table.attach(self.mac_label,0,1,2,3)
        table.attach(self.info_mac_label,1,2,2,3)
        
        self.address_expander.add(hbox)
        self._pack_noexpand_nofill(self.address_expander)
    
    def set_hostnames(self, hostname):
        if hostname:
            self.hostnames_expander.set_use_markup(True)
            self.hostnames_expander.set_expanded(True)
            table, hbox = self.create_table_hbox()
            
            y1 = 1
            y2 = 2
            
            for h in hostname:
                name = na
                try:name = h['hostname']
                except:pass
                
                type = na
                try:type = h['hostname_type']
                except:pass
                
                table.attach(HIGEntryLabel(_('Name - Type:')),0,1,y1,y2)
                table.attach(HIGEntryLabel(name+' - '+\
                                           type),1,2,y1,y2)
                y1+=1;y2+=1
            
            self.hostnames_expander.add(hbox)
            self._pack_noexpand_nofill(self.hostnames_expander)

    def os_selection_changed(self, widget):
        current_selection = widget.get_active_text()
        self.set_os_image(get_os_logo(current_selection))
        
        for os_match in self.current_os_list:
            if isinstance(os_match, dict) and \
               current_selection == os_match.get('name', None):
                self.os_progress.set_fraction(float(os_match['accuracy'])/100.0)
                self.os_progress.set_text(os_match['accuracy'] + "%")
                self.os_progress.set_sensitive(True)
                break
        else:
            self.os_progress.set_fraction(0.0)
            self.os_progress.set_text(_("Not Available"))
            self.os_progress.set_sensitive(False)

    def set_os_list(self, os_list, os_match):
        # Creating the main widgets for this section
        self.os_expander.set_use_markup(True)
        self.os_expander.set_expanded(True)
        self.os_table, self.os_hbox = self.create_table_hbox()
        self.os_progress = gtk.ProgressBar()
        
        # Setting the current match's details in the widgets
        if len(os_list) > 1:
            self.os_list = gtk.combo_box_new_text()
            
            model = self.os_list.get_model()
            [model.append([os['name']]) for os in os_list if os.has_key("name")]
            self.os_list.set_active(0)
            
            # In case we have the os selection changed, we need to change the
            # icon and the current accuracy. Also, we need to save the selection
            # in the usr result.
            self.os_list.connect("changed", self.os_selection_changed)
        else:
            self.os_list = HIGEntryLabel(os_match.get("name", "Not Available"))
        
        self.os_table.attach(HIGEntryLabel(_('Name:')), 0, 1, 0, 1)
        self.os_table.attach(self.os_list, 1, 2, 0, 1)
        
        # Setting current os_match accuracy
        if os_match.get("accuracy", ''):
            self.os_progress.set_fraction(float(os_match['accuracy']) / 100.0)
            self.os_progress.set_text(os_match['accuracy'] + '%')
            self.os_progress.set_sensitive(True)
        else:
            self.os_progress.set_sensitive(False)
            self.os_progress.set_text(_('Not Available'))
        
        self.os_table.attach(HIGEntryLabel(_('Accuracy:')), 0, 1, 1, 2)
        self.os_table.attach(self.os_progress, 1, 2, 1, 2)
        
        ###################
        ## Setting the list of matches and the list of ports used in the scan
        if os_match.has_key("portsused"):
            self.set_ports_used(os_match["portsused"])
            self.portsused_expander.set_sensitive(True)
        else:
            # In case we don't have any port, we still show the expander widget
            # but in a non-sensitive manner
            self.portsused_expander.set_sensitive(False)
        self.portsused_expander.set_use_markup(True)
        self.os_table.attach(self.portsused_expander, 0, 2, 2, 3)
        
        if os_match.has_key('osclass'):
            self.set_osclass(os_match['osclass'])
            self.osclass_expander.set_sensitive(True)
        else:
            self.osclass_expander.set_sensitive(False)
        self.osclass_expander.set_use_markup(True)
        self.os_table.attach(self.osclass_expander, 0, 2, 3, 4)
        
        self.os_expander.add(self.os_hbox)
        self._pack_noexpand_nofill(self.os_expander)
        
        # Saving os_list and os_match for latter access
        self.current_os_list = os_list
        self.current_os_match = os_match

    def set_ports_used(self, ports=None):
        # Removing old childs
        child = self.portsused_expander.get_child()
        if child is not None:
            self.portsused_expander.remove(child)
        
        if ports is None:
            self.portsused_expander.set_sensitive(False)
            return
        else:
            self.portsused_expander.set_sensitive(True)
        
        self.portsused_expander.set_use_markup(True)
        table, hbox = self.create_table_hbox()
        
        y1=0
        y2=1
        
        for p in ports:
            table.attach(HIGEntryLabel(_('Port-Protocol-State:')), 0, 1, y1, y2)
            table.attach(HIGEntryLabel(p['portid']+' - '+p['proto']+' - '+\
                                       p['state']), 1, 2, y1, y2)
            y1+=1
            y2+=1
        
        self.portsused_expander.add(hbox)

    def set_osclass(self, osclass=None):
        child = self.osclass_expander.get_child()
        if child is not None:
            self.osclass_expander.remove(child)
        
        if osclass is None:
            self.osclass_expander.set_sensitive(False)
            return
        else:
            self.osclass_expander.set_sensitive(True)
            self.osclass_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()
            
            table.attach(HIGEntryLabel(_('Type')),0,1,0,1)
            table.attach(HIGEntryLabel(_('Vendor')),1,2,0,1)
            table.attach(HIGEntryLabel(_('OS Family')),2,3,0,1)
            table.attach(HIGEntryLabel(_('OS Generation')),3,4,0,1)
            table.attach(HIGEntryLabel(_('Accuracy')),4,5,0,1)
            
            y1=1;y2=2
            
            for o in osclass:
                table.attach(HIGEntryLabel(o['type']),0,1,y1,y2)
                table.attach(HIGEntryLabel(o['vendor']),1,2,y1,y2)
                table.attach(HIGEntryLabel(o['osfamily']),2,3,y1,y2)
                table.attach(HIGEntryLabel(o.get('osgen', '')),3,4,y1,y2)
                
                progress = gtk.ProgressBar()
                progress.set_text(o['accuracy']+'%')
                progress.set_fraction(float(o['accuracy'])/100.0)
                table.attach(progress,4,5,y1,y2)
                y1+=1;y2+=1
            
            self.osclass_expander.add(hbox)
    
    def set_tcpseq(self, tcpseq):
        if tcpseq:
            self.tcp_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            combo = gtk.combo_box_new_text()
            for v in tcpseq['values'].split(','):
                combo.append_text(v)

            table.attach(HIGEntryLabel(_('Class:')),0,1,0,1)
            table.attach(HIGEntryLabel(tcpseq.get('class', '')),1,2,0,1)
            
            table.attach(HIGEntryLabel(_('Difficulty:')),0,1,1,2)
            table.attach(HIGEntryLabel(tcpseq['difficulty']),1,2,1,2)
            
            table.attach(HIGEntryLabel(_('Index:')),0,1,2,3)
            table.attach(HIGEntryLabel(tcpseq['index']),1,2,2,3)
            
            table.attach(HIGEntryLabel(_('Values:')),0,1,3,4)
            table.attach(combo,1,2,3,4)
            
            self.tcp_expander.add(hbox)
            self._pack_noexpand_nofill(self.tcp_expander)
    
    def set_ipseq(self, ipseq):
        if ipseq:
            self.ip_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()
            
            combo = gtk.combo_box_new_text()
            
            for i in ipseq['values'].split(','):
                combo.append_text(i)
            
            table.attach(HIGEntryLabel(_('Class:')),0,1,0,1)
            table.attach(HIGEntryLabel(ipseq['class']),1,2,0,1)
            
            table.attach(HIGEntryLabel(_('Values:')),0,1,1,2)
            table.attach(combo,1,2,1,2)
            
            self.ip_expander.add(hbox)
            self._pack_noexpand_nofill(self.ip_expander)
    
    def set_tcptsseq(self, tcptsseq):
        if tcptsseq:
            self.tcpts_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            combo = gtk.combo_box_new_text()

            for i in tcptsseq.get('values', '').split(','):
                combo.append_text(i)
            
            table.attach(HIGEntryLabel(_('Class:')),0,1,0,1)
            table.attach(HIGEntryLabel(tcptsseq['class']),1,2,0,1)
            
            table.attach(HIGEntryLabel(_('Values:')),0,1,1,2)
            table.attach(combo,1,2,1,2)
            
            self.tcpts_expander.add(hbox)
            self._pack_noexpand_nofill(self.tcpts_expander)
    
    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)
    
    def get_comment(self):
        buffer = self.comment_txt_vw.get_buffer()
        return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())