예제 #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)
예제 #3
0
 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)
예제 #4
0
    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 __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
예제 #6
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
    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
예제 #8
0
 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
예제 #9
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)
    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)
예제 #11
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)
예제 #12
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)
예제 #13
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())
예제 #14
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)
예제 #15
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())
예제 #16
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)
    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)
    def __layout(self):
        self.set_position(gtk.WIN_POS_CENTER)

        main_vbox = HIGVBox()
        top_hbox = HIGHBox()

        top_hbox._pack_noexpand_nofill(self.iimg)
        top_hbox._pack_noexpand_nofill(self.topic)

        main_vbox._pack_noexpand_nofill(top_hbox)
        main_vbox._pack_noexpand_nofill(self.message)

        self.add(main_vbox)
예제 #19
0
    def __layout(self):
        self.set_position(gtk.WIN_POS_CENTER)

        main_vbox = HIGVBox()
        top_hbox = HIGHBox()

        top_hbox._pack_noexpand_nofill(self.iimg)
        top_hbox._pack_noexpand_nofill(self.topic)

        main_vbox._pack_noexpand_nofill(top_hbox)
        main_vbox._pack_noexpand_nofill(self.message)

        self.add(main_vbox)
예제 #20
0
        def buildtv(*args):
            """
            Build treeview and append results.
            """
            lsmodel = gtk.ListStore(str, str, str, str)
            tview = gtk.TreeView(lsmodel)
            columns = 4
            columns_text = (
                _("Inventory"), _("Host"),
                _("First Matched Category"), _("Entry Date")
                )
            tview.columns = [None]*columns

            for n in range(columns):
                tview.columns[n] = gtk.TreeViewColumn(columns_text[n])
                tview.columns[n].cell = gtk.CellRendererText()
                tview.columns[n].pack_start(tview.columns[n].cell, True)
                tview.columns[n].set_attributes(tview.columns[n].cell, text=n)

                tview.append_column(tview.columns[n])

            tview.connect('row-activated', row_activated)

            # layout
            matches = len(args[1])
            word = append_s(_("result"), matches)
            upper_title = gtk.Label()
            upper_title.set_markup(
                    ("<b>%d " % matches) + word + _(" found.") +
                    "</b>")
            hutbox = HIGHBox()
            hutbox._pack_noexpand_nofill(upper_title)
            sw = HIGScrolledWindow()
            sw.add(tview)
            vbox = gtk.VBox()
            vbox.pack_start(hutbox, False, False, 3)
            vbox.pack_start(sw, True, True, 0)

            vbox.show_all()

            # append results to treeview
            results = args[1]

            for res, date in results.items():
                invname = self.invdb.get_inventory_name_for_id(res[0])
                lsmodel.append((invname, res[1], res[2], str(date)))

            title = _("Search: %s") % args[0]
            tab_label = HIGAnimatedTabLabel(title)
            tab_label.connect("close-clicked", close_page, vbox)
            self.viewernb.append_page(vbox, tab_label)
class HIGExpander(gtk.Expander):
    def __init__(self, label):
        gtk.Expander.__init__(self)
		
        self.set_use_markup(True)
        self.set_label(label)
		
        self.hbox = HIGHBox()
        self.hbox.set_border_width(5)
        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
		
        self.add(self.hbox)
	
    def get_container(self):
        return self.hbox
class HIGExpander(gtk.Expander):
    def __init__(self, label):
        gtk.Expander.__init__(self)
		
        self.set_use_markup(True)
        self.set_label(label)
		
        self.hbox = HIGHBox()
        self.hbox.set_border_width(5)
        self.hbox._pack_noexpand_nofill(hig_box_space_holder())
		
        self.add(self.hbox)
	
    def get_container(self):
        return self.hbox
        def buildtv(*args):
            """
            Build treeview and append results.
            """
            lsmodel = gtk.ListStore(str, str, str, str)
            tview = gtk.TreeView(lsmodel)
            columns = 4
            columns_text = (_("Inventory"), _("Host"),
                            _("First Matched Category"), _("Entry Date"))
            tview.columns = [None] * columns

            for n in range(columns):
                tview.columns[n] = gtk.TreeViewColumn(columns_text[n])
                tview.columns[n].cell = gtk.CellRendererText()
                tview.columns[n].pack_start(tview.columns[n].cell, True)
                tview.columns[n].set_attributes(tview.columns[n].cell, text=n)

                tview.append_column(tview.columns[n])

            tview.connect('row-activated', row_activated)

            # layout
            matches = len(args[1])
            word = append_s(_("result"), matches)
            upper_title = gtk.Label()
            upper_title.set_markup(("<b>%d " % matches) + word + _(" found.") +
                                   "</b>")
            hutbox = HIGHBox()
            hutbox._pack_noexpand_nofill(upper_title)
            sw = HIGScrolledWindow()
            sw.add(tview)
            vbox = gtk.VBox()
            vbox.pack_start(hutbox, False, False, 3)
            vbox.pack_start(sw, True, True, 0)

            vbox.show_all()

            # append results to treeview
            results = args[1]

            for res, date in results.items():
                invname = self.invdb.get_inventory_name_for_id(res[0])
                lsmodel.append((invname, res[1], res[2], str(date)))

            title = _("Search: %s") % args[0]
            tab_label = HIGAnimatedTabLabel(title)
            tab_label.connect("close-clicked", close_page, vbox)
            self.viewernb.append_page(vbox, tab_label)
예제 #24
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()]
예제 #25
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()]
    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)
예제 #27
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)
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())
예제 #29
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)
예제 #30
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)
예제 #31
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()
예제 #32
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 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)
예제 #34
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()
예제 #35
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 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())
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()
예제 #38
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 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()
예제 #40
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)
예제 #41
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)
예제 #42
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)
예제 #43
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
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)
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)
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])
    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)
예제 #48
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
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)
예제 #50
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()
예제 #51
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)
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()
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)        
         
예제 #54
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)