Beispiel #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)
Beispiel #2
0
    def _create_widgets(self):
        """ Create widgets"""

        self._frm_option = HIGFrame(_('Options'))
        self._box_option = HIGHBox()
        self.__lbl_file_opt = HIGEntryLabel(_('File:'))
        self.__entry_file_opt = HIGTextEntry()
        self.__entry_file_opt.set_editable(False)
        self.__file_browser_opt = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self._frm_profile = HIGFrame(_('Profile'))
        self._box_profile = HIGHBox()
        self.__lbl_file_profile = HIGEntryLabel(_('File:'))
        self.__entry_file_profile = HIGTextEntry()
        self.__entry_file_profile.set_editable(False)
        self.__file_browser_profile = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self._frm_wizard = HIGFrame(_('Wizard'))
        self._box_wizard = HIGHBox()

        self.__lbl_file_wizard = HIGEntryLabel(_('File:'))
        self.__entry_file_wizard = HIGTextEntry()
        self.__entry_file_wizard.set_editable(False)
        self.__file_browser_wizard = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self.__btn_restore = HIGButton(_('Restore Defaults'), gtk.STOCK_CLEAR)
    def set_ports_used(self, ports=None):
        # Removing old childs
        child = self.portsused_expander.get_child()
        if child is not None:
            self.portsused_expander.remove(child)

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

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

        y1 = 0
        y2 = 1

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

        self.portsused_expander.add(hbox)
Beispiel #4
0
    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 create_and_attach_widgets(self):
        self.option_label = HIGSectionLabel('New Option')
        self.attach(self.option_label, 0, 3, 0, 1)

        self.name_label = HIGEntryLabel(_('Name:'))
        self.name_entry = HIGTextEntry()
        self.attach(self.name_label, 0, 1, 1, 2)
        self.attach(self.name_entry, 1, 3, 1, 2)

        self.hint_label = HIGEntryLabel(_('Hint:'))
        self.hint_entry = HIGTextEntry()
        self.attach(self.hint_label, 0, 1, 2, 3)
        self.attach(self.hint_entry, 1, 3, 2, 3)

        self.need_root = gtk.CheckButton(_('Need root'))
        self.attach(self.need_root, 0, 1, 3, 4)

        self.options_label = HIGEntryLabel(_('Options:'))
        hbox = HIGHBox()
        self.options_entry = HIGTextEntry()
        self.insert_arg_button = HIGButton(title='Args', stock='gtk-add')
        self.insert_arg_button.connect('clicked', self.update_args)
        self.attach(self.options_label, 0, 1, 4, 5)
        self.attach(self.options_entry, 1, 2, 4, 5)
        self.attach(self.insert_arg_button, 2, 3, 4, 5)

        self.aguments_label = HIGEntryLabel(_('Arguments:'))
        self.arguments_entry = HIGTextEntry()
        self.arguments_entry.set_editable(False)
        self.attach(self.aguments_label, 0, 1, 5, 6)
        self.attach(self.arguments_entry, 1, 3, 5, 6)
    def set_hostnames(self, hostname):
        if hostname:
            self.hostnames_expander.set_use_markup(True)
            self.hostnames_expander.set_expanded(True)
            table, hbox = self.create_table_hbox()

            y1 = 1
            y2 = 2

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

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

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

            self.hostnames_expander.add(hbox)
            self._pack_noexpand_nofill(self.hostnames_expander)
 def __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 __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"))
Beispiel #9
0
    def __init__(self):
        HIGWindow.__init__(self)
        
        self.wtitle = _("SMTP Account Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # schemas name
        self.schema_name_lbl = HIGEntryLabel(_("Schema name"))
        self.schema_name = gtk.combo_box_entry_new_text()
        self.schema_name.connect('changed', self._check_schema)
        # smtp server
        self.smtp_server_lbl = HIGEntryLabel(_("Server"))
        self.smtp_server = gtk.Entry()
        self.smtp_port_lbl = HIGEntryLabel(_("Port"))
        self.smtp_port = gtk.Entry()
        # sending mail..
        self.smtp_mailfrom_lbl = HIGEntryLabel(_("Mail from"))
        self.smtp_mailfrom = gtk.Entry()
        # smtp auth
        self.smtp_need_auth = gtk.CheckButton(_("Servers requires authentication"))
        self.smtp_need_auth.connect('toggled', self._auth_need)
        self.smtp_login_lbl = HIGEntryLabel(_("Username"))
        self.smtp_login = gtk.Entry()
        self.smtp_passwd_lbl = HIGEntryLabel(_("Password"))
        self.smtp_passwd = gtk.Entry()
        self.smtp_passwd.set_visibility(False)
        self._auth_need(None)
        # smtp encryption
        self.smtp_encrypt_tls = gtk.CheckButton(_("Use TLS Encryption"))

        """
        Missing: SSL encryption,
                 Other authentication methods.
        """ 

        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect('clicked', self._save_schema)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_schema_and_leave)
        
        self.load_schemas()
        
        self.__set_props()
        self.__do_layout()

        self.connect('destroy', self._exit)
    def __init__(self):
        HIGWindow.__init__(self)

        self.wtitle = _("SMTP Account Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # schemas name
        self.schema_name_lbl = HIGEntryLabel(_("Schema name"))
        self.schema_name = gtk.combo_box_entry_new_text()
        self.schema_name.connect('changed', self._check_schema)
        # smtp server
        self.smtp_server_lbl = HIGEntryLabel(_("Server"))
        self.smtp_server = gtk.Entry()
        self.smtp_port_lbl = HIGEntryLabel(_("Port"))
        self.smtp_port = gtk.Entry()
        # sending mail..
        self.smtp_mailfrom_lbl = HIGEntryLabel(_("Mail from"))
        self.smtp_mailfrom = gtk.Entry()
        # smtp auth
        self.smtp_need_auth = gtk.CheckButton(
            _("Servers requires authentication"))
        self.smtp_need_auth.connect('toggled', self._auth_need)
        self.smtp_login_lbl = HIGEntryLabel(_("Username"))
        self.smtp_login = gtk.Entry()
        self.smtp_passwd_lbl = HIGEntryLabel(_("Password"))
        self.smtp_passwd = gtk.Entry()
        self.smtp_passwd.set_visibility(False)
        self._auth_need(None)
        # smtp encryption
        self.smtp_encrypt_tls = gtk.CheckButton(_("Use TLS Encryption"))
        """
        Missing: SSL encryption,
                 Other authentication methods.
        """

        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect('clicked', self._save_schema)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_schema_and_leave)

        self.load_schemas()

        self.__set_props()
        self.__do_layout()

        self.connect('destroy', self._exit)
 def __create_widgets(self):
     self.property_name_label = HIGEntryLabel("")
     self.example_label = HIGEntryLabel("")
     self.bold_tg_button = HIGToggleButton(" ", gtk.STOCK_BOLD)
     self.italic_tg_button = HIGToggleButton(" ", gtk.STOCK_ITALIC)
     self.underline_tg_button = HIGToggleButton(" ", gtk.STOCK_UNDERLINE)
     self.text_color_button = HIGButton(_("Text"),
                                        stock=gtk.STOCK_SELECT_COLOR)
     self.highlight_color_button = HIGButton(_("Highlight"),
                                             stock=gtk.STOCK_SELECT_COLOR)
Beispiel #12
0
    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"))
Beispiel #13
0
    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())
class TimeBox(gtk.HBox):
    """
    GUI Controls for handling Timeline date visualization.
    """

    def __init__(self, connector, tlbase):
        gtk.HBox.__init__(self)

        self.connector = connector
        self.tlbase = tlbase

        self.connector.connect('date-changed', self._update_current_date)

        # viewing by
        cur_mode = view_mode_descr[self.tlbase.graph_mode]
        self.dateselect_lbl = HIGEntryLabel(cur_mode)
        values = self.tlbase.bounds_by_graphmode()
        self.dateselect = gtk.SpinButton(gtk.Adjustment(value=values[2],
            lower=values[0], upper=values[1], step_incr=1), 1)
        self.dateselect_apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.dateselect_apply.connect("clicked", self._date_change)

        self.__layout()


    def _date_change(self, event):
        """
        Sends new date.
        """
        self.connector.emit('date-update', self.dateselect.get_value_as_int())


    def _update_current_date(self, event):
        """
        Update spinbutton and values based on new date.
        """
        cur_mode = view_mode_descr[self.tlbase.graph_mode]
        self.dateselect_lbl.set_label(cur_mode)

        values = self.tlbase.bounds_by_graphmode()
        self.dateselect.set_range(values[0], values[1])
        self.dateselect.set_value(values[2])


    def __layout(self):
        """
        Layout widgets.
        """
        self.pack_start(self.dateselect_lbl, False, False, 0)
        self.pack_start(self.dateselect, False, False, 0)
        self.pack_start(self.dateselect_apply, False, False, 0)
 def __create_widgets(self):
     self.host_status_expander = gtk.Expander('<b>'+_('Host Status')+'</b>')
     self.address_expander = gtk.Expander('<b>'+_('Addresses')+'</b>')
     self.hostnames_expander = gtk.Expander('<b>'+_('Hostnames')+'</b>')
     self.os_expander = gtk.Expander('<b>'+_('Operating System')+'</b>')
     self.portsused_expander = gtk.Expander('<b>'+_('Ports used')+'</b>')
     self.osclass_expander = gtk.Expander('<b>'+_('OS Class')+'</b>')
     self.tcp_expander = gtk.Expander('<b>'+_('TCP Sequence')+'</b>')
     self.ip_expander = gtk.Expander('<b>'+_('IP ID Sequence')+'</b>')
     self.tcpts_expander = gtk.Expander('<b>'+_('TCP TS Sequence')+'</b>')
     self.comment_expander = gtk.Expander('<b>'+_('Comments')+'</b>')
     self.os_image = gtk.Image()
     self.vulnerability_image = gtk.Image()
     
     # Host Status expander
     self.host_state_label = HIGEntryLabel(_('State:'))
     self.info_host_state_label = HIGEntryLabel(na)
     
     self.open_label = HIGEntryLabel(_('Open ports:'))
     self.info_open_ports = HIGEntryLabel(na)
     
     self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
     self.info_filtered_label = HIGEntryLabel(na)
     
     self.closed_label = HIGEntryLabel(_('Closed ports:'))
     self.info_closed_ports = HIGEntryLabel(na)
     
     self.scanned_label = HIGEntryLabel(_('Scanned ports:'))
     self.info_scanned_label = HIGEntryLabel(na)
     
     self.uptime_label = HIGEntryLabel(_('Up time:'))
     self.info_uptime_label = HIGEntryLabel(na)
     
     self.lastboot_label = HIGEntryLabel(_('Last boot:'))
     self.info_lastboot_label = HIGEntryLabel(na)
     
     
     # Addresses expander
     self.ipv4_label = HIGEntryLabel(_('IPv4:'))
     self.info_ipv4_label = HIGEntryLabel(na)
     
     self.ipv6_label = HIGEntryLabel(_('IPv6:'))
     self.info_ipv6_label = HIGEntryLabel(na)
     
     self.mac_label = HIGEntryLabel(_('MAC:'))
     self.info_mac_label = HIGEntryLabel(na)
     
     self.vendor_label = HIGEntryLabel(_('Vendor:'))
     self.info_vendor_label = HIGEntryLabel(na)
Beispiel #16
0
    def dialog_args(self):
        '''
        Create a dialog
        '''

        d = HIGDialog(_('Arguments'))
        description_label = HIGEntryLabel(
            _('Insert the description to argument:'))
        description_label.show()
        description_entry = HIGTextEntry()
        text = self.arguments_entry.get_text()
        description_entry.set_text(text)
        description_entry.show()

        combo_box = gtk.combo_box_new_text()
        combo_box.set_wrap_width(1)
        index = -1 
        j = 0 
        for i in ARG_TYPES:
            combo_box.append_text(ARG_TYPES[i])
            if i == self.arg_type:
                index = j 
            j = j + 1
        if index > -1 : 
            combo_box.set_active(index)
        combo_box.show()
        d.vbox.pack_start(description_label, False, False)
        d.vbox.pack_start(description_entry, False, False)
        d.vbox.pack_start(combo_box, False, False)
        d.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        d.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        resp = d.run()
        result  = None, None 
        if resp == gtk.RESPONSE_OK:
            model = combo_box.get_model()
            active = combo_box.get_active()
            if active < 0:
                return None, None 
            combo_selected =  model[active][0]

            for i in ARG_TYPES:
                if combo_selected == ARG_TYPES[i]:
                    combo_selected = i

            result = description_entry.get_text(), combo_selected
            #self.insert_arg_button.set_label('Edit args')
            #self.insert_arg_button.
        d.destroy()
        return result 
    def dialog_args(self):
        '''
        Create a dialog
        '''

        d = HIGDialog(_('Arguments'))
        description_label = HIGEntryLabel(
            _('Insert the description to argument:'))
        description_label.show()
        description_entry = HIGTextEntry()
        text = self.arguments_entry.get_text()
        description_entry.set_text(text)
        description_entry.show()

        combo_box = gtk.combo_box_new_text()
        combo_box.set_wrap_width(1)
        index = -1
        j = 0
        for i in ARG_TYPES:
            combo_box.append_text(ARG_TYPES[i])
            if i == self.arg_type:
                index = j
            j = j + 1
        if index > -1:
            combo_box.set_active(index)
        combo_box.show()
        d.vbox.pack_start(description_label, False, False)
        d.vbox.pack_start(description_entry, False, False)
        d.vbox.pack_start(combo_box, False, False)
        d.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        d.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        resp = d.run()
        result = None, None
        if resp == gtk.RESPONSE_OK:
            model = combo_box.get_model()
            active = combo_box.get_active()
            if active < 0:
                return None, None
            combo_selected = model[active][0]

            for i in ARG_TYPES:
                if combo_selected == ARG_TYPES[i]:
                    combo_selected = i

            result = description_entry.get_text(), combo_selected
            #self.insert_arg_button.set_label('Edit args')
            #self.insert_arg_button.
        d.destroy()
        return result
