From f93b8f78f6b7ece06426b53dec851a4d46b8a076 Mon Sep 17 00:00:00 2001 From: bohwaz Date: Tue, 22 Nov 2022 16:11:28 +0100 Subject: [PATCH] Fix handling of auth --- index.php | 10 +++------- server.php | 6 +----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index ca693e5..5e95623 100644 --- a/index.php +++ b/index.php @@ -1786,7 +1786,7 @@ namespace PicoDAV public function route(?string $uri = null): bool { - if (!ANONYMOUS_WRITE && !ANONYMOUS_READ) { + if (!ANONYMOUS_WRITE && !ANONYMOUS_READ && !$this->storage->auth()) { $this->requireAuth(); return true; } @@ -1796,10 +1796,6 @@ namespace PicoDAV protected function requireAuth(): void { - if ($this->storage->auth()) { - return; - } - http_response_code(401); header('WWW-Authenticate: Basic realm="Please login"'); echo '

Error 401

You need to login to access this.

'; @@ -1867,11 +1863,11 @@ RewriteRule ^.*$ /index.php [END] $fp = fopen(__FILE__, 'r'); if ($relative_uri == '.webdav/webdav.js') { - fseek($fp, 50046, SEEK_SET); + fseek($fp, 50022, SEEK_SET); echo fread($fp, 27769); } else { - fseek($fp, 50046 + 27769, SEEK_SET); + fseek($fp, 50022 + 27769, SEEK_SET); echo fread($fp, 6988); } diff --git a/server.php b/server.php index 8fe4a72..8437f51 100644 --- a/server.php +++ b/server.php @@ -510,7 +510,7 @@ namespace PicoDAV public function route(?string $uri = null): bool { - if (!ANONYMOUS_WRITE && !ANONYMOUS_READ) { + if (!ANONYMOUS_WRITE && !ANONYMOUS_READ && !$this->storage->auth()) { $this->requireAuth(); return true; } @@ -520,10 +520,6 @@ namespace PicoDAV protected function requireAuth(): void { - if ($this->storage->auth()) { - return; - } - http_response_code(401); header('WWW-Authenticate: Basic realm="Please login"'); echo '

Error 401

You need to login to access this.

';