Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add per user home directories #143

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ [email protected]
# Make sure that these directories exist, with write permissions for your server.
# USE ABSOLUTE PATHS for better predictability
WEBDAV_TMP_DIR='/tmp'
WEBDAV_PUBLIC_DIR='/webdav'
WEBDAV_PUBLIC_DIR='/webdav/public'
# By default, home directories are disabled totally (env var set to an empty string).
# If needed, it is recommended to use a folder that is NOT a child of the public dir,
# such as /webdav/homes for instance, so that users cannot access other users' homes.
WEBDAV_HOMES_DIR=

# Logging path
# By default, it will log in the standard Symfony directory: var/log/prod.log (for production)
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,14 @@ f. The paths for the WebDAV installation

```
WEBDAV_TMP_DIR='/tmp'
WEBDAV_PUBLIC_DIR='/webdav'
WEBDAV_PUBLIC_DIR='/webdav/public'
WEBDAV_HOMES_DIR=
```

> [!NOTE]
>
> By default, home directories are disabled totally (the env var is set to an empty string). If needed, it is recommended to use a folder that is **NOT** a child of the public dir, such as `/webdav/homes` for instance, so that users cannot access other users' homes.

g. The log file path

You can use an absolute file path here, and you can use Symfony's `%kernel.logs_dir%` and `%kernel.environment%` placeholders if needed (as in the default value). Setting it to `/dev/null` will disable logging altogether.
Expand Down
5 changes: 3 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ services:
$inviteAddress: "%env(INVITE_FROM_ADDRESS)%"
$authMethod: "%env(AUTH_METHOD)%"
$authRealm: "%env(AUTH_REALM)%"
$webdavPublicDir: "%env(WEBDAV_PUBLIC_DIR)%"
$webdavTmpDir: "%env(WEBDAV_TMP_DIR)%"
$webdavPublicDir: "%env(resolve:WEBDAV_PUBLIC_DIR)%"
$webdavHomesDir: "%env(resolve:WEBDAV_HOMES_DIR)%"
$webdavTmpDir: "%env(resolve:WEBDAV_TMP_DIR)%"

App\Security\LoginFormAuthenticator:
arguments:
Expand Down
14 changes: 13 additions & 1 deletion src/Controller/DAVController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class DAVController extends AbstractController
*/
protected $webdavPublicDir;

/**
* WebDAV User Homes directory.
*
* @var string | null
*/
protected $webdavHomesDir;

/**
* WebDAV Temporary directory.
*
Expand Down Expand Up @@ -128,7 +135,7 @@ class DAVController extends AbstractController
*/
protected $server;

public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend, IMAPAuth $IMAPAuthBackend, LDAPAuth $LDAPAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, LoggerInterface $logger, string $publicDir, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, string $inviteAddress = null, string $authMethod = null, string $authRealm = null, string $webdavPublicDir = null, string $webdavTmpDir = null)
public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend, IMAPAuth $IMAPAuthBackend, LDAPAuth $LDAPAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, LoggerInterface $logger, string $publicDir, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, string $inviteAddress = null, string $authMethod = null, string $authRealm = null, string $webdavPublicDir = null, string $webdavHomesDir = null, string $webdavTmpDir = null)
{
$this->publicDir = $publicDir;

Expand All @@ -138,6 +145,7 @@ public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend
$this->inviteAddress = $inviteAddress ?? null;

$this->webdavPublicDir = $webdavPublicDir;
$this->webdavHomesDir = $webdavHomesDir;
$this->webdavTmpDir = $webdavTmpDir;

$this->em = $entityManager;
Expand Down Expand Up @@ -209,6 +217,10 @@ private function initServer(string $authMethod, string $authRealm = User::DEFAUL
new \Sabre\CalDAV\Principal\Collection($principalBackend),
];

if ($this->webdavHomesDir) {
$nodes[] = new \Sabre\DAVACL\FS\HomeCollection($principalBackend, $this->webdavHomesDir);
}

if ($this->calDAVEnabled) {
$calendarBackend = new \Sabre\CalDAV\Backend\PDO($pdo);
$nodes[] = new \Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend);
Expand Down
Loading