예제 #1
0
    def __create_widgets(self):

        ###
        # Vertical box to keep 3 boxes
        self.main_whole_box = HIGVBox()

        self.upper_box = HIGVBox()
        self.middle_box = HIGHBox()
        self.lower_box = HIGHBox()

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

        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_name_entry.connect('enter-notify-event',
                                        self.update_help_name)
        self.profile_description_label = HIGEntryLabel(_('Description'))
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_scroll.set_border_width(0)
        self.profile_description_text = HIGTextView()
        self.profile_description_text.connect('motion-notify-event',
                                              self.update_help_desc)

        # Buttons
        self.buttons_hbox = HIGHBox()

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

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

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

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)

        ###
        self.help_vbox = HIGVBox()
        self.help_label = HIGSectionLabel(_('Help'))
        self.help_scroll = HIGScrolledWindow()
        self.help_scroll.set_border_width(0)
        self.help_field = HIGTextView()
        self.help_field.set_cursor_visible(False)
        self.help_field.set_left_margin(5)
        self.help_field.set_editable(False)
        self.help_vbox.set_size_request(200, -1)
예제 #2
0
    def __create_widgets(self):

        ###
        # Vertical box to keep 3 boxes
        self.main_whole_box = HIGVBox()

        self.upper_box = HIGHBox()
        self.middle_box = HIGHBox()
        self.lower_box = HIGHBox()

        #self.main_vbox = HIGVBox()
        self.command_entry = gtk.Entry()
        self.command_entry_changed_cb_id = self.command_entry.connect(
                "changed", self.command_entry_changed_cb)

        self.scan_button = HIGButton(_("Scan"))
        self.scan_button.connect("clicked", self.run_scan)

        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_name_entry.connect(
                'enter-notify-event', self.update_help_name)
        self.profile_description_label = HIGEntryLabel(_('Description'))
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_scroll.set_border_width(0)
        self.profile_description_text = HIGTextView()
        self.profile_description_text.connect(
                'motion-notify-event', self.update_help_desc)

        # Buttons
        self.buttons_hbox = HIGHBox()

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

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

        self.save_button = HIGButton(_("Save Changes"), stock=gtk.STOCK_SAVE)
        self.save_button.connect('clicked', self.save_profile)

        ###
        self.help_vbox = HIGVBox()
        self.help_label = HIGSectionLabel(_('Help'))
        self.help_scroll = HIGScrolledWindow()
        self.help_scroll.set_border_width(0)
        self.help_field = HIGTextView()
        self.help_field.set_cursor_visible(False)
        self.help_field.set_left_margin(5)
        self.help_field.set_editable(False)
        self.help_vbox.set_size_request(200, -1)
예제 #3
0
class ScanResultNotebook(HIGNotebook):
    """This is the right side of a ScanResult, the notebook with the tabs such
    as "Nmap Output"."""
    def __init__(self, inventory, scans_store):
        HIGNotebook.__init__(self)
        self.set_border_width(5)

        self.__create_widgets(inventory, scans_store)

        self.scans_list.scans_list.connect(
                "row-activated", self._scan_row_activated)

        self.append_page(self.nmap_output_page, gtk.Label(_('Nmap Output')))
        self.append_page(self.open_ports_page, gtk.Label(_('Ports / Hosts')))
        self.append_page(self.topology_page, gtk.Label(_('Topology')))
        self.append_page(self.host_details_page, gtk.Label(_('Host Details')))
        self.append_page(self.scans_list_page, gtk.Label(_('Scans')))

    def host_mode(self):
        self.open_ports.host.host_mode()

    def port_mode(self):
        self.open_ports.host.port_mode()

    def __create_widgets(self, inventory, scans_store):
        self.open_ports_page = HIGVBox()
        self.nmap_output_page = HIGVBox()
        self.topology_page = HIGVBox()
        self.host_details_page = HIGScrolledWindow()
        self.host_details_vbox = HIGVBox()
        self.scans_list_page = HIGVBox()

        self.open_ports = ScanOpenPortsPage()
        self.nmap_output = ScanNmapOutputPage(scans_store)
        self.topology = TopologyPage(inventory)
        self.scans_list = ScanScanListPage(scans_store)

        self.no_selected = gtk.Label(_('No host selected.'))
        self.host_details = self.no_selected

        self.open_ports_page.add(self.open_ports)
        self.nmap_output_page.add(self.nmap_output)
        self.topology_page.add(self.topology)
        self.scans_list_page.add(self.scans_list)

        self.host_details_page.add_with_viewport(self.host_details_vbox)
        self.host_details_vbox._pack_expand_fill(self.host_details)

    def _scan_row_activated(self, treeview, path, view_column):
        """Switch back to the Nmap Output view when a scan is activated
        (double-clicked) on the scans list."""
        self.nmap_output.set_active_iter(treeview.get_model().get_iter(path))
        self.set_current_page(0)
예제 #4
0
    def make_arguments_widget(self):
        """Creates and packs widgets related to arguments box."""
        vbox = gtk.VBox()
        vbox.pack_start(gtk.Label(_("Arguments")), False, False, 0)
        arg_window = HIGScrolledWindow()
        arg_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        arg_window.set_shadow_type(gtk.SHADOW_OUT)

        arg_listview = gtk.TreeView(self.arg_liststore)
        arg_listview.connect("motion-notify-event", self.update_help_arg_cb)
        argument = gtk.CellRendererText()
        self.value = gtk.CellRendererText()
        self.value.connect("edited", self.value_edited_cb, self.arg_liststore)
        arg_col = gtk.TreeViewColumn("Arguments\t")
        val_col = gtk.TreeViewColumn("values")
        arg_listview.append_column(arg_col)
        arg_listview.append_column(val_col)
        arg_col.pack_start(argument, True)
        arg_col.add_attribute(argument, "text", 0)
        val_col.pack_start(self.value, True)
        val_col.add_attribute(self.value, "text", 1)

        arg_window.add(arg_listview)
        vbox.pack_start(arg_window, True, True, 0)

        return vbox
예제 #5
0
    def __init__(self, scans_store):
        HIGVBox.__init__(self)

        self.set_spacing(4)

        scans_store.connect("row-changed", self._row_changed)

        self.scans_list = gtk.TreeView(scans_store)
        self.scans_list.get_selection().connect(
                "changed", self._selection_changed)

        status_col = gtk.TreeViewColumn(_("Status"))
        cell = gtk.CellRendererText()
        status_col.pack_start(cell)
        status_col.set_cell_data_func(cell, status_data_func)
        self.scans_list.append_column(status_col)

        command_col = gtk.TreeViewColumn(_("Command"))
        cell = gtk.CellRendererText()
        command_col.pack_start(cell)
        command_col.set_cell_data_func(cell, command_data_func)
        self.scans_list.append_column(command_col)

        scrolled_window = HIGScrolledWindow()
        scrolled_window.set_border_width(0)
        scrolled_window.add(self.scans_list)

        self.pack_start(scrolled_window, True, True)

        hbox = HIGHBox()
        buttonbox = gtk.HButtonBox()
        buttonbox.set_layout(gtk.BUTTONBOX_START)
        buttonbox.set_spacing(4)

        self.append_button = HIGButton(_("Append Scan"), gtk.STOCK_ADD)
        buttonbox.pack_start(self.append_button, False)

        self.remove_button = HIGButton(_("Remove Scan"), gtk.STOCK_REMOVE)
        buttonbox.pack_start(self.remove_button, False)

        self.cancel_button = HIGButton(_("Cancel Scan"), gtk.STOCK_CANCEL)
        buttonbox.pack_start(self.cancel_button, False)

        hbox.pack_start(buttonbox, padding=4)

        self.pack_start(hbox, False, padding=4)

        self._update()
예제 #6
0
 def make_description_widget(self):
     """Creates and packs widgets related to displaying the description
     box."""
     sw = HIGScrolledWindow()
     sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
     sw.set_shadow_type(gtk.SHADOW_OUT)
     sw.set_border_width(5)
     text_view = gtk.TextView()
     text_view.connect("enter-notify-event", self.update_help_desc_cb)
     self.text_buffer = text_view.get_buffer()
     self.text_buffer.create_tag("Usage", font="Monospace")
     self.text_buffer.create_tag("Output", font="Monospace")
     text_view.set_wrap_mode(gtk.WRAP_WORD)
     text_view.set_editable(False)
     text_view.set_justification(gtk.JUSTIFY_LEFT)
     sw.add(text_view)
     return sw
