karadav/www/index.php

68 lines
1.6 KiB
PHP
Raw Normal View History

2022-08-30 05:01:39 +00:00
<?php
namespace KaraDAV;
if (!empty($_SERVER['PATH_INFO'])) {
require __DIR__ . '/_router.php';
exit;
}
2022-08-30 05:01:39 +00:00
require_once __DIR__ . '/_inc.php';
2022-08-31 06:06:27 +00:00
$users = new Users;
$user = $users->current();
2022-08-30 05:01:39 +00:00
if (isset($_GET['logout'])) {
$users->logout();
$user = null;
}
2022-08-31 06:06:27 +00:00
if (!$user) {
header(sprintf('Location: %slogin.php', WWW_URL));
exit;
}
2022-08-30 05:01:39 +00:00
2023-12-31 15:53:00 +00:00
if (isset($_GET['empty_trash'])) {
$users->emptyTrash($user);
header('Location: ./');
exit;
}
2023-09-11 14:38:07 +00:00
$quota = $users->quota($user, true);
2022-10-10 13:20:41 +00:00
$free = format_bytes($quota->free);
$used = format_bytes($quota->used);
$total = format_bytes($quota->total);
2023-09-11 14:38:07 +00:00
$trash = format_bytes($quota->trash ?? 0);
$percent = $quota->total ? floor(($quota->used / $quota->total)*100) . '%' : '100%';
2022-08-31 06:06:27 +00:00
$www_url = WWW_URL;
$username = htmlspecialchars($user->login);
2023-12-31 15:53:00 +00:00
$trash_button = '';
if ($quota->trash) {
$trash_button = '<br /><a href="?empty_trash" class="btn sm">Empty trash now</a>';
}
2022-08-30 05:01:39 +00:00
html_head('My files');
echo <<<EOF
<h2 class="myfiles"><a class="btn" href="{$user->dav_url}">Manage my files</a></h2>
<h3>Hello, {$username} !</h3>
2022-08-31 06:06:27 +00:00
<dl>
<dd><h3>{$percent} used, {$free} free</h3></dd>
<dd><progress max="{$quota->total}" value="{$quota->used}"></progress>
<dd>Used {$used} out of a total of {$total}.</dd>
2023-12-31 15:53:00 +00:00
<dd>Trash: {$trash}. {$trash_button}</dd>
2022-08-31 06:06:27 +00:00
<dt>WebDAV URL</dt>
<dd><h3><a href="{$user->dav_url}"><tt>{$user->dav_url}</tt></a></h3>
2022-08-31 06:06:27 +00:00
<dt>NextCloud URL</dt>
<dd><tt>{$www_url}</tt></dd>
2022-10-10 13:20:41 +00:00
<dd class="help">Use this URL to setup a NextCloud or ownCloud client to access your files.</dd>
2022-08-31 06:06:27 +00:00
</dl>
<p><a class="btn sm" href="?logout">Logout</a></p>
EOF;
if ($user->is_admin) {
echo '<p><a class="btn sm" href="users.php">Manager users</a></p>';
}
html_foot();