Add option to log HTTP

This commit is contained in:
bohwaz 2022-12-23 19:40:37 +01:00
parent 9b30c8da2b
commit 523d58ec9b
3 changed files with 50 additions and 2 deletions

View file

@ -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.

View file

@ -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 = [];

View file

@ -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 = [];