예제 #7
0
    def __create_widgets(self, inventory, scans_store):
        self.open_ports_page = HIGVBox()
        self.nmap_output_page = HIGVBox()
        self.topology_page = HIGVBox()
        self.host_details_page = HIGScrolledWindow()
        self.host_details_vbox = HIGVBox()
        self.scans_list_page = HIGVBox()

        self.open_ports = ScanOpenPortsPage()
        self.nmap_output = ScanNmapOutputPage(scans_store)
        self.topology = TopologyPage(inventory)
        self.scans_list = ScanScanListPage(scans_store)

        self.no_selected = gtk.Label(_('No host selected.'))
        self.host_details = self.no_selected

        self.open_ports_page.add(self.open_ports)
        self.nmap_output_page.add(self.nmap_output)
        self.topology_page.add(self.topology)
        self.scans_list_page.add(self.scans_list)

        self.host_details_page.add_with_viewport(self.host_details_vbox)
        self.host_details_vbox._pack_expand_fill(self.host_details)
    def __init__(self, scans_store):
        HIGVBox.__init__(self)

        self.set_spacing(4)

        scans_store.connect("row-changed", self._row_changed)

        self.scans_list = gtk.TreeView(scans_store)
        self.scans_list.get_selection().connect("changed",
                                                self._selection_changed)

        status_col = gtk.TreeViewColumn(_("Status"))
        cell = gtk.CellRendererText()
        status_col.pack_start(cell)
        status_col.set_cell_data_func(cell, status_data_func)
        self.scans_list.append_column(status_col)

        command_col = gtk.TreeViewColumn(_("Command"))
        cell = gtk.CellRendererText()
        command_col.pack_start(cell)
        command_col.set_cell_data_func(cell, command_data_func)
        self.scans_list.append_column(command_col)

        scrolled_window = HIGScrolledWindow()
        scrolled_window.set_border_width(0)
        scrolled_window.add(self.scans_list)

        self.pack_start(scrolled_window, True, True)

        hbox = HIGHBox()
        buttonbox = gtk.HButtonBox()
        buttonbox.set_layout(gtk.BUTTONBOX_START)
        buttonbox.set_spacing(4)

        self.append_button = HIGButton(_("Append Scan"), gtk.STOCK_ADD)
        buttonbox.pack_start(self.append_button, False)

        self.remove_button = HIGButton(_("Remove Scan"), gtk.STOCK_REMOVE)
        buttonbox.pack_start(self.remove_button, False)

        self.cancel_button = HIGButton(_("Cancel Scan"), gtk.STOCK_CANCEL)
        buttonbox.pack_start(self.cancel_button, False)

        hbox.pack_start(buttonbox, padding=4)

        self.pack_start(hbox, False, padding=4)

        self._update()
예제 #9
0
파일: About.py 프로젝트: EliseuTorres/nmap
    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.hbox = HIGHBox()
        self.notebook = HIGNotebook()
        self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)

        self.written_by_scroll = HIGScrolledWindow()
        self.written_by_text = HIGTextView()

        self.design_scroll = HIGScrolledWindow()
        self.design_text = HIGTextView()

        self.soc2007_scroll = HIGScrolledWindow()
        self.soc2007_text = HIGTextView()

        self.contributors_scroll = HIGScrolledWindow()
        self.contributors_text = HIGTextView()

        self.translation_scroll = HIGScrolledWindow()
        self.translation_text = HIGTextView()

        self.nokia_scroll = HIGScrolledWindow()
        self.nokia_text = HIGTextView()
예제 #10
0
class ProfileEditor(HIGWindow):
    def __init__(self, command=None, profile_name=None,
            deletable=True, overwrite=False):
        HIGWindow.__init__(self)
        self.connect("delete_event", self.exit)
        self.set_title(_('Profile Editor'))
        self.set_position(gtk.WIN_POS_CENTER)

        self.deletable = deletable
        self.profile_name = profile_name
        self.overwrite = overwrite

        # Used to block recursive updating of the command entry when the
        # command entry causes the OptionBuilder widgets to change.
        self.inhibit_command_update = False

        self.__create_widgets()
        self.__pack_widgets()

        self.profile = CommandProfile()

        self.ops = NmapOptions()
        if profile_name:
            log.debug("Showing profile %s" % profile_name)
            prof = self.profile.get_profile(profile_name)

            # Interface settings
            self.profile_name_entry.set_text(profile_name)
            self.profile_description_text.get_buffer().set_text(
                    prof['description'])

            command_string = prof['command']
            self.ops.parse_string(command_string)
        if command:
            self.ops.parse_string(command)

        self.option_builder = OptionBuilder(
                Path.profile_editor, self.ops,
                self.update_command, self.help_field.get_buffer())
        log.debug("Option groups: %s" % str(self.option_builder.groups))
        log.debug("Option section names: %s" % str(
            self.option_builder.section_names))
        #log.debug("Option tabs: %s" % str(self.option_builder.tabs))

        for tab in self.option_builder.groups:
            self.__create_tab(
                    _(tab),
                    _(self.option_builder.section_names[tab]),
                    self.option_builder.tabs[tab])

        self.update_command()

    def command_entry_changed_cb(self, widget):
        command_string = self.command_entry.get_text().decode("UTF-8")
        self.ops.parse_string(command_string)
        self.inhibit_command_update = True
        self.option_builder.update()
        self.inhibit_command_update = False

    def update_command(self):
        """Regenerate and display the command."""
        if not self.inhibit_command_update:
            # Block recursive updating of the OptionBuilder widgets when they
            # cause a change in the command entry.
            self.command_entry.handler_block(self.command_entry_changed_cb_id)
            self.command_entry.set_text(self.ops.render_string())
            self.command_entry.handler_unblock(
                    self.command_entry_changed_cb_id)

    def update_help_name(self, widget, extra):
        self.help_field.get_buffer().set_text(
                "Profile name\n\nThis is how the profile will be identified "
                "in the drop-down combo box in the scan tab.")

    def update_help_desc(self, widget, extra):
        self.help_field.get_buffer().set_text(
                "Description\n\nThe description is a full description of what "
                "the scan does, which may be long.")

    def __create_widgets(self):

        ###
        # Vertical box to keep 3 boxes
        self.main_whole_box = HIGVBox()

        self.upper_box = HIGHBox()
        self.middle_box = HIGHBox()
        self.lower_box = HIGHBox()

        #self.main_vbox = HIGVBox()
        self.command_entry = gtk.Entry()
        self.command_entry_changed_cb_id = self.command_entry.connect(
                "changed", self.command_entry_changed_cb)

        self.scan_button = HIGButton(_("Scan"))
        self.scan_button.connect("clicked", self.run_scan)

        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_name_entry.connect(
                'enter-notify-event', self.update_help_name)
        self.profile_description_label = HIGEntryLabel(_('Description'))
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_scroll.set_border_width(0)
        self.profile_description_text = HIGTextView()
        self.profile_description_text.connect(
                'motion-notify-event', self.update_help_desc)

        # Buttons
        self.buttons_hbox = HIGHBox()

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

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

        self.save_button = HIGButton(_("Save Changes"), stock=gtk.STOCK_SAVE)
        self.save_button.connect('clicked', self.save_profile)

        ###
        self.help_vbox = HIGVBox()
        self.help_label = HIGSectionLabel(_('Help'))
        self.help_scroll = HIGScrolledWindow()
        self.help_scroll.set_border_width(0)
        self.help_field = HIGTextView()
        self.help_field.set_cursor_visible(False)
        self.help_field.set_left_margin(5)
        self.help_field.set_editable(False)
        self.help_vbox.set_size_request(200, -1)
        ###

    def __pack_widgets(self):

        ###
        self.add(self.main_whole_box)

        # Packing command entry to upper box
        self.upper_box._pack_expand_fill(self.command_entry)
        self.upper_box._pack_noexpand_nofill(self.scan_button)

        # Packing notebook (left) and help box (right) to middle box
        self.middle_box._pack_expand_fill(self.notebook)
        self.middle_box._pack_expand_fill(self.help_vbox)

        # Packing buttons to lower box
        self.lower_box.pack_end(self.buttons_hbox)

        # Packing the three vertical boxes to the main box
        self.main_whole_box._pack_noexpand_nofill(self.upper_box)
        self.main_whole_box._pack_expand_fill(self.middle_box)
        self.main_whole_box._pack_noexpand_nofill(self.lower_box)
        ###

        # Packing profile information tab on notebook
        self.notebook.append_page(
                self.profile_info_vbox, gtk.Label(_('Profile')))
        self.profile_info_vbox.set_border_width(5)
        table = HIGTable()
        self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label)
        self.profile_info_vbox._pack_expand_fill(HIGSpacer(table))

        self.profile_description_scroll.add(self.profile_description_text)

        vbox_desc = HIGVBox()
        vbox_desc._pack_noexpand_nofill(self.profile_description_label)
        vbox_desc._pack_expand_fill(hig_box_space_holder())

        vbox_ann = HIGVBox()
        vbox_ann._pack_expand_fill(hig_box_space_holder())

        table.attach(
                self.profile_name_label, 0, 1, 0, 1, xoptions=0, yoptions=0)
        table.attach(self.profile_name_entry, 1, 2, 0, 1, yoptions=0)
        table.attach(vbox_desc, 0, 1, 1, 2, xoptions=0)
        table.attach(self.profile_description_scroll, 1, 2, 1, 2)

        # Packing buttons on button_hbox
        self.buttons_hbox._pack_expand_fill(hig_box_space_holder())
        if self.deletable:
            self.buttons_hbox._pack_noexpand_nofill(self.delete_button)
        self.buttons_hbox._pack_noexpand_nofill(self.cancel_button)
        self.buttons_hbox._pack_noexpand_nofill(self.save_button)

        self.buttons_hbox.set_border_width(5)
        self.buttons_hbox.set_spacing(6)

        ###
        self.help_vbox._pack_noexpand_nofill(self.help_label)
        self.help_vbox._pack_expand_fill(self.help_scroll)
        self.help_scroll.add(self.help_field)
        self.help_vbox.set_border_width(1)
        self.help_vbox.set_spacing(1)
        ###

    def __create_tab(self, tab_name, section_name, tab):
        log.debug(">>> Tab name: %s" % tab_name)
        log.debug(">>>Creating profile editor section: %s" % section_name)
        vbox = HIGVBox()
        if tab.notscripttab:  # if notscripttab is set
            table = HIGTable()
            table.set_row_spacings(2)
            section = HIGSectionLabel(section_name)
            vbox._pack_noexpand_nofill(section)
            vbox._pack_noexpand_nofill(HIGSpacer(table))
            vbox.set_border_width(5)
            tab.fill_table(table, True)
        else:
            hbox = tab.get_hmain_box()
            vbox.pack_start(hbox, True, True, 0)
        self.notebook.append_page(vbox, gtk.Label(tab_name))

    def save_profile(self, widget):
        if self.overwrite:
            self.profile.remove_profile(self.profile_name)
        profile_name = self.profile_name_entry.get_text()
        if profile_name == '':
            alert = HIGAlertDialog(
                    message_format=_('Unnamed profile'),
                    secondary_text=_(
                        'You must provide a name for this profile.'))
            alert.run()
            alert.destroy()

            self.profile_name_entry.grab_focus()

            return None

        command = self.ops.render_string()

        buf = self.profile_description_text.get_buffer()
        description = buf.get_text(
                buf.get_start_iter(), buf.get_end_iter())

        try:
            self.profile.add_profile(
                    profile_name,
                    command=command,
                    description=description)
        except ValueError:
            alert = HIGAlertDialog(
                    message_format=_('Disallowed profile name'),
                    secondary_text=_('Sorry, the name "%s" is not allowed due '
                        'to technical limitations. (The underlying '
                        'ConfigParser used to store profiles does not allow '
                        'it.) Choose a different name.' % profile_name))
            alert.run()
            alert.destroy()
            return

        self.scan_interface.toolbar.profile_entry.update()
        self.destroy()

    def clean_profile_info(self):
        self.profile_name_entry.set_text('')
        self.profile_description_text.get_buffer().set_text('')

    def set_scan_interface(self, interface):
        self.scan_interface = interface

    def exit(self, *args):
        self.destroy()

    def delete_profile(self, widget=None, extra=None):
        if self.deletable:
            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! ClickOk 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 True
            self.profile.remove_profile(self.profile_name)

        self.update_profile_entry()
        self.destroy()

    def run_scan(self, widget=None):
        command_string = self.command_entry.get_text().decode("UTF-8")
        self.scan_interface.command_toolbar.command = command_string
        self.scan_interface.start_scan_cb()
        self.exit()

    def update_profile_entry(self, widget=None, extra=None):
        self.scan_interface.toolbar.profile_entry.update()
        list = self.scan_interface.toolbar.profile_entry.get_model()
        length = len(list)
        if length > 0:
            self.scan_interface.toolbar.profile_entry.set_active(0)