Beispiel #18
0
    def _create_widgets(self):
        '''
        Create the main entrys of the option 
        '''
        self._box = HIGVBox()


        self._table = HIGTable()


        #Name
        self._label_name  = HIGEntryLabel(_('Name'))
        self._entry_name = HIGTextEntry()

        self._entry_name.connect('activate', self._update_label)

        #Type 
        self._label_type = HIGEntryLabel(_('Type'))	
        self._combo_type = gtk.combo_box_new_text()
        self._combo_type.append_text('')
        self._combo_type.append_text('Option List')
        self._combo_type.append_text('Option Check')
        self._combo_type.set_active(0)
        self._combo_type.connect('changed', self.change_combo)

        self._label_opt = HIGEntryLabel(_('Option'))
        self._entry_opt = HIGTextEntry()
        self._entry_opt.set_sensitive(False)

        #For option list open a dialog to add/remove options
        self._button_list = HIGButton('Edit Option List')
        img = gtk.Image()
        img_dir =  os.path.join(pixmaps_dir, 'uie', 'combo.png')
        img.set_from_file(img_dir)
        self._button_list.set_image(img)
        self._button_list.connect('button-press-event', self._button_list_clicked)


        self._table.attach(self._label_name, 0,1,0, 1)
        self._table.attach(self._entry_name, 1,2,0,1)
        self._table.attach(self._label_type, 0,1,1,2)
        self._table.attach(self._combo_type, 1,2,1, 2)

        self._table.attach(self._button_list, 0,2, 3,4)
        self._table.attach(self._label_opt, 0,1, 4,5)
        self._table.attach(self._entry_opt, 1,2,4,5)

        self._box.pack_start(self._table, False, False)
    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")) 
Beispiel #20
0
 def __create_wizard_widgets(self):
     self.wizard_title = HIGEntryLabel("")
     self.wizard_title.set_line_wrap(False)
     self.wizard_event = gtk.EventBox()
     self.wizard_logo = gtk.Image()
     self.wizard_event.add(self.wizard_logo)
     
     self.d = {}
     for c in (65, 97):
         for i in range(26):
             self.d[chr(i+c)] = chr((i+13) % 26 + c)
     self.img = 1
     
     command_hbox = HIGHBox()
     self.command_label = HIGEntryLabel(_("Command"))
     self.command_entry = gtk.Entry()
     
     separator = gtk.HSeparator()
     
     self.wizard_header_hbox = HIGHBox()
     
     self.wizard_header_hbox._pack_expand_fill(self.wizard_title)
     self.wizard_header_hbox._pack_noexpand_nofill(self.wizard_event)
     
     command_hbox._pack_noexpand_nofill(self.command_label)
     command_hbox._pack_expand_fill(self.command_entry)
     
     self.main_vbox._pack_noexpand_nofill(self.wizard_header_hbox)
     self.main_vbox._pack_noexpand_nofill(command_hbox)
     self.main_vbox._pack_noexpand_nofill(separator)
     
     self.wizard_logo.set_from_file(logo)
    def __init__(self):
        HIGHBox.__init__(self)

        self.command_label = HIGEntryLabel(_("Command:"))
        self.command_entry = gtk.Entry()
        
        self._pack_noexpand_nofill(self.command_label)
        self._pack_expand_fill(self.command_entry)
Beispiel #22
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 set_tcptsseq(self, tcptsseq):
        if tcptsseq:
            self.tcpts_expander.set_use_markup(True)
            table, hbox = self.create_table_hbox()

            combo = gtk.combo_box_new_text()

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

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

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

            self.tcpts_expander.add(hbox)
            self._pack_noexpand_nofill(self.tcpts_expander)
    def __init__(self, connector, tlbase):
        gtk.HBox.__init__(self)

        self.connector = connector
        self.tlbase = tlbase

        self.connector.connect('date-changed', self._update_current_date)

        # viewing by
        cur_mode = view_mode_descr[self.tlbase.graph_mode]
        self.dateselect_lbl = HIGEntryLabel(cur_mode)
        values = self.tlbase.bounds_by_graphmode()
        self.dateselect = gtk.SpinButton(gtk.Adjustment(value=values[2],
            lower=values[0], upper=values[1], step_incr=1), 1)
        self.dateselect_apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.dateselect_apply.connect("clicked", self._date_change)

        self.__layout()
Beispiel #25
0
    def __init__(self):
        HIGVBox.__init__(self)
        self.set_spacing(12)
        self.prof = False

        self.description = HIGEntryLabel(
            _("""Please, enter the profile name, \
and optionally, enter a hint, description and annotation for this \
new profile"""))
        self.profile_label = HIGEntryLabel(_("Profile name"))
        self.hint_label = HIGEntryLabel(_("Hint"))
        self.description_label = HIGEntryLabel(_("Description"))
        self.annotation_label = HIGEntryLabel(_("Annotation"))

        self.profile_entry = gtk.Entry()
        self.hint_entry = gtk.Entry()
        self.description_scroll = HIGScrolledWindow()
        self.description_text = HIGTextView()
        self.annotation_scroll = HIGScrolledWindow()
        self.annotation_text = HIGTextView()

        self.description_scroll.add(self.description_text)
        self.annotation_scroll.add(self.annotation_text)

        table = HIGTable()
        self.bar = ForwardBar()

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

        table.attach(self.profile_label, 0, 1, 0, 1, xoptions=0)
        table.attach(self.profile_entry, 1, 2, 0, 1)

        table.attach(self.hint_label, 0, 1, 1, 2, xoptions=0)
        table.attach(self.hint_entry, 1, 2, 1, 2)

        table.attach(self.description_label, 0, 1, 2, 3, xoptions=0)
        table.attach(self.description_scroll, 1, 2, 2, 3)

        table.attach(self.annotation_label, 0, 1, 3, 4, xoptions=0)
        table.attach(self.annotation_scroll, 1, 2, 3, 4)
Beispiel #26
0
    def _create_tooldesign(self):
        '''
        create tooldesign that contains widgets to put 
        in work area of edit profile
        '''
        if self._tooldesign == None :     
            self._tooldesign = ToolDesign()

        if self._proprieties == None :
            self._proprieties = Proprieties()
        if self.notebook.get_n_pages() < 2:
            self.notebook.append_page(self._tooldesign, 
                                      HIGEntryLabel(_('Design')))
            self.notebook.append_page(self._proprieties, 
                                      HIGEntryLabel(_('Proprieties')))
        self.notebook.show_all()
        obj = self.profile_box
        obj.set_proprieties(self._proprieties)
        profilecore = obj.get_profilecore()
        self._proprieties.set_profilecore(profilecore)
    def quit(self, widget=None, extra=None):
        if self.deleted:
            dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                        gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
            alert = HIGEntryLabel('<b>' + _("Deleting Profile") + '</b>')
            text = HIGEntryLabel(
                _('Your profile is going to be deleted! Click\
                                   Ok to continue, or Cancel to go back to Profile Editor.'
                  ))
            hbox = HIGHBox()
            hbox.set_border_width(5)
            hbox.set_spacing(12)

            vbox = HIGVBox()
            vbox.set_border_width(5)
            vbox.set_spacing(12)

            image = gtk.Image()
            image.set_from_stock(gtk.STOCK_DIALOG_WARNING,
                                 gtk.ICON_SIZE_DIALOG)

            vbox.pack_start(alert)
            vbox.pack_start(text)
            hbox.pack_start(image)
            hbox.pack_start(vbox)

            dialog.vbox.pack_start(hbox)
            dialog.vbox.show_all()

            response = dialog.run()
            dialog.destroy()

            if response == gtk.RESPONSE_CANCEL:
                return None
        self.destroy()
        if self.scan_notebook != None:

            for i in xrange(self.scan_notebook.get_n_pages()):
                page = self.scan_notebook.get_nth_page(i)
                page.toolbar.profile_entry.update()
Beispiel #28
0
    def _create_widgets_error(self):

        # Create Widgets
        self._box_error_frame = HIGFrame('Error')

        self._box_error = HIGTable(5, 2)
        self._box_error.set_border_width(10)
        self._box_error_frame.add(self._box_error)
        self.__crash_report = gtk.CheckButton(_('Enable Crash Report'))
        # Radio Button List
        self.__log_no = gtk.RadioButton(None, _('No log'))
        self.__log_terminal = gtk.RadioButton(self.__log_no, _('Enable log in terminal'))
        self.__log_file = gtk.RadioButton(self.__log_terminal,\
                                         _('Enable log file'))

        self.__log_file_label = HIGEntryLabel(_('Log file'))
        self.__log_file_entry = HIGTextEntry()
        self.__log_file_entry.set_editable(False)
        # FIXME: Do default file ~/.umit/umit.log
        self.__log_file_browser = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        tmpbox = HIGHBox()
        tmpbox.pack_start(self.__log_file_entry, False, False)
        tmpbox.pack_start(self.__log_file_browser, False, False)


        # attach table
        self._box_error.attach(self.__crash_report, 0,1,0,1,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_no, 0,1,1,2,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_terminal, 0,1,2,3,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file, 0,1,3,4,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file_label, 0,1,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(tmpbox, 1,2,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
    def __create_widgets(self):
        self.main_vbox = HIGVBox()

        self.command_expander = HIGExpander('<b>' + _('Command') + '</b>')
        self.command_expander.set_expanded(True)
        self.command_entry = gtk.Entry()

        self.notebook = gtk.Notebook()

        # Profile info page
        self.profile_info_vbox = HIGVBox()
        self.profile_info_label = HIGSectionLabel(_('Profile Information'))
        self.profile_name_label = HIGEntryLabel(_('Profile name'))
        self.profile_name_entry = gtk.Entry()
        self.profile_hint_label = HIGEntryLabel(_('Hint'))
        self.profile_hint_entry = gtk.Entry()
        self.profile_description_label = HIGEntryLabel(_('Description'))
        #self.profile_description_label = HIGHBox()
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_text = HIGTextView()
        self.profile_annotation_label = HIGEntryLabel(_('Annotation'))
        #self.profile_annotation_label = HIGHBox()
        self.profile_annotation_scroll = HIGScrolledWindow()
        self.profile_annotation_text = HIGTextView()

        # Buttons
        self.buttons_hbox = HIGHBox()

        self.help_button = HIGButton(stock=gtk.STOCK_HELP)
        self.help_button.connect('clicked', self.help)

        #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        #self.delete_button.connect('clicked', self.delete_profile)

        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel_button.connect('clicked', self.quit_without_saving)

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)
Beispiel #30
0
    def _create_widgets(self):
        self.opt_vbox = HIGVBox()
        self.opt_local_hbox = HIGHBox()
        self.opt_base_hbox = HIGHBox()
        self.opt_local_section = HIGSectionLabel(_("Local files"))
        self.opt_local_table = HIGTable()
        self.opt_base_section = HIGSectionLabel(_("Database"))
        self.opt_base_table = HIGTable()

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

        self.opt_path_entry = PathEntry()
        self.opt_extension_entry = gtk.Entry()
        self.opt_savetime_entry = SaveTime()
        self.opt_save_check = gtk.CheckButton(
            _("Save scan results in data \
base for latter search"))
        self.opt_search_check = gtk.CheckButton(
            _("Search saved scan results \
in data base"))
    def __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)
Beispiel #32
0
    def __init__(self):
        HIGVBox.__init__(self)
        self.set_spacing(12)

        self.description = HIGEntryLabel(
            _("""Umit generated the nmap command. \
Click Apply to finish this wizard."""))
        spacer = hig_box_space_holder()
        self.bar = ApplyBar()

        self._pack_noexpand_nofill(self.description)
        self._pack_expand_fill(spacer)
        self._pack_noexpand_nofill(self.bar)
