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b1QBb
reXI1aYc0cX7bAuvJ6Jut4OmtbYVS5I2xCl98cdmiyaGYtII8PPIzF8NOx6PbV+Yo
Cgl1KUNepBqVnODB6CfdJKLp2RBv1WIwGsRmzZ+cOYBVbntj6urUrwfRTBxb95NkF
nM6xiLZhPlQlLwlvDVlxONeVTrKiJ1T6jg/piv8AZunrTHRaTAJd8rEX4ZtJ4kJDw
Zdor1tSgWF4n7ZSs4eKxwRHTCe4+Y/CKCHUGT1ntmpfB75ZC12h+XiqOifG1p0l96
sJhUNp6++mfh+nowQ02j3v6QMxOqRFwhfNfTTvQMlelLpXMU5lGjcv8GrecP4p+7s
w==
</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 2021-04-10
*/
declare(ticks=1);
class MediaWikiVersionCheck extends VNag {
protected $argSystemDir = null;
public function __construct() {
parent::__construct();
$this->registerExpectedStandardArguments('Vht');
$this->getHelpManager()->setPluginName('check_mediawiki_version');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if a local MediaWiki 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, 'mediawikiPath', 'The local directory where MediaWiki installation is located.'));
}
protected function get_mediawiki_version($path) {
if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $c, $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('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) {
throw new Exception("Cannot find version information on the website");
}
return $m[2];
}
protected function cbRun
($optional_args=array()) {
$system_dir = $this->argSystemDir->getValue();
if (empty($system_dir)) {
throw new Exception("Please specify the directory of the MediaWiki installation.");
}
$system_dir = realpath($system_dir) === false ?
$system_dir : realpath($system_dir);
throw new Exception('Directory "'.$system_dir.'" not found.');
}
$version = $this->get_mediawiki_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);
}
}
}