From e484cc4dd98cd7b7d98b40515fc0f2a8d585df48 Mon Sep 17 00:00:00 2001 From: jonnylamb Date: Fri, 14 Sep 2007 13:18:33 +0000 Subject: [PATCH] * Misc. fixes in bongo-standalone, Auth and PropfindView. * Added Server.py for use in Apache. * Note: this currently doesn't work, so unless you have a way to send the Authorization header manually, Sundial through Apache will not work. This is pretty high up on my TODO list. --- src/www/Bongo.rules | 3 +- src/www/bongo-standalone.py | 2 +- src/www/bongo/sundial/Auth.py | 2 +- src/www/bongo/sundial/PropfindView.py | 1 + src/www/bongo/sundial/Server.py | 52 +++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/www/bongo/sundial/Server.py diff --git a/src/www/Bongo.rules b/src/www/Bongo.rules index ebc91e2..68908b1 100644 --- a/src/www/Bongo.rules +++ b/src/www/Bongo.rules @@ -365,7 +365,8 @@ pkgpythonsundial_PYTHON := \ src/www/bongo/sundial/OptionsView.py \ src/www/bongo/sundial/ReportView.py \ src/www/bongo/sundial/DeleteView.py \ - src/www/bongo/sundial/PutView.py + src/www/bongo/sundial/PutView.py \ + src/www/bongo/sundial/Server.py pkgpythoncommonwebdir = $(pkgpythondir)/commonweb diff --git a/src/www/bongo-standalone.py b/src/www/bongo-standalone.py index 2fb818e..573864d 100755 --- a/src/www/bongo-standalone.py +++ b/src/www/bongo-standalone.py @@ -219,7 +219,7 @@ class DragonflyHandler(SimpleHTTPRequestHandler): handler = rp.GetHandler(req, rp) if handler.NeedsAuth(rp): - if req.user == None: + if req.user is None: self.req.headers_out["WWW-Authenticate"] = "Basic realm=\"Bongo\"" self.send_error(bongo.commonweb.HTTP_UNAUTHORIZED) return bongo.commonweb.HTTP_UNAUTHORIZED diff --git a/src/www/bongo/sundial/Auth.py b/src/www/bongo/sundial/Auth.py index 115f735..10241d1 100644 --- a/src/www/bongo/sundial/Auth.py +++ b/src/www/bongo/sundial/Auth.py @@ -35,7 +35,7 @@ def AcceptCredentials(req): # Upon a success or failure, return the appropriate HTTP error code. def authenhandler(req): if AcceptCredentials(req): - req.log.debug("successful auth") +# req.log.debug("successful auth") return bongo.commonweb.HTTP_OK return bongo.commonweb.HTTP_UNAUTHORIZED diff --git a/src/www/bongo/sundial/PropfindView.py b/src/www/bongo/sundial/PropfindView.py index 40d9b4d..8dcd324 100644 --- a/src/www/bongo/sundial/PropfindView.py +++ b/src/www/bongo/sundial/PropfindView.py @@ -6,6 +6,7 @@ import bongo.commonweb import bongo.commonweb.ElementTree +from bongo.commonweb.HttpError import HttpError from SundialHandler import SundialHandler from bongo.store.StoreClient import StoreClient from bongo.store.StoreClient import DocTypes diff --git a/src/www/bongo/sundial/Server.py b/src/www/bongo/sundial/Server.py new file mode 100644 index 0000000..304132d --- /dev/null +++ b/src/www/bongo/sundial/Server.py @@ -0,0 +1,52 @@ +from bongo.commonweb.ApacheLogHandler import ApacheLogHandler, RequestLogProxy +from SundialPath import SundialPath +from bongo.commonweb.HttpError import HttpError + +import Auth +import bongo.commonweb + +# Add a handler so messages from python's logging module go to apache. +# We don't use that module in the Bongo server proper, because we need +# to log to apache requests directly +import logging +logging.getLogger('').addHandler(ApacheLogHandler()) +logging.root.setLevel(logging.DEBUG) + +def handler(req): + req.log = RequestLogProxy(req) + + req.log.debug("Request: %s", req) + + try: + rp = SundialPath(req) + handler = rp.GetHandler(req, rp) + + +# if handler.NeedsAuth(rp): +# if req.user is None: +# self.req.headers_out["WWW-Authenticate"] = 'Basic realm="Bongo"' +# self.send_error(bongo.commonweb.HTTP_UNAUTHORIZED) +# return bongo.commonweb.HTTP_UNAUTHORIZED +# else: +# auth = bongo.sundial.Auth.authenhandler(req) + + req.log.debug("request for %s (handled by %s)", req.path_info, handler) + + mname = "do_" + req.method + + if not hasattr(handler, mname): + req.log.debug("%s has no %s", handler, mname) + return bongo.commonweb.HTTP_NOT_FOUND + + method = getattr(handler, mname) + + ret = method(req, rp) + + if ret is None: + req.log.error("Handler %s returned invalid value: None" % handler) + return bongo.commonweb.OK + + return ret + except HttpError, e: + req.log.debug(str(e), exc_info=1) + return e.code