diff --git a/LibreNMS/ComposerHelper.php b/LibreNMS/ComposerHelper.php index efab47d171..3de1cbed72 100644 --- a/LibreNMS/ComposerHelper.php +++ b/LibreNMS/ComposerHelper.php @@ -129,6 +129,11 @@ class ComposerHelper continue; } + // quote strings with spaces + if (strpos($value, ' ') !== false) { + $value = "\"$value\""; + } + if (strpos($content, "$key=") !== false) { // only replace ones that aren't already set for safety and uncomment $content = preg_replace("/#?$key=\n/", "$key=$value\n", $content); diff --git a/LibreNMS/Validations/Php.php b/LibreNMS/Validations/Php.php index 026ac0bb23..b39b02455b 100644 --- a/LibreNMS/Validations/Php.php +++ b/LibreNMS/Validations/Php.php @@ -79,7 +79,7 @@ class Php extends BaseValidation private function checkExtensions(Validator $validator) { - $required_modules = array('mysqli','pcre','curl','session', 'xml', 'gd'); + $required_modules = ['mysqli', 'mbstring', 'pcre', 'curl', 'session', 'xml', 'gd']; if (Config::get('distributed_poller')) { $required_modules[] = 'memcached'; diff --git a/app/Checks.php b/app/Checks.php index 86034a62c0..11c6921414 100644 --- a/app/Checks.php +++ b/app/Checks.php @@ -37,10 +37,24 @@ class Checks { public static function preBoot() { + // check php extensions + $missing = self::missingPhpExtensions(); + + if (!empty($missing)) { + self::printMessage( + "Missing PHP extensions. Please install and enable them on your LibreNMS server.", + $missing, + true + ); + } + // check file/folder permissions $check_folders = [ self::basePath('bootstrap/cache'), self::basePath('storage'), + self::basePath('storage/framework/sessions'), + self::basePath('storage/framework/views'), + self::basePath('storage/framework/cache'), self::basePath('logs'), ]; @@ -76,14 +90,28 @@ class Checks "setfacl -d -m g::rwx $dirs", ]; + $current_groups = explode(' ', trim(exec('groups'))); + if (!in_array($group, $current_groups)) { + $current_user = trim(exec('whoami')); + $chown_commands[] = "usermod -a -G $group $current_user"; + } + + //check for missing directories - $missing = array_filter($check, 'file_exists'); + $missing = array_filter($check, function ($file) { + return !file_exists($file); + }); + if (!empty($missing)) { array_unshift($chown_commands, 'mkdir -p ' . implode(' ', $missing)); } + $short_dirs = implode(', ', array_map(function ($dir) { + return str_replace(self::basePath(), '', $dir); + }, $check)); + self::printMessage( - "Error: $dirs not writable! Run these commands as root to fix:", + "Error: $short_dirs not writable! Run these commands as root on your LibreNMS server to fix:", $chown_commands ); @@ -154,7 +182,10 @@ class Checks $message = implode(PHP_EOL, $content); } else { $format = "

%s

%s

"; - $message = implode('
', $content); + $message = ''; + foreach ($content as $line) { + $message .= "

$line

\n"; + } } printf($format, $title, $message); @@ -169,4 +200,13 @@ class Checks $base_dir = realpath(__DIR__ . '/..'); return "$base_dir/$path"; } + + private static function missingPhpExtensions() + { + $required_modules = ['mysqli', 'mbstring', 'pcre', 'curl', 'session', 'xml', 'gd']; + + return array_filter($required_modules, function ($module) { + return !extension_loaded($module); + }); + } } diff --git a/config/app.php b/config/app.php index f9b8386252..b43d71da8c 100644 --- a/config/app.php +++ b/config/app.php @@ -64,7 +64,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => null, // set to null to avoid setting timezone /* |--------------------------------------------------------------------------