Subversion Repositories vnag

Rev

Rev 4 | 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>
29 daniel-mar 2
URC5lyHF7B7Z/hCr2eAcYLDKai5MDWwA6NK9uL37gGSh0pfGDEss7/vvlTbfFJPDo
3
/4zYu0T4mgcqPs8kKgLRmT4A/Hn0BlQRcaG5MV2r+ypF37avL06BYfsed8DwxXOVM
4
ENZ4fTolmbKBGaQ+0BXGgkO9TnXnXP/A1LuOUZj6v0PGrnI6wfyJ8+a0de1lAvXZh
5
WxKqN4RcHkbqEQy71Ox5XCS6Wl8ZDp2/uPyoyh8FM1c/XJalnzVTaAkJwjsP3Vtqd
6
qVv7QURFmetfkOqqvtNm4N5XGlNhd2/M2QolAJNzjVL4ZLd4hNB2dGlxo7eNag/+r
7
100zpq3/ZVJ65YKMfDXAAteHS/k/ajHO6bmh171pVj2cq5NlBqIPm7zk3dIeHhu1f
8
WhW6tV6aZu7ChK9waZ1i9G2g4FStOLzQdRrV9rqOqLjfXB4hyfXP9SIwPn+sZ+VxU
9
x4+PW9QCZxc16JW6tyik9MFqjmwD5cttzoAwa/EKvuoxXeMz+aIsqXNxv8YfgCUXN
10
dyZwWUBb9UTbsVpEZTU8wXNhLwYzLGKuv9t/xWEGr/+bknaEwiMxhqzt9j9P+Blhx
11
vw+0V2z6NtX/VOJJ/kaJFPS+U0Zj0M96QB/EUPKzuxtU4MpqyyKxrv4d3rWoH+I2i
12
G5Q4TI58+8UNBKG/UZZz6adF0VZ8TwuRxDL07USEgqkIV96NAzTguVhBYRmn/OROU
13
qUnfB16vvDI0qXpT/tMuthHWQK/qDkxF6JiBRBGQGSl+a1SBW7peEc7yQvgs94Prn
14
eTuisoHyZ6o2UY8iYCulOTiYAjLd6Ob45O0ggu3U2Y8e+avoJc7vZ3ix4AzsFPtLZ
15
q1QTSLakzPD6yKwSnr6WHk72R/VlWo3nGF5I53e+32tyqN9bgMol6BxGu6fMx/nAZ
16
581nqLgqhI/+WstBmQYysVJXkt2rCowgrtU35ErZD9tKwWC7pBGwJrH2zF88y8nxz
17
YmtfL5zdHVU0tY2wStySbWPC77+RWLTRRiNmDmM4xAWiJ53VsKBQiXO+/Ee1XieL/
18
s1qGqyUp3ZhWgqZSur1X3MxFnzt50g+VZUJOIYL4/8Zxn/jxwa+SQDazvsnxCQQFC
19
9Q43pB304ik4Ps0BBmcUzOIGy3UIzWeWl8p2nLFCJ9UmGoQcwfCAc/1zWdoBnHyNM
20
n/0Ody4uqN0qzo9z9B52YJzrTApC2m0EcbpUVCwfWWV0e8UGhw1Y3rR0ovPOHU53g
21
wxGtDzQoFySXk2RgxVxWn5DIa8B4gH94aCbQ6C4Msew1iHkYINWp4TUfbyGQDQLNQ
22
1ICXmi0Zs3lXHQsjHt/uTb/rjftdUivbKo0V+1AnW/jo7fzegS6Vv5+3A8TdBaa6d
23
w==
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
 *
32
 * Revision 2018-07-15
33
 */
34
 
35
// TODO: Should we also warn if a newer major version is released?
36
 
37
declare(ticks=1);
38
 
39
class PhpBbVersionCheck extends VNag {
40
        protected $argSystemDir = null;
41
 
42
        public function __construct() {
43
                parent::__construct();
44
 
45
                $this->registerExpectedStandardArguments('Vvht');
46
 
47
                $this->getHelpManager()->setPluginName('check_phpbb_version');
48
                $this->getHelpManager()->setVersion('1.0');
49
                $this->getHelpManager()->setShortDescription('This plugin checks if a local phpBB system has the latest version installed.');
50
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
51
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
52
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
53
 
54
                // Individual (non-standard) arguments:
55
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'phpBBPath', 'The local directory where your phpBB installation is located.'));
56
        }
57
 
58
        protected function get_phpbb_version($path) {
59
                $path = realpath($path) === false ? $path : realpath($path);
60
 
61
                // Version 3 support
62
                $cont = @file_get_contents("$path/includes/constants.php");
63
                preg_match("@define\('PHPBB_VERSION', '(.*)'\);@ismU", $cont, $m);
64
 
65
                if (isset($m[1])) {
66
                        return $m[1];
67
                } else {
68
                        // Version 2 support
69
                        $cont = @file_get_contents("$path/docs/INSTALL.html");
70
                        preg_match("@phpBB-(.*)_to_(.*)\.(zip|patch|tar)@ismU", $cont, $m);
71
 
72
                        if (isset($m[2])) {
73
                                return $m[2];
74
                        } else {
75
                                return false;
76
                        }
77
                }
78
        }
79
 
80
        protected function isVersionCurrentStable($json, $version) {
81
                foreach ($json['stable'] as $major => $data) {
82
                        if ($data['current'] == $version) return true;
83
                }
84
                return false;
85
        }
86
 
87
        protected function isVersionCurrentUnstable($json, $version) {
88
                foreach ($json['unstable'] as $major => $data) {
89
                        if ($data['current'] == $version) return true;
90
                }
91
                return false;
92
        }