예제 #11
0
class ScriptInterface:
    # Timeout, in milliseconds, after the user stops typing and we update the
    # interface from --script.
    SCRIPT_LIST_DELAY = 500
    # Timeout, in milliseconds, between polls of the Nmap subprocess.
    NMAP_DELAY = 200

    def __init__(self, root_tabs, ops, update_command, help_buf):
        self.hmainbox = HIGHBox(False, 0)
        self.notscripttab = False  # show profile editor it is a script tab
        self.nmap_process = None
        self.script_list_timeout_id = None
        self.nmap_timeout_id = None
        self.chk_nmap_timeout_id = None
        self.script_file_chooser = None
        self.ops = ops
        self.update_command = update_command
        self.help_buf = help_buf
        self.arg_values = {}
        self.current_arguments = []
        self.set_help_texts()
        self.prev_script_spec = None
        self.focusedentry = None

        self.liststore = gtk.ListStore(str, "gboolean", object)

        self.file_liststore = gtk.ListStore(str, "gboolean")

        # Arg name, arg value, (name, desc) tuple.
        self.arg_liststore = gtk.ListStore(str, str, object)

        # This is what is shown initially. After the initial Nmap run to get
        # the list of script is finished, this will be replaced with a TreeView
        # showing the scripts or an error message.
        self.script_list_container = gtk.VBox()
        self.script_list_container.pack_start(self.make_please_wait_widget())
        self.hmainbox.pack_start(self.script_list_container, False, False, 0)

        self.nmap_error_widget = gtk.Label(
            _("There was an error getting the list of scripts from Nmap. "
              "Try upgrading Nmap."))
        self.nmap_error_widget.set_line_wrap(True)
        self.nmap_error_widget.show_all()

        self.script_list_widget = self.make_script_list_widget()
        self.script_list_widget.show_all()

        vbox = HIGVBox(False, 5)
        vbox.pack_start(self.make_description_widget(), True, True, 0)
        vbox.pack_start(self.make_arguments_widget(), True, True, 0)
        self.hmainbox.pack_end(vbox, True, True, 0)

        self.update_argument_values(self.ops["--script-args"])

        # Start the initial backgrounded Nmap run to get the list of all
        # available scripts.
        self.get_script_list("all", self.initial_script_list_cb)

    def get_script_list(self, rules, callback):
        """Start an Nmap subprocess in the background with
        "--script-help=<rules> -oX -", and set it up to call the given callback
        when finished."""

        ops = NmapOptions()
        ops.executable = paths_config.nmap_command_path
        ops["--script-help"] = rules
        ops["-oX"] = "-"
        command_string = ops.render_string()
        # Separate stderr to avoid breaking XML parsing with "Warning: File
        # ./nse_main.lua exists, but Nmap is using...".
        stderr = tempfile.TemporaryFile(mode="rb",
                                        prefix=APP_NAME +
                                        "-script-help-stderr-")
        log.debug("Script interface: running %s" % repr(command_string))
        nmap_process = NmapCommand(command_string)
        try:
            nmap_process.run_scan(stderr=stderr)
        except Exception as e:
            callback(False, None)
            stderr.close()
            return
        stderr.close()

        self.script_list_widget.set_sensitive(False)

        gobject.timeout_add(self.NMAP_DELAY, self.script_list_timer_callback,
                            nmap_process, callback)

    def script_list_timer_callback(self, process, callback):
        try:
            status = process.scan_state()
        except Exception:
            status = None
        log.debug("Script interface: script_list_timer_callback %s" %
                  repr(status))

        if status is True:
            # Still running, schedule this timer to check again.
            return True

        self.script_list_widget.set_sensitive(True)

        if status is False:
            # Finished with success.
            callback(True, process)
        else:
            # Finished with error.
            callback(False, process)

    def initial_script_list_cb(self, status, process):
        log.debug("Script interface: initial_script_list_cb %s" % repr(status))
        for child in self.script_list_container.get_children():
            self.script_list_container.remove(child)
        if status and self.handle_initial_script_list_output(process):
            self.script_list_container.pack_start(self.script_list_widget)
        else:
            self.script_list_container.pack_start(self.nmap_error_widget)

    def handle_initial_script_list_output(self, process):
        process.stdout_file.seek(0)
        try:
            handler = ScriptHelpXMLContentHandler.parse_nmap_script_help(
                process.stdout_file)
        except (ValueError, xml.sax.SAXParseException) as e:
            log.debug("--script-help parse exception: %s" % str(e))
            return False

        # Check if any scripts were output; if not, Nmap is probably too old.
        if len(handler.script_filenames) == 0:
            return False

        if not handler.scripts_dir:
            log.debug("--script-help error: no scripts directory")
            return False
        if not handler.nselib_dir:
            log.debug("--script-help error: no nselib directory")
            return False

        log.debug("Script interface: scripts dir %s" %
                  repr(handler.scripts_dir))
        log.debug("Script interface: nselib dir %s" % repr(handler.nselib_dir))

        # Make a dict of script metadata entries.
        entries = {}
        for entry in get_script_entries(handler.scripts_dir,
                                        handler.nselib_dir):
            entries[entry.filename] = entry

        self.liststore.clear()
        for filename in handler.script_filenames:
            basename = os.path.basename(filename)
            entry = entries.get(basename)
            if entry:
                script_id = self.strip_file_name(basename)
                self.liststore.append([script_id, False, entry])
            else:
                # ScriptMetadata found nothing for this script?
                self.file_liststore.append([filename, False])

        # Now figure out which scripts are selected.
        self.update_script_list_from_spec(self.ops["--script"])
        return True

    def update_script_list_from_spec(self, spec):
        """Callback method for user edit delay."""
        log.debug("Script interface: update_script_list_from_spec %s" %
                  repr(spec))
        if spec:
            self.get_script_list(spec, self.update_script_list_cb)
        else:
            self.refresh_list_scripts([])

    def update_script_list_cb(self, status, process):
        log.debug("Script interface: update_script_list_cb %s" % repr(status))
        if status:
            self.handle_update_script_list_output(process)
        else:
            self.refresh_list_scripts([])

    def handle_update_script_list_output(self, process):
        process.stdout_file.seek(0)
        try:
            handler = ScriptHelpXMLContentHandler.parse_nmap_script_help(
                process.stdout_file)
        except (ValueError, xml.sax.SAXParseException) as e:
            log.debug("--script-help parse exception: %s" % str(e))
            return False

        self.refresh_list_scripts(handler.script_filenames)

    def get_hmain_box(self):
        """Returns main Hbox to ProfileEditor."""
        return self.hmainbox

    def update(self):
        """Updates the interface when the command entry is changed."""
        # updates list of scripts
        rules = self.ops["--script"]
        if (self.prev_script_spec != rules):
            self.renew_script_list_timer(rules)
        self.prev_script_spec = rules
        # updates arguments..
        raw_argument = self.ops["--script-args"]
        if raw_argument is not None:
            self.parse_script_args(raw_argument)
        self.arg_liststore.clear()
        for arg in self.current_arguments:
            arg_name, arg_desc = arg
            value = self.arg_values.get(arg_name)
            if not value:
                self.arg_liststore.append([arg_name, None, arg])
            else:
                self.arg_liststore.append([arg_name, value, arg])

    def renew_script_list_timer(self, spec):
        """Restart the timer to update the script list when the user edits the
        command. Because updating the script list is an expensive operation
        involving the creation of a subprocess, we don't do it for every typed
        character."""
        if self.script_list_timeout_id:
            gobject.source_remove(self.script_list_timeout_id)
        self.script_list_timeout_id = gobject.timeout_add(
            self.SCRIPT_LIST_DELAY, self.update_script_list_from_spec, spec)

    def parse_script_args(self, raw_argument):
        """When the command line is edited, this function is called to update
        the script arguments display according to the value of
        --script-args."""
        arg_dict = parse_script_args_dict(raw_argument)
        if arg_dict is None:  # if there is parsing error args_dict holds none
            self.arg_values.clear()
        else:
            self.arg_values.update(arg_dict)

    def update_argument_values(self, raw_argument):
        """When scripting tab starts up, argument values are updated."""
        if raw_argument is not None:
            self.parse_script_args(raw_argument)

    def set_help_texts(self):
        """Sets the help texts to be displayed."""
        self.list_scripts_help = _("""List of scripts

A list of all installed scripts. Activate or deactivate a script \
by clicking the box next to the script name.""")
        self.description_help = _("""Description

This box shows the categories a script belongs to. In addition, it gives a \
detailed description of the script which is present in script. A URL points \
to online NSEDoc documentation.""")
        self.argument_help = _("""Arguments

A list of arguments that affect the selected script. Enter a value by \
clicking in the value field beside the argument name.""")

    def make_please_wait_widget(self):
        vbox = gtk.VBox()
        label = gtk.Label(_("Please wait."))
        label.set_line_wrap(True)
        vbox.pack_start(label)
        return vbox

    def make_script_list_widget(self):
        """Creates and packs widgets associated with left hand side of
        Interface."""
        vbox = gtk.VBox()

        scrolled_window = HIGScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS)
        # Expand only vertically.
        scrolled_window.set_size_request(175, -1)
        listview = gtk.TreeView(self.liststore)
        listview.set_headers_visible(False)
        listview.connect("enter-notify-event", self.update_help_ls_cb)
        selection = listview.get_selection()
        selection.connect("changed", self.selection_changed_cb)
        cell = gtk.CellRendererText()
        togglecell = gtk.CellRendererToggle()
        togglecell.set_property("activatable", True)
        togglecell.connect("toggled", self.toggled_cb, self.liststore)
        col = gtk.TreeViewColumn(_('Names'))
        col.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
        col.set_resizable(True)
        togglecol = gtk.TreeViewColumn(None, togglecell)
        togglecol.add_attribute(togglecell, "active", 1)
        listview.append_column(togglecol)
        listview.append_column(col)
        col.pack_start(cell, True)
        col.add_attribute(cell, "text", 0)
        scrolled_window.add(listview)
        scrolled_window.show()
        vbox.pack_start(scrolled_window, True, True, 0)

        self.file_scrolled_window = HIGScrolledWindow()
        self.file_scrolled_window.set_policy(gtk.POLICY_ALWAYS,
                                             gtk.POLICY_ALWAYS)
        self.file_scrolled_window.set_size_request(175, -1)
        self.file_scrolled_window.hide()
        self.file_scrolled_window.set_no_show_all(True)

        self.file_listview = gtk.TreeView(self.file_liststore)
        self.file_listview.set_headers_visible(False)
        col = gtk.TreeViewColumn(None)
        self.file_listview.append_column(col)
        cell = gtk.CellRendererToggle()
        col.pack_start(cell, True)
        cell.set_property("activatable", True)
        col.add_attribute(cell, "active", 1)
        cell.connect("toggled", self.toggled_cb, self.file_liststore)

        col = gtk.TreeViewColumn(None)
        self.file_listview.append_column(col)
        cell = gtk.CellRendererText()
        col.pack_start(cell)
        col.add_attribute(cell, "text", 0)

        self.file_listview.show_all()
        self.file_scrolled_window.add(self.file_listview)
        vbox.pack_start(self.file_scrolled_window, False)

        hbox = HIGHBox(False, 2)
        self.remove_file_button = HIGButton(stock=gtk.STOCK_REMOVE)
        self.remove_file_button.connect("clicked",
                                        self.remove_file_button_clicked_cb)
        self.remove_file_button.set_sensitive(False)
        hbox.pack_end(self.remove_file_button)
        add_file_button = HIGButton(stock=gtk.STOCK_ADD)
        add_file_button.connect("clicked", self.add_file_button_clicked_cb)
        hbox.pack_end(add_file_button)

        vbox.pack_start(hbox, False, False, 0)

        return vbox

    def refresh_list_scripts(self, selected_scripts):
        """The list of selected scripts is refreshed in the list store."""
        for row in self.liststore:
            row[1] = False
        for row in self.file_liststore:
            row[1] = False
        for filename in selected_scripts:
            for row in self.liststore:
                if row[0] == self.strip_file_name(os.path.basename(filename)):
                    row[1] = True
                    break
            else:
                for row in self.file_liststore:
                    if row[0] == filename:
                        row[1] = True
                        break
                else:
                    self.file_liststore.append([filename, True])

    def strip_file_name(self, filename):
        """Removes a ".nse" extension from filename if present."""
        if (filename.endswith(".nse")):
            return filename[:-4]
        else:
            return filename

    def set_script_from_selection(self):
        scriptsname = []
        for entry in self.liststore:
            if entry[1]:
                scriptsname.append(self.strip_file_name(entry[0]))
        for entry in self.file_liststore:
            if entry[1]:
                scriptsname.append(entry[0])
        if len(scriptsname) == 0:
            self.ops["--script"] = None
        else:
            self.ops["--script"] = ",".join(scriptsname)
        self.update_command()

    def toggled_cb(self, cell, path, model):
        """Callback method, called when the check box in list of scripts is
        toggled."""
        model[path][1] = not model[path][1]
        self.set_script_from_selection()

    def make_description_widget(self):
        """Creates and packs widgets related to displaying the description
        box."""
        sw = HIGScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        sw.set_shadow_type(gtk.SHADOW_OUT)
        sw.set_border_width(5)
        text_view = gtk.TextView()
        text_view.connect("enter-notify-event", self.update_help_desc_cb)
        self.text_buffer = text_view.get_buffer()
        self.text_buffer.create_tag("Usage", font="Monospace")
        self.text_buffer.create_tag("Output", font="Monospace")
        text_view.set_wrap_mode(gtk.WRAP_WORD)
        text_view.set_editable(False)
        text_view.set_justification(gtk.JUSTIFY_LEFT)
        sw.add(text_view)
        return sw

    def make_arguments_widget(self):
        """Creates and packs widgets related to arguments box."""
        vbox = gtk.VBox()
        vbox.pack_start(gtk.Label(_("Arguments")), False, False, 0)
        arg_window = HIGScrolledWindow()
        arg_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        arg_window.set_shadow_type(gtk.SHADOW_OUT)

        arg_listview = gtk.TreeView(self.arg_liststore)
        arg_listview.connect("motion-notify-event", self.update_help_arg_cb)
        argument = gtk.CellRendererText()
        self.value = gtk.CellRendererText()
        self.value.connect("edited", self.value_edited_cb, self.arg_liststore)
        arg_col = gtk.TreeViewColumn("Arguments\t")
        val_col = gtk.TreeViewColumn("values")
        arg_listview.append_column(arg_col)
        arg_listview.append_column(val_col)
        arg_col.pack_start(argument, True)
        arg_col.add_attribute(argument, "text", 0)
        val_col.pack_start(self.value, True)
        val_col.add_attribute(self.value, "text", 1)

        arg_window.add(arg_listview)
        vbox.pack_start(arg_window, True, True, 0)

        return vbox

    def value_edited_cb(self, cell, path, new_text, model):
        """Called when the argument cell is edited."""
        self.arg_list = []
        model[path][1] = new_text
        argument_name = model[path][0]
        self.arg_values[argument_name] = new_text
        self.update_arg_values()

    def update_arg_values(self):
        """When the widget is updated with argument value, correspondingly
        update the command line."""
        for key in self.arg_values:
            if len(self.arg_values[key]) == 0:
                del self.arg_values[key]
            else:
                self.arg_list.append(key + "=" + self.arg_values[key])
        if len(self.arg_list) == 0:
            self.ops["--script-args"] = None
            self.arg_values.clear()
        else:
            self.ops["--script-args"] = ",".join(self.arg_list)
        self.update_command()

    def selection_changed_cb(self, selection):
        """Called back when the list of scripts is selected."""
        model, selection = selection.get_selected_rows()
        for path in selection:
            entry = model.get_value(model.get_iter(path), 2)
            self.set_description(entry)
            self.populate_arg_list(entry)
            # Remember the currently pointing script entry
            self.focusedentry = entry

    def update_help_ls_cb(self, widget, extra):  # list of scripts
        """Callback method to display the help for the list of scripts."""
        self.help_buf.set_text(self.list_scripts_help)

    def update_help_desc_cb(self, widget, extra):
        """Callback method for displaying description."""
        self.help_buf.set_text(self.description_help)

    def update_help_arg_cb(self, treeview, event):
        """Callback method for displaying argument help."""
        wx, wy = treeview.get_pointer()
        try:
            x, y = treeview.convert_widget_to_bin_window_coords(wx, wy)
        except AttributeError:
            # convert_widget_to_bin_window_coords was introduced in PyGTK 2.12.
            return
        path = treeview.get_path_at_pos(x, y)
        if not path or not self.focusedentry:
            self.help_buf.set_text("")
            return
        path = path[0]
        model, selected = treeview.get_selection().get_selected()
        arg_name, arg_desc = model.get_value(model.get_iter(path), 2)
        if arg_desc is not None:
            self.help_buf.set_text("")
            self.help_buf.insert(self.help_buf.get_end_iter(),
                                 text="%s\n" % arg_name)
            text_buffer_insert_nsedoc(self.help_buf, arg_desc)
        else:
            self.help_buf.set_text("")

    def add_file_button_clicked_cb(self, button):
        if self.script_file_chooser is None:
            self.script_file_chooser = \
                    zenmapGUI.FileChoosers.ScriptFileChooserDialog(
                            title=_("Select script files"))
        response = self.script_file_chooser.run()
        filenames = self.script_file_chooser.get_filenames()
        self.script_file_chooser.hide()
        if response != gtk.RESPONSE_OK:
            return
        for filename in filenames:
            self.file_liststore.append([filename, True])
        if len(self.file_liststore) > 0:
            self.file_scrolled_window.show()
            self.remove_file_button.set_sensitive(True)
        self.set_script_from_selection()

    def remove_file_button_clicked_cb(self, button):
        selection = self.file_listview.get_selection()
        model, selection = selection.get_selected_rows()
        for path in selection:
            self.file_liststore.remove(model.get_iter(path))
        if len(self.file_liststore) == 0:
            self.file_scrolled_window.hide()
            self.remove_file_button.set_sensitive(False)
        self.set_script_from_selection()

    def set_description(self, entry):
        """Sets the content that is to be displayed in the description box."""
        self.text_buffer.set_text(u"")

        self.text_buffer.insert(
            self.text_buffer.get_end_iter(), """\
Categories: %(cats)s
""" % {"cats": ", ".join(entry.categories)})
        text_buffer_insert_nsedoc(self.text_buffer, entry.description)
        if entry.usage:
            self.text_buffer.insert(self.text_buffer.get_end_iter(),
                                    "\nUsage\n")
            self.text_buffer.insert_with_tags_by_name(
                self.text_buffer.get_end_iter(), entry.usage, "Usage")
        if entry.output:
            self.text_buffer.insert(self.text_buffer.get_end_iter(),
                                    "\nOutput\n")
            self.text_buffer.insert_with_tags_by_name(
                self.text_buffer.get_end_iter(), entry.output, "Output")
        if entry.url:
            self.text_buffer.insert(self.text_buffer.get_end_iter(),
                                    "\n" + entry.url)

    def populate_arg_list(self, entry):
        """Called when a particular script is hovered over to display its
        arguments and values (if any)."""
        self.arg_liststore.clear()
        self.current_arguments = []
        self.value.set_property('editable', True)
        for arg in entry.arguments:
            arg_name, arg_desc = arg
            self.current_arguments.append(arg)
            value = self.arg_values.get(arg_name)
            if not value:
                self.arg_liststore.append([arg_name, None, arg])
            else:
                self.arg_liststore.append([arg_name, value, arg])
