diff --git a/README.md b/README.md index 101d861..1176a6c 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,12 @@ PicoDAV accepts a configuration file named `.picodav.ini`. It should be in the same directory as `index.php`. +It accepts these options: + +* `ANONYMOUS_READ` (boolean, see below) +* `ANONYMOUS_WRITE` (boolean, see below) +* `HTTP_LOG` (string, set to a file path to log HTTP requests for debug purposes) + ### Users and passwords By default, the WebDAV server is accessible to everyone. diff --git a/index.php b/index.php index a8ea18f..8400f4b 100644 --- a/index.php +++ b/index.php @@ -1809,6 +1809,26 @@ namespace PicoDAV parent::error($e); } + + protected string $_log = ''; + + public function log(string $message, ...$params): void + { + if (!HTTP_LOG_FILE) { + return; + } + + $this->_log .= vsprintf($message, $params) . "\n"; + } + + public function __destruct() + { + if (!$this->_log) { + return; + } + + file_put_contents(HTTP_LOG_FILE, $this->_log, \FILE_APPEND); + } } } @@ -1863,11 +1883,11 @@ RewriteRule ^.*$ /index.php [END] $fp = fopen(__FILE__, 'r'); if ($relative_uri == '.webdav/webdav.js') { - fseek($fp, 50036, SEEK_SET); + fseek($fp, 50403, SEEK_SET); echo fread($fp, 27769); } else { - fseek($fp, 50036 + 27769, SEEK_SET); + fseek($fp, 50403 + 27769, SEEK_SET); echo fread($fp, 7004); } @@ -1882,6 +1902,7 @@ RewriteRule ^.*$ /index.php [END] const DEFAULT_CONFIG = [ 'ANONYMOUS_READ' => true, 'ANONYMOUS_WRITE' => false, + 'HTTP_LOG_FILE' => null, ]; $config = []; diff --git a/server.php b/server.php index 6636984..ee2cf7d 100644 --- a/server.php +++ b/server.php @@ -533,6 +533,26 @@ namespace PicoDAV parent::error($e); } + + protected string $_log = ''; + + public function log(string $message, ...$params): void + { + if (!HTTP_LOG_FILE) { + return; + } + + $this->_log .= vsprintf($message, $params) . "\n"; + } + + public function __destruct() + { + if (!$this->_log) { + return; + } + + file_put_contents(HTTP_LOG_FILE, $this->_log, \FILE_APPEND); + } } } @@ -592,6 +612,7 @@ namespace { const DEFAULT_CONFIG = [ 'ANONYMOUS_READ' => true, 'ANONYMOUS_WRITE' => false, + 'HTTP_LOG_FILE' => null, ]; $config = [];