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n8HP+yzwbP6DGGqB
EsoFqI6oKTiEYo6amqmOcLFX8GjXR0DEb0tK4IIf73uN1ymPpM2AW3Z9h4f6SprmG
osKy0Lq0ASujUZJ0gZf2KVYlgpBrv8+kxss4LrEJutuHK+FKrOWCVYNEnrZ1GVPFP
7DxMolfnil8VVrBBFCs4gROiL9YcQSABt8x5Ol53mU/EmWx1KypCSml8J6nh4U87D
rKYbwwne9eaZURG0uzy0dOGS78+kSZwQPNgKmIsKT9VnJXQWG9MhA1UZlazsfnDGb
5oGdaHQPbJlYtJJmLg/RPw/BT9XzXIluF0VWosZ2zJWRijvnxaCO09nVeYwyPwj5f
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 2022-02-02
*/
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();
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);
}
}
}