Add support for ownCloud/NextCloud checksum verification
This commit is contained in:
parent
26863fd18a
commit
a1dfe67638
|
@ -1,4 +1,4 @@
|
|||
# KaraDAV - A lightweight WebDAV server, with NextCloud compatibility
|
||||
# KaraDAV - A lightweight WebDAV server, compatible with ownCloud and NextCloud clients
|
||||
|
||||
This is a simple and lighweight WebDAV server, allowing to easily set up a file sharing server compatible with WebDAV and NextCloud clients. It has no dependencies and good performance.
|
||||
|
||||
|
@ -72,7 +72,7 @@ It has been tested with:
|
|||
|
||||
**We recommend the ownCloud apps**, as they are more stable and lighter :)
|
||||
|
||||
Note that even though it has been tested with NC/OC clients, KaraDAV might stop working at any time with these clients.
|
||||
Note that even though it has been tested with NC/OC clients, KaraDAV might stop working at any time with these clients if their publishers decide so.
|
||||
|
||||
## WebDAV clients compatibility
|
||||
|
||||
|
@ -86,7 +86,7 @@ Here is a list of clients tested with KaraDAV:
|
|||
* CyberDuck (Windows) version 8.5.0
|
||||
* Dolphin (KDE)
|
||||
* Thunar (GTK/GNOME)
|
||||
* [rclone](https://rclone.org/webdav/) on Linux
|
||||
* [rclone](https://rclone.org/webdav/) on Linux, including [bi-directional sync](https://rclone.org/bisync/).
|
||||
* [csync](https://csync.org/) on Linux. This is a library offering two-way sync, it is used by the ownCloud client, but it has a command-line client. Just replace `http` with `owncloud`, and `https` with `ownclouds` in URL, eg. `csync /home/bohwaz/sync ownclouds://karadav.example/files/bohwaz/`
|
||||
|
||||
### Android
|
||||
|
|
|
@ -138,12 +138,15 @@ class Storage extends AbstractStorage
|
|||
case 'DAV::creationdate':
|
||||
return new \DateTime('@' . filectime($target));
|
||||
case WebDAV::PROP_DIGEST_MD5:
|
||||
if (!is_file($target)) {
|
||||
if (!is_file($target) || is_dir($target) || !is_readable($target)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return md5_file($target);
|
||||
// NextCloud stuff
|
||||
case NextCloud::PROP_OC_CHECKSUMS:
|
||||
// We are not returning OC checksums as this could slow directory listings
|
||||
return null;
|
||||
case NextCloud::PROP_NC_HAS_PREVIEW:
|
||||
case NextCloud::PROP_NC_IS_ENCRYPTED:
|
||||
return 'false';
|
||||
|
@ -238,7 +241,7 @@ class Storage extends AbstractStorage
|
|||
return $out;
|
||||
}
|
||||
|
||||
public function put(string $uri, $pointer, ?string $hash, ?int $mtime): bool
|
||||
public function put(string $uri, $pointer, ?string $hash_algo, ?string $hash, ?int $mtime): bool
|
||||
{
|
||||
if (preg_match(self::PUT_IGNORE_PATTERN, basename($uri))) {
|
||||
return false;
|
||||
|
@ -297,10 +300,14 @@ class Storage extends AbstractStorage
|
|||
@unlink($tmp_file);
|
||||
throw new WebDAV_Exception('Your quota is exhausted', 403);
|
||||
}
|
||||
elseif ($hash && md5_file($tmp_file) != $hash) {
|
||||
elseif ($hash && $hash_algo == 'MD5' && md5_file($tmp_file) != $hash) {
|
||||
@unlink($tmp_file);
|
||||
throw new WebDAV_Exception('The data sent does not match the supplied MD5 hash', 400);
|
||||
}
|
||||
elseif ($hash && $hash_algo == 'SHA1' && sha1_file($tmp_file) != $hash) {
|
||||
@unlink($tmp_file);
|
||||
throw new WebDAV_Exception('The data sent does not match the supplied SHA1 hash', 400);
|
||||
}
|
||||
else {
|
||||
rename($tmp_file, $target);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue