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ILFjiY927T7E8qFjAEpwLyKs6NgEvmhcIJzpWl8MdW/N68BN18h3DErrj6F
FNOAQmncJioW66h5vkBukmw/Gxwmq4LhKyBrFH0GsJ4kJ46jtsVqQgWyClTODlcyl
KNlxvUVaqneVyEQJ57+QXrfZx0p3cOT8UiZD6TsngfXa4vu82ZDQi7p25LMwd0xfn
ToWOh0AdSXLS9QtL1dK3X7dJrwLSeFuVFTIGdvn5WuOmgon4QndNpYBxE9L2BJUL7
/kGYskQXghIAE2vr7oQGNSeEPGb7WAKb4+LMd6jpvVMDIK26tnL+eXz2TURMyE037
A==
</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 2022-09-12
*/
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('@define\\( \'MW_VERSION\', \'([0-9\\.]+)\' \\);@is', $c, $m)) {
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) {
// The server replies to some older versions of PHP: 426 Upgrade Required
curl_setopt($ch, CURLOPT_URL
, "https://www.mediawiki.org/wiki/Download/en");
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();
$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);
}
}
}