Subversion Repositories vnag

Rev

Rev 46 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 46 Rev 57
1
<?php /* <ViaThinkSoftSignature>
1
<?php /* <ViaThinkSoftSignature>
2
PIyn+/UQNjCJmoA9tMfbQbKrqegzwomG9GtkDY2OujjD+3Bq2SBPkIjcjngGB/ZMa
2
tCxWODVQjpp/mnpKKNqXZG1LyUti7FjIhQIkV0I7YHQb5pKovjP1jwQMLMrtdKt8j
3
rSGVqBRzE3pxHHFliBnOtJEeeqAXSz90E+qMRHu41+a3yhwP3ixOBo8qB/sKX1xCn
3
fQEvKt1KGkeUcZfnQ1nU/7rXZ62zVgioXw35IodxQahtohyXErvCCAQ2e4Kh5UKMD
4
H8Vz4nW+NytnkCHUpGmw5S2bgG8c3jIXiamGrgQXgmVNtxjOB1zlVikuafLt2Kx1P
4
R5sC13rlgK2EGHwLJbLt6yQL2jc6sDuV3QyT/ggNTsGtOjSsQXHCSu0XywMEabcO0
5
/j2v7d0G3vHyi+0If9AqxM0fx3lxftBlTgv9WpFGx01ep/MoS0wXcvSFcrWtN/eg4
5
ESELIgGC9w4T7nPbXFKx8c49j1ZFfJZeqFVnSpVXxj59Qpn1WS07fRndrC3hzFlX7
6
5XlTZbqnF4pYnUhRq1/wfMjuhjvprRHoEd+HrAQqcOvo+Bi2bbh5F+z2VFg5USv1M
6
ds3q9Db/k74qPhzmvx9dZFFXLLhnP0l7GLVkmSBLiyO/wl7WBjIklL+ZTfFiyLMqb
7
IaC0kCFZs7/09gP5MjoLBxYzbcq0ItA+YdSpIdpTkBTP01ZvkN84jli5JaiGwkU5x
7
B14YZfULwH2z/Y226IrcTt+fiz3muuNjLeIirfhlvv54pTn3a/8C0yp0qNGaINghX
8
EWTaJwP1zHsjhrJzP+7drjjykdzoPs4b4hnjh1FRJ5U9KKMbDsLQrfmm6hb3XJ5Ic
8
LlWUxm7Jw0O5vLl991LHstIqZEr6uacFNF3pCyrHRTBuvUpB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B/20fYnb0B+dEf4STeGOojsQ9Y62
17
zsqFxmlnDSKbHO2Xo972yUJbvg8JrxpYAvuNVuxpBlsiSEx6Jn8HP+yzwbP6DGGqB
17
+LwkLd4Qm9etkXElZMsP9lY9C3pTzDb7HBGvRgqgI3B5BOXV1SuBOEsdHKO2q+eQK
18
EsoFqI6oKTiEYo6amqmOcLFX8GjXR0DEb0tK4IIf73uN1ymPpM2AW3Z9h4f6SprmG
18
2oB9f6ILFjiY927T7E8qFjAEpwLyKs6NgEvmhcIJzpWl8MdW/N68BN18h3DErrj6F
19
osKy0Lq0ASujUZJ0gZf2KVYlgpBrv8+kxss4LrEJutuHK+FKrOWCVYNEnrZ1GVPFP
19
FNOAQmncJioW66h5vkBukmw/Gxwmq4LhKyBrFH0GsJ4kJ46jtsVqQgWyClTODlcyl
20
7DxMolfnil8VVrBBFCs4gROiL9YcQSABt8x5Ol53mU/EmWx1KypCSml8J6nh4U87D
20
KNlxvUVaqneVyEQJ57+QXrfZx0p3cOT8UiZD6TsngfXa4vu82ZDQi7p25LMwd0xfn
21
rKYbwwne9eaZURG0uzy0dOGS78+kSZwQPNgKmIsKT9VnJXQWG9MhA1UZlazsfnDGb
21
ToWOh0AdSXLS9QtL1dK3X7dJrwLSeFuVFTIGdvn5WuOmgon4QndNpYBxE9L2BJUL7
22
5oGdaHQPbJlYtJJmLg/RPw/BT9XzXIluF0VWosZ2zJWRijvnxaCO09nVeYwyPwj5f
22
/kGYskQXghIAE2vr7oQGNSeEPGb7WAKb4+LMd6jpvVMDIK26tnL+eXz2TURMyE037
23
g==
23
A==
24
</ViaThinkSoftSignature> */ ?>
24
</ViaThinkSoftSignature> */ ?>
25
<?php
25
<?php
26
 
26
 
27
/*
27
/*
28
 * VNag - Nagios Framework for PHP
28
 * VNag - Nagios Framework for PHP
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
30
 * Licensed under the terms of the Apache 2.0 license
30
 * Licensed under the terms of the Apache 2.0 license
31
 *
31
 *
32
 * Revision 2022-02-02
32
 * Revision 2022-09-12
33
 */
33
 */
34
 
34
 
35
declare(ticks=1);
35
declare(ticks=1);
36
 
36
 
