extend app calls with remote host+useragent
This commit is contained in:
@@ -371,7 +371,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
|
|||||||
|
|
||||||
if not login or user:
|
if not login or user:
|
||||||
status, headers, answer = function(
|
status, headers, answer = function(
|
||||||
environ, base_prefix, path, user)
|
environ, base_prefix, path, user, remote_host, remote_useragent)
|
||||||
if (status, headers, answer) == httputils.NOT_ALLOWED:
|
if (status, headers, answer) == httputils.NOT_ALLOWED:
|
||||||
logger.info("Access to %r denied for %s", path,
|
logger.info("Access to %r denied for %s", path,
|
||||||
repr(user) if user else "anonymous user")
|
repr(user) if user else "anonymous user")
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ def xml_delete(base_prefix: str, path: str, collection: storage.BaseCollection,
|
|||||||
class ApplicationPartDelete(ApplicationBase):
|
class ApplicationPartDelete(ApplicationBase):
|
||||||
|
|
||||||
def do_DELETE(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_DELETE(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage DELETE request."""
|
"""Manage DELETE request."""
|
||||||
access = Access(self._rights, user, path)
|
access = Access(self._rights, user, path)
|
||||||
if not access.check("w"):
|
if not access.check("w"):
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class ApplicationPartGet(ApplicationBase):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def do_GET(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
def do_GET(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||||
user: str) -> types.WSGIResponse:
|
user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage GET request."""
|
"""Manage GET request."""
|
||||||
# Redirect to /.web if the root path is requested
|
# Redirect to /.web if the root path is requested
|
||||||
if not pathutils.strip_path(path):
|
if not pathutils.strip_path(path):
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from radicale.app.get import ApplicationPartGet
|
|||||||
class ApplicationPartHead(ApplicationPartGet, ApplicationBase):
|
class ApplicationPartHead(ApplicationPartGet, ApplicationBase):
|
||||||
|
|
||||||
def do_HEAD(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
def do_HEAD(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||||
user: str) -> types.WSGIResponse:
|
user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage HEAD request."""
|
"""Manage HEAD request."""
|
||||||
# Body is dropped in `Application.__call__` for HEAD requests
|
# Body is dropped in `Application.__call__` for HEAD requests
|
||||||
return self.do_GET(environ, base_prefix, path, user)
|
return self.do_GET(environ, base_prefix, path, user, remote_host, remote_useragent)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ from radicale.log import logger
|
|||||||
class ApplicationPartMkcalendar(ApplicationBase):
|
class ApplicationPartMkcalendar(ApplicationBase):
|
||||||
|
|
||||||
def do_MKCALENDAR(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_MKCALENDAR(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage MKCALENDAR request."""
|
"""Manage MKCALENDAR request."""
|
||||||
if "w" not in self._rights.authorization(user, path):
|
if "w" not in self._rights.authorization(user, path):
|
||||||
return httputils.NOT_ALLOWED
|
return httputils.NOT_ALLOWED
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ from radicale.log import logger
|
|||||||
class ApplicationPartMkcol(ApplicationBase):
|
class ApplicationPartMkcol(ApplicationBase):
|
||||||
|
|
||||||
def do_MKCOL(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_MKCOL(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage MKCOL request."""
|
"""Manage MKCOL request."""
|
||||||
permissions = self._rights.authorization(user, path)
|
permissions = self._rights.authorization(user, path)
|
||||||
if not rights.intersect(permissions, "Ww"):
|
if not rights.intersect(permissions, "Ww"):
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ def get_server_netloc(environ: types.WSGIEnviron, force_port: bool = False):
|
|||||||
class ApplicationPartMove(ApplicationBase):
|
class ApplicationPartMove(ApplicationBase):
|
||||||
|
|
||||||
def do_MOVE(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_MOVE(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage MOVE request."""
|
"""Manage MOVE request."""
|
||||||
raw_dest = environ.get("HTTP_DESTINATION", "")
|
raw_dest = environ.get("HTTP_DESTINATION", "")
|
||||||
to_url = urlparse(raw_dest)
|
to_url = urlparse(raw_dest)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from radicale.app.base import ApplicationBase
|
|||||||
class ApplicationPartOptions(ApplicationBase):
|
class ApplicationPartOptions(ApplicationBase):
|
||||||
|
|
||||||
def do_OPTIONS(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_OPTIONS(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage OPTIONS request."""
|
"""Manage OPTIONS request."""
|
||||||
headers = {
|
headers = {
|
||||||
"Allow": ", ".join(
|
"Allow": ", ".join(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from radicale.app.base import ApplicationBase
|
|||||||
class ApplicationPartPost(ApplicationBase):
|
class ApplicationPartPost(ApplicationBase):
|
||||||
|
|
||||||
def do_POST(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_POST(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage POST request."""
|
"""Manage POST request."""
|
||||||
if path == "/.web" or path.startswith("/.web/"):
|
if path == "/.web" or path.startswith("/.web/"):
|
||||||
return self._web.post(environ, base_prefix, path, user)
|
return self._web.post(environ, base_prefix, path, user)
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ class ApplicationPartPropfind(ApplicationBase):
|
|||||||
yield item, permission
|
yield item, permission
|
||||||
|
|
||||||
def do_PROPFIND(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_PROPFIND(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage PROPFIND request."""
|
"""Manage PROPFIND request."""
|
||||||
access = Access(self._rights, user, path)
|
access = Access(self._rights, user, path)
|
||||||
if not access.check("r"):
|
if not access.check("r"):
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def xml_proppatch(base_prefix: str, path: str,
|
|||||||
class ApplicationPartProppatch(ApplicationBase):
|
class ApplicationPartProppatch(ApplicationBase):
|
||||||
|
|
||||||
def do_PROPPATCH(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_PROPPATCH(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage PROPPATCH request."""
|
"""Manage PROPPATCH request."""
|
||||||
access = Access(self._rights, user, path)
|
access = Access(self._rights, user, path)
|
||||||
if not access.check("w"):
|
if not access.check("w"):
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ def prepare(vobject_items: List[vobject.base.Component], path: str,
|
|||||||
class ApplicationPartPut(ApplicationBase):
|
class ApplicationPartPut(ApplicationBase):
|
||||||
|
|
||||||
def do_PUT(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_PUT(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage PUT request."""
|
"""Manage PUT request."""
|
||||||
access = Access(self._rights, user, path)
|
access = Access(self._rights, user, path)
|
||||||
if not access.check("w"):
|
if not access.check("w"):
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ def free_busy_report(base_prefix: str, path: str, xml_request: Optional[ET.Eleme
|
|||||||
def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
|
def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
|
||||||
collection: storage.BaseCollection, encoding: str,
|
collection: storage.BaseCollection, encoding: str,
|
||||||
unlock_storage_fn: Callable[[], None],
|
unlock_storage_fn: Callable[[], None],
|
||||||
max_occurrence: int = 0, user: str = ""
|
max_occurrence: int = 0, user: str = "", remote_addr: str = "", remote_useragent: str = ""
|
||||||
) -> Tuple[int, ET.Element]:
|
) -> Tuple[int, ET.Element]:
|
||||||
"""Read and answer REPORT requests that return XML.
|
"""Read and answer REPORT requests that return XML.
|
||||||
|
|
||||||
@@ -776,7 +776,7 @@ def test_filter(collection_tag: str, item: radicale_item.Item,
|
|||||||
class ApplicationPartReport(ApplicationBase):
|
class ApplicationPartReport(ApplicationBase):
|
||||||
|
|
||||||
def do_REPORT(self, environ: types.WSGIEnviron, base_prefix: str,
|
def do_REPORT(self, environ: types.WSGIEnviron, base_prefix: str,
|
||||||
path: str, user: str) -> types.WSGIResponse:
|
path: str, user: str, remote_host: str, remote_useragent: str) -> types.WSGIResponse:
|
||||||
"""Manage REPORT request."""
|
"""Manage REPORT request."""
|
||||||
access = Access(self._rights, user, path)
|
access = Access(self._rights, user, path)
|
||||||
if not access.check("r"):
|
if not access.check("r"):
|
||||||
@@ -820,7 +820,7 @@ class ApplicationPartReport(ApplicationBase):
|
|||||||
try:
|
try:
|
||||||
status, xml_answer = xml_report(
|
status, xml_answer = xml_report(
|
||||||
base_prefix, path, xml_content, collection, self._encoding,
|
base_prefix, path, xml_content, collection, self._encoding,
|
||||||
lock_stack.close, max_occurrence, user)
|
lock_stack.close, max_occurrence, user, remote_host, remote_useragent)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Bad REPORT request on %r: %s", path, e, exc_info=True)
|
"Bad REPORT request on %r: %s", path, e, exc_info=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user