Configuration missing"; echo "

KaraDAV cannot write to config.local.php

"; echo "

Please append the following code to the config.local.php file:

"; printf('', htmlspecialchars($c)); exit(1); } $cfg = preg_replace('/\?>\s*$|$/', $c, $cfg, 1); file_put_contents($cfg_file, $cfg); define('KaraDAV\SECRET_KEY', $secret); unset($secret, $cfg_file, $cfg); } } if (!defined('KaraDAV\WWW_URL')) { $https = (!empty($_SERVER['HTTPS']) || $_SERVER['SERVER_PORT'] == 443) ? 's' : ''; $name = $_SERVER['SERVER_NAME']; $port = !in_array($_SERVER['SERVER_PORT'], [80, 443]) ? ':' . $_SERVER['SERVER_PORT'] : ''; $root = '/'; define('KaraDAV\WWW_URL', sprintf('http%s://%s%s%s', $https, $name, $port, $root)); } if (!defined('KaraDAV\DEFAULT_QUOTA')) { define('KaraDAV\DEFAULT_QUOTA', 200); } if (!defined('KaraDAV\DISABLE_SLOW_OPERATIONS')) { define('KaraDAV\DISABLE_SLOW_OPERATIONS', false); } // Init database if (!file_exists(DB_FILE)) { $db = DB::getInstance(); $db->exec('BEGIN;'); $db->exec(file_get_contents(__DIR__ . '/../schema.sql')); if (!LDAP::enabled()) { $users = new Users; $p = 'karadavdemo'; $users->create('demo', $p, 10, true); $users->login('demo', $p); $_SESSION['install_password'] = $p; } $db->exec('END;'); } function html_head(string $title): void { $title = htmlspecialchars($title); echo << {$title}

{$title}

EOF; if (isset($_SESSION['install_password'])) { printf('

Your server has been installed with a user named demo and the password %s, please change it.

This message will disappear when you log out.

', htmlspecialchars($_SESSION['install_password'])); } } function html_foot(): void { echo '
'; } function format_bytes(int $bytes, string $unit = 'B'): string { if ($bytes >= 1024*1024*1024) { return round($bytes / (1024*1024*1024), 1) . ' G' . $unit; } elseif ($bytes >= 1024*1024) { return round($bytes / (1024*1024), 1) . ' M' . $unit; } elseif ($bytes >= 1024) { return round($bytes / 1024, 1) . ' K' . $unit; } else { return $bytes . ' ' . $unit; } } function http_log(string $message, ...$params): void { if (!LOG_FILE) { return; } $msg = vsprintf($message, $params) . "\n\n"; if (LOG_FILE) { file_put_contents(LOG_FILE, $msg, FILE_APPEND); } } function html_csrf() { $expire = time() + 1800; $random = random_bytes(10); $action = $_SERVER['REQUEST_URI']; $token = hash_hmac('sha256', $expire . $random . $action, STORAGE_PATH . session_id()); return sprintf('', $token, base64_encode($random), $expire); } function csrf_check(): bool { if (empty($_POST['_c_'])) { return false; } $verify = strtok($_POST['_c_'], ':'); $random = base64_decode(strtok(':')); $expire = strtok(false); if ($expire < time()) { return false; } $action = $_SERVER['REQUEST_URI']; $token = hash_hmac('sha256', $expire . $random . $action, STORAGE_PATH . session_id()); return hash_equals($token, $verify); } function html_csrf_error() { if (empty($_POST['_c_'])) { return; } if (!csrf_check()) { echo '

Sorry, but the form expired, please submit it again.

'; } }