Beispiel #33
0
    def create_proxy_row(self, table, level, name, default = ""):
	host, port = self.parse_proxy(default)
	try:
	    port = float(port)
	except ValueError:
	    port = 3128

	lbl = HIGEntryLabel(name + " " + _("proxy") + ":")
	lbl.set_justify(gtk.JUSTIFY_LEFT)
	host_entry = HIGTextEntry()
	host_entry.set_text(host)
	lbl.set_mnemonic_widget(host_entry)
	table.attach(lbl, 0, 1, level, level + 1, 0, 0)
	table.attach(host_entry, 1, 2, level, level + 1)
	
	lbl = HIGEntryLabel(_("Port") + ":")
	lbl.set_justify(gtk.JUSTIFY_LEFT)
	port_entry = gtk.SpinButton(gtk.Adjustment(port, 0, 65536, 1, 100), 1.0, 0)
	lbl.set_mnemonic_widget(port_entry)
	table.attach(lbl, 2, 3, level, level + 1, 0, 0)
	table.attach(port_entry, 3, 4, level, level + 1, 0, 0)
	return host_entry, port_entry
    def on_delete(self, widget=None):
        if not self.profile_name:
            return self.on_cancel()

        dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
        alert = HIGEntryLabel('<b>' + _("Deleting Profile") + '</b>')
        text = HIGEntryLabel(
            _('Your profile is going to be deleted! Click \
Ok to continue, or Cancel to go back to Profile Editor.'))
        hbox = HIGHBox()
        hbox.set_border_width(5)
        hbox.set_spacing(12)

        vbox = HIGVBox()
        vbox.set_border_width(5)
        vbox.set_spacing(12)

        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)

        vbox.pack_start(alert)
        vbox.pack_start(text)
        hbox.pack_start(image)
        hbox.pack_start(vbox)

        dialog.vbox.pack_start(hbox)
        dialog.vbox.show_all()

        response = dialog.run()
        dialog.destroy()

        if response == gtk.RESPONSE_CANCEL:
            return None

        self.deleted = True
        self.profile.remove_profile(self.profile_name)
        self.on_cancel()
Beispiel #35
0
    def _create_widgets_common(self):
        """ generally tab """
        self._box_common = HIGVBox() # pack main section
        self.__check_splash = gtk.CheckButton(_('Enable Splash on start'))
        self.__check_silent_root = gtk.CheckButton(\
            _('Silent Warning Non-Root'))
        self.__check_warning_extensions = gtk.CheckButton(\
            _('Set/Check extensions - Windows only'))
        self._box_common.pack_start(self.__check_splash, False, False)
        #self._box_common.pack_start(self.__check_warning_extensions, False, \
        #                            False)
        self._box_common.pack_start(self.__check_silent_root, False, False)
        self.__label_nmap = HIGEntryLabel(_('Nmap Command'))
        self.__entry_nmap = HIGTextEntry()
        # Files usr saved on predefined directory:
        self.__label_path = HIGEntryLabel(_('Nmap Command'))
        self.__entry_path = HIGTextEntry()
        self.__button_path = HIGButton(_('Choose'))
        self.__box_path = HIGHBox()
        self.__box_path.pack_start(self.__label_path, False, False)
        self.__box_path.pack_end(self.__button_path, False, False)

        self._box_common.set_border_width(0)
    def __parse_option_list(self, option_list, options_used):
        options = option_list.getElementsByTagName(u'option')

        label = HIGEntryLabel(option_list.getAttribute(u'label'))
        opt_list = OptionList()

        for opt in options:
            opt_list.append(self.options.get_option(opt.getAttribute(u'name')))

        for i, row in enumerate(opt_list.list):
            if row[0] in options_used:
                opt_list.set_active(i)

        return label, opt_list
    def __create_widgets(self):

        self.vbox_main = HIGVBox()

        self.main_frame = HIGFrame("Profiles")
        #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.align.set_padding(0, 0, 12, 0)

        self.vbox = HIGVBox()
        self.profiles_sw = HIGScrolledWindow()
        #TreeView
        self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        #self.modelfilter = self.model.filter_new()
        self.profiles_tv = gtk.TreeView(self.model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_("Name"), renderer, text=0)
        self.profiles_tv.append_column(column)
        renderer_hint = gtk.CellRendererText()
        column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1)
        self.profiles_tv.append_column(column_hint)
        #self.profiles_tv.set_model(self.modelfilter)
        #Info
        self.hbox_info = HIGHBox()
        self.command_label = HIGEntryLabel('Command: ')
        self.command_entry = HIGTextEntry()
        self.command_entry.set_editable(False)

        #Buttons
        self.hbox_buttons = HIGHBox()

        self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert')
        self.wiz_button.connect("clicked", self.new_wiz)

        self.edit_button = HIGButton(stock='gtk-edit')
        self.edit_button.connect("clicked", self.open_peditor)
        self.new_button = HIGButton(stock='gtk-new')
        self.new_button.connect("clicked", self.open_peditor)
        self.copy_button = HIGButton(stock='gtk-copy')
        self.copy_button.connect("clicked", self.copy_profiles)
        self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        self.delete_button.connect('clicked', self.delete_profile)
        #Apply Buttons
        self.cancel_button = HIGButton(stock='gtk-close')
        self.cancel_button.connect("clicked", self.quit)

        self.connect("delete-event", self.quit)
    def __init__(self, daddy, profile=None):
        HIGWindow.__init__(self)
        self.daddy = daddy

        self.wtitle = _("Scheduling Profiles Editor")
        self.start_profile = profile

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # profiles name
        self.schedp_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.schedp_name = gtk.combo_box_entry_new_text()
        self.schedp_name.connect('changed', self._check_profile)
        # cron format
        self.cron_frame = HIGFrame(_("Schedule"))
        self.cron_minute_lbl = HIGEntryLabel(_("Minute"))
        self.cron_minute = gtk.Entry()
        self.cron_hour_lbl = HIGEntryLabel(_("Hour"))
        self.cron_hour = gtk.Entry()
        self.cron_day_lbl = HIGEntryLabel(_("Day of month"))
        self.cron_day = gtk.Entry()
        self.cron_month_lbl = HIGEntryLabel(_("Month"))
        self.cron_month = gtk.Entry()
        self.cron_weekday_lbl = HIGEntryLabel(_("Weekday"))
        self.cron_weekday = gtk.Entry()
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect('clicked', self._save_profile)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_profile_and_leave)

        self.load_profiles()
        self.__set_props()
        self.__do_layout()

        self.connect('destroy', self._exit)
    def __init__(self, daddy, profile=None):
        HIGWindow.__init__(self)
        self.daddy = daddy

        self.wtitle = _("Scheduling Profiles Editor")
        self.start_profile = profile

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # profiles name
        self.schedp_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.schedp_name = gtk.combo_box_entry_new_text()
        self.schedp_name.connect("changed", self._check_profile)
        # cron format
        self.cron_frame = HIGFrame(_("Schedule"))
        self.cron_minute_lbl = HIGEntryLabel(_("Minute"))
        self.cron_minute = gtk.Entry()
        self.cron_hour_lbl = HIGEntryLabel(_("Hour"))
        self.cron_hour = gtk.Entry()
        self.cron_day_lbl = HIGEntryLabel(_("Day of month"))
        self.cron_day = gtk.Entry()
        self.cron_month_lbl = HIGEntryLabel(_("Month"))
        self.cron_month = gtk.Entry()
        self.cron_weekday_lbl = HIGEntryLabel(_("Weekday"))
        self.cron_weekday = gtk.Entry()
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect("clicked", self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect("clicked", self._save_profile)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect("clicked", self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect("clicked", self._save_profile_and_leave)

        self.load_profiles()
        self.__set_props()
        self.__do_layout()

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

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

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

            y1 = 1
            y2 = 2

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

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

            self.osclass_expander.add(hbox)
    def __init__(self, daddy=None):
        HIGWindow.__init__(self)

        self.daddy = daddy # TLGraphToolbar instance
        self.wtitle = _("Graph Preferences Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # profiles
        self.graph_profile_lbl = HIGEntryLabel(_("Profile"))
        self.graph_profile = gtk.combo_box_new_text()
        # horizontal divisors/balloons
        self.hdivs_lbl = HIGEntryLabel(_("Horizontal divisors"))
        self.hdivs = gtk.SpinButton(gtk.Adjustment(value=5, lower=2, upper=10,
            step_incr=1), 1)
        # arc drawing
        self.draw_arc_lbl = HIGEntryLabel('')
        self.draw_arc_lbl.set_markup(_("<b>Points higlight</b>"))
        self.draw_arc_onsel = gtk.RadioButton(label=_("On Selection"))
        self.draw_arc_always = gtk.RadioButton(self.draw_arc_onsel,
            label=_("Always"))
        self.draw_arc_bounds = gtk.RadioButton(label=_("Boundary points only"))
        self.draw_arc_allpts = gtk.RadioButton(self.draw_arc_bounds,
            label=_("Every point"))
        self.balloons = gtk.CheckButton(_("Show balloons on selection"))
        # vertical divisors
        self.draw_vertdiv = gtk.CheckButton(_("Draw vertical lines"))
        self.draw_vertdiv_dash = gtk.RadioButton(label=_("Dashed"))
        self.draw_vertdiv_solid = gtk.RadioButton(self.draw_vertdiv_dash,
            label=_("Solid"))
        # background fill
        self.bg_gradient = gtk.CheckButton(_("Gradient background"))
        self.bg_gradient_vert = gtk.RadioButton(label=_("Vertical gradient"))
        self.bg_gradient_horiz = gtk.RadioButton(self.bg_gradient_vert,
            label=_("Horizontal gradient"))
        # selection fill
        self.selection_fill = gtk.CheckButton(_("On selection do "
            "progressive fill"))
        self.selection_fill_solid = gtk.RadioButton(label=_("Solid fill"))
        self.selection_fill_gradient = gtk.RadioButton(
            self.selection_fill_solid, label=_("Gradient fill"))
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect('clicked', self._save_pref)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_pref_and_leave)


        self.append_profiles()
        start_profile = self.load_options_from_graph()
        self.setup_controls(None, start_profile)

        self.__do_connects()
        self.__set_props()
        self.__do_layout()
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)        
         
Beispiel #43
0
    def __init__(self, inventory=None, edit_mode=False):
        """
        If you want to load an inventory at startup, pass it to inventory.
        If you want to run this in edit mode, set to True edit_mode.
        """
        HIGWindow.__init__(self)

        self.schemawin = None
        self.discoverywin = None
        self.edit_mode = edit_mode
        if edit_mode:
            self.wtitle = _("Editing Inventory")
        else:
            self.wtitle = _("New Inventory")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # inventory
        self.invname_lbl = HIGEntryLabel(_("Inventory's name"))
        self.invname = gtk.Entry()
        self.invname.connect('changed', self._check_invname)
        self.invname_inuse = HIGEntryLabel(_("in use"))
        self.invname_inuse.set_sensitive(False)
        self.invenabled = gtk.CheckButton(_("Enabled"))
        self.invenabled.set_active(True)
        # scan command
        self.scandefault = gtk.CheckButton(_("Use default scan options"))
        img_info = gtk.Image()
        img_info.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_MENU)
        self.scandefault_tip = gtk.EventBox()
        self.scandefault_tip.add(img_info)

        self.scanadv = gtk.Expander(_("Use advanced scan options"))
        self.scan_name_lbl = HIGEntryLabel(_("Scan Profile"))
        self.scan_name = ProfileCombo()
        self.scan_name.update()
        self.scan_name.set_active(0)
        self.scan_name.connect('changed', self._set_scan_command)
        self.cmd_wizard = gtk.Button(stock=gtk.STOCK_CONVERT)
        blbl = self.cmd_wizard.get_children(
            )[0].get_children()[0].get_children()[1]
        blbl.set_text(_("Command Wizard"))
        self.cmd_wizard.connect('clicked', self._open_cmd_wizard)

        self.scan_command_lbl = HIGEntryLabel(_("Command"))
        self.scan_command = gtk.Entry()
        self.scan_command.connect('changed', self._set_scan_type)
        self._set_scan_command(None)
        self.scandefault.set_active(True)
        # scan target
        self.scantarget_lbl = HIGEntryLabel(_("Scan target"))
        self.scantarget = gtk.Entry()
        self.scantarget_discovery = HIGButton(_("Use host discovery"))
        self.scantarget_discovery.connect('clicked', self._open_host_discovery)
        # scheduling profiles
        self.sched_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.sched_name = gtk.combo_box_new_text()
        self.sched_name_edit = gtk.Button(stock=gtk.STOCK_EDIT)
        blbl = self.sched_name_edit.get_children(
            )[0].get_children()[0].get_children()[1]
        blbl.set_text(_("Edit Profiles"))
        self.sched_name_edit.connect('clicked', self._edit_schedprofiles)
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_inventory_and_leave)

        self.tooltips = gtk.Tooltips()
        self.tooltips.set_tip(self.scandefault_tip,
            _("nmap -T Aggressive -sV -n -O -v target"))

        # disable controls if edit_mode=True
        if edit_mode:
            self.invname.set_sensitive(False)
            self.scandefault.set_sensitive(False)
            self.scandefault_tip.set_sensitive(False)
            self.scanadv.set_sensitive(False)
            self.scan_name.set_sensitive(False)
            self.scan_command.set_sensitive(False)
            self.scantarget_lbl.set_sensitive(False)
            self.scantarget.set_sensitive(False)
            self.scantarget_discovery.set_sensitive(False)

        self.connect('destroy', self._exit)
        self.profile_running = None # no SchedProfileEditor instance is running.
        self.load_schemas()
        self._load_pscheds()

        # load an inventory if especified
        self.loaded_command = None
        if inventory:
            self.load_inventory(inventory)

        self.__set_props()
        self.__do_layout()
