Subversion Repositories vnag

Rev

Rev 29 | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. ISv4gHvD/9kQtWE/SPYuEUnOdEDii0T07ud44GyGM0+pMX84eqR8FziJfACrSOGki
  3. biOuiR7eAvFtoo+JHG9Lg59yO+3BE9gKIda2eeh2mek2XPBGM5XppwRIHQ+4DnL5x
  4. Gzol6qmr8IKLTScgVJZWogNX+CfkjSYiLMpbBYEL/bVolUEdfJSbh9D3NQ1kDbAjm
  5. H5UHlJbnSXm77xj0gSEAFZ7MpmUjPNlhDewpLyzsyVMp5/GJ2N7M8Lujq/JdZYbVs
  6. unbAUJR7kzBIXkXsPcimOFesS6kB1xI3+y+pgHJ8y6ODLLHZ/ec23lIw2EFHCWt3B
  7. lcE2XSTdFey7z578vWWl9fAHw41HZq38SSgz8IfFFllWYKmwzap2ZN93GbQNa+jaR
  8. gAETrvVpGorFAEvZJyhhhSelVFP9gagx7aFh34Q4qpM1cNTgsP9HUe7cyULuOsvmE
  9. lKFCeadIuuV7QHx7miQmlCWPKjzdAOkTRMYzYfZVzSStRsjk+Qwnz3OqoEpbfggkq
  10. gj6Ynd/rtzMcqbz9FibhjQHsvyDR/OFr5mzLt7UhFWWSiOrS0XLj7soLMMXWWDtZo
  11. pSRIyGyspZH2IuU89ZQUakJpP2N1srq9zH4f0TWwS01jCfdz8ZYxfAbUKQQmsQv6R
  12. CTRAIOo+MjgBe3VQspksTL3h03Uy7xgSa1l0xeGYCRGAUV2NAlU7IdxXVAfqMmdvt
  13. s0X1Aw/s2XyJRIIXzHb2axDRXqXDJGIeIvHTu/Y3kVuU3ilr1XnyVlfBeNg22LAwo
  14. Zd2EoBfx8WejxOHSC11oHnm8qQuED6FSp4SzZGzYKq16+tZm4H5OcxNk1dsaoVY1Z
  15. 59wCSxke/ZMhEiAIl1C/SlmCiqXSVMQR6IYVLtCfajS1oyWw+jf107IpEjETm7eBs
  16. HsScH7/1Aa650UPTwkIDNxakRhaNa+LaF/U+ML8q4DSZJolmDvv2Ra5nlULteEXjD
  17. bZghdLENdIQBsWIuPXVmOXcD3/CR2by+F0I8yX5rTYLXwbVV0L4dQWqYxNS7tRugO
  18. oR5NIKEf0EA3bMWs8LBFrXy6amfFkWfYN5TPZYRbjGAfpBqqy844jocKOdNpjrKVB
  19. 6Y/cO2n9swccNoYOxUrcsGU/9rKe/2p15pT1DjlYWN/nXyzvCGA4XTss0kgJ94SB/
  20. rRNattVBzoqMDbP2gGsVJgf+pIpN6q5Ny3MuxuA5ROTZNC3qjT3DswtzrN00mRQBG
  21. xL1IvfRDSW9ag+HPYAJty0MZr8SxD3Flj7SuuznTN/DC5RAVUz58i6O+pQ/7QkkyI
  22. u3LnJUYdMUcJidVv6VvpwCGZs1Iouw0UDHabbubXAAYz+Evt1Qu4ovNPDs8HnJ64w
  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 2021-12-19
  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/Defines.php");
  60.                 if (!preg_match('@define\\( \'MW_VERSION\', \'([0-9\\.]+)\' \\);@is', $c, $m)) {
  61.                         $c = @file_get_contents("$path/includes/DefaultSettings.php");
  62.                         if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $c, $m)) {
  63.                                 throw new Exception("Cannot find version information at $path");
  64.                         }
  65.                 }
  66.  
  67.                 return $m[1];
  68.         }
  69.  
  70.         protected function get_latest_version() {
  71.                 $cont = @file_get_contents('https://www.mediawiki.org/wiki/Download/en');
  72.                 if (!$cont) {
  73.                         throw new Exception("Cannot access website with latest version");
  74.                 }
  75.  
  76.                 if (!preg_match('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) {
  77.                         throw new Exception("Cannot find version information on the website");
  78.                 }
  79.  
  80.                 return $m[2];
  81.         }
  82.  
  83.         protected function cbRun($optional_args=array()) {
  84.                 $system_dir = $this->argSystemDir->getValue();
  85.                 if (empty($system_dir)) {
  86.                         throw new Exception("Please specify the directory of the MediaWiki installation.");
  87.                 }
  88.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  89.  
  90.                 if (!is_dir($system_dir)) {
  91.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  92.                 }
  93.  
  94.                 $version = $this->get_mediawiki_version($system_dir);
  95.  
  96.                 $latest_version = $this->get_latest_version();
  97.  
  98.                 if ($version == $latest_version) {
  99.                         $this->setStatus(VNag::STATUS_OK);
  100.                         $this->setHeadline("Version $version at $system_dir", true);
  101.                 } else {
  102.                         $this->setStatus(VNag::STATUS_WARNING);
  103.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  104.                 }
  105.         }
  106. }
  107.