Add support for when group doesnt exist (#12817)

Previously this errored out the validation
This commit is contained in:
Jellyfrog
2021-04-30 05:44:31 +02:00
committed by GitHub
parent 49ec6aabd6
commit f7fbf9fe07

View File

@@ -48,12 +48,18 @@ class User extends BaseValidation
if (! ($username === 'root' || $username === $lnms_username)) {
if (isCli()) {
$validator->fail("You need to run this script as $lnms_username or root");
$validator->fail("You need to run this script as '$lnms_username' or root");
} elseif (function_exists('posix_getgrnam')) {
$lnms_group = posix_getgrnam($lnms_groupname);
if (! in_array($username, $lnms_group['members'])) {
if ($lnms_group === false) {
$validator->fail(
"Your web server or php-fpm is not running as user '$lnms_username' or in the group '$lnms_groupname''",
"The group '$lnms_groupname' does not exist",
"groupadd $lnms_groupname"
);
} elseif (! in_array($username, $lnms_group['members'])) {
$validator->fail(
"Your web server or php-fpm is not running as user '$lnms_username' or in the group '$lnms_groupname'",
"usermod -a -G $lnms_groupname $username"
);
}
@@ -108,7 +114,7 @@ class User extends BaseValidation
if (! empty($files)) {
$result = ValidationResult::fail(
"We have found some files that are owned by a different user than $lnms_username, this " .
"We have found some files that are owned by a different user than '$lnms_username', this " .
'will stop you updating automatically and / or rrd files being updated causing graphs to fail.'
)
->setFix($fix)
@@ -121,7 +127,7 @@ class User extends BaseValidation
}
}
} else {
$validator->warn("You don't have LIBRENMS_USER set, this most likely needs to be set to librenms");
$validator->warn("You don't have LIBRENMS_USER set, this most likely needs to be set to 'librenms'");
}
}
}