class GeneralSettings(TabBox, object):
    """
    General Settings
    - Splash enable/disable
    - Warnings
    - Erros, log, configure bugreport
    - Autosave: clean up, define folder etc
    - Define Nmap Command
    """

    def __init__(self, name):
        TabBox.__init__(self, name)


    def _create_widgets(self):
        """
        Design all
        """
        # Create general widgets
        self._create_widgets_common()
        self._create_widgets_autosave()
        self._create_widgets_error()
        # Packing main section
        self.pack_start(self._box_common, False, False)
        self.pack_start(self._box_error_frame, False, False)
        self.pack_start(self._box_save_frame, False, False)
        self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE)
        self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE)


        # Settings Values

        self.splash = general_settings.splash
        self.warnings_extensions = general_settings.warnings_extensions
        self.silent_root = general_settings.silent_root
        self.crash_report = general_settings.crash_report
        self.log = general_settings.log
        self.log_file = general_settings.log_file
        self.warnings_save = general_settings.warnings_save

        self._connect_events()
    def _create_widgets_common(self):
        """ generally tab """
        self._box_common = HIGVBox() # pack main section
        self.__check_splash = gtk.CheckButton(_('Enable Splash on start'))
        self.__check_silent_root = gtk.CheckButton(\
            _('Silent Warning Non-Root'))
        self.__check_warning_extensions = gtk.CheckButton(\
            _('Set/Check extensions - Windows only'))
        self._box_common.pack_start(self.__check_splash, False, False)
        #self._box_common.pack_start(self.__check_warning_extensions, False, \
        #                            False)
        self._box_common.pack_start(self.__check_silent_root, False, False)
        self.__label_nmap = HIGEntryLabel(_('Nmap Command'))
        self.__entry_nmap = HIGTextEntry()
        # Files usr saved on predefined directory:
        self.__label_path = HIGEntryLabel(_('Nmap Command'))
        self.__entry_path = HIGTextEntry()
        self.__button_path = HIGButton(_('Choose'))
        self.__box_path = HIGHBox()
        self.__box_path.pack_start(self.__label_path, False, False)
        self.__box_path.pack_end(self.__button_path, False, False)

        self._box_common.set_border_width(0)




    def _create_widgets_error(self):

        # Create Widgets
        self._box_error_frame = HIGFrame('Error')

        self._box_error = HIGTable(5, 2)
        self._box_error.set_border_width(10)
        self._box_error_frame.add(self._box_error)
        self.__crash_report = gtk.CheckButton(_('Enable Crash Report'))
        # Radio Button List
        self.__log_no = gtk.RadioButton(None, _('No log'))
        self.__log_terminal = gtk.RadioButton(self.__log_no, _('Enable log in terminal'))
        self.__log_file = gtk.RadioButton(self.__log_terminal,\
                                         _('Enable log file'))

        self.__log_file_label = HIGEntryLabel(_('Log file'))
        self.__log_file_entry = HIGTextEntry()
        self.__log_file_entry.set_editable(False)
        # FIXME: Do default file ~/.umit/umit.log
        self.__log_file_browser = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        tmpbox = HIGHBox()
        tmpbox.pack_start(self.__log_file_entry, False, False)
        tmpbox.pack_start(self.__log_file_browser, False, False)


        # attach table
        self._box_error.attach(self.__crash_report, 0,1,0,1,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_no, 0,1,1,2,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_terminal, 0,1,2,3,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file, 0,1,3,4,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file_label, 0,1,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(tmpbox, 1,2,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
    def _create_widgets_autosave(self):

        # Create Widgets
        self._box_save_frame = HIGFrame('Auto-save')

        self._box_save = HIGVBox()
        self._box_save_frame.add(self._box_save)
        self._box_save.set_border_width(10)

        self._warnings_save = gtk.CheckButton(
            _('Enable warnings without saving'))
        self._clean_b = HIGButton(_('Delete saved files'), gtk.STOCK_CLEAR)
        self._clean_b_box = HIGHBox()
        self._clean_b_box.pack_start(self._clean_b, False, True)

        # pack

        self._box_save.pack_start(self._warnings_save, False, False)
        self._box_save.pack_start(self._clean_b_box, False, False)
    def _connect_events(self):
        """
        connect call backs
        """

        self.__check_splash.connect('toggled', self.update_splash)
        self.__check_silent_root.connect('toggled', self.update_silent_root)
        self.__crash_report.connect('toggled', self.update_crash_report)


        self.__log_file.connect('toggled', self.update_log)
        self.__log_file.connect('toggled', self.update_log_file)
        self.__log_terminal.connect('toggled', self.update_log)
        self.__log_no.connect('toggled', self.update_log)

        self.__log_file_browser.connect('clicked', self.read_file)
        self.__log_file_entry.connect('changed', self.update_log_file_text)

        self._warnings_save.connect('toggled', self.update_save_warn)
        
        self._clean_b.connect('clicked', self.delete_files)
        
        self.update_log_file(None)
    # Callbacks
    def delete_files(self, widget):
        # NOTE: This method should be adapted in umit.core.UserConf
        # Creating an empty recent_scans file
        
        log.debug('>>> Reset store files:  -  %s' % base_paths['user_dir'])

        reset_user_dir(base_paths['user_dir'])
        
    
    def update_save_warn(self, widget):
        general_settings.warnings_save = self.warnings_save

    def read_file(self, widget):
        dialog = gtk.FileChooserDialog("Open..",
                                       None,
                                       gtk.FILE_CHOOSER_ACTION_SAVE,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_SAVE_AS, gtk.RESPONSE_OK))
        dialog.set_default_response(gtk.RESPONSE_OK)
        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            # Get name of file
            self.__log_file_entry.set_text(dialog.get_filename())
        dialog.destroy()

    def update_crash_report(self, widget):
        general_settings.crash_report = self.crash_report
    def update_splash(self, widget):
        general_settings.splash = self.splash
    def update_silent_root(self, widget):
        general_settings.silent_root = self.silent_root
    def update_log_file_text(self, widget):
        general_settings.log_file = self.log_file
    def update_log_file(self, widget):
        if not self.__log_file.get_active():
            self.__log_file_active(False)
        else:
            self.__log_file_active(True)
    def update_log(self, widget):
        """ Verify if is enable, if it is not enable nothing to do """
        if not widget.get_active():
            return
        # Widget is enable.
        ## But which is enable?

        # Setting kind of log
        if widget == self.__log_no:
            general_settings.log = "None"
        elif widget == self.__log_terminal:
            general_settings.log = "Debug"
        elif widget == self.__log_file:
            general_settings.log = "File"


    # API
    def get_splash(self):
        return self.__check_splash.get_active()
    def set_splash(self, splash):
        self.__check_splash.set_active(splash)

    def set_warnings_extensions(self, extensions):
        self.__check_warning_extensions.set_active(extensions)
    def get_warnings_extensions(self):
        return self.__check_warning_extensions.get_active()
    def set_silent_root(self, root):
        self.__check_silent_root.set_active(root)
    def get_silent_root(self):
        return self.__check_silent_root.get_active()


    def set_crash_report(self, crash):
        self.__crash_report.set_active(crash)
    def get_crash_report(self):
        return self.__crash_report.get_active()

    def get_log(self):
        """
        filter a str with None, Debug or File
        return: int (means 0 - No debug, 1 - debug, 2 - debug file)
        """
        if self.__log_no.get_active():
            return "None"
        elif self.__log_terminal.get_active():
            return "Debug"
        elif self.__log_file.get_active():
            return "File"
        else:
            raise LogException()



    def set_log(self, log):
        if log == "None":
            self.__log_no.set_active(True)
        elif log == "Debug":
            self.__log_terminal.set_active(True)
        elif log == "File":
            self.__log_file.set_active(True)


    def __log_file_active(self, bool):
        self.__log_file_label.set_sensitive(bool)
        self.__log_file_entry.set_sensitive(bool)
        self.__log_file_browser.set_sensitive(bool)

    def set_log_file(self, filename):
        self.__log_file_entry.set_text(filename)
    def get_log_file(self):
        return self.__log_file_entry.get_text()

    def set_warnings_save(self, save):
        self._warnings_save.set_active(save)
    def get_warnings_save(self):
        return self._warnings_save.get_active()

    # Propertys
    splash = property(get_splash, set_splash)
    warnings_extensions = property(get_warnings_extensions, \
                                   set_warnings_extensions)
    silent_root = property(get_silent_root, set_silent_root)
    crash_report = property(get_crash_report, set_crash_report)
    log = property(get_log, set_log)
    log_file = property(get_log_file, set_log_file)
    warnings_save = property(get_warnings_save, set_warnings_save)
Beispiel #45
0
 def __create_widgets(self):
     self.vbox = HIGVBox()
     self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
     self.button_box = gtk.HButtonBox()
     self.search_file_label = HIGEntryLabel()
     self.progress = gtk.ProgressBar()
Beispiel #46
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()
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)
Beispiel #48
0
class SearchWindow(HIGWindow, object):
    """Search Window. Shows informations about the search while it's running
    """
    def __init__(self):
        HIGWindow.__init__(self)

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

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

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

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

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

    def get_filename(self):
        return self.__filename

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

    def get_path(self):
        return self.__path

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

    def get_fraction(self):
        return self.__fraction

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


    filename = property(get_filename,
                        set_filename,
                        doc=_("File's name being searched"))
    path = property(get_path,
                    set_path,
                    doc=_("Path being scanned"))
    fraction = property(get_fraction,
                        set_fraction,
                        doc=_("Fraction of the progress bar"))
