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L9AOz5RR53Y2
Fk9neknuhFv/PUfePhQZd8mhxBgbzlRpN1v8enDY4bY+A695Vmz6Lx3XWvb8os1aO
CIkperWfF336r+lj3fDGDHnlqXYVrOKgiBSFBqtQZ8l4xmcxE/On8el2B95LTY4hE
D4KKRPTBqanx75Ajgv0o5FVHtNripTFA2PXOv9NaEjqkvckBCHnLOcUUSfT4GCqe/
EZwmgNGc8eQ6Jf09Lr4B7ppmUFD/mEx/wsaQrVwFNclFtOhJi6Y1KDBqq/I9tmB0P
31b1a4OfVuclmipIyFphLOhAkKYD7l4kpuaJ2i4ij+OAfBikVcZr+sVliDrKQhWvG
Q==
</ViaThinkSoftSignature> */ ?>
<?php
/*
* VNag - Nagios Framework for PHP
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
* Licensed under the terms of the Apache 2.0 license
*
* Revision 2023-10-13
*/
declare(ticks=1);
class ViewVCVersionCheck extends VNag {
protected $argSystemDir = null;
public function __construct() {
parent::__construct();
$this->registerExpectedStandardArguments('Vht');
$this->getHelpManager()->setPluginName('check_viewvc_version');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if a local ViewVC system has the latest version installed.');
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
// Individual (non-standard) arguments:
$this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'viewvcPath', 'The local directory where your ViewVC installation is located.'));
}
protected function get_local_version($path) {
throw new VNagException("Cannot find ViewVC settings file at $path");
}
if ($cont === false) {
throw new VNagException("Cannot determine version for system $path (cannot read viewvc.py)");
}
if (!preg_match('@__version__\\s*=\\s*([\'"])(.+)\\1@ismU', $cont, $m)) {
throw new VNagException("Cannot determine version for system $path (cannot find version string)");
}
return $m[2]; // e.g. "1.3.0-dev"
}
protected function get_latest_version() {
$cont = $this->url_get_contents('https://api.github.com/repos/viewvc/viewvc/releases/latest');
if ($cont === false) {
throw new VNagException('Cannot parse version from GitHub API. The plugin probably needs to be updated. (Cannot access api.github.com)');
}
if ($data === false) {
throw new VNagException('Cannot parse version from GitHub API. The plugin probably needs to be updated. (Invalid JSON data downloaded from api.github.com)');
}
return $data['tag_name']; // e.g. "1.2.1"
}
protected function cbRun
($optional_args=array()) {
$system_dir = $this->argSystemDir->getValue();
if (empty($system_dir)) {
throw new VNagException("Please specify the directory of the ViewVC installation.");
}
$system_dir = realpath($system_dir) === false ?
$system_dir : realpath($system_dir);
throw new VNagException('Directory "'.$system_dir.'" not found.');
}
$local_version = $this->get_local_version($system_dir);
$latest_stable = $this->get_latest_version();
// Note: version_compare() correctly assumes that 1.3.0-dev is higher than 1.3.0
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("Version $local_version (Latest stable version $latest_stable) at $system_dir", true);
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("Version $local_version (Latest stable version) at $system_dir", true);
} else {
$this->setStatus(VNag::STATUS_WARNING);
$this->setHeadline("Version $local_version is outdated (Latest version is $latest_stable) at $system_dir", true);
}
}
}