Subversion Repositories vnag

Rev

Rev 76 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. Lme5HcTC/7qI1KUKY012sAKAHRs+Xe2raUjKRYPkpBP0vUbn70cyw8Lql37CmVH4h
  3. 9eJ9Gs3tCYDZdslW42Rh/WNFVy4hMsyhLUzwvp8pks//pqoAgv3fVDit1x5z8NxIP
  4. 5EWxsAEOWp1ty2aNF/lD9aJHGjq+IZb7fMq5PLWoFMWQGukZovbI+dVBkhiA/2AMZ
  5. r2xie9GESJlyAVfhDtQEiMFSpgpJvbd2SmzJoJg+3aLfpVj6Ro4HF/7KY+kjJxFR4
  6. rDmK5lmyQqfuwUfG0cqOnQQjODi/LCFSOgF7hyboMT+wAztkMAHhiSWrWd2jgy9Mk
  7. PV1L7ktcyoS+RwFGAJznRG4PGAb7kE4ygS7CMjbh/yGrerOhdsFgI0URBx6UE2Dgh
  8. URlefSxPODIxt7ol39bN7IDJHjz+z1xPDKP9VgACuaNue/oZfrc7gyAjvWJrIahLe
  9. /tPsrn0HURYLZflCSy7VtUKpMtu4RSAKOaM2DJRWR7XAC7LoQWQg672JtK4rHzMX1
  10. cEKlCM28C+JRTd+FH5V3iLOoLjgGrGQr9coZPJ2r8s8pGNic1L/d2x5YUFWSwv74H
  11. WJuMe8zQ8f541RKFZllU4OueISitWVUd1KYLHEpxa/ioDDXnpH3xD4ILDhrwng67B
  12. 1eabFPtNNHgahtvePAzRlmE+hOKZitOsEOI8bB2IbYAyYbluaj69b8JOWDpWVWiqW
  13. n9g/bXhQu//7CY+X+9p6Lsm5mwtQp2syKe29MSuOYRT3eBRFDs0D1sBLREiivoX1v
  14. 1U6vDHHndtPq1UeaNB3UHxM3Wdmc0X3VDDcGn3qPnl6x4jQSB1Gp9QCIpYprNOLyd
  15. RCVnPwy+qgfU97iEEpDxduJRSaQrmr6KximkE3GrFHxp3j8fwHGA/ryvNK9CRXII+
  16. tetvf1f60+gEPsrmxziPZgVLGfko5lmugItSXFpS4xdyrtk/pUSHE3cG0Ke2yt25M
  17. f8jGG0nQLLsaUA+6zbPBfMCP3niT1OzoHV4domlqak7KOpmqbjlJoEHrEptDQGnB4
  18. It41TI37j/7qIfVAJkkpTAWFsOuLd5dwiPBp6JMF7apf/n8rnpXWNDAT8N0NeIGpN
  19. B9lBll/jtnSBVn9hD6zQBt4MkP62gVevLfA54gRqjTAeb+JDM8E4aeQ60n0p3P7lO
  20. PhOPQa2K13nyXaYxL0ogu634jdiN4B8aBlK8UUWFzEE5VFNTIg7tr7bEHd+MeadCt
  21. YUKMq0372Bgp0B3cqfnTC+946xsJYnMUGnqM4A/haK6ttiIpf5w/0O9+uRIf8Fixr
  22. 5blWfXw2HvRuIz2uAoiu+Tk3luxH/SHazJ3FiXgV0TEEzo8/GPH8cHFlFnsKXJB7L
  23. Q==
  24. </ViaThinkSoftSignature> */ ?>
  25. <?php
  26.  
  27. /*
  28.  * VNag - Nagios Framework for PHP
  29.  * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
  30.  * Licensed under the terms of the Apache 2.0 license
  31.  *
  32.  * Revision 2023-10-13
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class MediaWikiVersionCheck extends VNag {
  38.         protected $argSystemDir = null;
  39.  
  40.         public function __construct() {
  41.                 parent::__construct();
  42.  
  43.                 $this->registerExpectedStandardArguments('Vht');
  44.  
  45.                 $this->getHelpManager()->setPluginName('check_mediawiki_version');
  46.                 $this->getHelpManager()->setVersion('1.0');
  47.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local MediaWiki system has the latest version installed.');
  48.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  49.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
  50.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  51.  
  52.                 // Individual (non-standard) arguments:
  53.                 $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'mediawikiPath', 'The local directory where MediaWiki installation is located.'));
  54.         }
  55.  
  56.         protected function get_local_version($path) {
  57.                 $path = realpath($path) === false ? $path : realpath($path);
  58.  
  59.                 $cont = @file_get_contents("$path/includes/Defines.php");
  60.                 if ($cont !== false) {
  61.                         if (preg_match('@define\\( \'MW_VERSION\', \'([0-9\\.]+)\' \\);@is', $cont, $m)) return $m[1];
  62.                 }
  63.  
  64.                 $cont = @file_get_contents("$path/includes/DefaultSettings.php");
  65.                 if ($cont !== false) {
  66.                         if (preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $cont, $m)) return $m[1];
  67.                 }
  68.  
  69.                 throw new VNagException("Cannot find version information at $path");
  70.         }
  71.  
  72.         protected function get_latest_version() {
  73.                 $cont = $this->url_get_contents('https://www.mediawiki.org/wiki/Download/en');
  74.                 if ($cont === false) {
  75.  
  76.                         // The server replies to some older versions of PHP: 426 Upgrade Required
  77.                         $ch = curl_init();
  78.                         curl_setopt($ch, CURLOPT_URL, "https://www.mediawiki.org/wiki/Download/en");
  79.                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  80.                         $cont = @curl_exec( $ch );
  81.                         curl_close($ch);
  82.  
  83.                         if (!$cont) {
  84.                                 throw new VNagException("Cannot access website with latest version");
  85.                         }
  86.                 }
  87.  
  88.                 if (!preg_match('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) {
  89.                         throw new VNagException("Cannot find version information on the website");
  90.                 }
  91.  
  92.                 return $m[2];
  93.         }
  94.  
  95.         protected function cbRun($optional_args=array()) {
  96.                 $system_dir = $this->argSystemDir->getValue();
  97.                 if (empty($system_dir)) {
  98.                         throw new VNagException("Please specify the directory of the MediaWiki installation.");
  99.                 }
  100.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  101.  
  102.                 if (!is_dir($system_dir)) {
  103.                         throw new VNagException('Directory "'.$system_dir.'" not found.');
  104.                 }
  105.  
  106.                 $version = $this->get_local_version($system_dir);
  107.  
  108.                 $latest_version = $this->get_latest_version();
  109.  
  110.                 if (version_compare($version,$latest_version) >= 0) {
  111.                         $this->setStatus(VNag::STATUS_OK);
  112.                         $this->setHeadline("Version $version at $system_dir", true);
  113.                 } else {
  114.                         $this->setStatus(VNag::STATUS_WARNING);
  115.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  116.                 }
  117.         }
  118. }
  119.