aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--radicale_infcloud/__init__.py45
-rwxr-xr-xsetup.py4
2 files changed, 27 insertions, 22 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:
diff --git a/setup.py b/setup.py
index bb64475..0e1bf2a 100755
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ import os
from setuptools import setup
-VERSION = "2.0.0"
+VERSION = "3.0.0"
os.chdir("radicale_infcloud")
web_data = sum(([os.path.join(root, f) for f in files
@@ -23,4 +23,4 @@ setup(
platforms="Any",
packages=["radicale_infcloud"],
package_data={"radicale_infcloud": web_data},
- install_requires=["radicale>=2.1.0"])
+ install_requires=["radicale>=3.0.0"])
bgstack15