mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
WIP validation cleanup missing config
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
3
daily.sh
3
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")
|
||||
|
||||
#######################################
|
||||
|
39
validate.php
39
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, '<?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;
|
||||
}
|
||||
}
|
||||
|
||||
$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();
|
||||
$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;
|
||||
|
Reference in New Issue
Block a user