Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature>TvlSnBB9oFkMG8t23W8SFnhWVFc86YGpHfet/Nbgyd080A7CHl5DO+RWvS7H19uskpIrRBrXZYgt5c1gawuV/u0sH0F+7gJNIGcjO3kaqWzXeaceO4pvNjjPJwLShLq+FbE9kyw08XxHYYHkoJhtxnRiqaEEq4zmQ8U7S+JOnCHhP6cL3eP8/iY0jVFonPpwIcpIKHEd9p5/t5ZIFW02HCSB+wRT+jSXHe9TGieS9Yc7cODueJ80J3Jkh/EDbTOlgiOkgCROGf5zWqZUGaogvaLHk6WmO/XNyP1zUFj0lvNFfK4rhqbSy1Oa6UX+ZlVmpHAXLIR3nrpdFyYR2/zj0wXd21MpG5sN7zGgW98IpvJVSkb9eqsRr7IzmKkGvaEQ55lNYxYVgOQLOo+D9d5qb3V9stJ1R7h+VAN5uouMAd3Kj2uGp1QTUoxzy/cp1UU2ub9zQ8Q4WOvnm0TVaoyFnpptfXvRMIHbfaB4wshglKwnDvzPtQnlsJfq2R9lZ6zqvgEuIEnJtfpk6FOjCCIYR55IO1UVVryBqBWHtRBT2Y3Z0Tg5A1kuqwVcsw0d3rHRrjyhMu70DyMr4aHs1HE042coo4uYfkhmlETSNQgNntKyKcgdon/kOqxxhlc3NGopO5JVR5wBgYmX3tBYJ5OcFEzXgD4mmaF+2MG/K80sxh8t3jg+XCD7oq9dZTAAthWc7ojuWNb3a91uw6gb2lfogiCBSyCyMVRdakeA3gWZ/7zYhzWshW1sU+vegpIkTUt9Atq17k9i6WDI8wNctTvx3ItmTencuUNXmfGyrFC4iUkHlYJy8JnuC4da568M+AX9kxr/qgtsC4yhjRj+ZuEeZgVqBmYt3OIDMgdzK97+e45c0ixe4AAutbAvY00W3NiKOVe/cvYlefCxX0NjBqQ/+1gh4vhsf9Hew5TMIvlvgAVGNwGt4mQfNjcVjXk/QJb52EZ/EsKJbkBqeQqg7jrkgxH3aDhAnCKDVhjBBThQJanjAeCte/EEU3I3jnkYEktBEG6aVcYLPwC+b7joc+KMB23YhlGPfTr1dalKGp+rBLEcZQtIRPRHgsxmWpQbRqjJ6YiEhdB7RafpoN+aalxr8t1BRXiBFvOHSi/UZsRyiMjopKTMHTKuwV+TgWkgatr5oMhUYjF25bHLep2vjHBOLBcLbkvofUMYcC5SzwaT1QbzHmkPNRDMB9X5ghXgCStXGwFnbGZud+GfSnKvpBceAOxpuBgY8qVQipDeuTN0nKEkmjRyIXjsHtcBvJiYk6+7v32xC/QSXP5zdu+1bDQXqx1O1uRtC49kgX259WivMmv/TXaPc/9LMevM1eZIJ0QnMZ3lJFNCmdYr9GTklIIlDg==</ViaThinkSoftSignature> */ ?> |
2 | <?php |
||
3 | |||
4 | /* |
||
5 | * VNag - Nagios Framework for PHP |
||
6 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
7 | * Licensed under the terms of the Apache 2.0 license |
||
8 | * |
||
9 | * Revision 2018-07-15 |
||
10 | */ |
||
11 | |||
12 | declare(ticks=1); |
||
13 | |||
14 | class MediaWikiVersionCheck extends VNag { |
||
15 | protected $argSystemDir = null; |
||
16 | |||
17 | public function __construct() { |
||
18 | parent::__construct(); |
||
19 | |||
20 | $this->registerExpectedStandardArguments('Vht'); |
||
21 | |||
22 | $this->getHelpManager()->setPluginName('check_mediawiki_version'); |
||
23 | $this->getHelpManager()->setVersion('1.0'); |
||
24 | $this->getHelpManager()->setShortDescription('This plugin checks if a local MediaWiki system has the latest version installed.'); |
||
25 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
26 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
||
27 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
28 | |||
29 | // Individual (non-standard) arguments: |
||
30 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'mediawikiPath', 'The local directory where MediaWiki installation is located.')); |
||
31 | } |
||
32 | |||
33 | protected function get_mediawiki_version($path) { |
||
34 | $path = realpath($path) === false ? $path : realpath($path); |
||
35 | |||
36 | $c = @file_get_contents("$path/includes/DefaultSettings.php"); |
||
37 | |||
38 | if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $c, $m)) { |
||
39 | throw new Exception("Cannot find version information at $path"); |
||
40 | } |
||
41 | |||
42 | return $m[1]; |
||
43 | } |
||
44 | |||
45 | protected function get_latest_version() { |
||
46 | $cont = @file_get_contents('https://www.mediawiki.org/wiki/MediaWiki'); |
||
47 | if (!$cont) { |
||
48 | throw new Exception("Cannot access website with latest version"); |
||
49 | } |
||
50 | |||
51 | if (!preg_match('@/Release notes/([^"]+)">@ismU', $cont, $m)) { |
||
52 | throw new Exception("Cannot find version information on the website"); |
||
53 | } |
||
54 | |||
55 | return $m[1]; |
||
56 | } |
||
57 | |||
58 | protected function cbRun($optional_args=array()) { |
||
59 | $system_dir = $this->argSystemDir->getValue(); |
||
60 | if (empty($system_dir)) { |
||
61 | throw new Exception("Please specify the directory of the MediaWiki installation."); |
||
62 | } |
||
63 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
64 | |||
65 | if (!is_dir($system_dir)) { |
||
66 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
67 | } |
||
68 | |||
69 | $version = $this->get_mediawiki_version($system_dir); |
||
70 | |||
71 | $latest_version = $this->get_latest_version(); |
||
72 | |||
73 | if ($version == $latest_version) { |
||
74 | $this->setStatus(VNag::STATUS_OK); |
||
75 | $this->setHeadline("Version $version at $system_dir", true); |
||
76 | } else { |
||
77 | $this->setStatus(VNag::STATUS_WARNING); |
||
78 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
79 | } |
||
80 | } |
||
81 | } |