Merge pull request #11867 from murrant/more-install-changes

Fix validation and other issues when config.php is missing
This commit is contained in:
Tony Murray
2020-06-29 17:49:28 -05:00
committed by GitHub
5 changed files with 26 additions and 28 deletions

View File

@@ -78,7 +78,7 @@ class Python extends BaseValidation
$process->run();
if ($process->getExitCode() !== 0) {
$user = Config::get('user', 'librenms');
$user = \config('librenms.user');
$user_mismatch = function_exists('posix_getpwuid') ? (posix_getpwuid(posix_geteuid())['name'] ?? null) !== $user : false;
if ($user_mismatch) {

View File

@@ -44,8 +44,8 @@ class User extends BaseValidation
{
// Check we are running this as the root user
$username = $validator->getUsername();
$lnms_username = Config::get('user', 'librenms');
$lnms_groupname = Config::get('group', $lnms_username); // if group isn't set, fall back to user
$lnms_username = \config('librenms.user');
$lnms_groupname = \config('librenms.group');
if (!($username === 'root' || $username === $lnms_username)) {
if (isCli()) {
@@ -119,7 +119,7 @@ class User extends BaseValidation
}
}
} else {
$validator->warn("You don't have \$config['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");
}
}
}

View File

@@ -252,7 +252,7 @@ class Validator
public function execAsUser($command, &$output = null, &$code = null)
{
if (self::getUsername() === 'root') {
$command = 'su ' . Config::get('user') . ' -s /bin/sh -c "' . $command . '"';
$command = 'su ' . \config('librenms.user') . ' -s /bin/sh -c "' . $command . '"';
}
exec($command, $output, $code);
}

View File

@@ -30,7 +30,8 @@ COMPOSER="php ${LIBRENMS_DIR}/scripts/composer_wrapper.php --no-interaction"
LOG_DIR=$(php -r "@include '${LIBRENMS_DIR}/config.php'; echo isset(\$config['log_dir']) ? \$config['log_dir'] : '${LIBRENMS_DIR}/logs';")
# get the librenms user
LIBRENMS_USER=$(php -r "@include '${LIBRENMS_DIR}/config.php'; echo isset(\$config['user']) ? \$config['user'] : 'root';")
source ".env"
LIBRENMS_USER="${LIBRENMS_USER:-librenms}"
LIBRENMS_USER_ID=$(id -u "$LIBRENMS_USER")
#######################################

View File

@@ -81,30 +81,27 @@ register_shutdown_function(function () {
}
});
// critical config.php checks
if (!file_exists('config.php')) {
print_fail('config.php does not exist, please copy config.php.default to config.php');
exit;
}
$pre_checks_failed = false;
$syntax_check = `php -ln config.php`;
if (strpos($syntax_check, 'No syntax errors detected') === false) {
print_fail('Syntax error in config.php');
echo $syntax_check;
$pre_checks_failed = true;
}
$first_line = rtrim(`head -n1 config.php`);
if (!strpos($first_line, '<?php') === 0) {
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
$pre_checks_failed = true;
}
if (strpos(`tail config.php`, '?>') !== false) {
print_fail("Remove the ?> at the end of config.php");
$pre_checks_failed = true;
}
// config.php checks
if (file_exists('config.php')) {
$syntax_check = `php -ln config.php`;
if (strpos($syntax_check, 'No syntax errors detected') === false) {
print_fail('Syntax error in config.php');
echo $syntax_check;
$pre_checks_failed = true;
}
$first_line = rtrim(`head -n1 config.php`);
if (!strpos($first_line, '<?php') === 0) {
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
$pre_checks_failed = true;
}
if (strpos(`tail config.php`, '?>') !== false) {
print_fail("Remove the ?> at the end of config.php");
$pre_checks_failed = true;
}
}
// Composer check
$validator = new Validator();
@@ -121,7 +118,7 @@ $init_modules = [];
require 'includes/init.php';
// make sure install_dir is set correctly, or the next includes will fail
if (!file_exists(Config::get('install_dir').'/config.php')) {
if (!file_exists(Config::get('install_dir').'/.env')) {
$suggested = realpath(__DIR__);
print_fail('\'install_dir\' config setting is not set correctly.', "It should probably be set to: $suggested");
exit;