improved writable directory checking

This commit is contained in:
Roman 2024-04-22 12:03:24 +02:00
parent 3d4b179984
commit fcccf18644
2 changed files with 33 additions and 5 deletions

@ -235,11 +235,31 @@ namespace Documents\Install {
$success = true; $success = true;
$failedRequirements = array(); $failedRequirements = array();
// TODO: rather give a list of directories which have to be writable $requiredDirectories = [
// this should be: /Site/Cache, /Site/Logs, /Core/External/vendor, /react/dist/ "/Site/Cache",
// also likely: /react and /Site/API for cli.php "/Site/Logs",
if (!is_writeable(WEBROOT)) { "/Site/Configuration",
$failedRequirements[] = sprintf("<b>%s</b> is not writeable. Try running <b>chmod 700 %s</b>", WEBROOT, WEBROOT); "/Core/External/vendor",
"/files/uploaded",
];
$nonWritableDirectories = [];
foreach ($requiredDirectories as $directory) {
if (!is_writeable(WEBROOT . $directory)) {
$nonWritableDirectories[] = $directory;
}
}
if (!empty($nonWritableDirectories)) {
$currentUser = getCurrentUsername();
if (function_exists("posix_getuid")) {
$currentUser .= " (uid: " . posix_getuid() . ")";
}
$failedRequirements[] = "One or more directories are not writable. " .
"Make sure the current user $currentUser has write-access to following locations:" .
$this->createUnorderedList($nonWritableDirectories);
$success = false; $success = false;
} }

@ -298,6 +298,14 @@ function isClass(string $str): bool {
return is_file($path) && class_exists($str); return is_file($path) && class_exists($str);
} }
function getCurrentUsername(): string {
if (function_exists("posix_getpwuid") && function_exists("posix_geteuid")) {
return posix_getpwuid(posix_geteuid())['name'];
}
return exec('whoami') ?? "Unknown";
}
function rrmdir(string $dir): void { function rrmdir(string $dir): void {
if (is_dir($dir)) { if (is_dir($dir)) {
$objects = scandir($dir); $objects = scandir($dir);