Esempio n. 1
0
    def create_ui(self):
        # Toolbar
        self.toolbar = gtk.Toolbar()
        self.toolbar.set_style(gtk.TOOLBAR_ICONS)

        self.intf_combo = InterfacesCombo()

        item = gtk.ToolItem()
        item.add(self.intf_combo)

        self.toolbar.insert(item, -1)

        action = gtk.Action(None, None, _('Run the sequence'),
                            gtk.STOCK_EXECUTE)
        action.connect('activate', self.__on_run)
        self.toolbar.insert(action.create_tool_item(), -1)

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        stocks = (gtk.STOCK_GO_UP, gtk.STOCK_GO_DOWN)
        tooltips = (_('Send packet'), _('Send/receive packet'))
        callbacks = (self.__on_send, self.__on_send_receive)

        for tooltip, stock, callback in zip(tooltips, stocks, callbacks):
            action = gtk.Action(None, None, tooltip, stock)
            action.connect('activate', callback)
            self.toolbar.insert(action.create_tool_item(), -1)

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        # Count/interval

        self.packet_count = gtk.SpinButton(gtk.Adjustment(1, 0, maxint, 1, 10))
        self.packet_interval = gtk.SpinButton(
            gtk.Adjustment(500, 0, maxint, 1, 10))

        for lbl, widget in zip((_('No:'), _('Interval (ms):')),
                               (self.packet_count, self.packet_interval)):

            hbox = gtk.HBox(False, 4)
            hbox.set_border_width(2)

            label = gtk.Label(lbl)
            label.set_use_markup(True)
            label.set_alignment(0, 0.5)

            hbox.pack_start(label)
            hbox.pack_start(widget)

            item = gtk.ToolItem()
            item.add(hbox)

            self.toolbar.insert(item, -1)

        tooltips = (_('Use strict checking for the replies'),
                    _('Report also received packets'),
                    _('Report also sent packets'))

        self.check_strict = gtk.CheckButton("Strict")
        self.check_received = gtk.CheckButton("Received")
        self.check_sent = gtk.CheckButton("Sent")

        self.check_strict.set_active(True)
        self.check_sent.set_active(True)

        for widget, tip in zip(
            (self.check_strict, self.check_received, self.check_sent),
                tooltips):

            item = gtk.ToolItem()
            item.add(widget)

            widget.set_tooltip_text(tip)
            self.toolbar.insert(item, -1)

        # Combo
        space = gtk.ToolItem()
        space.set_homogeneous(False)
        space.set_expand(True)
        self.toolbar.insert(space, -1)

        action = gtk.Action(None, None, _('Merge selection'),
                            gtk.STOCK_COLOR_PICKER)
        action.connect('activate', self.__on_merge)
        self.toolbar.insert(action.create_tool_item(), -1)

        self.combo = FilterLayer()

        item = gtk.ToolItem()
        item.add(self.combo)
        item.set_homogeneous(False)
        self.toolbar.insert(item, -1)

        self.pack_start(self.toolbar, False, False)

        # Packet
        self.store = gtk.TreeStore(object)
        self.tree = gtk.TreeView(self.store)

        rend = GridRenderer()
        col = gtk.TreeViewColumn(_('Packet sequence'), rend)
        col.set_cell_data_func(rend, self.__txt_cell_data)

        self.tree.append_column(col)
        self.tree.set_rules_hint(True)

        self.use_colors = False

        # Filtering
        self.active_layer = None
        self.active_packets = []
        self.active_diff = None

        self.merging = False
        self.filter_store = gtk.ListStore(str, object)

        target_packet = ('PMPacket', gtk.TARGET_SAME_WIDGET, 0)
        target_plain = ('text/plain', 0, 0)

        self.tree.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                                           [target_packet],
                                           gtk.gdk.ACTION_MOVE)
        self.tree.enable_model_drag_dest([target_plain, target_packet],
                                         gtk.gdk.ACTION_MOVE | \
                                         gtk.gdk.ACTION_COPY)

        sw = gtk.ScrolledWindow()
        sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(self.tree)

        self.pack_start(sw)

        self.selected_packets = []
        self.context_menu = gtk.Menu()

        labels = (_('&Remove selected'), _('&Copy selected'),
                  _('&Paste selected'))

        icons = (gtk.STOCK_DELETE, gtk.STOCK_COPY, gtk.STOCK_PASTE)
        callbacks = (self.__on_remove, self.__on_copy, self.__on_paste)

        for lbl, icon, cb in zip(labels, icons, callbacks):
            action = gtk.Action(None, None, lbl, icon)
            action.connect_accelerator()
            action.connect('activate', cb)
            self.context_menu.append(action.create_menu_item())

        self.context_menu.show_all()

        # Connect signals here

        # TODO: get from preference
        self.colors = (
            gtk.gdk.color_parse('#FFFA99'),
            gtk.gdk.color_parse('#8DFF7F'),
            gtk.gdk.color_parse('#FFE3E5'),
            gtk.gdk.color_parse('#C797FF'),
            gtk.gdk.color_parse('#A0A0A0'),
            gtk.gdk.color_parse('#D6E8FF'),
            gtk.gdk.color_parse('#C2C2FF'),
        )

        Prefs()['gui.maintab.sequenceview.font'].connect(self.__modify_font)
        Prefs()['gui.maintab.sequenceview.usecolors'].connect(
            self.__modify_colors)

        self.tree.connect('button-press-event', self.__on_tree_button_pressed)
        self.tree.connect('drag-data-received', self.__on_drag_data)
        self.tree.get_selection().connect('changed',
                                          self.__on_selection_changed)

        self.combo.connect('changed', self.__on_filter)

        # Setting up the gui controls

        if isinstance(self.session.context, SequenceContext):
            self.packet_count.set_value(self.session.context.tot_loop_count)
            self.packet_interval.set_value(self.session.context.inter * 1000.0)

        self.check_received.set_active(self.session.context.report_recv)
        self.check_sent.set_active(self.session.context.report_sent)
        self.check_strict.set_active(self.session.context.strict)

        self.check_strict.connect('toggled', self.__on_strict_toggled)
        self.check_received.connect('toggled', self.__on_recv_toggled)
        self.check_sent.connect('toggled', self.__on_sent_toggled)

        self.packet_count.connect('value-changed', self.__on_pcount_changed)
        self.packet_interval.connect('value-changed', self.__on_pinter_changed)
    def create_ui(self):
        self._main_widget.set_border_width(4)
        self._main_widget.set_spacing(2)

        self.intf_combo = InterfacesCombo()

        self._main_widget.pack_start(self.intf_combo, False, False)

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)

        self.store = gtk.ListStore(str, str, str)
        self.tree = gtk.TreeView(self.store)

        rend = gtk.CellRendererText()

        self.tree.append_column(gtk.TreeViewColumn(_('IP'), rend, text=0))
        self.tree.append_column(gtk.TreeViewColumn(_('MAC'), rend, text=1))
        self.tree.append_column(
            gtk.TreeViewColumn(_('Description'), rend, text=2))

        self.tree.get_column(2).set_resizable(True)
        self.tree.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                                           [('text/plain', 0, 0)],
                                           gtk.gdk.ACTION_DEFAULT | \
                                           gtk.gdk.ACTION_COPY)

        # Enable multiple selection
        self.tree.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        self.tree.set_rubber_banding(True)

        self.last_pos = (0, 0)
        self.tree.connect("drag-begin", self.__on_drag_begin)
        self.tree.connect("drag-data-get", self.__on_drag_data_get)
        self.tree.connect("button-press-event", self.__on_button_press)

        self.tree.set_rules_hint(True)
        self.tree.set_search_column(0)
        self.tree.set_enable_search(True)

        sw.add(self.tree)
        self._main_widget.pack_start(sw)

        bb = gtk.HButtonBox()
        bb.set_layout(gtk.BUTTONBOX_END)

        self.btn_refresh = new_button(gtk.STOCK_REFRESH, _('Refresh the list'))
        self.btn_refresh.connect('clicked', self.__on_refresh)

        self.btn_info = new_button(gtk.STOCK_INFO,
                                   _('Information for selected host'))
        self.btn_info.connect('clicked', self.__on_info)

        bb.pack_start(self.btn_refresh, False, False)
        bb.pack_end(self.btn_info, False, False)

        self._main_widget.pack_end(bb, False, False)
        self._main_widget.show_all()

        self.btn_info.set_sensitive(False)
        self.btn_refresh.set_sensitive(False)

        svc = ServiceBus().get_service('pm.hostlist')
        svc.connect('func-binded', self.__on_func_assigned)
        svc.connect('func-unbinded', self.__on_func_assigned)

        self.populate()