예제 #12
0
파일: About.py 프로젝트: EliseuTorres/nmap
class UmitCredits(HIGWindow):
    def __init__(self):
        HIGWindow.__init__(self)
        self.set_title(_("%s credits") % UMIT_DISPLAY_NAME)
        self.set_size_request(-1, 250)
        self.set_position(gtk.WIN_POS_CENTER)

        self.__create_widgets()
        self.__packing()
        self.set_text()

    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.hbox = HIGHBox()
        self.notebook = HIGNotebook()
        self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)

        self.written_by_scroll = HIGScrolledWindow()
        self.written_by_text = HIGTextView()

        self.design_scroll = HIGScrolledWindow()
        self.design_text = HIGTextView()

        self.soc2007_scroll = HIGScrolledWindow()
        self.soc2007_text = HIGTextView()

        self.contributors_scroll = HIGScrolledWindow()
        self.contributors_text = HIGTextView()

        self.translation_scroll = HIGScrolledWindow()
        self.translation_text = HIGTextView()

        self.nokia_scroll = HIGScrolledWindow()
        self.nokia_text = HIGTextView()

    def __packing(self):
        self.add(self.vbox)
        self.vbox.set_spacing(12)
        self.vbox._pack_expand_fill(self.notebook)
        self.vbox._pack_noexpand_nofill(self.hbox)

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

        self.notebook.append_page(
                self.written_by_scroll, gtk.Label(_("Written by")))
        self.notebook.append_page(
                self.design_scroll, gtk.Label(_("Design")))
        self.notebook.append_page(
                self.soc2007_scroll, gtk.Label(_("SoC 2007")))
        self.notebook.append_page(
                self.contributors_scroll, gtk.Label(_("Contributors")))
        self.notebook.append_page(
                self.translation_scroll, gtk.Label(_("Translation")))
        self.notebook.append_page(
                self.nokia_scroll, gtk.Label(_("Maemo")))

        self.written_by_scroll.add(self.written_by_text)
        self.written_by_text.set_wrap_mode(gtk.WRAP_NONE)

        self.design_scroll.add(self.design_text)
        self.design_text.set_wrap_mode(gtk.WRAP_NONE)

        self.soc2007_scroll.add(self.soc2007_text)
        self.soc2007_text.set_wrap_mode(gtk.WRAP_NONE)

        self.contributors_scroll.add(self.contributors_text)
        self.contributors_text.set_wrap_mode(gtk.WRAP_NONE)

        self.translation_scroll.add(self.translation_text)
        self.translation_text.set_wrap_mode(gtk.WRAP_NONE)

        self.nokia_scroll.add(self.nokia_text)
        self.nokia_text.set_wrap_mode(gtk.WRAP_NONE)

        self.btn_close.connect('clicked', lambda x, y=None: self.destroy())

    def set_text(self):
        b = self.written_by_text.get_buffer()
        b.set_text("""Adriano Monteiro Marques <*****@*****.**>""")

        b = self.design_text.get_buffer()
        b.set_text("""Operating System and Vulnerability Icons:
Takeshi Alexandre Gondo <*****@*****.**>

Logo, Application Icons and Splash screen:
Virgílio Carlo de Menezes Vasconcelos <*****@*****.**>

The Umit Project Web Site Design:
Joao Paulo Pacheco <*****@*****.**>""")

        b = self.soc2007_text.get_buffer()
        b.set_text("""Independent Features:
Adriano Monteiro Marques <*****@*****.**>
Frederico Silva Ribeiro <*****@*****.**>

Network Inventory:
Guilherme Henrique Polo Gonçalves <*****@*****.**>

Umit Radial Mapper:
João Paulo de Souza Medeiros <*****@*****.**>

Profile/Wizard interface editor:
Luis Antonio Bastião Silva <*****@*****.**>

NSE Facilitator:
Maxim I. Gavrilov <*****@*****.**>

Umit Web:
Rodolfo da Silva Carvalho <*****@*****.**>""")

        b = self.contributors_text.get_buffer()
        b.set_text("""Sponsored by (SoC 2005, 2006 and 2007):
Google <*****@*****.**>

Mentor of Umit for Google SoC 2005 and 2006:
Fyodor <*****@*****.**>

Mentor of Umit for Google SoC 2007 Projects:
Adriano Monteiro Marques <*****@*****.**>

Initial development:
Adriano Monteiro Marques <*****@*****.**>
Cleber Rodrigues Rosa Junior <*****@*****.**>

Nmap students from Google SoC 2007 that helped Umit:
Eddie Bell <*****@*****.**>
David Fifield <*****@*****.**>
Kris Katterjohn <*****@*****.**>

The Umit Project WebSite:
AbraoBarbosa dos Santos Neto <*****@*****.**>
Adriano Monteiro Marques <*****@*****.**>
Heitor de Lima Matos <*****@*****.**>
Joao Paulo Pacheco <*****@*****.**>
João Paulo de Souza Medeiros <*****@*****.**>
Luis Antonio Bastião Silva <*****@*****.**>
Rodolfo da Silva Carvalho <*****@*****.**>

Beta testers for 0.9.5RC1:
Drew Miller <*****@*****.**>
Igor Feghali <*****@*****.**>
Joao Paulo Pacheco <*****@*****.**>
Luis Antonio Bastião Silva <*****@*****.**>
<*****@*****.**>
<*****@*****.**>
<*****@*****.**>

Initial attempt on Maemo port:
Adriano Monteiro Marques <*****@*****.**>
Osvaldo Santana Neto <*****@*****.**>""")

        b = self.translation_text.get_buffer()
        b.set_text("""Brazilian Portuguese:
Adriano Monteiro Marques <*****@*****.**>""")

        b = self.nokia_text.get_buffer()
        b.set_text("""Adriano Monteiro Marques <*****@*****.**>""")
