Exemplo n.º 1
0
    def post(self):

        # see the pingback specification for more info: http://hixie.ch/specs/pingback/pingback

        ip_address = self.request.remote_addr
        blog = self.blog
        result = None

        if not blog:
            result = xmlrpclib.Fault(32, 'Blog Not Found')
        elif not blog.enable_linkbacks or ip_address in blog.blocklist:
            result = xmlrpclib.Fault(49, 'Access Denied')
        else:
            params, methodname = xmlrpclib.loads(self.request.body)
            
            if methodname != 'pingback.ping':
                result = xmlrpclib.Fault(0, 'Unsupported Method')
            elif len(params) != 2:
                result = xmlrpclib.Fault(0, 'Invalid Request')
            else:
                source, target = params

                valid_source, source = validateRequiredUrl(source)
                valid_target, target = validateRequiredUrl(target)

                if not valid_source or not valid_target:
                    result = xmlrpclib.Fault(0, 'Invalid Request')
                else:
                    root_url = self.request.host_url + self.blog_url + '/post/'
                    post_slug = target.replace(root_url, '')
                    if not post_slug:
                        result = xmlrpclib.Fault(32, 'Post ID Not Found')
                    else:
                        post = model.BlogPost.get_by_id(post_slug, parent=blog.key)

                        # only allow pingbacking to a post if it's actually published
                        if not post or not post.published:
                            result = xmlrpclib.Fault(33, 'Post Not Found')
                        else:
                            # look for a comment from this URL address on this blog already (redundancy check)
                            exists = post.comments.filter(model.BlogComment.url == source).filter(model.BlogComment.pingback == True)
                            if exists.count():
                                result = xmlrpclib.Fault(48, 'Pingback Already Registered')
                        
                if not result:
                    comment = model.BlogComment(url=source, pingback=True, ip_address=ip_address, parent=post.key)
                    comment.put()

                    result = ('Pingback Receieved Successfully',)

                    self.linkbackEmail(post, comment)

        xml = xmlrpclib.dumps(result, methodresponse=True)

        self.response.headers['Content-Type'] = "text/xml"
        self.response.out.write(xml)
Exemplo n.º 2
0
    def post(self):

        # best technical resource on webmentions: https://github.com/converspace/webmention

        ip_address = self.request.remote_addr
        blog = self.blog

        if not blog:
            self.renderError(404)
        elif not blog.enable_linkbacks or ip_address in blog.blocklist:
            self.renderError(403)
        else:
            source = self.request.get("source")
            target = self.request.get("target")

            valid_source, source = validateRequiredUrl(source)
            valid_target, target = validateRequiredUrl(target)

            if not valid_source or not valid_target:
                self.renderError(400)
            else:
                root_url = self.request.host_url + self.blog_url + '/post/'
                post_slug = target.replace(root_url, '')
                if not post_slug:
                    self.renderError(404)
                else:
                    post = model.BlogPost.get_by_id(post_slug, parent=blog.key)

                    # only allow webmentions to a post if it's actually published
                    if not post or not post.published:
                        self.renderError(404)
                    else:
                        # look for a comment from this URL address on this blog already (redundancy check)
                        exists = post.comments.filter(model.BlogComment.url == source).filter(model.BlogComment.webmention == True)
                        if exists.count():
                            self.renderError(400)
                        else:
                            comment = model.BlogComment(url=source, webmention=True, ip_address=ip_address, parent=post.key)
                            comment.put()

                            self.linkbackEmail(post, comment)

                            self.response.set_status(202) # Accepted
                            self.response.out.write("Awaiting Moderation")
Exemplo n.º 3
0
    def post(self):

        # see the pingback specification for more info: http://hixie.ch/specs/pingback/pingback

        ip_address = self.request.remote_addr
        blog = self.blog
        result = None

        if not blog:
            result = xmlrpclib.Fault(32, 'Blog Not Found')
        elif not blog.enable_linkbacks or ip_address in blog.blocklist:
            result = xmlrpclib.Fault(49, 'Access Denied')
        else:
            params, methodname = xmlrpclib.loads(self.request.body)

            if methodname != 'pingback.ping':
                result = xmlrpclib.Fault(0, 'Unsupported Method')
            elif len(params) != 2:
                result = xmlrpclib.Fault(0, 'Invalid Request')
            else:
                source, target = params

                valid_source, source = validateRequiredUrl(source)
                valid_target, target = validateRequiredUrl(target)

                if not valid_source or not valid_target:
                    result = xmlrpclib.Fault(0, 'Invalid Request')
                else:
                    root_url = self.request.host_url + self.blog_url + '/post/'
                    post_slug = target.replace(root_url, '')
                    if not post_slug:
                        result = xmlrpclib.Fault(32, 'Post ID Not Found')
                    else:
                        post = model.BlogPost.get_by_id(post_slug,
                                                        parent=blog.key)

                        # only allow pingbacking to a post if it's actually published
                        if not post or not post.published:
                            result = xmlrpclib.Fault(33, 'Post Not Found')
                        else:
                            # look for a comment from this URL address on this blog already (redundancy check)
                            exists = post.comments.filter(
                                model.BlogComment.url == source).filter(
                                    model.BlogComment.pingback == True)
                            if exists.count():
                                result = xmlrpclib.Fault(
                                    48, 'Pingback Already Registered')

                if not result:
                    comment = model.BlogComment(url=source,
                                                pingback=True,
                                                ip_address=ip_address,
                                                parent=post.key)
                    comment.put()

                    result = ('Pingback Receieved Successfully', )

                    self.linkbackEmail(post, comment)

        xml = xmlrpclib.dumps(result, methodresponse=True)

        self.response.headers['Content-Type'] = "text/xml"
        self.response.out.write(xml)