Esempio n. 3
0
    def __init__(self, parent):
        super(NewAuditDialog,
              self).__init__(_('New audit - PacketManipulator'), parent,
                             gtk.DIALOG_DESTROY_WITH_PARENT,
                             (gtk.STOCK_CLOSE, gtk.RESPONSE_REJECT,
                              gtk.STOCK_NEW, gtk.RESPONSE_ACCEPT))

        lbl1 = gtk.Label(_('Interface:'))
        lbl1.set_alignment(.0, .5)

        lbl2 = gtk.Label(_('Interface:'))
        lbl2.set_alignment(.0, .5)

        lbl3 = gtk.Label(_('Pcap filter:'))
        lbl3.set_alignment(.0, .5)

        self.intf1_combo = InterfacesCombo(False)

        bridge_check = gtk.CheckButton(_('Use bridged sniffing'))
        bridge_check.connect('toggled', self.__on_check_toggled)

        self.unoffensive_check = gtk.CheckButton(_('Unoffensie mode'))
        self.skipforwarded_check = gtk.CheckButton(_('Skip forwarded packets'))

        self.intf2_combo = InterfacesCombo(False)

        self.filter = gtk.Entry()

        table = gtk.Table(5, 2, False)

        table.set_border_width(4)
        table.set_row_spacings(4)
        table.set_col_spacings(10)

        table.attach(lbl1, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
        table.attach(self.intf1_combo, 1, 2, 0, 1, yoptions=gtk.FILL)

        table.attach(bridge_check, 0, 2, 1, 2, gtk.FILL, gtk.FILL)
        table.attach(lbl2, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
        table.attach(self.intf2_combo, 1, 2, 2, 3, yoptions=gtk.FILL)

        table.attach(lbl3, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
        table.attach(self.filter, 1, 2, 3, 4, yoptions=gtk.FILL)

        table.attach(self.unoffensive_check, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
        table.attach(self.skipforwarded_check, 0, 1, 5, 6, gtk.FILL, gtk.FILL)

        self.vbox.pack_start(table)

        self.intf2_combo.set_sensitive(False)

        table.show_all()

        for btn in self.action_area:
            if btn.get_label() == gtk.STOCK_NEW:
                self.intf1_combo.connect('changed', self.__on_changed, btn)
                self.intf2_combo.connect('changed', self.__on_changed, btn)

                self.__on_changed(self.intf1_combo, btn)

        self.set_size_request(400, 250)