Merge pull request #225 from deronnax/well-known
Support "well known" URLs
This commit is contained in:
commit
4e59d734a1
4
config
4
config
@ -46,6 +46,10 @@ request = utf-8
|
|||||||
# Encoding for storing local collections
|
# Encoding for storing local collections
|
||||||
stock = utf-8
|
stock = utf-8
|
||||||
|
|
||||||
|
[well-known]
|
||||||
|
caldav = '/%(user)s/caldav/'
|
||||||
|
carddav = '/%(user)s/carddav/'
|
||||||
|
|
||||||
|
|
||||||
[auth]
|
[auth]
|
||||||
# Authentication method
|
# Authentication method
|
||||||
|
@ -36,6 +36,7 @@ import posixpath
|
|||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import wsgiref.simple_server
|
import wsgiref.simple_server
|
||||||
|
import re
|
||||||
# Manage Python2/3 different modules
|
# Manage Python2/3 different modules
|
||||||
# pylint: disable=F0401,E0611
|
# pylint: disable=F0401,E0611
|
||||||
try:
|
try:
|
||||||
@ -55,6 +56,7 @@ VERSION = "0.9"
|
|||||||
# Standard "not allowed" response that is returned when an authenticated user
|
# Standard "not allowed" response that is returned when an authenticated user
|
||||||
# tries to access information they don't have rights to
|
# tries to access information they don't have rights to
|
||||||
NOT_ALLOWED = (client.FORBIDDEN, {}, None)
|
NOT_ALLOWED = (client.FORBIDDEN, {}, None)
|
||||||
|
WELLKNOWNRE = re.compile(r'/.well-known/(carddav|caldav)/?')
|
||||||
|
|
||||||
|
|
||||||
class HTTPServer(wsgiref.simple_server.WSGIServer, object):
|
class HTTPServer(wsgiref.simple_server.WSGIServer, object):
|
||||||
@ -277,6 +279,25 @@ class Application(object):
|
|||||||
user = environ.get("REMOTE_USER")
|
user = environ.get("REMOTE_USER")
|
||||||
password = None
|
password = None
|
||||||
|
|
||||||
|
wkfragment = WELLKNOWNRE.match(path)
|
||||||
|
if wkfragment:
|
||||||
|
if not user: del user
|
||||||
|
redirect = config.get("well-known", wkfragment.group(1))
|
||||||
|
try:
|
||||||
|
redirect = redirect % locals()
|
||||||
|
status = client.SEE_OTHER
|
||||||
|
log.LOGGER.info("/.well-known/ redirection to: %s" % redirect)
|
||||||
|
headers = {"Location": redirect.encode('utf8')}
|
||||||
|
except KeyError:
|
||||||
|
status = client.UNAUTHORIZED
|
||||||
|
headers = {
|
||||||
|
"WWW-Authenticate":
|
||||||
|
"Basic realm=\"%s\"" % config.get("server", "realm")}
|
||||||
|
log.LOGGER.info("refused /.well-known/ redirection to anonymous user")
|
||||||
|
status = "%i %s" % (status, client.responses.get(status, "Unknown"))
|
||||||
|
start_response(status, headers.items())
|
||||||
|
return []
|
||||||
|
|
||||||
is_authenticated = auth.is_authenticated(user, password)
|
is_authenticated = auth.is_authenticated(user, password)
|
||||||
is_valid_user = is_authenticated or not user
|
is_valid_user = is_authenticated or not user
|
||||||
|
|
||||||
|
@ -51,6 +51,9 @@ INITIAL_CONFIG = {
|
|||||||
"base_prefix": "/",
|
"base_prefix": "/",
|
||||||
"can_skip_base_prefix": "False",
|
"can_skip_base_prefix": "False",
|
||||||
"realm": "Radicale - Password Required"},
|
"realm": "Radicale - Password Required"},
|
||||||
|
"well-known": {
|
||||||
|
"caldav": "/%(user)s/caldav/",
|
||||||
|
"carddav": "/%(user)s/carddav/"},
|
||||||
"encoding": {
|
"encoding": {
|
||||||
"request": "utf-8",
|
"request": "utf-8",
|
||||||
"stock": "utf-8"},
|
"stock": "utf-8"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user