def _terminateRequest(self, body, request): if body == server.NOT_DONE_YET: # _renderRequest will return NOT_DONE_YET if it started serving the # file. This means the callback chain started by _renderRequest has # finished and we're currently serving the file. return if isinstance(body, Failure): # Something went wrong, log it self.warning("Failure during request rendering: %s", log.getFailureMessage(body)) if body.check(weberror.Error): err = body.value page = weberror.ErrorPage(err.status, err.message, err.response) elif body.check(fileprovider.UnavailableError): page = self.serviceUnavailable elif body.check(fileprovider.AccessError): page = self.forbiddenResource elif body.check(fileprovider.NotFoundError): page = self.childNotFound else: page = self.internalServerError body = page.render(request) if body: # the callback chain from _renderRequest chose to return a string # body, write it out to the client request.write(body) self.debug('[fd %5d] Terminate request %r', request.transport.fileno(), request) request.finish()
def getChildWithDefault(self, path, request): if self.login(request.getUser(), request.getPassword()) == False: request.setHeader('WWW-authenticate', 'Basic realm="%s"' % ("OpenWebif")) errpage = error.ErrorPage(http.UNAUTHORIZED,"Unauthorized","401 Authentication required") return errpage else: return self.resource.getChildWithDefault(path, request)
def render(self, request): if request.getClientIP() == "127.0.0.1": return self.resource.render(request) if self.login(request.getUser(), request.getPassword()) == False: request.setHeader('WWW-authenticate', 'Basic realm="%s"' % ("OpenWebif")) errpage = error.ErrorPage(http.UNAUTHORIZED, "Unauthorized", "401 Authentication required") return errpage.render(request) else: return self.resource.render(request)
def getChildWithDefault(self, path, request): session = request.getSession().sessionNamespaces if request.getClientIP() == "127.0.0.1": return self.resource.getChildWithDefault(path, request) if "logged" in session.keys() and session["logged"]: return self.resource.getChildWithDefault(path, request) if self.login(request.getUser(), request.getPassword()) == False: request.setHeader('WWW-authenticate', 'Basic realm="%s"' % ("OpenWebif")) errpage = error.ErrorPage(http.UNAUTHORIZED, "Unauthorized", "401 Authentication required") return errpage else: session["logged"] = True return self.resource.getChildWithDefault(path, request)
def errorPage(self, *args): return error.ErrorPage(*args)