Ejemplo n.º 1
0
    def _check_preconditions(self, req, author, content):
        if self.karma_points == 0:
            return False

        if len(content) == 0:
            return False

        if is_binary(content):
            self.log.warning("Content is binary, BlogSpam content check "
                             "skipped")
            return False

        return True
Ejemplo n.º 2
0
    def _check_preconditions(self, req, author, content):
        if not self.api_key:
            self.log.warning('Akismet API key is missing')
            return False

        if is_binary(content):
            self.log.warning('Content is binary, Akismet content check skipped')
            return False

        try:
            if not self._verify_key(req):
                self.log.warning('Akismet API key is invalid')
                return False
            return True
        except urllib2.URLError, e:
            self.log.warn('Akismet request failed (%s)', e)
Ejemplo n.º 3
0
    def _check_preconditions(self, req, author, content):
        if self.karma_points == 0:
            return False

        if not self.api_key:
            self.log.warning("Akismet API key is missing")
            return False

        if is_binary(content):
            self.log.warning("Content is binary, Akismet content check "
                             "skipped")
            return False

        try:
            if not self.verify_key(req):
                self.log.warning("Akismet API key is invalid")
                return False
            return True
        except urllib2.URLError, e:
            self.log.warn("Akismet request failed (%s)", e)
Ejemplo n.º 4
0
    def _check_preconditions(self, req, author, content):
        if self.karma_points == 0:
            return False

        if not self.public_key or not self.private_key:
            self.log.warning("Mollom API keys missing")
            return False

        if is_binary(content):
            self.log.warning("Content is binary, Mollom content check "
                             "skipped")
            return False

        try:
            if not self.verify_key(req):
                self.log.warning("Mollom API keys are invalid")
                return False
            return True
        except urllib2.URLError, e:
            self.log.warn("Mollom request failed (%s)", e)
Ejemplo n.º 5
0
    def _render_file(self, req, context, repos, node, rev=None):
        req.perm(node.resource).require('FILE_VIEW')

        mimeview = Mimeview(self.env)

        # MIME type detection
        content = node.get_content()
        chunk = content.read(CHUNK_SIZE)
        mime_type = node.content_type
        if not mime_type or mime_type == 'application/octet-stream':
            mime_type = mimeview.get_mimetype(node.name, chunk) or \
                        mime_type or 'text/plain'

        # Eventually send the file directly
        format = req.args.get('format')
        if format in ('raw', 'txt'):
            req.send_response(200)
            req.send_header('Content-Type',
                            'text/plain' if format == 'txt' else mime_type)
            req.send_header('Content-Length', node.content_length)
            req.send_header('Last-Modified', http_date(node.last_modified))
            if rev is None:
                req.send_header('Pragma', 'no-cache')
                req.send_header('Cache-Control', 'no-cache')
                req.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT')
            if not self.render_unsafe_content:
                # Force browser to download files instead of rendering
                # them, since they might contain malicious code enabling
                # XSS attacks
                req.send_header('Content-Disposition', 'attachment')
            req.end_headers()

            while 1:
                if not chunk:
                    raise RequestDone
                req.write(chunk)
                chunk = content.read(CHUNK_SIZE)
        else:
            # The changeset corresponding to the last change on `node`
            # is more interesting than the `rev` changeset.
            changeset = repos.get_changeset(node.created_rev)

            # add ''Plain Text'' alternate link if needed
            if not is_binary(chunk) and mime_type != 'text/plain':
                plain_href = req.href.browser(repos.reponame or None,
                                              node.path, rev=rev, format='txt')
                add_link(req, 'alternate', plain_href, _('Plain Text'),
                         'text/plain')

            # add ''Original Format'' alternate link (always)
            raw_href = req.href.export(rev or repos.youngest_rev,
                                       repos.reponame or None, node.path)
            add_link(req, 'alternate', raw_href, _('Original Format'),
                     mime_type)

            self.log.debug("Rendering preview of node %s@%s with mime-type %s"
                           % (node.name, str(rev), mime_type))

            del content # the remainder of that content is not needed

            add_stylesheet(req, 'common/css/code.css')

            annotations = ['lineno']
            annotate = req.args.get('annotate')
            if annotate:
                annotations.insert(0, annotate)
            preview_data = mimeview.preview_data(context, node.get_content(),
                                                 node.get_content_length(),
                                                 mime_type, node.created_path,
                                                 raw_href,
                                                 annotations=annotations,
                                                 force_source=bool(annotate))
            return {
                'changeset': changeset,
                'size': node.content_length,
                'preview': preview_data,
                'annotate': annotate,
                }
Ejemplo n.º 6
0
    def _render_file(self, req, context, repos, node, rev=None):
        req.perm(node.resource).require("FILE_VIEW")

        mimeview = Mimeview(self.env)

        # MIME type detection
        content = node.get_processed_content()
        chunk = content.read(CHUNK_SIZE)
        mime_type = node.content_type
        if not mime_type or mime_type == "application/octet-stream":
            mime_type = mimeview.get_mimetype(node.name, chunk) or mime_type or "text/plain"

        # Eventually send the file directly
        format = req.args.get("format")
        if format in ("raw", "txt"):
            req.send_response(200)
            req.send_header("Content-Type", "text/plain" if format == "txt" else mime_type)
            req.send_header("Last-Modified", http_date(node.last_modified))
            if rev is None:
                req.send_header("Pragma", "no-cache")
                req.send_header("Cache-Control", "no-cache")
                req.send_header("Expires", "Fri, 01 Jan 1999 00:00:00 GMT")
            if not self.render_unsafe_content:
                # Force browser to download files instead of rendering
                # them, since they might contain malicious code enabling
                # XSS attacks
                req.send_header("Content-Disposition", "attachment")
            req.end_headers()
            # Note: don't pass an iterable instance to RequestDone, instead
            # call req.write() with each chunk here to avoid SEGVs (#11805)
            while chunk:
                req.write(chunk)
                chunk = content.read(CHUNK_SIZE)
            raise RequestDone
        else:
            # The changeset corresponding to the last change on `node`
            # is more interesting than the `rev` changeset.
            changeset = repos.get_changeset(node.created_rev)

            # add ''Plain Text'' alternate link if needed
            if not is_binary(chunk) and mime_type != "text/plain":
                plain_href = req.href.browser(repos.reponame or None, node.path, rev=rev, format="txt")
                add_link(req, "alternate", plain_href, _("Plain Text"), "text/plain")

            # add ''Original Format'' alternate link (always)
            raw_href = req.href.export(rev or repos.youngest_rev, repos.reponame or None, node.path)
            add_link(req, "alternate", raw_href, _("Original Format"), mime_type)

            self.log.debug("Rendering preview of node %s@%s with mime-type %s", node.name, rev, mime_type)

            content = None  # the remainder of that content is not needed

            add_stylesheet(req, "common/css/code.css")

            annotations = ["lineno"]
            annotate = req.args.get("annotate")
            if annotate:
                annotations.insert(0, annotate)
            preview_data = mimeview.preview_data(
                context,
                node.get_processed_content(),
                node.get_content_length(),
                mime_type,
                node.created_path,
                raw_href,
                annotations=annotations,
                force_source=bool(annotate),
            )
            return {"changeset": changeset, "size": node.content_length, "preview": preview_data, "annotate": annotate}