diff options
author | Unrud <unrud@outlook.com> | 2020-05-19 07:25:21 +0200 |
---|---|---|
committer | Unrud <unrud@outlook.com> | 2020-05-19 07:25:21 +0200 |
commit | c4925ae7db6704ca440a6bf3bc3195e0262d7722 (patch) | |
tree | cb01b9862588ff7530bbadb9f5c72dbf8e17577c /radicale_infcloud | |
parent | Add .gitignore (diff) | |
download | radicaleinfcloud-c4925ae7db6704ca440a6bf3bc3195e0262d7722.tar.gz radicaleinfcloud-c4925ae7db6704ca440a6bf3bc3195e0262d7722.tar.bz2 radicaleinfcloud-c4925ae7db6704ca440a6bf3bc3195e0262d7722.zip |
Update for Radicale 3.0.x
Diffstat (limited to 'radicale_infcloud')
-rw-r--r-- | radicale_infcloud/__init__.py | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/radicale_infcloud/__init__.py b/radicale_infcloud/__init__.py index 7f1b3ea..8dc04df 100644 --- a/radicale_infcloud/__init__.py +++ b/radicale_infcloud/__init__.py @@ -1,5 +1,5 @@ # RadicaleWeb web interface for Radicale. -# Copyright (C) 2017 Unrud <unrud@outlook.com> +# Copyright © 2017-2018, 2020 Unrud <unrud@outlook.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,18 +15,22 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os -import pkg_resources import posixpath import time - from http import client -from radicale import storage, web -from radicale.web import NOT_FOUND, MIMETYPES, FALLBACK_MIMETYPE +from radicale import httputils, pathutils +from radicale.log import logger +from radicale.web import internal +from radicale.web.internal import MIMETYPES, FALLBACK_MIMETYPE + +import pkg_resources + +PLUGIN_CONFIG_SCHEMA = {"web": {}} -class Web(web.Web): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) +class Web(internal.Web): + def __init__(self, configuration): + super().__init__(configuration.copy(PLUGIN_CONFIG_SCHEMA)) self.infcloud_folder = pkg_resources.resource_filename(__name__, "web") def get(self, environ, base_prefix, path, user): @@ -35,28 +39,29 @@ class Web(web.Web): user) if status == client.OK and path in ("/.web/", "/.web/index.html"): answer = answer.replace(b"""\ - <nav> - <ul>""", b"""\ - <nav> - <ul> - <li><a href="infcloud">InfCloud</a></li>""") +<nav> + <ul>""", b"""\ +<nav> + <ul> + <li><a href="infcloud">InfCloud</a></li>""") return status, headers, answer + assert pathutils.sanitize_path(path) == path try: - filesystem_path = storage.path_to_filesystem( - self.infcloud_folder, path[len("/.web/infcloud"):]) + filesystem_path = pathutils.path_to_filesystem( + self.infcloud_folder, path[len("/.web/infcloud"):].strip("/")) except ValueError as e: - self.logger.debug("Web content with unsafe path %r requested: %s", - path, e, exc_info=True) - return NOT_FOUND + logger.debug("Web content with unsafe path %r requested: %s", + path, e, exc_info=True) + return httputils.NOT_FOUND if os.path.isdir(filesystem_path) and not path.endswith("/"): location = posixpath.basename(path) + "/" - return (client.SEE_OTHER, + return (client.FOUND, {"Location": location, "Content-Type": "text/plain"}, "Redirected to %s" % location) if os.path.isdir(filesystem_path): filesystem_path = os.path.join(filesystem_path, "index.html") if not os.path.isfile(filesystem_path): - return NOT_FOUND + return httputils.NOT_FOUND content_type = MIMETYPES.get( os.path.splitext(filesystem_path)[1].lower(), FALLBACK_MIMETYPE) with open(filesystem_path, "rb") as f: |