37
class MediaWikiVersionCheck extends VNag {
37
class MediaWikiVersionCheck extends VNag {
38
        protected $argSystemDir = null;
38
        protected $argSystemDir = null;
39
 
39
 
40
        public function __construct() {
40
        public function __construct() {
41
                parent::__construct();
41
                parent::__construct();
42
 
42
 
43
                $this->registerExpectedStandardArguments('Vht');
43
                $this->registerExpectedStandardArguments('Vht');
44
 
44
 
45
                $this->getHelpManager()->setPluginName('check_mediawiki_version');
45
                $this->getHelpManager()->setPluginName('check_mediawiki_version');
46
                $this->getHelpManager()->setVersion('1.0');
46
                $this->getHelpManager()->setVersion('1.0');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local MediaWiki system has the latest version installed.');
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.');
48
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
49
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
49
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
50
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
50
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
51
 
51
 
52
                // Individual (non-standard) arguments:
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.'));
53
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'mediawikiPath', 'The local directory where MediaWiki installation is located.'));
54
        }
54
        }
55
 
55
 
56
        protected function get_mediawiki_version($path) {
56
        protected function get_mediawiki_version($path) {
57
                $path = realpath($path) === false ? $path : realpath($path);
57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
58
 
59
                $c = @file_get_contents("$path/includes/Defines.php");
59
                $c = @file_get_contents("$path/includes/Defines.php");
60
                if (!preg_match('@define\\( \'MW_VERSION\', \'([0-9\\.]+)\' \\);@is', $c, $m)) {
60
                if (!preg_match('@define\\( \'MW_VERSION\', \'([0-9\\.]+)\' \\);@is', $c, $m)) {
61
                        $c = @file_get_contents("$path/includes/DefaultSettings.php");
61
                        $c = @file_get_contents("$path/includes/DefaultSettings.php");
62
                        if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $c, $m)) {
62
                        if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@is', $c, $m)) {
63
                                throw new Exception("Cannot find version information at $path");
63
                                throw new Exception("Cannot find version information at $path");
64
                        }
64
                        }
65
                }
65
                }
66
 
66
 
67
                return $m[1];
67
                return $m[1];
68
        }
68
        }
69
 
69
 
70
        protected function get_latest_version() {
70
        protected function get_latest_version() {
71
                $cont = @file_get_contents('https://www.mediawiki.org/wiki/Download/en');
71
                $cont = @file_get_contents('https://www.mediawiki.org/wiki/Download/en');
72
                if (!$cont) {
72
                if (!$cont) {
73
 
73
 
74
                        // The server replies to some older versions of PHP: 426 Upgrade Required
74
                        // The server replies to some older versions of PHP: 426 Upgrade Required
75
                        $ch = curl_init();
75
                        $ch = curl_init();
76
                        curl_setopt($ch, CURLOPT_URL, "https://www.mediawiki.org/wiki/Download/en");
76
                        curl_setopt($ch, CURLOPT_URL, "https://www.mediawiki.org/wiki/Download/en");
77
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
77
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
78
                        $cont = @curl_exec( $ch );
78
                        $cont = @curl_exec( $ch );
79
                        curl_close($ch);
79
                        curl_close($ch);
80
 
80
 
81
                        if (!$cont) {
81
                        if (!$cont) {
82
                                throw new Exception("Cannot access website with latest version");
82
                                throw new Exception("Cannot access website with latest version");
83
                        }
83
                        }
84
                }
84
                }
85
 
85
 
86
                if (!preg_match('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) {
86
                if (!preg_match('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) {
87
                        throw new Exception("Cannot find version information on the website");
87
                        throw new Exception("Cannot find version information on the website");
88
                }
88
                }
89
 
89
 
90
                return $m[2];
90
                return $m[2];
91
        }
91
        }
92
 
92
 
93
        protected function cbRun($optional_args=array()) {
93
        protected function cbRun($optional_args=array()) {
94
                $system_dir = $this->argSystemDir->getValue();
94
                $system_dir = $this->argSystemDir->getValue();
95
                if (empty($system_dir)) {
95
                if (empty($system_dir)) {
96
                        throw new Exception("Please specify the directory of the MediaWiki installation.");
96
                        throw new Exception("Please specify the directory of the MediaWiki installation.");
97
                }
97
                }
98
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
98
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
99
 
99
 
100
                if (!is_dir($system_dir)) {
100
                if (!is_dir($system_dir)) {
101
                        throw new Exception('Directory "'.$system_dir.'" not found.');
101
                        throw new Exception('Directory "'.$system_dir.'" not found.');
102
                }
102
                }
103
 
103
 
104
                $version = $this->get_mediawiki_version($system_dir);
104
                $version = $this->get_mediawiki_version($system_dir);
105
 
105
 
106
                $latest_version = $this->get_latest_version();
106
                $latest_version = $this->get_latest_version();
107
 
107
 
108
                if ($version == $latest_version) {
108
                if (version_compare($version,$latest_version) >= 0) {
109
                        $this->setStatus(VNag::STATUS_OK);
109
                        $this->setStatus(VNag::STATUS_OK);
110
                        $this->setHeadline("Version $version at $system_dir", true);
110
                        $this->setHeadline("Version $version at $system_dir", true);
111
                } else {
111
                } else {
112
                        $this->setStatus(VNag::STATUS_WARNING);
112
                        $this->setStatus(VNag::STATUS_WARNING);
113
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
113
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
114
                }
114
                }
115
        }
115
        }
116
}
116
}
117
 
117