2022-10-03 02:44:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KaraDAV;
|
|
|
|
|
|
|
|
use KD2\WebDAV\Server as WebDAV_Server;
|
|
|
|
|
|
|
|
class WebDAV extends WebDAV_Server
|
|
|
|
{
|
2022-10-10 12:01:20 +00:00
|
|
|
protected function html_directory(string $uri, iterable $list): ?string
|
2022-10-03 02:44:20 +00:00
|
|
|
{
|
2022-10-10 12:01:20 +00:00
|
|
|
$out = parent::html_directory($uri, $list);
|
2022-10-03 02:44:20 +00:00
|
|
|
|
|
|
|
if (null !== $out) {
|
2022-10-15 00:15:39 +00:00
|
|
|
if (WOPI_DISCOVERY_URL) {
|
|
|
|
$out = str_replace('<html', sprintf('<html data-wopi-discovery-url="%s" data-wopi-host-url="%s"', WOPI_DISCOVERY_URL, WWW_URL . 'wopi/'), $out);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:01:20 +00:00
|
|
|
$out = str_replace('<body>', sprintf('<body style="opacity: 0"><script type="text/javascript" src="%swebdav.js"></script>', WWW_URL), $out);
|
2022-10-03 02:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
2022-10-10 12:01:20 +00:00
|
|
|
|
|
|
|
public function http_options(): void
|
|
|
|
{
|
|
|
|
parent::http_options();
|
|
|
|
|
2022-10-28 21:57:47 +00:00
|
|
|
if (ACCESS_CONTROL_ALL) {
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
header('Access-Control-Allow-Credentials: true');
|
|
|
|
header('Access-Control-Allow-Headers: Authorization, *');
|
|
|
|
header('Access-Control-Allow-Methods: GET,HEAD,PUT,DELETE,COPY,MOVE,PROPFIND,MKCOL,LOCK,UNLOCK');
|
|
|
|
}
|
2022-10-10 12:01:20 +00:00
|
|
|
}
|
2022-10-21 16:21:38 +00:00
|
|
|
|
|
|
|
public function log(string $message, ...$params)
|
|
|
|
{
|
|
|
|
http_log('DAV: ' . $message, ...$params);
|
|
|
|
}
|
2022-10-29 22:52:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility function to create HMAC hash of data, useful for NextCloud and WOPI
|
|
|
|
*/
|
|
|
|
static public function hmac(array $data, string $key = '')
|
|
|
|
{
|
|
|
|
$key = SECRET_KEY . sha1($key);
|
|
|
|
return parent::hmac($data, $key);
|
|
|
|
}
|
2022-10-03 02:44:20 +00:00
|
|
|
}
|