Rev 46 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
57 | daniel-mar | 2 | tCxWODVQjpp/mnpKKNqXZG1LyUti7FjIhQIkV0I7YHQb5pKovjP1jwQMLMrtdKt8j |
3 | fQEvKt1KGkeUcZfnQ1nU/7rXZ62zVgioXw35IodxQahtohyXErvCCAQ2e4Kh5UKMD |
||
4 | R5sC13rlgK2EGHwLJbLt6yQL2jc6sDuV3QyT/ggNTsGtOjSsQXHCSu0XywMEabcO0 |
||
5 | ESELIgGC9w4T7nPbXFKx8c49j1ZFfJZeqFVnSpVXxj59Qpn1WS07fRndrC3hzFlX7 |
||
6 | ds3q9Db/k74qPhzmvx9dZFFXLLhnP0l7GLVkmSBLiyO/wl7WBjIklL+ZTfFiyLMqb |
||
7 | B14YZfULwH2z/Y226IrcTt+fiz3muuNjLeIirfhlvv54pTn3a/8C0yp0qNGaINghX |
||
8 | LlWUxm7Jw0O5vLl991LHstIqZEr6uacFNF3pCyrHRTBuvUpBs1Wa+xLNQdRBfj9hd |
||
9 | 7gJhVpYB1bJXFFx5XVAHmCGehPvQb36r2dnX2p9pD7qC4gmEZJgsYSomsc9STN064 |
||
10 | dl5CKg5lDW8ZKew7D1rNKN47eoms92IWvHxkkgWYHGWCOKlZV2Ia5HtJYHsWjSz59 |
||
11 | pEaJ8+LLA9hL9cRHQ/iMp9d6roihJrjPYm8dkvBHntSTSoX50XFUHiOsgANnauOf+ |
||
12 | MuFhVFgdYyxPtTqcEhj9+cbP0G4C1CUgRZz9wSNc6n9qEOLYp4QbeD13wGic81BJo |
||
13 | tGI0p/eDhIewo4z4vPvDmquVisdvdZ/vIVXQcN9so9AwANqmaJaqhGyEFfh97uowD |
||
14 | S4SHOLcx195V42G5yo2x+nvkcDS0zewT832VG+mc96lrr0sWGNKndO42gtR0X54Q/ |
||
15 | Ly3c8MgEK8mu11J+Yz7R0G/OkL2nPEjPSdKP/2lM7t8zyLevIAI8O4vMAeSu3iChQ |
||
16 | DAzvDB4ZL5FhhQkujATeEKj+zdz1AvY9AgLSLB/20fYnb0B+dEf4STeGOojsQ9Y62 |
||
17 | +LwkLd4Qm9etkXElZMsP9lY9C3pTzDb7HBGvRgqgI3B5BOXV1SuBOEsdHKO2q+eQK |
||
18 | 2oB9f6ILFjiY927T7E8qFjAEpwLyKs6NgEvmhcIJzpWl8MdW/N68BN18h3DErrj6F |
||
19 | FNOAQmncJioW66h5vkBukmw/Gxwmq4LhKyBrFH0GsJ4kJ46jtsVqQgWyClTODlcyl |
||
20 | KNlxvUVaqneVyEQJ57+QXrfZx0p3cOT8UiZD6TsngfXa4vu82ZDQi7p25LMwd0xfn |
||
21 | ToWOh0AdSXLS9QtL1dK3X7dJrwLSeFuVFTIGdvn5WuOmgon4QndNpYBxE9L2BJUL7 |
||
22 | /kGYskQXghIAE2vr7oQGNSeEPGb7WAKb4+LMd6jpvVMDIK26tnL+eXz2TURMyE037 |
||
23 | A== |
||
4 | daniel-mar | 24 | </ViaThinkSoftSignature> */ ?> |
2 | daniel-mar | 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 | * |
||
57 | daniel-mar | 32 | * Revision 2022-09-12 |
2 | daniel-mar | 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 | |||
41 | daniel-mar | 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 | } |
||
2 | daniel-mar | 65 | } |
66 | |||
67 | return $m[1]; |
||
68 | } |
||
69 | |||
70 | protected function get_latest_version() { |
||
6 | daniel-mar | 71 | $cont = @file_get_contents('https://www.mediawiki.org/wiki/Download/en'); |
2 | daniel-mar | 72 | if (!$cont) { |
46 | daniel-mar | 73 | |
74 | // The server replies to some older versions of PHP: 426 Upgrade Required |
||
75 | $ch = curl_init(); |
||
76 | curl_setopt($ch, CURLOPT_URL, "https://www.mediawiki.org/wiki/Download/en"); |
||
77 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); |
||
78 | $cont = @curl_exec( $ch ); |
||
79 | curl_close($ch); |
||
80 | |||
81 | if (!$cont) { |
||
82 | throw new Exception("Cannot access website with latest version"); |
||
83 | } |
||
2 | daniel-mar | 84 | } |
85 | |||
26 | daniel-mar | 86 | if (!preg_match('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) { |
2 | daniel-mar | 87 | throw new Exception("Cannot find version information on the website"); |
88 | } |
||
89 | |||
26 | daniel-mar | 90 | return $m[2]; |
2 | daniel-mar | 91 | } |
92 | |||
93 | protected function cbRun($optional_args=array()) { |
||
94 | $system_dir = $this->argSystemDir->getValue(); |
||
95 | if (empty($system_dir)) { |
||
96 | throw new Exception("Please specify the directory of the MediaWiki installation."); |
||
97 | } |
||
98 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
99 | |||
100 | if (!is_dir($system_dir)) { |
||
29 | daniel-mar | 101 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 102 | } |
103 | |||
104 | $version = $this->get_mediawiki_version($system_dir); |
||
105 | |||
106 | $latest_version = $this->get_latest_version(); |
||
107 | |||
57 | daniel-mar | 108 | if (version_compare($version,$latest_version) >= 0) { |
2 | daniel-mar | 109 | $this->setStatus(VNag::STATUS_OK); |
110 | $this->setHeadline("Version $version at $system_dir", true); |
||
111 | } else { |
||
112 | $this->setStatus(VNag::STATUS_WARNING); |
||
113 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
114 | } |
||
115 | } |
||
116 | } |