Rev 2 | 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> |
2 | XTWdCCK0FEM0wejpeajPPdpwhBNotRfIAK4cUBRtt32pcQoxsNdP1sU8Zw38IEq2B |
||
3 | P1pK8ELVVyb20dUZGQouY42DJQaTE0RRDGSfKZVxsYWAdLyiRc1gWPVsj3fHFJHJO |
||
4 | jey16hbqsdiKLpwT8fHgqaCz0y87oeksLQOmGw1VXfbQECYz3XU1JGie+Mxbx/dZN |
||
5 | gMb3l3juVwrs9veDBU2Q0HyeVAsV1xebfm+AfKngIV0dBEFW+kkBAcFuwzfaLIlhT |
||
6 | C5Vt1mvs7ZVbrgFxybkTuPV0J7aHwqt9qrRUiJLCOT6Vd2JuMQisCjVecjKD6XSNq |
||
7 | 2+ZQ/YOuzuQ8HtPm3zKZeyk+PjQ+LqcoRY0i8MEXyxkHwZbBIgwko00Nw9hzSbtE0 |
||
8 | iQfDi/KtAYBr8bb3U8ufMgbRWWf3ayrDOAJ2wNVgt6CqZACtPncvdpEc0fTAMm5n7 |
||
9 | oinbC81zCpOCza9+Wka1Rl3w6forL9vezAG10K+9tn7PyUFKTxJKEUY2agFtumywK |
||
10 | Dh2tLoODZyZ8mNF3/pUeCgZFzoYgRvdRHBqc4E3Bnqb3ffB1JSaHl0FizufFv1UdH |
||
11 | rG0EYXL7VARPHjDAXNi9EiPsudZP3XREcQpDSk01zqajMrA4s7PphLKigGcvW9nw5 |
||
12 | BTlo8i10RWzQcSsIqQNP7wibr5TZUrkSVjRZZNOOXepdGiAHapKn9h2tTcYbQb8yG |
||
13 | 5j4bGTzFQsD/9wJql+acM/sdwDR3Gn/j0765eioW3DUCp0QeTmHewerq85aL+T+GJ |
||
14 | A3cjFkk1yemgOVI9QlDFBrCe1iYnep+XxuN8vEDM/AXy1e122FCDAHACWFTE6qrbD |
||
15 | SF5Gr92vMoQKyKtTTDJRDjrAIkPtQzSSHeyHUqKAFN2xapEiyq6rbuSQvbBnQPp+z |
||
16 | DPkJUTV55U84JpRWmVEDe2TdUJcrJKRRGGY0kXZk75M+9L3UUDJljSzTemvMSD/kL |
||
17 | Fz0tGFHLzLguUZFlKMMQwsV/+WqQ13jl9FO8r7zmEG+9f3S2kqhQEyF+ZjmqBeSh5 |
||
18 | vb6zOzQ5ZSyPMdVcdYtOnPhKAARA3/oj9T9IB0Ybji4bYs7u2cD00yxHJ/f9yR5CR |
||
19 | Y6T6CJHuY6qduzacD6t8wrigfLQtv2/K27hpdoTOQi6oqPCy1zbF9UY6N4JpBVHns |
||
20 | MDv7akwPTMNTB0tuYTIHH8rcQudrJfqXUXquTgL35k8KaB+IGtGlrGq0w9OtCA199 |
||
21 | or1heFAvPzi6lGkjF5rftF/V4HpO4JZQ2lKY41Z2ZXGK75oryv2DL79h4cvdFdhR7 |
||
22 | O88AHlwlcodGTMfaKa2o51scaVjjDirWe4lZb0uXXLHDr19dDeajObnBFnukl1FGa |
||
23 | Q== |
||
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)) { |
||
102 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
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) { |
||
123 | throw new Exception('Could not determinate current phpBB version in "'.$system_dir.'".', false); |
||
124 | return false; |
||
125 | } |
||
126 | |||
127 | if ($this->isVersionCurrentStable($json, $version)) { |
||
128 | $this->setStatus(VNag::STATUS_OK); |
||
129 | $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true); |
||
130 | } else if ($this->isVersionCurrentUnstable($json, $version)) { |
||
131 | $this->setStatus(VNag::STATUS_OK); |
||
132 | $this->setHeadline("Version $version (Latest Unstable version) at $system_dir", true); |
||
133 | } else { |
||
134 | $this->setStatus(VNag::STATUS_WARNING); |
||
135 | $this->setHeadline("Version $version (Old version!) at $system_dir", true); |
||
136 | } |
||
137 | |||
138 | // 2. Checking extensions |
||
139 | |||
140 | $total_extensions = 0; |
||
141 | $unknown_extensions = 0; |
||
142 | $old_extensions = 0; |
||
143 | $current_extensions = 0; |
||
144 | $check_errors = 0; |
||
145 | |||
146 | $ext_json_files = glob($system_dir.'/ext/*/*/composer.json'); |
||
147 | foreach ($ext_json_files as $ext_json_file) { |
||
148 | $ext_json_client = json_decode(file_get_contents($ext_json_file),true); |
||
149 | $extname = $ext_json_client['name']; |
||
150 | $version = $ext_json_client['version']; |
||
151 | $total_extensions++; |
||
152 | if (isset($ext_json_client['extra']) && isset($ext_json_client['extra']['version-check'])) { |
||
153 | if (!isset($ext_json_client['extra']['version-check']['ssl'])) $ext_json_client['extra']['version-check']['ssl'] = false; |
||
154 | $versionCheckUrl = $ext_json_client['extra']['version-check']['ssl'] ? 'https://' : 'http://'; |
||
155 | $versionCheckUrl .= $ext_json_client['extra']['version-check']['host']; |
||
156 | $versionCheckUrl .= $ext_json_client['extra']['version-check']['directory'].'/'; |
||
157 | $versionCheckUrl .= $ext_json_client['extra']['version-check']['filename']; |
||
158 | $cont = @file_get_contents($versionCheckUrl); |
||
159 | if ($cont === false) { |
||
160 | $this->setStatus(VNag::STATUS_WARNING); |
||
161 | $this->addVerboseMessage("Extension $extname : Cannot reach update-server (Version $version)!", VNag::VERBOSITY_SUMMARY); |
||
162 | $check_errors++; |
||
163 | continue; |
||
164 | } |
||
165 | $json = @json_decode($cont,true); |
||
166 | if ($json === false) { |
||
167 | $this->setStatus(VNag::STATUS_WARNING); |
||
168 | $this->addVerboseMessage("Extension $extname : Cannot reach update-server (Version $version)!", VNag::VERBOSITY_SUMMARY); |
||
169 | $check_errors++; |
||
170 | continue; |
||
171 | } |
||
172 | |||
173 | if ($this->isVersionCurrentStable($json, $version)) { |
||
174 | $this->setStatus(VNag::STATUS_OK); |
||
175 | $this->addVerboseMessage("Extension $extname : Version $version is latest stable.", VNag::VERBOSITY_ADDITIONAL_INFORMATION); |
||
176 | $current_extensions++; |
||
177 | } else if ($this->isVersionCurrentUnstable($json, $version)) { |
||
178 | $this->setStatus(VNag::STATUS_OK); |
||
179 | $this->addVerboseMessage("Extension $extname : Version $version is latest unstable.", VNag::VERBOSITY_ADDITIONAL_INFORMATION); |
||
180 | $current_extensions++; |
||
181 | } else { |
||
182 | $this->setStatus(VNag::STATUS_WARNING); |
||
183 | $this->addVerboseMessage("Extension $extname : Version $version is outdated!", VNag::VERBOSITY_SUMMARY); |
||
184 | $old_extensions++; |
||
185 | } |
||
186 | } else { |
||
187 | $this->addVerboseMessage("Extension $extname (version $version) does not have any update server information.", VNag::VERBOSITY_ADDITIONAL_INFORMATION); |
||
188 | $unknown_extensions++; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | if ($old_extensions > 0) { |
||
193 | $this->setHeadline("$old_extensions extensions require an update", true); |
||
194 | } |
||
195 | if ($check_errors > 0) { |
||
196 | $this->setHeadline("$old_extensions extensions can't be checked (update server error)", true); |
||
197 | } |
||
198 | $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); |
||
199 | } |
||
200 | } |