. * * @package LibreNMS * @link http://librenms.org * @copyright 2018 Tony Murray * @author Tony Murray */ namespace App; use App\Models\Device; use App\Models\Notification; use Auth; use Cache; use Carbon\Carbon; use LibreNMS\Config; use LibreNMS\Exceptions\FilePermissionsException; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Toastr; class Checks { public static function preBoot() { // check php extensions if ($missing = self::missingPhpExtensions()) { self::printMessage( "Missing PHP extensions. Please install and enable them on your LibreNMS server.", $missing, true ); } } /** * Pre-boot dependency check */ public static function postAutoload() { if (!class_exists(\Illuminate\Foundation\Application::class)) { self::printMessage( 'Error: Missing dependencies! Run the following command to fix:', './scripts/composer_wrapper.php install --no-dev', true ); } } /** * Post boot Toast messages */ public static function postAuth() { // limit popup messages frequency if (Cache::get('checks_popup_timeout') || !Auth::check()) { return; } Cache::put('checks_popup_timeout', true, Config::get('checks_popup_timer', 5)); $user = Auth::user(); if ($user->isAdmin()) { $notifications = Notification::isUnread($user)->where('severity', '>', 1)->get(); foreach ($notifications as $notification) { Toastr::error("$notification->body", $notification->title); } $warn_sec = Config::get('rrd.step', 300) * 3; if (Device::isUp()->where('last_polled', '<=', Carbon::now()->subSeconds($warn_sec))->exists()) { $warn_min = $warn_sec / 60; Toastr::warning('It appears as though you have some devices that haven\'t completed polling within the last ' . $warn_min . ' minutes, you may want to check that out :)', 'Devices unpolled'); } // Directory access checks $rrd_dir = Config::get('rrd_dir'); if (!is_dir($rrd_dir)) { Toastr::error("RRD Directory is missing ($rrd_dir). Graphing may fail. Validate your install"); } $temp_dir = Config::get('temp_dir'); if (!is_dir($temp_dir)) { Toastr::error("Temp Directory is missing ($temp_dir). Graphing may fail. Validate your install"); } elseif (!is_writable($temp_dir)) { Toastr::error("Temp Directory is not writable ($temp_dir). Graphing may fail. Validate your install"); } } } private static function printMessage($title, $content, $exit = false) { $content = (array)$content; if (PHP_SAPI == 'cli') { $format = "%s\n\n%s\n\n"; $message = implode(PHP_EOL, $content); } else { $format = "

%s

%s

"; $message = ''; foreach ($content as $line) { $message .= "

$line

\n"; } } printf($format, $title, $message); if ($exit) { exit(1); } } private static function missingPhpExtensions() { // allow mysqli, but prefer mysqlnd if (!extension_loaded('mysqlnd') && !extension_loaded('mysqli')) { return ['mysqlnd']; } $required_modules = ['mbstring', 'pcre', 'curl', 'session', 'xml', 'gd']; return array_filter($required_modules, function ($module) { return !extension_loaded($module); }); } }