93
 
94
        protected function cbRun($optional_args=array()) {
95
                $system_dir = $this->argSystemDir->getValue();
96
                if (empty($system_dir)) {
97
                        throw new Exception("Please specify the directory of the phpBB installation.");
98
                }
99
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
100
 
101
                if (!is_dir($system_dir)) {
29 daniel-mar 102
                        throw new Exception('Directory "'.$system_dir.'" not found.');
2 daniel-mar 103
                }
104
 
105
                // 1. Checking the main system
106
 
107
                // See also the original version checking code at "phpbb/version_helper.php"
108
                // More information about the JSON structure: https://area51.phpbb.com/docs/dev/extensions/tutorial_advanced.html#extension-version-checking
109
                // (Note: We should check regularly if the fields 'eol' and 'security' will be officially implemented/described)
110
                $versionCheckUrl = "https://version.phpbb.com/phpbb/versions.json";
111
                $cont = @file_get_contents($versionCheckUrl);
112
                if ($cont === false) {
113
                        throw new Exception('Could not determinate latest phpBB version');
114
                }
115
                $json = @json_decode($cont,true);
116
                if ($json === false) {
117
                        throw new Exception('Could not determinate latest phpBB version');
118
                }
119
 
120
                $version = $this->get_phpbb_version($system_dir);
121
 
122
                if ($version === false) {
29 daniel-mar 123
                        throw new Exception('Could not determinate current phpBB version in "'.$system_dir.'".');
2 daniel-mar 124
                }
125
 
126
                if ($this->isVersionCurrentStable($json, $version)) {
127
                        $this->setStatus(VNag::STATUS_OK);
128
                        $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
129
                } else if ($this->isVersionCurrentUnstable($json, $version)) {
130
                        $this->setStatus(VNag::STATUS_OK);
131
                        $this->setHeadline("Version $version (Latest Unstable version) at $system_dir", true);
132
                } else {
133
                        $this->setStatus(VNag::STATUS_WARNING);
134
                        $this->setHeadline("Version $version (Old version!) at $system_dir", true);
135
                }
136
 
137
                // 2. Checking extensions
138
 
139
                $total_extensions = 0;
140
                $unknown_extensions = 0;
141
                $old_extensions = 0;
142
                $current_extensions = 0;
143
                $check_errors = 0;
144
 
145
                $ext_json_files = glob($system_dir.'/ext/*/*/composer.json');
146
                foreach ($ext_json_files as $ext_json_file) {
147
                        $ext_json_client = json_decode(file_get_contents($ext_json_file),true);
148
                        $extname = $ext_json_client['name'];
149
                        $version = $ext_json_client['version'];
150
                        $total_extensions++;
151
                        if (isset($ext_json_client['extra']) && isset($ext_json_client['extra']['version-check'])) {
152
                                if (!isset($ext_json_client['extra']['version-check']['ssl'])) $ext_json_client['extra']['version-check']['ssl'] = false;
153
                                $versionCheckUrl  = $ext_json_client['extra']['version-check']['ssl'] ? 'https://' : 'http://';
154
                                $versionCheckUrl .= $ext_json_client['extra']['version-check']['host'];
155
                                $versionCheckUrl .= $ext_json_client['extra']['version-check']['directory'].'/';
156
                                $versionCheckUrl .= $ext_json_client['extra']['version-check']['filename'];
157
                                $cont = @file_get_contents($versionCheckUrl);
158
                                if ($cont === false) {
159
                                        $this->setStatus(VNag::STATUS_WARNING);
160
                                        $this->addVerboseMessage("Extension $extname : Cannot reach update-server (Version $version)!", VNag::VERBOSITY_SUMMARY);
161
                                        $check_errors++;
162
                                        continue;
163
                                }
164
                                $json = @json_decode($cont,true);
165
                                if ($json === false) {
166
                                        $this->setStatus(VNag::STATUS_WARNING);
167
                                        $this->addVerboseMessage("Extension $extname : Cannot reach update-server (Version $version)!", VNag::VERBOSITY_SUMMARY);
168
                                        $check_errors++;
169
                                        continue;
170
                                }
171
 
172
                                if ($this->isVersionCurrentStable($json, $version)) {
173
                                        $this->setStatus(VNag::STATUS_OK);
174
                                        $this->addVerboseMessage("Extension $extname : Version $version is latest stable.", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
175
                                        $current_extensions++;
176
                                } else if ($this->isVersionCurrentUnstable($json, $version)) {
177
                                        $this->setStatus(VNag::STATUS_OK);
178
                                        $this->addVerboseMessage("Extension $extname : Version $version is latest unstable.", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
179
                                        $current_extensions++;
180
                                } else {
181
                                        $this->setStatus(VNag::STATUS_WARNING);
182
                                        $this->addVerboseMessage("Extension $extname : Version $version is outdated!", VNag::VERBOSITY_SUMMARY);
183
                                        $old_extensions++;
184
                                }
185
                        } else {
186
                                $this->addVerboseMessage("Extension $extname (version $version) does not have any update server information.", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
187
                                $unknown_extensions++;
188
                        }
189
                }
190
 
191
                if ($old_extensions > 0) {
192
                        $this->setHeadline("$old_extensions extensions require an update", true);
193
                }
194
                if ($check_errors > 0) {
195
                        $this->setHeadline("$old_extensions extensions can't be checked (update server error)", true);
196
                }
197
                $this->addVerboseMessage("$total_extensions extensions total, $current_extensions up-to-date, $old_extensions outdated, $unknown_extensions without update information, $check_errors update server errors", VNag::VERBOSITY_SUMMARY);
198
        }
199
}