Explorar o código

add ".well-known" addresses feature (closes #126)

deronnax %!s(int64=11) %!d(string=hai) anos
pai
achega
b863e8390e
Modificáronse 3 ficheiros con 26 adicións e 0 borrados
  1. 4 0
      config
  2. 19 0
      radicale/__init__.py
  3. 3 0
      radicale/config.py

+ 4 - 0
config

@@ -46,6 +46,10 @@ request = utf-8
 # Encoding for storing local collections
 stock = utf-8
 
+[well-known]
+caldav = '/%(user)s/caldav/'
+carddav = '/%(user)s/carddav/'
+
 
 [auth]
 # Authentication method

+ 19 - 0
radicale/__init__.py

@@ -286,6 +286,25 @@ class Application(object):
             user = environ.get("REMOTE_USER")
             password = None
 
+        if path.startswith('/.well-known/'):
+            fragment = path.rstrip("/").rsplit('/', 1)[-1]
+            redirect = config.get("well-known", fragment)
+            if redirect:
+                if not user and "%(user)s" in redirect:
+                    status = client.UNAUTHORIZED
+                    headers = {
+                        "WWW-Authenticate":
+                        "Basic realm=\"%s\"" % config.get("server", "realm")}
+                    log.LOGGER.info("refused /.well-known/ redirection to anonymous user")
+                else:
+                    redirect = redirect % locals()
+                    status = client.SEE_OTHER
+                    log.LOGGER.info("/.well-known/ redirection to: %s" % redirect)
+                    headers = {"Location": redirect.encode('utf8')}
+                status = "%i %s" % (status, client.responses.get(status, "Unknown"))
+                start_response(status, headers.items())
+                return []
+
         is_authenticated = auth.is_authenticated(user, password)
         is_valid_user = is_authenticated or not user
 

+ 3 - 0
radicale/config.py

@@ -51,6 +51,9 @@ INITIAL_CONFIG = {
         "base_prefix": "/",
         "can_skip_base_prefix": "False",
         "realm": "Radicale - Password Required"},
+    "well-known": {
+         "caldav": "/%(user)s/caldav/",
+         "carddav": "/%(user)s/carddav/"},
     "encoding": {
         "request": "utf-8",
         "stock": "utf-8"},