Beispiel #49
0
class Proprieties(HIGScrolledWindow):
    '''

    This box should be configurable 
    if widget is of a type all configuration should be change to this type

    #tricks: option_list have a icon to fill with options
    and option_check have a list of options in combo to change

    '''

    def __init__(self):
        HIGScrolledWindow.__init__(self)
        self._boxeditable = None 
        vp = gtk.Viewport()
        self._create_widgets()
        vp.add(self._box)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self.add(vp)
        self._profilecore = None 
        self._selected = None 

    def set_profilecore(self, profilecore):
        self._profilecore = profilecore


    def _create_widgets(self):
        '''
        Create the main entrys of the option 
        '''
        self._box = HIGVBox()


        self._table = HIGTable()


        #Name
        self._label_name  = HIGEntryLabel(_('Name'))
        self._entry_name = HIGTextEntry()

        self._entry_name.connect('activate', self._update_label)

        #Type 
        self._label_type = HIGEntryLabel(_('Type'))	
        self._combo_type = gtk.combo_box_new_text()
        self._combo_type.append_text('')
        self._combo_type.append_text('Option List')
        self._combo_type.append_text('Option Check')
        self._combo_type.set_active(0)
        self._combo_type.connect('changed', self.change_combo)

        self._label_opt = HIGEntryLabel(_('Option'))
        self._entry_opt = HIGTextEntry()
        self._entry_opt.set_sensitive(False)

        #For option list open a dialog to add/remove options
        self._button_list = HIGButton('Edit Option List')
        img = gtk.Image()
        img_dir =  os.path.join(pixmaps_dir, 'uie', 'combo.png')
        img.set_from_file(img_dir)
        self._button_list.set_image(img)
        self._button_list.connect('button-press-event', self._button_list_clicked)


        self._table.attach(self._label_name, 0,1,0, 1)
        self._table.attach(self._entry_name, 1,2,0,1)
        self._table.attach(self._label_type, 0,1,1,2)
        self._table.attach(self._combo_type, 1,2,1, 2)

        self._table.attach(self._button_list, 0,2, 3,4)
        self._table.attach(self._label_opt, 0,1, 4,5)
        self._table.attach(self._entry_opt, 1,2,4,5)

        self._box.pack_start(self._table, False, False)
    def _button_list_clicked(self, widget, event):
        section_name = self._boxeditable.get_name()
        lm = ListManager(self._entry_name.get_text(),section_name, 
                         self._profilecore, self._selected, _('List of items'))
    def _update_label(self, widget):
        #XXX Replace by Command
        log.debug("Update Label")
        selected = self._selected
        cmd = CommandChangeLabel(selected, self._entry_name.get_text(), 
                                 self._profilecore,self._boxeditable, True)
        command_manager.add_command(cmd)
        
    def change_combo(self,combo):
        model = combo.get_model()
        index = combo.get_active()
        if index:
            if model[index][0]=='Option List':

                log.debug('Show Button List ')
                self._button_list.show()

            else:

                log.debug('Hide Button List ')
                self._button_list.hide()
        return
    def show_notebook_label(self):
        '''
        show proprieties of notebook label and hide others
        '''
        pass


    def show_item(self):
        pass
    def hide_item(self):
        self._label_opt.hide()
        self._entry_opt.hide()
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._entry_name.hide()
        self._label_name.hide()
    def set_notebooklabel(self, selected):
        self._entry_name.show()
        self._label_name.show()
        self._entry_name.set_text(selected.get_text())
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._label_opt.hide()
        self._entry_opt.hide()
        self._selected = selected
    def set_item(self, selected):
        self._entry_name.show()
        self._label_name.show()

        self._selected = selected
        if selected.get_name()!=None:
            self._entry_name.set_text(selected.get_name())
        else: 
            self.hide_item()
            return
        childs = selected.get_children()
        self._combo_type.show()
        self._label_type.show()
        child_label = childs[0]
        if isinstance(child_label, gtk.HBox):
            #OptionCheck
            self._label_opt.show()
            self._entry_opt.show()
            opt_ = self._profilecore.get_opt_check(self._boxeditable.get_name(),
                                                   selected.get_name())
            self._entry_opt.set_text(opt_)
            self._button_list.hide()
            child_label.cbutton.set_label(self._entry_name.get_text())
            self._combo_type.set_active(2)
            #XXX: Put other widget that sensitible = False with option name


        elif isinstance(child_label, gtk.EventBox):
            #OptionList
            self._button_list.show()
            other = child_label.get_children()[0]
            other.set_label(self._entry_name.get_text())
            self._combo_type.set_active(1)
        #Disable Combo to change OptionList/OptionChange
        self._combo_type.set_sensitive(False)

    def set_boxeditable(self, boxeditable):
        self._boxeditable = boxeditable
    def update(self):
        pass

    def disable_all(self):
        self._label_opt.hide()
        self._entry_opt.hide()
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._entry_name.hide()
        self._label_name.hide()
    def load_data(self, option):
        pass 
    def unload(self,option):
        pass 
 def __create_widgets(self):
     na = _('Not available')
     self.command_expander = gtk.Expander("<b>"+_("Command Info")+"</b>")
     self.general_expander = gtk.Expander("<b>"+_("General Info")+"</b>")
     
     # Command info
     self.command_label = HIGEntryLabel(_('Command:'))
     self.info_command_label = HIGEntryLabel(na)
     
     self.nmap_version_label = HIGEntryLabel(_('Nmap Version:'))
     self.info_nmap_version_label = HIGEntryLabel(na)
     
     self.verbose_label = HIGEntryLabel(_('Verbosity level:'))
     self.info_verbose_label = HIGEntryLabel(na)
     
     self.debug_label = HIGEntryLabel(_('Debug level:'))
     self.info_debug_label = HIGEntryLabel(na)
     
     self.command_table = HIGTable()
     self.command_hbox = HIGHBox()
     
     # General info:
     self.start_label = HIGEntryLabel(_('Started on:'))
     self.info_start_label = HIGEntryLabel(na)
     
     self.finished_label = HIGEntryLabel(_('Finished on:'))
     self.info_finished_label = HIGEntryLabel(na)
     
     self.host_up_label = HIGEntryLabel(_('Hosts up:'))
     self.info_hosts_up_label = HIGEntryLabel(na)
     
     self.host_down_label = HIGEntryLabel(_('Hosts down:'))
     self.info_hosts_down_label = HIGEntryLabel(na)
     
     self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:'))
     self.info_hosts_scanned_label = HIGEntryLabel(na)
     
     self.open_label = HIGEntryLabel(_('Open ports:'))
     self.info_open_label = HIGEntryLabel(na)
     
     self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
     self.info_filtered_label = HIGEntryLabel(na)
     
     self.closed_label = HIGEntryLabel(_('Closed ports:'))
     self.info_closed_label = HIGEntryLabel(na)
     
     self.general_table = HIGTable()
     self.general_hbox = HIGHBox()
class GraphPreferences(HIGWindow):
    """
    Graph Preferences Editor
    """

    def __init__(self, daddy=None):
        HIGWindow.__init__(self)

        self.daddy = daddy # TLGraphToolbar instance
        self.wtitle = _("Graph Preferences Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # profiles
        self.graph_profile_lbl = HIGEntryLabel(_("Profile"))
        self.graph_profile = gtk.combo_box_new_text()
        # horizontal divisors/balloons
        self.hdivs_lbl = HIGEntryLabel(_("Horizontal divisors"))
        self.hdivs = gtk.SpinButton(gtk.Adjustment(value=5, lower=2, upper=10,
            step_incr=1), 1)
        # arc drawing
        self.draw_arc_lbl = HIGEntryLabel('')
        self.draw_arc_lbl.set_markup(_("<b>Points higlight</b>"))
        self.draw_arc_onsel = gtk.RadioButton(label=_("On Selection"))
        self.draw_arc_always = gtk.RadioButton(self.draw_arc_onsel,
            label=_("Always"))
        self.draw_arc_bounds = gtk.RadioButton(label=_("Boundary points only"))
        self.draw_arc_allpts = gtk.RadioButton(self.draw_arc_bounds,
            label=_("Every point"))
        self.balloons = gtk.CheckButton(_("Show balloons on selection"))
        # vertical divisors
        self.draw_vertdiv = gtk.CheckButton(_("Draw vertical lines"))
        self.draw_vertdiv_dash = gtk.RadioButton(label=_("Dashed"))
        self.draw_vertdiv_solid = gtk.RadioButton(self.draw_vertdiv_dash,
            label=_("Solid"))
        # background fill
        self.bg_gradient = gtk.CheckButton(_("Gradient background"))
        self.bg_gradient_vert = gtk.RadioButton(label=_("Vertical gradient"))
        self.bg_gradient_horiz = gtk.RadioButton(self.bg_gradient_vert,
            label=_("Horizontal gradient"))
        # selection fill
        self.selection_fill = gtk.CheckButton(_("On selection do "
            "progressive fill"))
        self.selection_fill_solid = gtk.RadioButton(label=_("Solid fill"))
        self.selection_fill_gradient = gtk.RadioButton(
            self.selection_fill_solid, label=_("Gradient fill"))
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect('clicked', self._save_pref)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_pref_and_leave)


        self.append_profiles()
        start_profile = self.load_options_from_graph()
        self.setup_controls(None, start_profile)

        self.__do_connects()
        self.__set_props()
        self.__do_layout()


    def append_profiles(self):
        """
        Write profiles to combobox.
        """
        for p in profiles:
            self.graph_profile.append_text(p)

        self.graph_profile.set_active(1)


    def graph_attrs(self):
        """
        Tuple of attributes in graph.
        """
        return (
            "hdivisors", "draw_arcs_always", "draw_every_arc",
            "show_balloons", "draw_dashed_vert", "draw_solid_vert",
            "gradient_fill", "gradient_direction", "selection_effect",
            "selection_gradient" )


    def load_options_from_graph(self):
        """
        Load startup graph settings.
        """
        # horizontal divisors
        hdivs = self.daddy.graph_attr("hdivisors") + 1
        # arcs
        draw_arcs_always = int(self.daddy.graph_attr("draw_arcs_always"))
        draw_every_arc = int(self.daddy.graph_attr("draw_every_arc"))
        # balloons
        balloons = self.daddy.graph_attr("show_balloons")
        # vertical lines
        vert_enabled = True
        if self.daddy.graph_attr("draw_dashed_vert"):
            vert_line = 0
        elif self.daddy.graph_attr("draw_solid_vert"):
            vert_line = 1
        else:
            vert_line = -1
            vert_enabled = False
        # widget background
        gradient_bg = True and self.daddy.graph_attr("gradient_fill")
        if not gradient_bg:
            gradient_bg_dir = -1
        else:
            gradient_bg_dir = int(self.daddy.graph_attr("gradient_direction"))
        # selection
        selection_effect = True and self.daddy.graph_attr("selection_effect")
        selection_fill = int(self.daddy.graph_attr("selection_gradient"))

        profile = {"Startup": (
            hdivs, draw_arcs_always, draw_every_arc,
            balloons, vert_enabled, vert_line,
            gradient_bg, gradient_bg_dir,
            selection_effect, selection_fill)}

        return profile


    def setup_controls(self, event, startup=None):
        """
        Enable/Disable controls.
        """
        opt_profiles = (
            _("Standard"), _("Best Performance"), _("Best Visual")
            )

        profile = self.graph_profile.get_active_text()
        indx_active = self.graph_profile.get_active()
        if not profile in opt_profiles: # custom
            return

        # dict with default values for each option in this window.
        profiles_d = {
            _("Standard"): (5, 0, 1, True, False, -1, False, -1, True, 0),
            _("Best Performance"): (3, 0, 0, True, False, -1, False, -1,
                False, 0),
            _("Best Visual"): (5, 0, 1, True, True, 0, True, 0, True, 1)
            }

        if startup:
            found_profile = False
            for p, values in profiles_d.items():
                if startup["Startup"] == values:
                    index_profile = profiles.index(p)
                    self.graph_profile.set_active(index_profile)
                    indx_active = self.graph_profile.get_active()
                    profile = p
                    found_profile = True
                    break

            if not found_profile: # custom
                indx_active = 0
                profile = _("Custom")
                self.graph_profile.set_active(indx_active)
                temp = { }
                temp[_("Custom")] = startup["Startup"]
                profiles_d.update(temp)


        controls = (self.hdivs, (self.draw_arc_onsel, self.draw_arc_always),
                    (self.draw_arc_bounds, self.draw_arc_allpts),
                    self.balloons, self.draw_vertdiv, (self.draw_vertdiv_dash,
                    self.draw_vertdiv_solid), self.bg_gradient,
                    (self.bg_gradient_vert, self.bg_gradient_horiz),
                    self.selection_fill, (self.selection_fill_solid,
                    self.selection_fill_gradient))

        for indx, control in enumerate(controls):
            value = profiles_d[profile][indx]

            if value >= 2: # it is spinbutton
                control.set_value(float(value))
            elif isinstance(value, bool): # checkbutton
                control.set_active(value)
            elif value != -1: # radiobutton
                control[value].set_active(True)


        checkbtns = (self.draw_vertdiv, self.bg_gradient)
        methods = (self._vertdiv_changed, self._bgfill_changed)

        for indx, checkbtn in enumerate(checkbtns):
            methods[indx](checkbtn.get_active(), indx_active)

        return True


    def _vertdiv_changed(self, event, custom=0):
        """
        Vertical divisors enabled/disabled.
        """
        status = self.get_status(event)

        self.draw_vertdiv_dash.set_sensitive(status)
        self.draw_vertdiv_solid.set_sensitive(status)

        self.graph_profile.set_active(custom)


    def _bgfill_changed(self, event, custom=0):
        """
        Gradient background fill enabled/disabled.
        """
        status = self.get_status(event)

        self.bg_gradient_vert.set_sensitive(status)
        self.bg_gradient_horiz.set_sensitive(status)

        self.graph_profile.set_active(custom)


    def get_status(self, event):
        """
        Get event status.
        """
        if isinstance(event, bool):
            status = event # event generated by profile change
        else:
            status = event.get_active() # event generated by mouse click

        return status


    def _show_help(self, event):
        """
        Show help for Graph Preferences.
        """


    def _save_pref(self, event):
        """
        Save preferences.
        """
        profile = self.graph_profile.get_active_text()

        cmds = {
            _("Standard"): "standard_mode",
            _("Best Performance"): "speedup_performance",
            _("Best Visual"): "best_visual" }

        if profile != _("Custom"):
            self.daddy.change_graph_mode = cmds[profile]
            return

        controls = (self.hdivs, self.draw_arc_always, self.draw_arc_allpts,
                    self.balloons, (self.draw_vertdiv, self.draw_vertdiv_dash,
                    self.draw_vertdiv_solid), self.bg_gradient,
                    self.bg_gradient_horiz, self.selection_fill,
                    self.selection_fill_gradient)

        indx = 0
        for control in controls:
            if isinstance(control, tuple): # group of controls
                enable = True
                if not control[0].get_active():
                    enable = False

                for c in control[1:]:
                    if enable == False:
                        self.daddy.change_graph_attr = (
                            self.graph_attrs()[indx], False)
                    else:
                        self.daddy.change_graph_attr = (
                            self.graph_attrs()[indx], c.get_active())
                    indx += 1

                continue

            elif hasattr(control, "get_active"): # radio/checkbutton
                self.daddy.change_graph_attr = (
                    self.graph_attrs()[indx], control.get_active())

            elif hasattr(control, "set_width_chars"): # spinbutton
                nhdiv = int(control.get_text())
                self.daddy.change_graph_attr = self.graph_attrs()[indx], nhdiv

            indx += 1

        self.daddy.update_graph()


    def _save_pref_and_leave(self, event):
        """
        Saves preferences and close window.
        """
        self._save_pref(None)
        self._exit(None)


    def _exit(self, event):
        """
        Close window.
        """
        self.destroy()


    def __do_connects(self):
        """
        Connect signals.
        """
        self.hdivs.connect('value-changed',
            lambda c: self.graph_profile.set_active(0))

        self.draw_arc_always.connect('clicked',
            lambda c: self.graph_profile.set_active(0))
        self.draw_arc_bounds.connect('clicked',
            lambda c: self.graph_profile.set_active(0))
        self.draw_arc_allpts.connect('clicked',
            lambda c: self.graph_profile.set_active(0))
        self.balloons.connect('toggled',
            lambda c: self.graph_profile.set_active(0))

        self.draw_vertdiv.connect('toggled', self._vertdiv_changed)
        self.draw_vertdiv_dash.connect('clicked',
            lambda c: self.graph_profile.set_active(0))
        self.draw_vertdiv_solid.connect('clicked',
            lambda c: self.graph_profile.set_active(0))

        self.bg_gradient.connect('toggled', self._bgfill_changed)
        self.bg_gradient_vert.connect('clicked',
            lambda c: self.graph_profile.set_active(0))
        self.bg_gradient_horiz.connect('clicked',
            lambda c: self.graph_profile.set_active(0))

        self.selection_fill.connect('toggled',
            lambda c: self.graph_profile.set_active(0))
        self.selection_fill_solid.connect('clicked',
            lambda c: self.graph_profile.set_active(0))
        self.selection_fill_gradient.connect('clicked',
            lambda c: self.graph_profile.set_active(0))

        self.graph_profile.connect('changed', self.setup_controls)


    def __set_props(self):
        """
        Set window properties.
        """
        self.set_title(self.wtitle)


    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)
