. * * @package LibreNMS * @link http://librenms.org * @copyright 2017 Tony Murray * @author Tony Murray */ namespace LibreNMS\Validations; use DateTime; use DateTimeZone; use Exception; use LibreNMS\Config; use LibreNMS\Interfaces\ValidationGroup; use LibreNMS\ValidationResult; use LibreNMS\Validator; class Updates implements ValidationGroup { public function validate(Validator $validator) { // if git is not available, we cannot do the other tests if (!check_git_exists()) { $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') { if ($versions['local_branch'] == 'php53') { $validator->warn( "You are on the PHP 5.3 support branch, this will prevent automatic updates.", "Update to PHP 5.6.4 or newer (PHP 7.1 recommended) to continue to receive updates." ); } 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" ); } } } // 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); } } /** * Returns if this test should be run by default or not. * * @return bool */ public function isDefault() { return true; } }