Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. TvlSnBB9oFkMG8t23W8SFnhWVFc86YGpHfet/Nbgyd080A7CHl5DO+RWvS7H19usk
  3. pIrRBrXZYgt5c1gawuV/u0sH0F+7gJNIGcjO3kaqWzXeaceO4pvNjjPJwLShLq+Fb
  4. E9kyw08XxHYYHkoJhtxnRiqaEEq4zmQ8U7S+JOnCHhP6cL3eP8/iY0jVFonPpwIcp
  5. IKHEd9p5/t5ZIFW02HCSB+wRT+jSXHe9TGieS9Yc7cODueJ80J3Jkh/EDbTOlgiOk
  6. gCROGf5zWqZUGaogvaLHk6WmO/XNyP1zUFj0lvNFfK4rhqbSy1Oa6UX+ZlVmpHAXL
  7. IR3nrpdFyYR2/zj0wXd21MpG5sN7zGgW98IpvJVSkb9eqsRr7IzmKkGvaEQ55lNYx
  8. YVgOQLOo+D9d5qb3V9stJ1R7h+VAN5uouMAd3Kj2uGp1QTUoxzy/cp1UU2ub9zQ8Q
  9. 4WOvnm0TVaoyFnpptfXvRMIHbfaB4wshglKwnDvzPtQnlsJfq2R9lZ6zqvgEuIEnJ
  10. tfpk6FOjCCIYR55IO1UVVryBqBWHtRBT2Y3Z0Tg5A1kuqwVcsw0d3rHRrjyhMu70D
  11. yMr4aHs1HE042coo4uYfkhmlETSNQgNntKyKcgdon/kOqxxhlc3NGopO5JVR5wBgY
  12. mX3tBYJ5OcFEzXgD4mmaF+2MG/K80sxh8t3jg+XCD7oq9dZTAAthWc7ojuWNb3a91
  13. uw6gb2lfogiCBSyCyMVRdakeA3gWZ/7zYhzWshW1sU+vegpIkTUt9Atq17k9i6WDI
  14. 8wNctTvx3ItmTencuUNXmfGyrFC4iUkHlYJy8JnuC4da568M+AX9kxr/qgtsC4yhj
  15. Rj+ZuEeZgVqBmYt3OIDMgdzK97+e45c0ixe4AAutbAvY00W3NiKOVe/cvYlefCxX0
  16. NjBqQ/+1gh4vhsf9Hew5TMIvlvgAVGNwGt4mQfNjcVjXk/QJb52EZ/EsKJbkBqeQq
  17. g7jrkgxH3aDhAnCKDVhjBBThQJanjAeCte/EEU3I3jnkYEktBEG6aVcYLPwC+b7jo
  18. c+KMB23YhlGPfTr1dalKGp+rBLEcZQtIRPRHgsxmWpQbRqjJ6YiEhdB7RafpoN+aa
  19. lxr8t1BRXiBFvOHSi/UZsRyiMjopKTMHTKuwV+TgWkgatr5oMhUYjF25bHLep2vjH
  20. BOLBcLbkvofUMYcC5SzwaT1QbzHmkPNRDMB9X5ghXgCStXGwFnbGZud+GfSnKvpBc
  21. eAOxpuBgY8qVQipDeuTN0nKEkmjRyIXjsHtcBvJiYk6+7v32xC/QSXP5zdu+1bDQX
  22. qx1O1uRtC49kgX259WivMmv/TXaPc/9LMevM1eZIJ0QnMZ3lJFNCmdYr9GTklIIlD
  23. g==
  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 2018-07-15
  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_mediawiki_version($path) {
  57.                 $path = realpath($path) === false ? $path : realpath($path);
  58.  
  59.                 $c = @file_get_contents("$path/includes/DefaultSettings.php");
  60.  
  61.                 if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $c, $m)) {
  62.                         throw new Exception("Cannot find version information at $path");
  63.                 }
  64.  
  65.                 return $m[1];
  66.         }
  67.  
  68.         protected function get_latest_version() {
  69.                 $cont = @file_get_contents('https://www.mediawiki.org/wiki/MediaWiki');
  70.                 if (!$cont) {
  71.                         throw new Exception("Cannot access website with latest version");
  72.                 }
  73.  
  74.                 if (!preg_match('@/Release notes/([^"]+)">@ismU', $cont, $m)) {
  75.                         throw new Exception("Cannot find version information on the website");
  76.                 }
  77.  
  78.                 return $m[1];
  79.         }
  80.  
  81.         protected function cbRun($optional_args=array()) {
  82.                 $system_dir = $this->argSystemDir->getValue();
  83.                 if (empty($system_dir)) {
  84.                         throw new Exception("Please specify the directory of the MediaWiki installation.");
  85.                 }
  86.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  87.  
  88.                 if (!is_dir($system_dir)) {
  89.                         throw new Exception('Directory "'.$system_dir.'" not found.', false);
  90.                 }
  91.  
  92.                 $version = $this->get_mediawiki_version($system_dir);
  93.  
  94.                 $latest_version = $this->get_latest_version();
  95.  
  96.                 if ($version == $latest_version) {
  97.                         $this->setStatus(VNag::STATUS_OK);
  98.                         $this->setHeadline("Version $version at $system_dir", true);
  99.                 } else {
  100.                         $this->setStatus(VNag::STATUS_WARNING);
  101.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  102.                 }
  103.         }
  104. }
  105.