From 23c33f753f0c6a624f1ab10417ad499d70c53c27 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sat, 27 Jun 2020 22:24:54 -0500 Subject: [PATCH] WIP validation cleanup missing config --- LibreNMS/Validations/Python.php | 2 +- LibreNMS/Validations/User.php | 6 ++--- LibreNMS/Validator.php | 2 +- daily.sh | 3 ++- validate.php | 39 ++++++++++++++++----------------- 5 files changed, 26 insertions(+), 26 deletions(-) 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 496a9cfbf2..4a6a6f08d4 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()) { @@ -138,7 +138,7 @@ class User extends BaseValidation )->setFix($fix)->setList('Files', explode(PHP_EOL, $incorrect))); } } 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..e15529b185 100755 --- a/validate.php +++ b/validate.php @@ -81,31 +81,30 @@ register_shutdown_function(function () { } }); +$pre_checks_failed = false; + // 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; -} +} else { + $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; + } -$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; + } } -$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(); $validator->validate(array('dependencies')); @@ -121,7 +120,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;