2017-10-26 06:56:09 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Updates.php
|
|
|
|
*
|
|
|
|
* Checks the status of git and updates.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @package LibreNMS
|
|
|
|
* @link http://librenms.org
|
|
|
|
* @copyright 2017 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Validations;
|
|
|
|
|
|
|
|
use DateTime;
|
|
|
|
use DateTimeZone;
|
|
|
|
use Exception;
|
|
|
|
use LibreNMS\Config;
|
2019-11-25 14:05:34 +00:00
|
|
|
use LibreNMS\Util\Env;
|
2019-01-09 03:42:56 +00:00
|
|
|
use LibreNMS\Util\Git;
|
2017-10-26 06:56:09 +00:00
|
|
|
use LibreNMS\ValidationResult;
|
|
|
|
use LibreNMS\Validator;
|
2020-04-24 09:04:36 +00:00
|
|
|
use LibreNMS\Validations\Php;
|
2017-10-26 06:56:09 +00:00
|
|
|
|
2018-02-27 15:57:20 +00:00
|
|
|
class Updates extends BaseValidation
|
2017-10-26 06:56:09 +00:00
|
|
|
{
|
|
|
|
public function validate(Validator $validator)
|
|
|
|
{
|
2019-11-25 14:05:34 +00:00
|
|
|
if (Env::librenmsDocker()) {
|
|
|
|
$validator->warn('Updates are managed through the official Docker image');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-09 03:42:56 +00:00
|
|
|
if (!Git::repoPresent()) {
|
2018-12-07 22:29:37 +00:00
|
|
|
$validator->warn('Non-git install, updates are manual or from package');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-26 06:56:09 +00:00
|
|
|
// if git is not available, we cannot do the other tests
|
2019-01-09 03:42:56 +00:00
|
|
|
if (!Git::binaryExists()) {
|
2017-10-26 06:56:09 +00:00
|
|
|
$validator->warn('Unable to locate git. This should probably be installed.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$versions = $validator->getVersions(true);
|
|
|
|
|
|
|
|
// check if users on master update channel are up to date
|
|
|
|
if (Config::get('update_channel') == 'master') {
|
|
|
|
if ($versions['local_sha'] != $versions['github']['sha']) {
|
|
|
|
try {
|
|
|
|
$commit_date = new DateTime('@' . $versions['local_date'], new DateTimeZone(date_default_timezone_get()));
|
|
|
|
if ($commit_date->diff(new DateTime())->days > 0) {
|
|
|
|
$validator->warn(
|
|
|
|
"Your install is over 24 hours out of date, last update: " . $commit_date->format('r'),
|
|
|
|
'Make sure your daily.sh cron is running and run ./daily.sh by hand to see if there are any errors.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$validator->fail($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($versions['local_branch'] != 'master') {
|
2018-01-10 14:40:58 +00:00
|
|
|
if ($versions['local_branch'] == 'php53') {
|
|
|
|
$validator->warn(
|
|
|
|
"You are on the PHP 5.3 support branch, this will prevent automatic updates.",
|
2020-04-24 09:04:36 +00:00
|
|
|
"Update to PHP 5.6.4 or newer (PHP " . Php::PHP_RECOMMENDED_VERSION . " recommended) to continue to receive updates."
|
2019-02-07 19:23:30 +00:00
|
|
|
);
|
|
|
|
} elseif ($versions['local_branch'] == 'php56') {
|
|
|
|
$validator->warn(
|
|
|
|
"You are on the PHP 5.6/7.0 support branch, this will prevent automatic updates.",
|
2020-04-24 09:04:36 +00:00
|
|
|
"Update to PHP " . Php::PHP_MIN_VERSION . " or newer (PHP " . Php::PHP_RECOMMENDED_VERSION . " recommended) to continue to receive updates."
|
2018-01-10 14:40:58 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$validator->warn(
|
|
|
|
"Your local git branch is not master, this will prevent automatic updates.",
|
|
|
|
"You can switch back to master with git checkout master"
|
|
|
|
);
|
|
|
|
}
|
2017-10-26 06:56:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO check update channel stable version
|
|
|
|
|
|
|
|
// check for modified files
|
|
|
|
$modifiedcmd = 'git diff --name-only --exit-code';
|
|
|
|
$validator->execAsUser($modifiedcmd, $cmdoutput, $code);
|
|
|
|
if ($code !== 0 && !empty($cmdoutput)) {
|
|
|
|
$result = ValidationResult::warn(
|
|
|
|
"Your local git contains modified files, this could prevent automatic updates.",
|
|
|
|
"You can fix this with ./scripts/github-remove"
|
|
|
|
);
|
|
|
|
$result->setList('Modified Files', $cmdoutput);
|
|
|
|
$validator->result($result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|