예제 #1
0
    def render(self, environ, start_response):
        path = environ["PATH_INFO"].lstrip("/")
        query_string = environ["QUERY_STRING"].lstrip("/")
        params = cgi.parse_qs(query_string)
        content = params.get('content', [''])[0]
        space = params.get('render_space', None)
        if space:
            space = space[0]
        else:
            start_response('200 OK', [('Content-Type', "text/html")])
            return 'Parameter "space" not supplied'

        doc = params.get('render_doc', None)
        if doc:
            doc = doc[0]
        else:
            start_response('200 OK', [('Content-Type', "text/html")])
            return 'Parameter "doc" not supplied'

        ctx = RequestContext(application="", actor="", method="", env=environ,
                             start_response=start_response, path=path, params=None)
        ctx.params = self._getParamsFromEnv(environ, ctx)

        doc, _ = self.pageprocessor.getDoc(space, doc, ctx)

        doc = doc.copy()
        doc.source = content
        doc.loadFromSource()
        doc.preprocess()

        content, doc = doc.executeMacrosDynamicWiki(ctx=ctx)

        page = self.confluence2htmlconvertor.convert(
            content,
            doc=doc,
            requestContext=ctx,
            page=self.pageprocessor.getpage(),
            paramsExtra=ctx.params)

        if not 'postprocess' in page.processparameters or page.processparameters['postprocess']:
            page.body = page.body.replace("$$space", space)
            page.body = page.body.replace("$$page", doc.original_name)
            page.body = page.body.replace("$$path", doc.path)
            page.body = page.body.replace("$$querystr", ctx.env['QUERY_STRING'])

        page.body = page.body.replace("$$$menuright", "")

        if "todestruct" in doc.__dict__:
            doc.destructed = True

        start_response('200 OK', [('Content-Type', "text/html")])
        return str(page)
예제 #2
0
    def router(self, environ, start_response):
        path = environ["PATH_INFO"].lstrip("/")
        print(("path:%s" % path))
        pathparts = path.split('/')
        if pathparts[0] == 'wiki':
            pathparts = pathparts[1:]

        if path.find("favicon.ico") != -1:
            return self.pageprocessor.processor_page(environ, start_response, self.filesroot, "favicon.ico", prefix="")

        ctx = RequestContext(application="", actor="", method="", env=environ,
                             start_response=start_response, path=path, params=None)
        ctx.params = self._getParamsFromEnv(environ, ctx)
        ctx.env['JS_CTX'] = ctx

        for proxypath, proxy in self.proxies.items():
            if path.startswith(proxypath.lstrip('/')):
                return self.pageprocessor.process_proxy(ctx, proxy)

        if path.find("jslib/") == 0:
            path = path[6:]
            user = "******"
            # self.pageprocessor.log(ctx, user, path)
            return self.pageprocessor.processor_page(environ, start_response, self.jslibroot, path, prefix="jslib/")

        if path.find("images/") == 0:
            space, image = pathparts[1:3]
            spaceObject = self.getSpace(space)
            image = image.lower()

            if image in spaceObject.docprocessor.images:
                path2 = j.tools.path.get(spaceObject.docprocessor.images[image])

                return self.pageprocessor.processor_page(
                    environ, start_response, path2.dirname(), path2.basename(), prefix="images")
            ctx.start_response('404', [])

        if path.find("files/specs/") == 0:
            path = path[6:]
            user = "******"
            self.pageprocessor.log(ctx, user, path)
            return self.pageprocessor.processor_page(environ, start_response, self.filesroot, path, prefix="files/")

        if path.find(".files") != -1:
            user = "******"
            self.pageprocessor.log(ctx, user, path)
            space = pathparts[0].lower()
            path = "/".join(pathparts[2:])
            sploader = self.spacesloader.getSpaceFromId(space)
            filesroot = j.tools.path.get(sploader.model.path).joinpath(".files")
            return self.pageprocessor.processor_page(environ, start_response, filesroot, path, prefix="")

        if path.find(".static") != -1:
            user = "******"
            self.pageprocessor.log(ctx, user, path)
            space, pagename = self.pageprocessor.path2spacePagename(path)
            space = pathparts[0].lower()
            path = "/".join(pathparts[2:])
            sploader = self.spacesloader.getSpaceFromId(space)
            filesroot = j.tools.path.get(sploader.model.path).joinpath(".static")

            return self.pageprocessor.processor_page(
                environ, start_response, filesroot, path, prefix="", includedocs=True, ctx=ctx, space=space)

        # user is logged in now
        is_session, session = self.startSession(ctx, path)
        if not is_session:
            return session
        user = session['user']
        match = pathparts[0]
        path = ""
        if len(pathparts) > 1:
            path = "/".join(pathparts[1:])

        if match == "restmachine":
            return self.rest.processor_rest(environ, start_response, path, human=False, ctx=ctx)

        elif match == "elfinder":
            return self.pageprocessor.process_elfinder(path, ctx)

        elif match == "restextmachine":
            if not self.authentication_method:
                try:
                    j.clients.osis.getByInstance(self.hrd.get('instance', 'main'))
                except Exception as e:
                    self.pageprocessor.raiseError(
                        ctx,
                        msg="You have a minimal portal with no OSIS configured",
                        msginfo="",
                        errorObject=None,
                        httpcode="500 Internal Server Error")
            return self.rest.processor_restext(environ, start_response, path, human=False, ctx=ctx)

        elif match == "rest":
            space, pagename = self.pageprocessor.path2spacePagename(path.strip("/"))
            self.pageprocessor.log(ctx, user, path, space, pagename)
            return self.rest.processor_rest(environ, start_response, path, ctx=ctx)

        elif match == "restext":
            space, pagename = self.pageprocessor.path2spacePagename(path.strip("/"))
            self.pageprocessor.log(ctx, user, path, space, pagename)
            return self.rest.processor_restext(environ, start_response, path,
                                               ctx=ctx)
        elif match == "ping":
            status = '200 OK'
            headers = [
                ('Content-Type', "text/html"),
            ]
            start_response(status, headers)
            return ["pong"]

        elif match == "files":
            self.pageprocessor.log(ctx, user, path)
            return self.pageprocessor.processor_page(environ, start_response, self.filesroot, path, prefix="files")

        elif match == "specs":
            return self.pageprocessor.processor_page(environ, start_response, "specs", path, prefix="specs")

        elif match == "appservercode":
            return self.pageprocessor.processor_page(
                environ, start_response, "code", path, prefix="code", webprefix="appservercode")

        elif match == "lib":
            # print self.libpath
            return self.pageprocessor.processor_page(environ, start_response, self.libpath, path, prefix="lib")

        elif match == 'render':
            return self.render(environ, start_response)

        else:
            path = '/'.join(pathparts)
            ctx.params["path"] = '/'.join(pathparts)
            space, pagename = self.pageprocessor.path2spacePagename(path)
            self.pageprocessor.log(ctx, user, path, space, pagename)
            pagestring = str(self.pageprocessor.returnDoc(ctx, start_response, space, pagename, {}))
            return [pagestring]