def __on_open_session(self, action):
        types = {}
        sessions = (backend.StaticContext, backend.SequenceContext,
                    backend.SniffContext)

        for ctx in sessions:
            for name, pattern in ctx.file_types:
                types[pattern] = (name, ctx)

        dialog = gtk.FileChooserDialog(
            _("Select a session"),
            self,
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
                     gtk.RESPONSE_ACCEPT))
        dialog.set_transient_for(self)

        filterall = gtk.FileFilter()
        filterall.set_name(_('All supported files'))
        [filterall.add_pattern(k) for k in types]
        dialog.add_filter(filterall)

        for pattern, (name, ctx) in types.items():
            filter = gtk.FileFilter()
            filter.set_name(name)
            filter.add_pattern(pattern)
            dialog.add_filter(filter)

        if dialog.run() == gtk.RESPONSE_ACCEPT:
            ctx = None
            fname = dialog.get_filename()

            try:
                find = fname.split('.')[-1]

                for pattern in types:
                    if pattern.split('.')[-1] == find:
                        ctx = types[pattern][1]
            except:
                pass

            if ctx is not backend.SequenceContext and \
               ctx is not backend.SniffContext and \
               ctx is not backend.StaticContext:

                d = HIGAlertDialog(
                    type=gtk.MESSAGE_ERROR,
                    message_format=_("Unable to open selected session"),
                    secondary_text=_(
                        "PacketManipulator is unable to guess the "
                        "file type. Try to modify the extension "
                        "and to reopen the file."))
                d.set_transient_for(self)
                d.run()
                d.destroy()
            else:
                self.open_generic_file_async(fname)

        dialog.hide()
        dialog.destroy()
示例#2
0
    def __on_open_session(self, action):
        types = {}
        sessions = (backend.StaticContext,
                    backend.SequenceContext,
                    backend.SniffContext)

        for ctx in sessions:
            for name, pattern in ctx.file_types:
                types[pattern] = (name, ctx)

        dialog = gtk.FileChooserDialog(_("Select a session"), self,
                               buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT))
        dialog.set_transient_for(self)

        filterall = gtk.FileFilter()
        filterall.set_name(_('All supported files'))
        [filterall.add_pattern(k) for k in types]
        dialog.add_filter(filterall)

        for pattern, (name, ctx) in types.items():
            filter = gtk.FileFilter()
            filter.set_name(name)
            filter.add_pattern(pattern)
            dialog.add_filter(filter)

        if dialog.run() == gtk.RESPONSE_ACCEPT:
            ctx = None
            fname = dialog.get_filename()

            try:
                find = fname.split('.')[-1]

                for pattern in types:
                    if pattern.split('.')[-1] == find:
                        ctx = types[pattern][1]
            except:
                pass

            if ctx is not backend.SequenceContext and \
               ctx is not backend.SniffContext and \
               ctx is not backend.StaticContext:

                d = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                    message_format=_("Unable to open selected session"),
                    secondary_text=_("PacketManipulator is unable to guess the "
                                     "file type. Try to modify the extension "
                                     "and to reopen the file."))
                d.set_transient_for(self)
                d.run()
                d.destroy()
            else:
                self.open_generic_file_async(fname)

        dialog.hide()
        dialog.destroy()
        #    ctx.join()

        errs = []

        try:
            log.debug('Saving options before exiting')
            Prefs().write_options()
        except IOError, err:
            errs.append(err)

        try:
            log.debug('Saving audit configurations')
            AuditManager().write_configurations()
        except IOError, err:
            errs.append(err)

        if errs:
            errstr = '\n'.join(
                map(lambda x: 'on %s (%s)' % (x.filename, x.strerror), errs))

            dialog = HIGAlertDialog(
                type=gtk.MESSAGE_ERROR,
                message_format=_('Error while saving configurations'),
                secondary_text=errstr + '\n\n' + _('Be sure to have ' \
                                 'read and write permission.'))
            dialog.set_transient_for(self)
            dialog.run()
            dialog.destroy()

        gtk.main_quit()
示例#4
0
        errs = []

        try:
            log.debug('Saving options before exiting')
            Prefs().write_options()
        except IOError, err:
            errs.append(err)

        try:
            log.debug('Saving audit configurations')
            AuditManager().write_configurations()
        except IOError, err:
            errs.append(err)

        if errs:
            errstr = '\n'.join(
                map(lambda x: 'on %s (%s)' % (x.filename, x.strerror),
                errs)
            )

            dialog = HIGAlertDialog(
                type=gtk.MESSAGE_ERROR,
                message_format=_('Error while saving configurations'),
                secondary_text=errstr + '\n\n' + _('Be sure to have ' \
                                 'read and write permission.'))
            dialog.set_transient_for(self)
            dialog.run()
            dialog.destroy()

        gtk.main_quit()