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/Nfcj6abeOdVMX+7rkjsB+xe8AQC1PTHig7bqnJElw0jTJEP83A5
OrZt3p7lWDKzAlIPXgDWAsBOWoCjVKx8WWQsxcOdpUzqv1K4VApCsVgKmXoOWeRVb
3kwvJHGR9C0qkUKEmYcpCI1cIPo+UmR35Ox9/im48jIXgA0SDs3vegLVECvoz00Fr
7zRfkvOq/0mnDZN/nKceGogyCBPmImZ2PU6wyDztvkfxT7EbE12T3dWKiw1sXM9L/
hHR8FZxhV4x3ZxqeyRHjKv0itK+vEBpTvCQX6kUMPn0WUi7A9Mj76LHCqlPAAIi2N
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 2018-07-15
*/
declare(ticks=1);
class FourImagesVersionCheck extends VNag {
protected $argSystemDir = null;
public function __construct() {
parent::__construct();
$this->registerExpectedStandardArguments('Vht');
$this->getHelpManager()->setPluginName('check_4images_version');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if a local 4images 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, '4imagesPath', 'The local directory where your 4images installation is located.'));
}
protected function get_4images_version($path) {
if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) {
throw new Exception("Cannot find version information at $path");
}
return $m[1];
}
protected function get_latest_version() {
if (!$cont) {
throw new Exception("Cannot access website with latest version");
}
if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) {
if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) {
throw new Exception("Cannot find version information on the website");
}
}
}
protected function cbRun
($optional_args=array()) {
$system_dir = $this->argSystemDir->getValue();
if (empty($system_dir)) {
throw new Exception("Please specify the directory of the 4images installation.");
}
$system_dir = realpath($system_dir) === false ?
$system_dir : realpath($system_dir);
throw new Exception('Directory "'.$system_dir.'" not found.');
}
$version = $this->get_4images_version($system_dir);
$latest_version = $this->get_latest_version();
if ($version == $latest_version) {
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("Version $version at $system_dir", true);
} else {
$this->setStatus(VNag::STATUS_WARNING);
$this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
}
}
}