Skip to content

Commit fd14ec0

Browse files
committed
Check if directories used for uploads are writable
Closes: #2910
1 parent 6c9496b commit fd14ec0

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

webapp/src/Service/CheckConfigService.php

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function runAll(): array
6868
'hashtime' => $this->checkHashTime(),
6969
];
7070

71+
foreach (['affiliations', 'banners', 'countries', 'teams'] as $key) {
72+
$config['publicdirwritable_' . $key] = $this->checkPublicdirWritable($key);
73+
}
74+
7175
$results['Configuration'] = $config;
7276
$this->stopwatch->stopSection('Configuration');
7377

@@ -356,30 +360,55 @@ public function checkDebugDisabled(): ConfigCheckItem
356360
);
357361
}
358362

359-
public function checkTmpdirWritable(): ConfigCheckItem
363+
public function checkDirWritable(string $directory, string $name, string $success_description, string $warning_description): ConfigCheckItem
360364
{
361365
$this->stopwatch->start(__FUNCTION__);
362-
$tmpdir = $this->dj->getDomjudgeTmpDir();
363-
if (is_writable($tmpdir)) {
366+
if (is_writable($directory)) {
364367
$this->stopwatch->stop(__FUNCTION__);
365368
return new ConfigCheckItem(
366-
caption: 'TMPDIR writable',
369+
caption: $name . ' writable',
367370
result: 'O',
368-
desc: sprintf('TMPDIR (`%s`) can be used to store temporary ' .
369-
'files for submission diffs and edits.',
370-
$tmpdir)
371+
desc: $success_description,
371372
);
372373
}
373374
$this->stopwatch->stop(__FUNCTION__);
374375
return new ConfigCheckItem(
375-
caption: 'TMPDIR writable',
376+
caption: $name . ' writable',
376377
result: 'W',
377-
desc: sprintf('TMPDIR (`%s`) is not writable by the webserver; ' .
378+
desc: $warning_description,
379+
);
380+
}
381+
382+
public function checkTmpdirWritable(): ConfigCheckItem
383+
{
384+
$tmpdir = $this->dj->getDomjudgeTmpDir();
385+
return $this->checkDirWritable(
386+
$tmpdir,
387+
'TMPDIR',
388+
sprintf('TMPDIR (`%s`) can be used to store temporary ' .
389+
'files for submission diffs and edits.',
390+
$tmpdir),
391+
sprintf('TMPDIR (`%s`) is not writable by the webserver; ' .
378392
'Showing diffs and editing of submissions may not work.',
379393
$tmpdir)
380394
);
381395
}
382396

397+
public function checkPublicdirWritable(string $directory): ConfigCheckItem
398+
{
399+
$dir = $this->dj->getDomjudgeWebappDir() . '/public/images/' . $directory;
400+
return $this->checkDirWritable(
401+
$dir,
402+
'PUBLICDIR_' . strtoupper($directory),
403+
sprintf('The public directory (`%s`) can be used to store ' .
404+
' images, logo\'s and other resources for team affiliations.',
405+
$dir),
406+
sprintf('The public Organization directory (`%s`) is not writable by the webserver; ' .
407+
'Uploading images such as photo\'s and logo\'s may not work.',
408+
$dir)
409+
);
410+
}
411+
383412
private function randomString(int $length): string
384413
{
385414
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

0 commit comments

Comments
 (0)