Rev 41 | 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> |
46 | daniel-mar | 2 | PIyn+/UQNjCJmoA9tMfbQbKrqegzwomG9GtkDY2OujjD+3Bq2SBPkIjcjngGB/ZMa |
3 | rSGVqBRzE3pxHHFliBnOtJEeeqAXSz90E+qMRHu41+a3yhwP3ixOBo8qB/sKX1xCn |
||
4 | H8Vz4nW+NytnkCHUpGmw5S2bgG8c3jIXiamGrgQXgmVNtxjOB1zlVikuafLt2Kx1P |
||
5 | /j2v7d0G3vHyi+0If9AqxM0fx3lxftBlTgv9WpFGx01ep/MoS0wXcvSFcrWtN/eg4 |
||
6 | 5XlTZbqnF4pYnUhRq1/wfMjuhjvprRHoEd+HrAQqcOvo+Bi2bbh5F+z2VFg5USv1M |
||
7 | IaC0kCFZs7/09gP5MjoLBxYzbcq0ItA+YdSpIdpTkBTP01ZvkN84jli5JaiGwkU5x |
||
8 | EWTaJwP1zHsjhrJzP+7drjjykdzoPs4b4hnjh1FRJ5U9KKMbDsLQrfmm6hb3XJ5Ic |
||
9 | W7dea7o00FYMxUUuse0jhZdpHcdTtO7ivLBFs0Fzhquff1BubBA8zUJvyj3kUs4+X |
||
10 | bUKmvsi+i3TDz1jUaAtPd6moEqDnIxVd7kuG40KjlPaIjLx4L0zshr1pSrUYv4o55 |
||
11 | /7cycdN4wdY5S/DnMRk6d/O/4fWrUoY2Vh76gUlHD9g/uz8c62a1OTwiHA152HrjP |
||
12 | 4p6U9PwBu0u4h4IhNwnHPPXaanVt0o1wgvz2O98AiuNcusur4QBE9AgVCgoa+hi5Q |
||
13 | FmK4/Ik9UqZ+zgKMz43QCiIyoQHnmvwBCQQDH+KRHgc1BR8nXQPD04YdLHd6Gp7av |
||
14 | cnrdE3v/YvHQUHVwEFfkC0TUO/C4t/aStQPTnat2W68GGf1szh8YV5d9eZ/VUA7zY |
||
15 | HxIHOt8YH7aP7D1OvN7hoxHxwtxW0oWJownfKxgbXNkv3sJb+pMgGlYrNwm3uZ9Qd |
||
16 | d+LPQcL4wMi6HGwRrWJGg+P57RqYeJT2B8lhubFrsCNNmJn7KtSuVfoh57JqMqOjN |
||
17 | zsqFxmlnDSKbHO2Xo972yUJbvg8JrxpYAvuNVuxpBlsiSEx6Jn8HP+yzwbP6DGGqB |
||
18 | EsoFqI6oKTiEYo6amqmOcLFX8GjXR0DEb0tK4IIf73uN1ymPpM2AW3Z9h4f6SprmG |
||
19 | osKy0Lq0ASujUZJ0gZf2KVYlgpBrv8+kxss4LrEJutuHK+FKrOWCVYNEnrZ1GVPFP |
||
20 | 7DxMolfnil8VVrBBFCs4gROiL9YcQSABt8x5Ol53mU/EmWx1KypCSml8J6nh4U87D |
||
21 | rKYbwwne9eaZURG0uzy0dOGS78+kSZwQPNgKmIsKT9VnJXQWG9MhA1UZlazsfnDGb |
||
22 | 5oGdaHQPbJlYtJJmLg/RPw/BT9XzXIluF0VWosZ2zJWRijvnxaCO09nVeYwyPwj5f |
||
41 | daniel-mar | 23 | g== |
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 | * |
||
46 | daniel-mar | 32 | * Revision 2022-02-02 |
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 | |||
108 | if ($version == $latest_version) { |
||
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 | } |