2016-09-14 10:53:04 -05:00
|
|
|
#!/usr/bin/env php
|
2015-05-22 16:35:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LibreNMS
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version. Please see LICENSE.txt at the top level of
|
|
|
|
* the source code distribution for details.
|
|
|
|
*/
|
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
use LibreNMS\Config;
|
2018-02-27 09:57:20 -06:00
|
|
|
use LibreNMS\ValidationResult;
|
2017-10-26 01:56:09 -05:00
|
|
|
use LibreNMS\Validator;
|
|
|
|
|
2016-09-14 10:53:04 -05:00
|
|
|
chdir(__DIR__); // cwd to the directory containing this script
|
|
|
|
|
2018-02-27 09:57:20 -06:00
|
|
|
ini_set('display_errors', 1);
|
|
|
|
|
2016-10-03 11:48:19 -05:00
|
|
|
require_once 'includes/common.php';
|
2017-07-17 13:02:28 -05:00
|
|
|
require_once 'includes/functions.php';
|
|
|
|
require_once 'includes/dbFacile.php';
|
2016-10-03 11:48:19 -05:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
$options = getopt('g:m:s::h::');
|
2015-05-22 16:35:38 +01:00
|
|
|
|
|
|
|
if (isset($options['h'])) {
|
2016-08-28 17:32:55 -05:00
|
|
|
echo
|
2015-07-13 20:10:26 +02:00
|
|
|
"\n Validate setup tool
|
2015-05-22 16:35:38 +01:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
Usage: ./validate.php [-g <group>] [-s] [-h]
|
2015-07-13 20:10:26 +02:00
|
|
|
-h This help section.
|
2017-10-26 01:56:09 -05:00
|
|
|
-s Print the status of each group
|
|
|
|
-g Any validation groups you want to run, comma separated:
|
|
|
|
Non-default groups:
|
|
|
|
- mail: this will test your email settings (uses default_mail option even if default_only is not set)
|
|
|
|
- distributedpoller: this will test for the install running as a distributed poller
|
2016-02-01 23:29:37 +00:00
|
|
|
- rrdcheck: this will check to see if your rrd files are corrupt
|
2017-10-26 01:56:09 -05:00
|
|
|
Default groups:
|
|
|
|
- configuration: checks various config settings are correct
|
|
|
|
- database: checks the database for errors
|
2018-02-27 09:57:20 -06:00
|
|
|
- dependencies: checks that all required libraries are installed and up-to-date
|
2017-10-26 01:56:09 -05:00
|
|
|
- disk: checks for disk space and other disk related issues
|
|
|
|
- php: check that various PHP modules and functions exist
|
|
|
|
- poller: check that the poller and discovery are running properly
|
|
|
|
- programs: check that external programs exist and are executable
|
|
|
|
- updates: checks the status of git and updates
|
|
|
|
- user: check that the LibreNMS user is set properly
|
|
|
|
|
|
|
|
Example: ./validate.php -g mail.
|
2015-05-22 16:35:38 +01:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
"
|
2015-08-06 19:02:05 +00:00
|
|
|
;
|
2015-07-13 20:10:26 +02:00
|
|
|
exit;
|
2015-05-22 16:35:38 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 11:48:19 -05:00
|
|
|
|
2017-07-17 13:02:28 -05:00
|
|
|
// Buffer output
|
|
|
|
ob_start();
|
2017-10-26 01:56:09 -05:00
|
|
|
$precheck_complete = false;
|
2017-07-17 13:02:28 -05:00
|
|
|
register_shutdown_function(function () {
|
2017-10-26 01:56:09 -05:00
|
|
|
global $precheck_complete;
|
2017-07-17 13:02:28 -05:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
if (!$precheck_complete) {
|
|
|
|
print_header(version_info());
|
|
|
|
}
|
2017-07-17 13:02:28 -05:00
|
|
|
});
|
|
|
|
|
2016-10-03 11:48:19 -05:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2017-07-17 13:02:28 -05:00
|
|
|
$pre_checks_failed = false;
|
2016-10-03 11:48:19 -05:00
|
|
|
$syntax_check = `php -ln config.php`;
|
|
|
|
if (!str_contains($syntax_check, 'No syntax errors detected')) {
|
2015-05-22 16:35:38 +01:00
|
|
|
print_fail('Syntax error in config.php');
|
2016-10-03 11:48:19 -05:00
|
|
|
echo $syntax_check;
|
2017-07-17 13:02:28 -05:00
|
|
|
$pre_checks_failed = true;
|
2015-05-22 16:35:38 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 11:48:19 -05:00
|
|
|
$first_line = rtrim(`head -n1 config.php`);
|
|
|
|
if (!starts_with($first_line, '<?php')) {
|
|
|
|
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
|
2017-07-17 13:02:28 -05:00
|
|
|
$pre_checks_failed = true;
|
2016-08-31 10:20:07 +02:00
|
|
|
}
|
2016-10-03 11:48:19 -05:00
|
|
|
if (str_contains(`tail config.php`, '?>')) {
|
|
|
|
print_fail("Remove the ?> at the end of config.php");
|
2017-07-17 13:02:28 -05:00
|
|
|
$pre_checks_failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Composer checks
|
|
|
|
if (!file_exists('vendor/autoload.php')) {
|
|
|
|
print_fail('Composer has not been run, dependencies are missing', 'composer install --no-dev');
|
2018-02-27 09:57:20 -06:00
|
|
|
exit;
|
2017-07-17 13:02:28 -05:00
|
|
|
}
|
|
|
|
|
2018-02-27 09:57:20 -06:00
|
|
|
// init autoloading
|
|
|
|
require_once 'vendor/autoload.php';
|
|
|
|
|
2018-01-22 08:16:37 -06:00
|
|
|
|
|
|
|
$dep_check = shell_exec('php scripts/composer_wrapper.php install --no-dev --dry-run');
|
|
|
|
preg_match_all('/Installing ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_missing);
|
|
|
|
if (!empty($dep_missing[0])) {
|
2018-02-07 20:45:18 -06:00
|
|
|
print_fail("Missing dependencies!", "./scripts/composer_wrapper.php install --no-dev");
|
2018-01-22 08:16:37 -06:00
|
|
|
$pre_checks_failed = true;
|
|
|
|
print_list($dep_missing[1], "\t %s\n");
|
|
|
|
}
|
|
|
|
preg_match_all('/Updating ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_outdated);
|
|
|
|
if (!empty($dep_outdated[0])) {
|
2018-02-07 20:45:18 -06:00
|
|
|
print_fail("Outdated dependencies", "./scripts/composer_wrapper.php install --no-dev");
|
2018-01-22 08:16:37 -06:00
|
|
|
print_list($dep_outdated[1], "\t %s\n");
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:57:20 -06:00
|
|
|
$validator = new Validator();
|
|
|
|
$validator->validate(array('dependencies'));
|
|
|
|
if ($validator->getGroupStatus('dependencies') == ValidationResult::FAILURE) {
|
|
|
|
$pre_checks_failed = true;
|
|
|
|
}
|
|
|
|
|
2017-07-17 13:02:28 -05:00
|
|
|
if ($pre_checks_failed) {
|
2016-10-03 11:48:19 -05:00
|
|
|
exit;
|
2015-12-10 23:02:48 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 13:02:28 -05:00
|
|
|
$init_modules = array('nodb');
|
2016-11-21 14:12:59 -06:00
|
|
|
require 'includes/init.php';
|
2016-04-29 12:53:02 -05:00
|
|
|
|
|
|
|
// make sure install_dir is set correctly, or the next includes will fail
|
2017-10-26 01:56:09 -05:00
|
|
|
if (!file_exists(Config::get('install_dir').'/config.php')) {
|
2018-02-27 09:57:20 -06:00
|
|
|
$suggested = realpath(__DIR__);
|
2017-10-26 01:56:09 -05:00
|
|
|
print_fail('$config[\'install_dir\'] is not set correctly.', "It should probably be set to: $suggested");
|
2016-04-29 12:53:02 -05:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2015-09-21 21:06:57 +00:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
// Connect to MySQL
|
2018-08-17 15:29:20 -05:00
|
|
|
\LibreNMS\DB\Eloquent::boot();
|
2017-04-05 09:00:28 +01:00
|
|
|
|
2018-08-17 15:29:20 -05:00
|
|
|
if (\LibreNMS\DB\Eloquent::isConnected()) {
|
2017-10-26 01:56:09 -05:00
|
|
|
$validator->ok('Database connection successful', null, 'database');
|
2018-08-17 15:29:20 -05:00
|
|
|
} else {
|
2018-09-05 13:29:27 -05:00
|
|
|
$validator->fail('Error connecting to your database.', null, 'database');
|
2017-07-17 13:02:28 -05:00
|
|
|
}
|
|
|
|
|
2018-04-11 10:15:13 -05:00
|
|
|
Config::load();
|
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
$precheck_complete = true; // disable shutdown function
|
|
|
|
print_header($validator->getVersions());
|
2017-07-17 13:02:28 -05:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
if (isset($options['g'])) {
|
|
|
|
$modules = explode(',', $options['g']);
|
|
|
|
} elseif (isset($options['m'])) {
|
|
|
|
$modules = explode(',', $options['m']); // backwards compat
|
2017-07-17 13:02:28 -05:00
|
|
|
} else {
|
2017-10-26 01:56:09 -05:00
|
|
|
$modules = array(); // all modules
|
2015-11-19 10:20:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
// run checks
|
|
|
|
$validator->validate($modules, isset($options['s'])||!empty($modules));
|
2015-05-22 16:35:38 +01:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
function print_header($versions)
|
|
|
|
{
|
|
|
|
$output = ob_get_clean();
|
2018-02-27 09:57:20 -06:00
|
|
|
@ob_end_clean();
|
2017-03-22 03:14:03 -05:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
echo <<< EOF
|
|
|
|
====================================
|
|
|
|
Component | Version
|
|
|
|
--------- | -------
|
|
|
|
LibreNMS | ${versions['local_ver']}
|
|
|
|
DB Schema | ${versions['db_schema']}
|
|
|
|
PHP | ${versions['php_ver']}
|
|
|
|
MySQL | ${versions['mysql_ver']}
|
|
|
|
RRDTool | ${versions['rrdtool_ver']}
|
|
|
|
SNMP | ${versions['netsnmp_ver']}
|
|
|
|
====================================
|
2017-03-22 03:14:03 -05:00
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
$output
|
|
|
|
EOF;
|
2016-10-03 11:48:19 -05:00
|
|
|
}
|
|
|
|
|
2017-10-26 01:56:09 -05:00
|
|
|
// output matches that of ValidationResult
|
2017-03-02 08:04:29 +00:00
|
|
|
function print_fail($msg, $fix = null)
|
2016-08-28 17:32:55 -05:00
|
|
|
{
|
2017-03-02 08:04:29 +00:00
|
|
|
c_echo("[%RFAIL%n] $msg");
|
|
|
|
if ($fix && strlen($msg) > 72) {
|
|
|
|
echo PHP_EOL . " ";
|
|
|
|
}
|
2015-05-22 16:35:38 +01:00
|
|
|
|
2017-03-02 08:04:29 +00:00
|
|
|
if (!empty($fix)) {
|
|
|
|
c_echo(" [%BFIX%n] %B$fix%n");
|
|
|
|
}
|
|
|
|
echo PHP_EOL;
|
|
|
|
}
|