예제 #13
0
class ProfileEditor(HIGWindow):
    def __init__(self, profile_name=None, deletable=True, overwrite=False):
        HIGWindow.__init__(self)
        self.connect("delete_event", self.exit)
        self.set_title(_('Profile Editor'))
        self.set_position(gtk.WIN_POS_CENTER)

        self.deletable = deletable
        self.profile_name = profile_name
        self.overwrite = overwrite

        self.__create_widgets()
        self.__pack_widgets()

        self.profile = CommandProfile()

        options_used = {}
        if profile_name:
            log.debug("Showing profile %s" % profile_name)
            prof = self.profile.get_profile(profile_name)
            options_used = prof['options']

            # Interface settings
            self.profile_name_entry.set_text(profile_name)
            self.profile_description_text.get_buffer().set_text(
                prof['description'])

        self.constructor = CommandConstructor(options_used)
        ###
        self.profilehelp = ProfileHelp(options_used)
        ###
        self.options = OptionBuilder(Path.profile_editor, self.constructor,
                                     self.update_command, self.profilehelp)
        log.debug("Option groups: %s" % str(self.options.groups))
        log.debug("Option section names: %s" % str(self.options.section_names))
        #log.debug("Option tabs: %s" % str(self.options.tabs))

        for tab in self.options.groups:
            self.__create_tab(tab, self.options.section_names[tab],
                              self.options.tabs[tab])

        self.update_command()

    def update_command(self):
        """Regenerate command with target '<target>' and set the value for the command entry"""
        self.command_entry.set_text(self.constructor.get_command('<target>'))
        ### whenever the command would be updated, thats when we update the help
        self.update_help()

    def update_help(self, text=None):
        helpText = self.help_field.get_buffer()
        if text:
            helpText.set_text(text)
        else:
            tempText = ""
            if self.profilehelp.get_currentstate() == "Default":
                helpText.set_text(" ")
            else:
                tempText += self.profilehelp.get_label()
                tempText += "\n\n"
                tempText += self.profilehelp.get_shortdesc()
                if self.profilehelp.get_example():
                    tempText += "\n\nExample input:\n"
                    tempText += self.profilehelp.get_example()
                helpText.set_text(tempText)

    def update_help_name(self, widget, extra):
        self.update_help(
            text="Profile name\n\nThis is how the" +
            " profile will be identified in the drop-down combo box in the" +
            " scan tab.")

    def update_help_desc(self, widget, extra):
        self.update_help(
            text="Description\n\nThe description is a" +
            " full description of what the scan does, which may be long.")

    def help(self, widget):
        d = HIGAlertDialog(
            parent=self,
            message_format=_("Help not implemented"),
            secondary_text=_("Profile editor help is not implemented yet."))
        d.run()
        d.destroy()

    def __create_widgets(self):

        ###
        # Vertical box to keep 3 boxes
        self.main_whole_box = HIGVBox()

        self.upper_box = HIGVBox()
        self.middle_box = HIGHBox()
        self.lower_box = HIGHBox()

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

        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_name_entry.connect('enter-notify-event',
                                        self.update_help_name)
        self.profile_description_label = HIGEntryLabel(_('Description'))
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_scroll.set_border_width(0)
        self.profile_description_text = HIGTextView()
        self.profile_description_text.connect('motion-notify-event',
                                              self.update_help_desc)

        # Buttons
        self.buttons_hbox = HIGHBox()

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

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

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

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)

        ###
        self.help_vbox = HIGVBox()
        self.help_label = HIGSectionLabel(_('Help'))
        self.help_scroll = HIGScrolledWindow()
        self.help_scroll.set_border_width(0)
        self.help_field = HIGTextView()
        self.help_field.set_cursor_visible(False)
        self.help_field.set_left_margin(5)
        self.help_field.set_editable(False)
        self.help_vbox.set_size_request(200, -1)
        ###
    def __pack_widgets(self):

        ###
        self.add(self.main_whole_box)

        # Packing command expander to upper box
        self.upper_box._pack_noexpand_nofill(self.command_expander)

        # Packing notebook (left) and help box (right) to middle box
        self.middle_box._pack_expand_fill(self.notebook)
        self.middle_box._pack_expand_fill(self.help_vbox)

        # Packing buttons to lower box
        self.lower_box.pack_end(self.buttons_hbox)

        # Packing the three vertical boxes to the main box
        self.main_whole_box._pack_noexpand_nofill(self.upper_box)
        self.main_whole_box._pack_noexpand_nofill(self.middle_box)
        self.main_whole_box._pack_noexpand_nofill(self.lower_box)
        ###

        # Packing command_entry on command_expander
        self.command_expander.hbox.pack_start(self.command_entry)

        # Packing profile information tab on notebook
        self.notebook.append_page(self.profile_info_vbox,
                                  gtk.Label(_('Profile')))
        self.profile_info_vbox.set_border_width(5)
        table = HIGTable()
        self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label)
        self.profile_info_vbox._pack_expand_fill(HIGSpacer(table))

        self.profile_description_scroll.add(self.profile_description_text)

        vbox_desc = HIGVBox()
        vbox_desc._pack_noexpand_nofill(self.profile_description_label)
        vbox_desc._pack_expand_fill(hig_box_space_holder())

        vbox_ann = HIGVBox()
        vbox_ann._pack_expand_fill(hig_box_space_holder())

        table.attach(self.profile_name_label,
                     0,
                     1,
                     0,
                     1,
                     xoptions=0,
                     yoptions=0)
        table.attach(self.profile_name_entry, 1, 2, 0, 1, yoptions=0)
        table.attach(vbox_desc, 0, 1, 1, 2, xoptions=0)
        table.attach(self.profile_description_scroll, 1, 2, 1, 2)

        # Packing buttons on button_hbox
        #self.buttons_hbox.pack_start(self.help_button)
        self.buttons_hbox._pack_expand_fill(hig_box_space_holder())
        if self.deletable:
            self.buttons_hbox._pack_noexpand_nofill(self.delete_button)
        self.buttons_hbox._pack_noexpand_nofill(self.cancel_button)
        self.buttons_hbox._pack_noexpand_nofill(self.ok_button)

        self.buttons_hbox.set_border_width(5)
        self.buttons_hbox.set_spacing(6)

        ###
        self.help_vbox._pack_noexpand_nofill(self.help_label)
        self.help_vbox._pack_expand_fill(self.help_scroll)
        self.help_scroll.add(self.help_field)
        self.help_vbox.set_border_width(1)
        self.help_vbox.set_spacing(1)
        ###

    def __create_tab(self, tab_name, section_name, tab):
        log.debug(">>> Tab name: %s" % tab_name)
        log.debug(">>>Creating profile editor section: %s" % section_name)

        vbox = HIGVBox()
        table = HIGTable()
        table.set_row_spacings(2)
        section = HIGSectionLabel(section_name)

        vbox._pack_noexpand_nofill(section)
        vbox._pack_noexpand_nofill(HIGSpacer(table))
        vbox.set_border_width(5)

        tab.fill_table(table, True)

        self.notebook.append_page(vbox, gtk.Label(tab_name))

    def save_profile(self, widget):
        if self.overwrite:
            self.profile.remove_profile(self.profile_name)
        profile_name = self.profile_name_entry.get_text()
        if profile_name == '':
            alert = HIGAlertDialog(message_format=_('Unnamed profile'),\
                                   secondary_text=_('You must provide a name \
for this profile.'                  ))
            alert.run()
            alert.destroy()

            self.profile_name_entry.grab_focus()

            return None

        command = self.constructor.get_command('%s')

        buf = self.profile_description_text.get_buffer()
        description = buf.get_text(buf.get_start_iter(),\
                                      buf.get_end_iter())

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

        self.scan_interface.toolbar.profile_entry.update()
        self.scan_interface.refresh_command(None)
        self.destroy()

    def clean_profile_info(self):
        self.profile_name_entry.set_text('')
        self.profile_description_text.get_buffer().set_text('')

    def set_scan_interface(self, interface):
        self.scan_interface = interface

    def exit(self, *args):
        self.destroy()

    def delete_profile(self, widget=None, extra=None):
        if self.deletable:
            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 True
            self.profile.remove_profile(self.profile_name)

        self.update_profile_entry()
        self.destroy()

    def update_profile_entry(self, widget=None, extra=None):
        self.scan_interface.toolbar.profile_entry.update()
        list = self.scan_interface.toolbar.profile_entry.get_model()
        length = len(list)
        if length > 0:
            self.scan_interface.toolbar.profile_entry.set_active(0)