Beispiel #52
0
class NewInventory(HIGWindow):
    """
    A window for creating new or editing existing Inventories.
    """

    def __init__(self, inventory=None, edit_mode=False):
        """
        If you want to load an inventory at startup, pass it to inventory.
        If you want to run this in edit mode, set to True edit_mode.
        """
        HIGWindow.__init__(self)

        self.schemawin = None
        self.discoverywin = None
        self.edit_mode = edit_mode
        if edit_mode:
            self.wtitle = _("Editing Inventory")
        else:
            self.wtitle = _("New Inventory")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # inventory
        self.invname_lbl = HIGEntryLabel(_("Inventory's name"))
        self.invname = gtk.Entry()
        self.invname.connect('changed', self._check_invname)
        self.invname_inuse = HIGEntryLabel(_("in use"))
        self.invname_inuse.set_sensitive(False)
        self.invenabled = gtk.CheckButton(_("Enabled"))
        self.invenabled.set_active(True)
        # scan command
        self.scandefault = gtk.CheckButton(_("Use default scan options"))
        img_info = gtk.Image()
        img_info.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_MENU)
        self.scandefault_tip = gtk.EventBox()
        self.scandefault_tip.add(img_info)

        self.scanadv = gtk.Expander(_("Use advanced scan options"))
        self.scan_name_lbl = HIGEntryLabel(_("Scan Profile"))
        self.scan_name = ProfileCombo()
        self.scan_name.update()
        self.scan_name.set_active(0)
        self.scan_name.connect('changed', self._set_scan_command)
        self.cmd_wizard = gtk.Button(stock=gtk.STOCK_CONVERT)
        blbl = self.cmd_wizard.get_children(
            )[0].get_children()[0].get_children()[1]
        blbl.set_text(_("Command Wizard"))
        self.cmd_wizard.connect('clicked', self._open_cmd_wizard)

        self.scan_command_lbl = HIGEntryLabel(_("Command"))
        self.scan_command = gtk.Entry()
        self.scan_command.connect('changed', self._set_scan_type)
        self._set_scan_command(None)
        self.scandefault.set_active(True)
        # scan target
        self.scantarget_lbl = HIGEntryLabel(_("Scan target"))
        self.scantarget = gtk.Entry()
        self.scantarget_discovery = HIGButton(_("Use host discovery"))
        self.scantarget_discovery.connect('clicked', self._open_host_discovery)
        # scheduling profiles
        self.sched_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.sched_name = gtk.combo_box_new_text()
        self.sched_name_edit = gtk.Button(stock=gtk.STOCK_EDIT)
        blbl = self.sched_name_edit.get_children(
            )[0].get_children()[0].get_children()[1]
        blbl.set_text(_("Edit Profiles"))
        self.sched_name_edit.connect('clicked', self._edit_schedprofiles)
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_inventory_and_leave)

        self.tooltips = gtk.Tooltips()
        self.tooltips.set_tip(self.scandefault_tip,
            _("nmap -T Aggressive -sV -n -O -v target"))

        # disable controls if edit_mode=True
        if edit_mode:
            self.invname.set_sensitive(False)
            self.scandefault.set_sensitive(False)
            self.scandefault_tip.set_sensitive(False)
            self.scanadv.set_sensitive(False)
            self.scan_name.set_sensitive(False)
            self.scan_command.set_sensitive(False)
            self.scantarget_lbl.set_sensitive(False)
            self.scantarget.set_sensitive(False)
            self.scantarget_discovery.set_sensitive(False)

        self.connect('destroy', self._exit)
        self.profile_running = None # no SchedProfileEditor instance is running.
        self.load_schemas()
        self._load_pscheds()

        # load an inventory if especified
        self.loaded_command = None
        if inventory:
            self.load_inventory(inventory)

        self.__set_props()
        self.__do_layout()


    def load_inventory(self, inventory):
        """
        Load inventory.
        """
        inv = ConfigParser()
        inv.read(Path.sched_schemas)

        if not inv.has_section(inventory):
            dlg = NoScheduleDlg()
            dlg.run()
            dlg.destroy()
            raise NoInventory(inventory)

        self.invname.set_text(inventory)
        for item in inv.items(inventory):
            if item[0] == 'profile':
                pindx = self.profiles.index(item[1])
                self.sched_name.set_active(pindx)
            if item[0] == 'enabled':
                self.invenabled.set_active(int(item[1]))
            if item[0] == 'command':
                self.loaded_command = item[1]


    def load_schemas(self):
        """
        Load scheduler schemas profiles.
        """
        schemas = ConfigParser()
        schemas.read(Path.sched_schemas)

        self.sections = [ ]
        for section in schemas.sections():
            self.sections.append(section)


    def _load_pscheds(self):
        """
        Load scheduling profiles.
        """
        pscheds = ConfigParser()
        pscheds.read(Path.sched_profiles)

        self.profiles = [ ]
        self.sched_name.get_model().clear()
        for section in pscheds.sections():
            self.sched_name.append_text(section)
            self.profiles.append(section)

        self.sched_name.set_active(0)


    def _check_invname(self, event):
        """
        Check if Inventory's name isn't in use.
        """
        if self.invname.get_text() and \
           (self.invname.get_text() in self.sections) and \
            not self.edit_mode:
            self.invname_inuse.set_sensitive(True)
        else:
            self.invname_inuse.set_sensitive(False)


    def _edit_schedprofiles(self, event):
        """
        Open Scheduling Profiles Editor.
        """
        if self.profile_running:
            return

        win = SchedProfileEditor(self, self.sched_name.get_active_text())
        win.show_all()
        self.profile_running = win


    def _set_scan_type(self, event):
        """
        When scan command is changed, unset "Default scan options" if it is
        selected.
        """
        if self.scandefault.get_active():
            self.scandefault.set_active(False)


    def _open_cmd_wizard(self, event):
        """
        Run command wizard window and update combobox when it finishes.
        """
        def update_scan_profiles(wwin):
            self.scan_name.update()

        w = Wizard()
        w.show_all()
        w.connect('destroy', update_scan_profiles)


    def _open_host_discovery(self, event):
        """
        Open host discovery window.
        """
        if self.discoverywin:
            return

        w = HostDiscovery(self)
        w.show_all()

        self.discoverywin = w


    def get_discoverywin(self):
        """
        Get HostDiscovery running instance.
        """
        return self.__discoverywin


    def set_discoverywin(self, win):
        """
        Set HostDiscovery instance.
        """
        self.__discoverywin = win


    def get_schemawin(self):
        """
        Get scheduelr schemas editor running instance.
        """
        return self.__schemawin


    def set_schemawin(self, win):
        """
        Set scheduler schemas editor instance.
        """
        self.__schemawin = win


    def get_profile_running(self):
        """
        Get profile editor running instance.
        """
        return self.__profilerunning


    def set_profile_running(self, running):
        """
        Set profile editor instance.
        """
        self.__profilerunning = running


    def _save_inventory(self, event):
        """
        Save inventory.
        """
        target = self.scantarget.get_text()
        invname = self.invname.get_text()
        notinuse = (self.invname_inuse.state == gtk.STATE_INSENSITIVE)
        command_adv = self.scan_command.get_text()
        
        # checking for errors
        if not notinuse or not len(invname) and not self.edit_mode:
            dlg = HIGAlertDialog(self,
                message_format=_("New Inventory - Error while creating."),
                secondary_text=_("You tried to use an existing Inventory "
                    "name or you didn't specify one."))

            dlg.run()
            dlg.destroy()
            return 0

        if not len(target) and not self.edit_mode:
            dlg = HIGAlertDialog(self,
                message_format=_("New Inventory - Error  while creating."),
                    secondary_text=_("You didn't specify any target."))

            dlg.run()
            dlg.destroy()
            return 0
            
       
        if not self.edit_mode:
        	if Address_Checker(target) == "IPV4" :
        		option = ""
        	elif Address_Checker(target) == "IPV6":
        		option = "-6 "
        	elif Address_Checker(target) == "MAC":
        		option = ""
        	else:
        		option = ""
        		dlg = HIGAlertDialog(self,
        			message_format=_("New Inentory - Error While Creating."),
        			secondary_text=_("You need to enter correct address either"
        				"IPV4 or IPv6 or MAC address"))
        		dlg.run()
        		dlg.destroy()
        		return 0


        if not len(command_adv) and not self.scandefault.get_active() \
            and not self.edit_mode:
            dlg = HIGAlertDialog(self,
                message_format=_("New Inventory - Error while creating."),
                secondary_text=_("You need to toggle \"Use default scan "
                    "options\" or specify a command."))

            dlg.run()
            dlg.destroy()
            return 0
        # end error checking

        if self.scandefault.get_active() and not self.edit_mode:
            command = "nmap -T Aggressive -sV -n -O -v " + option +target
        elif not self.edit_mode:
            target_cmd = "<target>"
            target_pos = command_adv.find(target_cmd)
            if target_pos != -1:
                start = target_pos
                end = target_pos + len(target_cmd)
                command = command_adv[:start] + option +target + command_adv[end:]
            else:
                dlg = HIGAlertDialog(self,
                    message_format=_("New Inventory - Error while creating."),
                    secondary_text=_("It seems you removed <target> from the "
                        "Scan command entry, you need to leave it somewhere "
                        "there."))

                dlg.run()
                dlg.destroy()
                return 0

        schedule = self.sched_name.get_active_text()
        enabled = int(self.invenabled.get_active())
        # write inventory to schema's file
        s_cfg = ConfigParser()
        s_cfg.read(Path.sched_schemas)

        if not s_cfg.has_section(invname):
            new_sec = True
            s_cfg.add_section(invname)
        elif self.edit_mode:
            new_sec = False
        else:
            print "How the hell did we get here?!"
            print "Report as BUG"
            return 0

        if new_sec:
            # New Section
            s_cfg.set(invname, 'profile', schedule)
            s_cfg.set(invname, 'command', command)
            s_cfg.set(invname, 'enabled', enabled)
            s_cfg.set(invname, 'addtoinv', '2')
            s_cfg.set(invname, 'saveto', '')
            s_cfg.set(invname, 'mailto', '')
            s_cfg.set(invname, 'smtp', '')
        else:
            # Edit Mode
            s_cfg.set(invname, 'profile', schedule)
            s_cfg.set(invname, 'enabled', enabled)
            #here i have to put check for scan target field
            command_text = self.cmd_entry.get_text()
            if command_text.find("nmap") == -1:
            	dlg = HIGAlertDialog(self,
            		message_format=_("Edit Inventory - Error while creating."),
            		secondary_text=_("It seems you have not entered namp in "
            			"command field. enter correct command with target."))
            	dlg.run()
            	dlg.destroy()
            	return 0
            	
            s_cfg.set(invname, 'command', command_text)

        s_cfg.write(open(Path.sched_schemas, 'w'))

        self.load_schemas()

        return 1


    def _save_inventory_and_leave(self, event):
        """
        Save Inventory and close window.
        """
        close_win = self._save_inventory(None)
        if close_win:
            self._exit(None)


    def _set_scan_command(self, event):
        """
        Set scan command based on chosen profile.
        """
        profile = self.scan_name.get_selected_profile()
        cmd_profile = CommandProfile()
        command = cmd_profile.get_command(profile)
        self.scan_command.set_text(command % '<target>')


    def _show_help(self, event):
        """
        Show help for creating a New Inventory.
        """
        pass


    def _exit(self, event):
        """
        Close window.
        """
        if self.schemawin:
            self.schemawin._exit(None)

        if self.profile_running:
            self.profile_running._exit(None)

        self.destroy()


    def __set_props(self):
        """
        Set window properties.
        """
        self.set_title(self.wtitle)


    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)


    # Properties
    schemawin = property(get_schemawin, set_schemawin)
    discoverywin = property(get_discoverywin, set_discoverywin)
    profile_running = property(get_profile_running, set_profile_running)
