diff --git a/LibreNMS/Validations/Python.php b/LibreNMS/Validations/Python.php index 9997b482d9..815eeb1366 100644 --- a/LibreNMS/Validations/Python.php +++ b/LibreNMS/Validations/Python.php @@ -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) { diff --git a/LibreNMS/Validations/User.php b/LibreNMS/Validations/User.php index 3ac4927ee6..913d1eaf33 100644 --- a/LibreNMS/Validations/User.php +++ b/LibreNMS/Validations/User.php @@ -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"); } } } diff --git a/LibreNMS/Validator.php b/LibreNMS/Validator.php index 52af1b5c1a..2a59dad663 100644 --- a/LibreNMS/Validator.php +++ b/LibreNMS/Validator.php @@ -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); } diff --git a/daily.sh b/daily.sh index 04f649c8ed..c5365abc7d 100755 --- a/daily.sh +++ b/daily.sh @@ -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") ####################################### diff --git a/validate.php b/validate.php index 8a9d5e8b58..e01bcfb551 100755 --- a/validate.php +++ b/validate.php @@ -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, '') !== 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, '') !== 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;