예제 #14
0
    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.hbox = HIGHBox()
        self.notebook = HIGNotebook()
        self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)

        self.written_by_scroll = HIGScrolledWindow()
        self.written_by_text = HIGTextView()

        self.design_scroll = HIGScrolledWindow()
        self.design_text = HIGTextView()

        self.soc2007_scroll = HIGScrolledWindow()
        self.soc2007_text = HIGTextView()

        self.contributors_scroll = HIGScrolledWindow()
        self.contributors_text = HIGTextView()

        self.translation_scroll = HIGScrolledWindow()
        self.translation_text = HIGTextView()

        self.nokia_scroll = HIGScrolledWindow()
        self.nokia_text = HIGTextView()
예제 #15
0
class UmitCredits(HIGWindow):
    def __init__(self):
        HIGWindow.__init__(self)
        self.set_title(_("%s credits") % UMIT_DISPLAY_NAME)
        self.set_size_request(-1, 250)
        self.set_position(gtk.WIN_POS_CENTER)

        self.__create_widgets()
        self.__packing()
        self.set_text()

    def __create_widgets(self):
        self.vbox = HIGVBox()
        self.hbox = HIGHBox()
        self.notebook = HIGNotebook()
        self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)

        self.written_by_scroll = HIGScrolledWindow()
        self.written_by_text = HIGTextView()

        self.design_scroll = HIGScrolledWindow()
        self.design_text = HIGTextView()

        self.soc2007_scroll = HIGScrolledWindow()
        self.soc2007_text = HIGTextView()

        self.contributors_scroll = HIGScrolledWindow()
        self.contributors_text = HIGTextView()

        self.translation_scroll = HIGScrolledWindow()
        self.translation_text = HIGTextView()

        self.nokia_scroll = HIGScrolledWindow()
        self.nokia_text = HIGTextView()

    def __packing(self):
        self.add(self.vbox)
        self.vbox.set_spacing(12)
        self.vbox._pack_expand_fill(self.notebook)
        self.vbox._pack_noexpand_nofill(self.hbox)

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

        self.notebook.append_page(self.written_by_scroll,
                                  gtk.Label(_("Written by")))
        self.notebook.append_page(self.design_scroll, gtk.Label(_("Design")))
        self.notebook.append_page(self.soc2007_scroll,
                                  gtk.Label(_("SoC 2007")))
        self.notebook.append_page(self.contributors_scroll,
                                  gtk.Label(_("Contributors")))
        self.notebook.append_page(self.translation_scroll,
                                  gtk.Label(_("Translation")))
        self.notebook.append_page(self.nokia_scroll, gtk.Label(_("Maemo")))

        self.written_by_scroll.add(self.written_by_text)
        self.written_by_text.set_wrap_mode(gtk.WRAP_NONE)

        self.design_scroll.add(self.design_text)
        self.design_text.set_wrap_mode(gtk.WRAP_NONE)

        self.soc2007_scroll.add(self.soc2007_text)
        self.soc2007_text.set_wrap_mode(gtk.WRAP_NONE)

        self.contributors_scroll.add(self.contributors_text)
        self.contributors_text.set_wrap_mode(gtk.WRAP_NONE)

        self.translation_scroll.add(self.translation_text)
        self.translation_text.set_wrap_mode(gtk.WRAP_NONE)

        self.nokia_scroll.add(self.nokia_text)
        self.nokia_text.set_wrap_mode(gtk.WRAP_NONE)

        self.btn_close.connect('clicked', lambda x, y=None: self.destroy())

    def set_text(self):
        b = self.written_by_text.get_buffer()
        b.set_text("""Adriano Monteiro Marques <*****@*****.**>""")

        b = self.design_text.get_buffer()
        b.set_text("""Operating System and Vulnerability Icons:
Takeshi Alexandre Gondo <*****@*****.**>

Logo, Application Icons and Splash screen:
Virgílio Carlo de Menezes Vasconcelos <*****@*****.**>

The Umit Project Web Site Design:
Joao Paulo Pacheco <*****@*****.**>""")

        b = self.soc2007_text.get_buffer()
        b.set_text("""Independent Features:
Adriano Monteiro Marques <*****@*****.**>
Frederico Silva Ribeiro <*****@*****.**>

Network Inventory:
Guilherme Henrique Polo Gonçalves <*****@*****.**>

Umit Radial Mapper:
João Paulo de Souza Medeiros <*****@*****.**>

Profile/Wizard interface editor:
Luis Antonio Bastião Silva <*****@*****.**>

NSE Facilitator:
Maxim I. Gavrilov <*****@*****.**>

Umit Web:
Rodolfo da Silva Carvalho <*****@*****.**>""")

        b = self.contributors_text.get_buffer()
        b.set_text("""Sponsored by (SoC 2005, 2006 and 2007):
Google <*****@*****.**>

Mentor of Umit for Google SoC 2005 and 2006:
Fyodor <*****@*****.**>

Mentor of Umit for Google SoC 2007 Projects:
Adriano Monteiro Marques <*****@*****.**>

Initial development:
Adriano Monteiro Marques <*****@*****.**>
Cleber Rodrigues Rosa Junior <*****@*****.**>

Nmap students from Google SoC 2007 that helped Umit:
Eddie Bell <*****@*****.**>
David Fifield <*****@*****.**>
Kris Katterjohn <*****@*****.**>

The Umit Project WebSite:
AbraoBarbosa dos Santos Neto <*****@*****.**>
Adriano Monteiro Marques <*****@*****.**>
Heitor de Lima Matos <*****@*****.**>
Joao Paulo Pacheco <*****@*****.**>
João Paulo de Souza Medeiros <*****@*****.**>
Luis Antonio Bastião Silva <*****@*****.**>
Rodolfo da Silva Carvalho <*****@*****.**>

Beta testers for 0.9.5RC1:
Drew Miller <*****@*****.**>
Igor Feghali <*****@*****.**>
Joao Paulo Pacheco <*****@*****.**>
Luis Antonio Bastião Silva <*****@*****.**>
<*****@*****.**>
<*****@*****.**>
<*****@*****.**>

Initial attempt on Maemo port:
Adriano Monteiro Marques <*****@*****.**>
Osvaldo Santana Neto <*****@*****.**>""")

        b = self.translation_text.get_buffer()
        b.set_text("""Brazilian Portuguese:
Adriano Monteiro Marques <*****@*****.**>""")

        b = self.nokia_text.get_buffer()
        b.set_text("""Adriano Monteiro Marques <*****@*****.**>""")
