Add option to log HTTP
This commit is contained in:
parent
9b30c8da2b
commit
523d58ec9b
3 changed files with 50 additions and 2 deletions
|
@ -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.
|
||||
|
|
25
index.php
25
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 = [];
|
||||
|
|
21
server.php
21
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 = [];
|
||||
|
|
Loading…
Reference in a new issue