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Y3BHDoT
Y10ThdjaiL26cQq/Y/mZ/en9L+IewGeLbC9c11U8N41IvywyQxuTLraqHN85qDGVO
ibIEzToi4HAJXorbHXkemfJrIPS7JrUTEwDUiO+Xrys+L9oOZl5EUHYUc+GebaMm3
nzcSkDjxGfC+44WnDvYDOdEMPtGGjH40fhhawlHO1K4+DlHNLbmBMBCoE5KaHkanN
jeLh5pvNkMrJWK/1dfr5moDftU/glkHwq2srUs7/8xZU5AqcbBWQSZNztT7p58UwZ
Kf6hlHOQYdY1dujII1sj2vGqKn1O+57twJpfJ/dEmEzDcii/SFml8zViWZHUG4A7d
g==
</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 NoccVersionCheck extends VNag {
protected $argSystemDir = null;
public function __construct() {
parent::__construct();
$this->registerExpectedStandardArguments('Vht');
$this->getHelpManager()->setPluginName('check_nocc_version');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if a local NOCC Webmail 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, 'noccPath', 'The local directory where your NOCC installation is located.'));
}
protected function get_nocc_version($path) {
if (!preg_match('@\$conf\->nocc_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('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) {
if (!preg_match('@/nocc\-(.+)\.tar\.gz"@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 NOCC installation.");
}
$system_dir = realpath($system_dir) === false ?
$system_dir : realpath($system_dir);
throw new Exception('Directory "'.$system_dir.'" not found.');
}
$version = $this->get_nocc_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);
}
}
}