예제 #16
0
class ProfileEditor(HIGWindow):
    def __init__(self, command=None, profile_name=None, deletable=True, overwrite=False):
        HIGWindow.__init__(self)
        self.connect("delete_event", self.exit)
        self.set_title(_('Profile Editor'))
        self.set_position(gtk.WIN_POS_CENTER)

        self.deletable = deletable
        self.profile_name = profile_name
        self.overwrite = overwrite

        # Used to block recursive updating of the command entry when the command
        # entry causes the OptionBuilder widgets to change.
        self.inhibit_command_update = False

        self.__create_widgets()
        self.__pack_widgets()

        self.profile = CommandProfile()

        self.ops = NmapOptions()
        if profile_name:
            log.debug("Showing profile %s" % profile_name)
            prof = self.profile.get_profile(profile_name)

            # Interface settings
            self.profile_name_entry.set_text(profile_name)
            self.profile_description_text.get_buffer().set_text(prof['description'])

            command_string = prof['command']
            self.ops.parse_string(command_string)
        if command:
            self.ops.parse_string(command)

        self.option_builder = OptionBuilder(Path.profile_editor, self.ops, self.update_command, self.help_field.get_buffer())
        log.debug("Option groups: %s" % str(self.option_builder.groups))
        log.debug("Option section names: %s" % str(self.option_builder.section_names))
        #log.debug("Option tabs: %s" % str(self.option_builder.tabs))

        for tab in self.option_builder.groups:
            self.__create_tab(_(tab), _(self.option_builder.section_names[tab]), self.option_builder.tabs[tab])

        self.update_command()

    def command_entry_changed_cb(self, widget):
        command_string = self.command_entry.get_text().decode("UTF-8")
        self.ops.parse_string(command_string)
        self.inhibit_command_update = True
        self.option_builder.update()
        self.inhibit_command_update = False

    def update_command(self):
        """Regenerate and display the command."""
        if not self.inhibit_command_update:
            # Block recursive updating of the OptionBuilder widgets when they
            # cause a change in the command entry.
            self.command_entry.handler_block(self.command_entry_changed_cb_id)
            self.command_entry.set_text(self.ops.render_string())
            self.command_entry.handler_unblock(self.command_entry_changed_cb_id)

    def update_help_name(self, widget, extra):
        self.help_field.get_buffer().set_text("Profile name\n\nThis is how the"
        +" profile will be identified in the drop-down combo box in the"
        +" scan tab.")

    def update_help_desc(self, widget, extra):
        self.help_field.get_buffer().set_text("Description\n\nThe description is a"
        + " full description of what the scan does, which may be long.")

    def __create_widgets(self):

        ###
        # Vertical box to keep 3 boxes
        self.main_whole_box = HIGVBox()

        self.upper_box = HIGHBox()
        self.middle_box = HIGHBox()
        self.lower_box = HIGHBox()

        #self.main_vbox = HIGVBox()
        self.command_entry = gtk.Entry()
        self.command_entry_changed_cb_id = \
            self.command_entry.connect("changed", self.command_entry_changed_cb)

        self.scan_button = HIGButton(_("Scan"))
        self.scan_button.connect("clicked", self.run_scan)

        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_name_entry.connect('enter-notify-event', self.update_help_name)
        self.profile_description_label = HIGEntryLabel(_('Description'))
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_scroll.set_border_width(0)
        self.profile_description_text = HIGTextView()
        self.profile_description_text.connect('motion-notify-event', self.update_help_desc)

        # Buttons
        self.buttons_hbox = HIGHBox()

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

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

        self.save_button = HIGButton(_("Save Changes"), stock=gtk.STOCK_SAVE)
        self.save_button.connect('clicked', self.save_profile)

        ###
        self.help_vbox = HIGVBox()
        self.help_label = HIGSectionLabel(_('Help'))
        self.help_scroll = HIGScrolledWindow()
        self.help_scroll.set_border_width(0)
        self.help_field = HIGTextView()
        self.help_field.set_cursor_visible(False)
        self.help_field.set_left_margin(5)
        self.help_field.set_editable(False)
        self.help_vbox.set_size_request(200,-1)
        ###
    def __pack_widgets(self):

        ###
        self.add(self.main_whole_box)

        # Packing command entry to upper box
        self.upper_box._pack_expand_fill(self.command_entry)
        self.upper_box._pack_noexpand_nofill(self.scan_button)

        # Packing notebook (left) and help box (right) to middle box
        self.middle_box._pack_expand_fill(self.notebook)
        self.middle_box._pack_expand_fill(self.help_vbox)

        # Packing buttons to lower box
        self.lower_box.pack_end(self.buttons_hbox)

        # Packing the three vertical boxes to the main box
        self.main_whole_box._pack_noexpand_nofill(self.upper_box)
        self.main_whole_box._pack_expand_fill(self.middle_box)
        self.main_whole_box._pack_noexpand_nofill(self.lower_box)
        ###


        # Packing profile information tab on notebook
        self.notebook.append_page(self.profile_info_vbox, gtk.Label(_('Profile')))
        self.profile_info_vbox.set_border_width(5)
        table = HIGTable()
        self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label)
        self.profile_info_vbox._pack_expand_fill(HIGSpacer(table))

        self.profile_description_scroll.add(self.profile_description_text)

        vbox_desc = HIGVBox()
        vbox_desc._pack_noexpand_nofill(self.profile_description_label)
        vbox_desc._pack_expand_fill(hig_box_space_holder())

        vbox_ann = HIGVBox()
        vbox_ann._pack_expand_fill(hig_box_space_holder())

        table.attach(self.profile_name_label,0,1,0,1,xoptions=0,yoptions=0)
        table.attach(self.profile_name_entry,1,2,0,1,yoptions=0)
        table.attach(vbox_desc,0,1,1,2,xoptions=0)
        table.attach(self.profile_description_scroll,1,2,1,2)

        # Packing buttons on button_hbox
        self.buttons_hbox._pack_expand_fill(hig_box_space_holder())
        if self.deletable:
            self.buttons_hbox._pack_noexpand_nofill(self.delete_button)
        self.buttons_hbox._pack_noexpand_nofill(self.cancel_button)
        self.buttons_hbox._pack_noexpand_nofill(self.save_button)

        self.buttons_hbox.set_border_width(5)
        self.buttons_hbox.set_spacing(6)

        ###
        self.help_vbox._pack_noexpand_nofill(self.help_label)
        self.help_vbox._pack_expand_fill(self.help_scroll)
        self.help_scroll.add(self.help_field)
        self.help_vbox.set_border_width(1)
        self.help_vbox.set_spacing(1)
        ###

    def __create_tab(self, tab_name, section_name, tab):
        log.debug(">>> Tab name: %s" % tab_name)
        log.debug(">>>Creating profile editor section: %s" % section_name)
        vbox = HIGVBox()
        if  tab.notscripttab: # if notscripttab is set
            table = HIGTable()
            table.set_row_spacings(2)
            section = HIGSectionLabel(section_name)
            vbox._pack_noexpand_nofill(section)
            vbox._pack_noexpand_nofill(HIGSpacer(table))
            vbox.set_border_width(5)
            tab.fill_table(table, True)
        else:
            hbox = tab.get_hmain_box()
            vbox.pack_start(hbox,True,True,0)
        self.notebook.append_page(vbox, gtk.Label(tab_name))

    def save_profile(self, widget):
        if self.overwrite:
            self.profile.remove_profile(self.profile_name)
        profile_name = self.profile_name_entry.get_text()
        if profile_name == '':
            alert = HIGAlertDialog(message_format=_('Unnamed profile'),\
                                   secondary_text=_('You must provide a name \
for this profile.'))
            alert.run()
            alert.destroy()

            self.profile_name_entry.grab_focus()

            return None

        command = self.ops.render_string()

        buf = self.profile_description_text.get_buffer()
        description = buf.get_text(buf.get_start_iter(),\
                                      buf.get_end_iter())

        try:
            self.profile.add_profile(profile_name,\
                                     command=command,\
                                     description=description)
        except ValueError:
            alert = HIGAlertDialog(message_format=_('Disallowed profile name'),\
                                   secondary_text=_('Sorry, the name "%s" \
is not allowed due to technical limitations. (The underlying ConfigParser \
used to store profiles does not allow it.) Choose a different \
name.' % profile_name))
            alert.run()
            alert.destroy()
            return

        self.scan_interface.toolbar.profile_entry.update()
        self.destroy()

    def clean_profile_info(self):
        self.profile_name_entry.set_text('')
        self.profile_description_text.get_buffer().set_text('')

    def set_scan_interface(self, interface):
        self.scan_interface = interface

    def exit(self, *args):
        self.destroy()

    def delete_profile(self, widget=None, extra=None):
        if self.deletable:
            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 True
            self.profile.remove_profile(self.profile_name)

        self.update_profile_entry()
        self.destroy()

    def run_scan(self, widget=None):
        command_string = self.command_entry.get_text().decode("UTF-8")
        self.scan_interface.command_toolbar.command = command_string
        self.scan_interface.start_scan_cb()
        self.exit()

    def update_profile_entry(self, widget=None, extra=None):
        self.scan_interface.toolbar.profile_entry.update()
        list = self.scan_interface.toolbar.profile_entry.get_model()
        length = len(list)
        if length >0 :
            self.scan_interface.toolbar.profile_entry.set_active(0)