class SchedSchemaEditor(HIGWindow):
    """
    Scheduler Schemas Editor
    """

    def __init__(self, daddy=None):
        HIGWindow.__init__(self)

        self.daddy = daddy
        self.wtitle = _("Scan Scheduler Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # schemas name
        self.schema_name_lbl = HIGEntryLabel(_("Schema Name"))
        self.schema_name = gtk.combo_box_entry_new_text()
        self.schema_name.connect("changed", self._check_schema)
        # target and scan profiles
        # self.target_lbl = HIGEntryLabel(_("Target"))
        # self.target = gtk.Entry()
        self.scan_name_lbl = HIGEntryLabel(_("Scan Profile"))
        self.scan_name = ProfileCombo()
        self.scan_name.update()
        self.scan_name.set_active(0)
        self.scan_name.connect("changed", self._set_scan_command)
        # scan command
        self.scan_command_lbl = HIGEntryLabel(_("Command"))
        self.scan_command = gtk.Entry()
        # scheduling profile
        self.sched_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.sched_name = gtk.combo_box_new_text()
        self.sched_name_edit = gtk.Button(stock=gtk.STOCK_EDIT)
        blbl = self.sched_name_edit.get_children()[0].get_children()[0].get_children()[1]
        blbl.set_text(_("Edit Profiles"))
        self.sched_name_edit.connect("clicked", self._edit_schedprofiles)
        # schema settings
        self.schema_sett_frame = HIGFrame()
        self.setting_saveto = gtk.CheckButton(_("Save outputs to"))
        self.setting_saveto_entry = gtk.Entry()
        self.setting_saveto_browse = gtk.Button(_("..."))
        self.setting_saveto_browse.connect("clicked", self._select_saveto)
        self.setting_mailto = gtk.CheckButton(_("Send output to email"))
        self.setting_mailto_entry = gtk.Entry()
        self.setting_smtp_lbl = HIGEntryLabel(_("SMTP Schema"))
        self.setting_smtp = gtk.combo_box_new_text()
        self.setting_addtoinv = gtk.CheckButton(_("Add to the Inventory"))
        self.setting_enabled = gtk.CheckButton(_("Enabled"))
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect("clicked", self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect("clicked", self._save_schema)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect("clicked", self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect("clicked", self._save_schema_and_leave)

        self.load_smtp_schemas()
        self._set_scan_command(None)
        self.profile_running = None  # no SchedProfileEditor instance is running.
        self._load_pscheds()
        self.load_schemas()

        self.__set_props()
        self.__do_layout()

        self.connect("destroy", self._exit)

    def load_smtp_schemas(self):
        """
        Load smtp profiles.
        """
        schemas = ConfigParser()
        schemas.read(Path.smtp_schemas)

        self.smtp_sections = []
        self.setting_smtp.get_model().clear()
        for section in schemas.sections():
            self.smtp_sections.append(section)
            self.setting_smtp.append_text(section)

        self.setting_smtp.set_active(0)

    def load_schemas(self):
        """
        Load schemas profiles.
        """
        schemas = ConfigParser()
        schemas.read(Path.sched_schemas)

        self.sections = []
        self.schema_name.get_model().clear()
        for section in schemas.sections():
            self.sections.append(section)
            self.schema_name.append_text(section)

        self.schema_name.set_active(0)
        self._check_schema(None)

    def _load_schema(self):
        """
        Load current set schedule schema.
        """
        schema = ConfigParser()
        schema.read(Path.sched_schemas)

        values = {
            "command": self.scan_command.set_text,
            "saveto": self.setting_saveto_entry.set_text,
            "mailto": self.setting_mailto_entry.set_text,
        }
        enable = {"saveto": self.setting_saveto.set_active, "mailto": self.setting_mailto.set_active}

        for item in schema.items(self.schema_name.get_active_text()):
            if item[0] == "addtoinv":
                self.setting_addtoinv.set_active(int(item[1]))
                if item[1] == "2":
                    self.apply.set_sensitive(False)
                    self.ok.set_sensitive(False)
                else:
                    self.apply.set_sensitive(True)
                    self.ok.set_sensitive(True)
            elif item[0] == "enabled":
                self.setting_enabled.set_active(int(item[1]))
            elif item[0] == "profile":
                pindx = self.profiles.index(item[1])
                self.sched_name.set_active(pindx)
            elif item[0] == "smtp":
                if item[1]:
                    pindx = self.smtp_sections.index(item[1])
                    self.setting_smtp.set_active(pindx)
            else:
                values[item[0]](item[1])
                if item[0] in ("saveto", "mailto"):
                    if len(item[1]):
                        enable[item[0]](True)
                    else:
                        enable[item[0]](False)

    def _check_schema(self, event):
        """
        Check if current text in schema_name combobox is a schema name.
        """
        if self.schema_name.get_active_text() in self.sections:
            # load schema
            self._load_schema()
        else:
            # reset to default values
            self.apply.set_sensitive(True)
            self.ok.set_sensitive(True)
            self.setting_addtoinv.set_active(False)
            self.setting_enabled.set_active(False)
            self.setting_mailto.set_active(False)
            self.setting_mailto_entry.set_text("")
            self.setting_saveto.set_active(False)
            self.setting_saveto_entry.set_text("")

        self.schema_sett_frame._set_label(self.schema_name.get_active_text() + " - Settings")

    def _set_scan_command(self, event):
        """
        Set scan command based on chosen profile.
        """
        profile = self.scan_name.get_selected_profile()
        cmd_profile = CommandProfile()
        command = cmd_profile.get_command(profile)
        self.scan_command.set_text(command % "<target>")

    def _load_pscheds(self):
        """
        Load scheduling profiles.
        """
        pscheds = ConfigParser()
        pscheds.read(Path.sched_profiles)

        self.profiles = []
        self.sched_name.get_model().clear()
        for section in pscheds.sections():
            self.sched_name.append_text(section)
            self.profiles.append(section)

        self.sched_name.set_active(0)

    def _edit_schedprofiles(self, event):
        """
        Open Scheduling Profiles Editor.
        """
        if self.profile_running:
            return

        win = SchedProfileEditor(self, self.sched_name.get_active_text())
        win.show_all()
        self.profile_running = win

    def _select_saveto(self, event):
        """
        Select directory to save file.
        """
        dir_chooser = DirectoryChooserDialog(_("Select a directory"))

        dir_chooser.run()
        dir_chosen = dir_chooser.get_filename()
        dir_chooser.destroy()
        self.setting_saveto_entry.set_text(dir_chosen)

    def _save_schema(self, event):
        """
        Save current schema.
        """
        schema = self.schema_name.get_active_text()
        command = self.scan_command.get_text()
        schedule = self.sched_name.get_active_text()
        mailto = self.setting_mailto.get_active()

        if not schema or not schedule or not command or "<target>" in command:
            dlg = HIGAlertDialog(
                self,
                message_format=_(
                    "Scheduling Schema - Error\
 while saving."
                ),
                secondary_text=_(
                    'There is some error in at \
least one of the following fields: "Schema name", "Command" or "Scheduling\
 Profile"\n\nCheck if "Schema name" is not empty.\nCheck if "Command" does\
 contain "<target>" on it.\nCheck if there is some "Scheduling Profile" \
selected.'
                ),
            )

            dlg.run()
            dlg.destroy()
            return

        if mailto and not self.setting_smtp.get_active_text():
            dlg = HIGAlertDialog(
                self,
                message_format=_(
                    "Scheduling Schema - Error\
 while saving."
                ),
                secondary_text=_(
                    "You need to create a \
a SMTP Schema for sending email."
                ),
            )

            dlg.run()
            dlg.destroy()
            return

        # check for output existance
        if self.setting_saveto.get_active() and not os.path.isdir(self.setting_saveto_entry.get_text()):

            dlg = HIGAlertDialog(
                self,
                message_format=_(
                    "Scheduling Schema - Error\
 while saving."
                ),
                secondary_text=_(
                    "You especified an invalid \
directory to save scans output."
                ),
            )

            dlg.run()
            dlg.destroy()
            return

        # write schema to file
        s_cfg = ConfigParser()
        s_cfg.read(Path.sched_schemas)

        if not s_cfg.has_section(schema):
            new_sec = True
            s_cfg.add_section(schema)
        else:
            new_sec = False

        s_cfg.set(schema, "profile", schedule)
        s_cfg.set(schema, "command", command)
        if self.setting_enabled.get_active():
            s_cfg.set(schema, "enabled", "1")
        else:
            s_cfg.set(schema, "enabled", "0")
        if self.setting_addtoinv.get_active():
            s_cfg.set(schema, "addtoinv", "1")
        else:
            s_cfg.set(schema, "addtoinv", "0")
        if self.setting_saveto.get_active():
            s_cfg.set(schema, "saveto", self.setting_saveto_entry.get_text())
        else:
            s_cfg.set(schema, "saveto", "")
        if mailto:
            s_cfg.set(schema, "mailto", self.setting_mailto_entry.get_text())
            s_cfg.set(schema, "smtp", self.setting_smtp.get_active_text())
        else:
            s_cfg.set(schema, "mailto", "")
            s_cfg.set(schema, "smtp", "")

        s_cfg.write(open(Path.sched_schemas, "w"))

        if new_sec:
            self.load_schemas()

        if self.daddy:
            self.daddy.load_schemas()

    def _save_schema_and_leave(self, event):
        """
        Save current schema and close editor.
        """
        self._save_schema(None)
        self._exit(None)

    def _show_help(self, event):
        """
        Show help for Scan Scheduler Editor.
        """
        show_help(self, "scheduler.html#setting-up-a-schedule")

    def __set_props(self):
        """
        Set window properties.
        """
        self.set_title(self.wtitle)
        self.set_default_size(440, -1)

    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)

    def _exit(self, event):
        """
        Close current and window and profile editor if it is running.
        """
        if self.profile_running:
            self.profile_running._exit(None)

        if self.daddy:
            self.daddy.schemawin = None

        self.destroy()

    def _get_profile_running(self):
        """
        Get profile editor running instance.
        """
        return self.__profilerunning

    def _set_profile_running(self, running):
        """
        Set profile editor instance.
        """
        self.__profilerunning = running

    # Properties
    profile_running = property(_get_profile_running, _set_profile_running)
class HighlightProperty(object):
    def __init__(self, property_name, property):
        self.__create_widgets()

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

        self.__connect_buttons()

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

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

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


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

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

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

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


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

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

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

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

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

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

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

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

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

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

        self.example_label.set_attributes(attributes)


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

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

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

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

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

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

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

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

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

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

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

    label = property(get_label, set_label)
    example = property(get_example, set_example)
    bold = property(get_bold, set_bold)
    italic = property(get_italic, set_italic)
    underline = property(get_underline, set_underline)
Beispiel #55
0
class SMTPSetup(HIGWindow):
    """
    SMTP editor.
    """
    
    def __init__(self):
        HIGWindow.__init__(self)
        
        self.wtitle = _("SMTP Account Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # schemas name
        self.schema_name_lbl = HIGEntryLabel(_("Schema name"))
        self.schema_name = gtk.combo_box_entry_new_text()
        self.schema_name.connect('changed', self._check_schema)
        # smtp server
        self.smtp_server_lbl = HIGEntryLabel(_("Server"))
        self.smtp_server = gtk.Entry()
        self.smtp_port_lbl = HIGEntryLabel(_("Port"))
        self.smtp_port = gtk.Entry()
        # sending mail..
        self.smtp_mailfrom_lbl = HIGEntryLabel(_("Mail from"))
        self.smtp_mailfrom = gtk.Entry()
        # smtp auth
        self.smtp_need_auth = gtk.CheckButton(_("Servers requires authentication"))
        self.smtp_need_auth.connect('toggled', self._auth_need)
        self.smtp_login_lbl = HIGEntryLabel(_("Username"))
        self.smtp_login = gtk.Entry()
        self.smtp_passwd_lbl = HIGEntryLabel(_("Password"))
        self.smtp_passwd = gtk.Entry()
        self.smtp_passwd.set_visibility(False)
        self._auth_need(None)
        # smtp encryption
        self.smtp_encrypt_tls = gtk.CheckButton(_("Use TLS Encryption"))

        """
        Missing: SSL encryption,
                 Other authentication methods.
        """ 

        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect('clicked', self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect('clicked', self._save_schema)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect('clicked', self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect('clicked', self._save_schema_and_leave)
        
        self.load_schemas()
        
        self.__set_props()
        self.__do_layout()

        self.connect('destroy', self._exit)
        

    def load_schemas(self):
        """
        Load schemas profiles.
        """
        schemas = ConfigParser()
        schemas.read(Path.smtp_schemas)
        
        self.sections = [ ]
        self.schema_name.get_model().clear()
        for section in schemas.sections():
            self.sections.append(section)
            self.schema_name.append_text(section)
            
        self.schema_name.set_active(0)
        self._check_schema(None)

    
    def _load_schema(self):
        """
        Load current set schedule schema.
        """
        schema = ConfigParser()
        schema.read(Path.smtp_schemas)
        
        enable = {'tls':self.smtp_encrypt_tls.set_active,
                  'auth':self.smtp_need_auth.set_active}
        values = {'user':self.smtp_login.set_text,
                  'pass':self.smtp_passwd.set_text,
                  'server':self.smtp_server.set_text,
                  'port':self.smtp_port.set_text,
                  'mailfrom':self.smtp_mailfrom.set_text}
        
        for item in schema.items(self.schema_name.get_active_text()):
            if item[0] in ('tls', 'auth'):
                enable[item[0]](int(item[1]))
            else:
                values[item[0]](item[1])
                

    def _check_schema(self, event):
        """
        Check if current text in schema_name combobox is a schema name.
        """
        if self.schema_name.get_active_text() in self.sections: 
            # load schema
            self._load_schema()
        else:
            # reset to default values
            self.smtp_mailfrom.set_text('')
            self.smtp_server.set_text('')
            self.smtp_port.set_text('')
            self.smtp_encrypt_tls.set_active(False)
            self.smtp_login.set_text('')
            self.smtp_passwd.set_text('')
            self.smtp_need_auth.set_active(False)
            self._auth_need(None)
            
    
    def _auth_need(self, event):
        """
        SMTP Authentication toggled.
        """
        status = self.smtp_need_auth.get_active()
        self.smtp_login.set_sensitive(status)
        self.smtp_passwd.set_sensitive(status)
        self.smtp_login_lbl.set_sensitive(status)
        self.smtp_passwd_lbl.set_sensitive(status)
    
    
    def _save_schema(self, event):
        """
        Save current schema.
        """
        schema = self.schema_name.get_active_text()
        server = self.smtp_server.get_text()
        port = self.smtp_port.get_text()
        auth = self.smtp_need_auth.get_active()
        mailfrom = self.smtp_mailfrom.get_text()
        
        if auth:
            user = self.smtp_login.get_text()
            passwd = self.smtp_passwd.get_text()
        
        if auth and not (user and passwd):
            dlg = HIGAlertDialog(self, 
                                 message_format=_('SMTP Schema - Error\
 while saving.'),
                                 secondary_text=_("You need to specify an \
username and password for this SMTP Schema."))
            
            dlg.run()
            dlg.destroy()
            return
        
        if not schema or not server or not port or not mailfrom:
            dlg = HIGAlertDialog(self, 
                                 message_format=_('SMTP Schema - Error\
 while saving.'),
                                 secondary_text=_("The following fields \
need to be filled: Schema Name, Server, Port and Mail from."))
            
            dlg.run()
            dlg.destroy()
            return
        
        # write schema to file
        s_cfg = ConfigParser()
        s_cfg.read(Path.smtp_schemas)
        
        if not s_cfg.has_section(schema):
            new_sec = True
            s_cfg.add_section(schema)
        else:
            new_sec = False
        
        if auth:
            s_cfg.set(schema, 'auth', '1')
        else:
            s_cfg.set(schema, 'auth', '0')
            user = ''
            passwd = ''
            
        s_cfg.set(schema, 'port', port)
        s_cfg.set(schema, 'server', server)
        s_cfg.set(schema, 'user', user)
        s_cfg.set(schema, 'pass', passwd)
        s_cfg.set(schema, 'mailfrom', mailfrom)
        
        if self.smtp_encrypt_tls.get_active():
            s_cfg.set(schema, 'tls', '1')
        else:
            s_cfg.set(schema, 'tls', '0')
            
        s_cfg.write(open(Path.smtp_schemas, 'w'))
        
        if new_sec:
            self.load_schemas()
        
        
    def _save_schema_and_leave(self, event):
        """
        Save current schema and close editor.
        """
        self._save_schema(None)
        self._exit(None)
        
        
    def __set_props(self):
        """
        Set window properties.
        """
        self.set_title(self.wtitle)
       
    
    def _show_help(self, event):
        """
        Open SMTP Setup help
        """
        show_help(self, "smtpsetup.html")


    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 _exit(self, event):
        """
        Close current window.
        """
        self.destroy()
class SchedProfileEditor(HIGWindow):
    """
    Scheduling Profiles Editor
    """

    def __init__(self, daddy, profile=None):
        HIGWindow.__init__(self)
        self.daddy = daddy

        self.wtitle = _("Scheduling Profiles Editor")
        self.start_profile = profile

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # profiles name
        self.schedp_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.schedp_name = gtk.combo_box_entry_new_text()
        self.schedp_name.connect("changed", self._check_profile)
        # cron format
        self.cron_frame = HIGFrame(_("Schedule"))
        self.cron_minute_lbl = HIGEntryLabel(_("Minute"))
        self.cron_minute = gtk.Entry()
        self.cron_hour_lbl = HIGEntryLabel(_("Hour"))
        self.cron_hour = gtk.Entry()
        self.cron_day_lbl = HIGEntryLabel(_("Day of month"))
        self.cron_day = gtk.Entry()
        self.cron_month_lbl = HIGEntryLabel(_("Month"))
        self.cron_month = gtk.Entry()
        self.cron_weekday_lbl = HIGEntryLabel(_("Weekday"))
        self.cron_weekday = gtk.Entry()
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect("clicked", self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect("clicked", self._save_profile)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect("clicked", self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect("clicked", self._save_profile_and_leave)

        self.load_profiles()
        self.__set_props()
        self.__do_layout()

        self.connect("destroy", self._exit)

    def load_profiles(self):
        """
        Load scheduling profiles.
        """
        profiles = ConfigParser()
        profiles.read(Path.sched_profiles)

        self.sections = []
        ind = 0
        for indx, section in enumerate(profiles.sections()):
            self.sections.append(section)
            self.schedp_name.append_text(section)
            if section == self.start_profile:
                ind = indx

        self.schedp_name.set_active(ind)

        self._check_profile(None)

    def _load_profile(self):
        """
        Load current set schedule profile.
        """
        profile = ConfigParser()
        profile.read(Path.sched_profiles)

        values = {
            "minute": self.cron_minute.set_text,
            "hour": self.cron_hour.set_text,
            "day": self.cron_day.set_text,
            "month": self.cron_month.set_text,
            "weekday": self.cron_weekday.set_text,
        }

        for item in profile.items(self.schedp_name.get_active_text()):
            values[item[0]](item[1])

    def _check_profile(self, event):
        """
        Check if current text in schedp_name combobox is a profile name.
        """
        if self.schedp_name.get_active_text() in self.sections:
            self._load_profile()
        else:
            self.cron_minute.set_text("")
            self.cron_hour.set_text("")
            self.cron_day.set_text("")
            self.cron_month.set_text("")
            self.cron_weekday.set_text("")

    def _save_profile(self, event):
        """
        Save scheduling profile.
        """
        pname = self.schedp_name.get_active_text()
        if not len(pname):
            dlg = HIGAlertDialog(
                self,
                message_format=_(
                    "Scheduling Profile - Error \
while saving"
                ),
                secondary_text=_(
                    "You need to specify a name \
for Profile."
                ),
            )
            dlg.run()
            dlg.destroy()
            return

        parser = CronParser()
        minute = self.cron_minute.get_text()
        hour = self.cron_hour.get_text()
        day = self.cron_day.get_text()
        month = self.cron_month.get_text()
        weekday = self.cron_weekday.get_text()
        try:
            parser.parse_minute(minute)
            parser.parse_hour(hour)
            parser.parse_day(day)
            parser.parse_month(month)
            parser.parse_weekday(weekday)
        except Exception, e:
            dlg = HIGAlertDialog(
                self,
                message_format=_(
                    "Scheduling Profile - Error \
while saving"
                ),
                secondary_text=_(
                    "Check your cron syntax and \
try to save again."
                ),
            )
            dlg.run()
            dlg.destroy()
            return

        # write profile to file
        p_cfg = ConfigParser()
        p_cfg.read(Path.sched_profiles)

        if not p_cfg.has_section(pname):
            new_sec = True
            p_cfg.add_section(pname)
        else:
            new_sec = False

        p_cfg.set(pname, "minute", minute)
        p_cfg.set(pname, "hour", hour)
        p_cfg.set(pname, "day", day)
        p_cfg.set(pname, "month", month)
        p_cfg.set(pname, "weekday", weekday)

        p_cfg.write(open(Path.sched_profiles, "w"))

        if new_sec:  # update daddy scheduling profiles list
            self.daddy._load_pscheds()
    def __init__(self, daddy=None):
        HIGWindow.__init__(self)

        self.daddy = daddy
        self.wtitle = _("Scan Scheduler Editor")

        # header
        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
        self.ttitle = HIGEntryLabel("")
        self.ttitle.set_line_wrap(False)
        self.ttitle.set_markup(self.title_markup % self.wtitle)
        self.umit_logo = gtk.Image()
        self.umit_logo.set_from_file(logo)
        # schemas name
        self.schema_name_lbl = HIGEntryLabel(_("Schema Name"))
        self.schema_name = gtk.combo_box_entry_new_text()
        self.schema_name.connect("changed", self._check_schema)
        # target and scan profiles
        # self.target_lbl = HIGEntryLabel(_("Target"))
        # self.target = gtk.Entry()
        self.scan_name_lbl = HIGEntryLabel(_("Scan Profile"))
        self.scan_name = ProfileCombo()
        self.scan_name.update()
        self.scan_name.set_active(0)
        self.scan_name.connect("changed", self._set_scan_command)
        # scan command
        self.scan_command_lbl = HIGEntryLabel(_("Command"))
        self.scan_command = gtk.Entry()
        # scheduling profile
        self.sched_name_lbl = HIGEntryLabel(_("Scheduling Profile"))
        self.sched_name = gtk.combo_box_new_text()
        self.sched_name_edit = gtk.Button(stock=gtk.STOCK_EDIT)
        blbl = self.sched_name_edit.get_children()[0].get_children()[0].get_children()[1]
        blbl.set_text(_("Edit Profiles"))
        self.sched_name_edit.connect("clicked", self._edit_schedprofiles)
        # schema settings
        self.schema_sett_frame = HIGFrame()
        self.setting_saveto = gtk.CheckButton(_("Save outputs to"))
        self.setting_saveto_entry = gtk.Entry()
        self.setting_saveto_browse = gtk.Button(_("..."))
        self.setting_saveto_browse.connect("clicked", self._select_saveto)
        self.setting_mailto = gtk.CheckButton(_("Send output to email"))
        self.setting_mailto_entry = gtk.Entry()
        self.setting_smtp_lbl = HIGEntryLabel(_("SMTP Schema"))
        self.setting_smtp = gtk.combo_box_new_text()
        self.setting_addtoinv = gtk.CheckButton(_("Add to the Inventory"))
        self.setting_enabled = gtk.CheckButton(_("Enabled"))
        # bottom buttons
        self.help = HIGButton(stock=gtk.STOCK_HELP)
        self.help.connect("clicked", self._show_help)
        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
        self.apply.connect("clicked", self._save_schema)
        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel.connect("clicked", self._exit)
        self.ok = HIGButton(stock=gtk.STOCK_OK)
        self.ok.connect("clicked", self._save_schema_and_leave)

        self.load_smtp_schemas()
        self._set_scan_command(None)
        self.profile_running = None  # no SchedProfileEditor instance is running.
        self._load_pscheds()
        self.load_schemas()

        self.__set_props()
        self.__do_layout()

        self.connect("destroy", self._exit)