class ScanResultNotebook(HIGNotebook):
    """
    ScanResultNotebook
    Creates a new Scan Results notebook page, which includes the sections Ports/Hosts,
    Nmap Output, Host Details, and Scan Details.
    Organizes the way the results for scan is displayed in its new tab.
    """
    def __init__(self, inventory, scans_store):
        HIGNotebook.__init__(self)
        self.set_border_width(5)

        self.__create_widgets(inventory, scans_store)
        self.__nmap_output_refreshing()

        self.scans_list.scans_list.connect("row-activated",
                                           self._scan_row_activated)

        self.append_page(self.nmap_output_page, gtk.Label(_('Nmap Output')))
        self.append_page(self.open_ports_page, gtk.Label(_('Ports / Hosts')))
        self.append_page(self.topology_page, gtk.Label(_('Topology')))
        self.append_page(self.host_details_page, gtk.Label(_('Host Details')))
        self.append_page(self.scans_list_page, gtk.Label(_('Scans')))

    def host_mode(self):
        self.open_ports.host.host_mode()

    def port_mode(self):
        self.open_ports.host.port_mode()

    def __create_widgets(self, inventory, scans_store):
        self.open_ports_page = HIGVBox()
        self.nmap_output_page = HIGVBox()
        self.topology_page = HIGVBox()
        self.host_details_page = HIGScrolledWindow()
        self.host_details_vbox = HIGVBox()
        self.scans_list_page = HIGVBox()

        self.open_ports = ScanOpenPortsPage()
        self.nmap_output = ScanNmapOutputPage(scans_store)
        self.topology = TopologyPage(inventory)
        self.scans_list = ScanScanListPage(scans_store)

        self.no_selected = gtk.Label(_('No host selected.'))
        self.host_details = self.no_selected

        self.open_ports_page.add(self.open_ports)
        self.nmap_output_page.add(self.nmap_output)
        self.topology_page.add(self.topology)
        self.scans_list_page.add(self.scans_list)

        self.host_details_page.add_with_viewport(self.host_details_vbox)
        self.host_details_vbox._pack_expand_fill(self.host_details)

    def __nmap_output_refreshing(self):
        self.connect('switch-page', self.refresh_cb)

    def _scan_row_activated(self, treeview, path, view_column):
        """Switch back to the Nmap Output view when a scan is activated
        (double-clicked) on the scans list."""
        self.nmap_output.set_active_iter(treeview.get_model().get_iter(path))
        self.set_current_page(0)

    def refresh_cb(self, widget, page=None, page_num=None):
        if self.nmap_output.nmap_output.thread.isAlive():
            if page_num == 2:
                self.nmap_output.nmap_output.refresh_output()
예제 #18
0
    def make_script_list_widget(self):
        """Creates and packs widgets associated with left hand side of
        Interface."""
        vbox = gtk.VBox()

        scrolled_window = HIGScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS)
        # Expand only vertically.
        scrolled_window.set_size_request(175, -1)
        listview = gtk.TreeView(self.liststore)
        listview.set_headers_visible(False)
        listview.connect("enter-notify-event", self.update_help_ls_cb)
        selection = listview.get_selection()
        selection.connect("changed", self.selection_changed_cb)
        cell = gtk.CellRendererText()
        togglecell = gtk.CellRendererToggle()
        togglecell.set_property("activatable", True)
        togglecell.connect("toggled", self.toggled_cb, self.liststore)
        col = gtk.TreeViewColumn(_('Names'))
        col.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
        col.set_resizable(True)
        togglecol = gtk.TreeViewColumn(None, togglecell)
        togglecol.add_attribute(togglecell, "active", 1)
        listview.append_column(togglecol)
        listview.append_column(col)
        col.pack_start(cell, True)
        col.add_attribute(cell, "text", 0)
        scrolled_window.add(listview)
        scrolled_window.show()
        vbox.pack_start(scrolled_window, True, True, 0)

        self.file_scrolled_window = HIGScrolledWindow()
        self.file_scrolled_window.set_policy(gtk.POLICY_ALWAYS,
                                             gtk.POLICY_ALWAYS)
        self.file_scrolled_window.set_size_request(175, -1)
        self.file_scrolled_window.hide()
        self.file_scrolled_window.set_no_show_all(True)

        self.file_listview = gtk.TreeView(self.file_liststore)
        self.file_listview.set_headers_visible(False)
        col = gtk.TreeViewColumn(None)
        self.file_listview.append_column(col)
        cell = gtk.CellRendererToggle()
        col.pack_start(cell, True)
        cell.set_property("activatable", True)
        col.add_attribute(cell, "active", 1)
        cell.connect("toggled", self.toggled_cb, self.file_liststore)

        col = gtk.TreeViewColumn(None)
        self.file_listview.append_column(col)
        cell = gtk.CellRendererText()
        col.pack_start(cell)
        col.add_attribute(cell, "text", 0)

        self.file_listview.show_all()
        self.file_scrolled_window.add(self.file_listview)
        vbox.pack_start(self.file_scrolled_window, False)

        hbox = HIGHBox(False, 2)
        self.remove_file_button = HIGButton(stock=gtk.STOCK_REMOVE)
        self.remove_file_button.connect("clicked",
                                        self.remove_file_button_clicked_cb)
        self.remove_file_button.set_sensitive(False)
        hbox.pack_end(self.remove_file_button)
        add_file_button = HIGButton(stock=gtk.STOCK_ADD)
        add_file_button.connect("clicked", self.add_file_button_clicked_cb)
        hbox.pack_end(add_file_button)

        vbox.pack_start(hbox, False, False, 0)

        return vbox