Rev 1061 | Rev 1116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
1086 | daniel-mar | 5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
635 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
635 | daniel-mar | 21 | |
1086 | daniel-mar | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
||
24 | // phpcs:enable PSR1.Files.SideEffects |
||
25 | |||
635 | daniel-mar | 26 | class OIDplusPageAdminSoftwareUpdate extends OIDplusPagePluginAdmin { |
27 | |||
28 | public function init($html=true) { |
||
29 | } |
||
30 | |||
697 | daniel-mar | 31 | private function getGitCommand() { |
698 | daniel-mar | 32 | return 'git --git-dir='.escapeshellarg(OIDplus::findGitFolder().'/').' --work-tree='.escapeshellarg(OIDplus::localpath()).' -C "" pull origin master -s recursive -X theirs'; |
697 | daniel-mar | 33 | } |
34 | |||
35 | private function getSvnCommand() { |
||
36 | return 'svn update --accept theirs-full'; |
||
37 | } |
||
38 | |||
635 | daniel-mar | 39 | public function action($actionID, $params) { |
40 | if ($actionID == 'update_now') { |
||
647 | daniel-mar | 41 | @set_time_limit(0); |
635 | daniel-mar | 42 | |
43 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
44 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
||
45 | } |
||
46 | |||
662 | daniel-mar | 47 | if (OIDplus::getInstallType() === 'git-wc') { |
697 | daniel-mar | 48 | $cmd = $this->getGitCommand().' 2>&1'; |
662 | daniel-mar | 49 | |
50 | $ec = -1; |
||
51 | $out = array(); |
||
52 | exec($cmd, $out, $ec); |
||
53 | |||
54 | $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out)); |
||
55 | if ($ec === 0) { |
||
56 | $rev = 'HEAD'; // do not translate |
||
57 | return array("status" => 0, "content" => $res, "rev" => $rev); |
||
58 | } else { |
||
59 | return array("status" => -1, "error" => $res, "content" => ""); |
||
60 | } |
||
653 | daniel-mar | 61 | } |
662 | daniel-mar | 62 | else if (OIDplus::getInstallType() === 'svn-wc') { |
697 | daniel-mar | 63 | $cmd = $this->getSvnCommand().' 2>&1'; |
653 | daniel-mar | 64 | |
662 | daniel-mar | 65 | $ec = -1; |
66 | $out = array(); |
||
67 | exec($cmd, $out, $ec); |
||
635 | daniel-mar | 68 | |
662 | daniel-mar | 69 | $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out)); |
70 | if ($ec === 0) { |
||
71 | $rev = 'HEAD'; // do not translate |
||
72 | return array("status" => 0, "content" => $res, "rev" => $rev); |
||
73 | } else { |
||
74 | return array("status" => -1, "error" => $res, "content" => ""); |
||
75 | } |
||
650 | daniel-mar | 76 | } |
662 | daniel-mar | 77 | else if (OIDplus::getInstallType() === 'svn-snapshot') { |
635 | daniel-mar | 78 | |
662 | daniel-mar | 79 | $rev = $params['rev']; |
650 | daniel-mar | 80 | |
807 | daniel-mar | 81 | $update_version = isset($params['update_version']) ? $params['update_version'] : 1; |
82 | if (($update_version != 1) && ($update_version != 2)) { |
||
83 | throw new OIDplusException(_L('Unknown update version')); |
||
84 | } |
||
85 | |||
662 | daniel-mar | 86 | // Download and unzip |
651 | daniel-mar | 87 | |
716 | daniel-mar | 88 | $cont = false; |
89 | for ($retry=1; $retry<=3; $retry++) { |
||
90 | if (function_exists('gzdecode')) { |
||
91 | $url = sprintf(OIDplus::getEditionInfo()['update_package_gz'], $rev-1, $rev); |
||
92 | $cont = url_get_contents($url); |
||
93 | if ($cont !== false) $cont = @gzdecode($cont); |
||
94 | } else { |
||
95 | $url = sprintf(OIDplus::getEditionInfo()['update_package'], $rev-1, $rev); |
||
96 | $cont = url_get_contents($url); |
||
97 | } |
||
98 | if ($cont !== false) { |
||
99 | break; |
||
100 | } else { |
||
101 | sleep(1); |
||
102 | } |
||
651 | daniel-mar | 103 | } |
662 | daniel-mar | 104 | if ($cont === false) throw new OIDplusException(_L("Update %1 could not be downloaded from ViaThinkSoft server. Please try again later.",$rev)); |
651 | daniel-mar | 105 | |
662 | daniel-mar | 106 | // Check signature... |
107 | |||
108 | if (function_exists('openssl_verify')) { |
||
109 | |||
110 | $m = array(); |
||
111 | if (!preg_match('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', $cont, $m)) { |
||
112 | throw new OIDplusException(_L("Update package file of revision %1 not digitally signed",$rev)); |
||
113 | } |
||
114 | $signature = base64_decode($m[1]); |
||
115 | |||
116 | $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont); |
||
117 | $hash = hash("sha256", $naked."update_".($rev-1)."_to_".($rev).".txt"); |
||
118 | |||
119 | $public_key = file_get_contents(__DIR__.'/public.pem'); |
||
120 | if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) { |
||
121 | throw new OIDplusException(_L("Update package file of revision %1: Signature invalid",$rev)); |
||
122 | } |
||
123 | |||
651 | daniel-mar | 124 | } |
125 | |||
662 | daniel-mar | 126 | // All OK! Now write file |
651 | daniel-mar | 127 | |
662 | daniel-mar | 128 | $tmp_filename = 'update_'.generateRandomString(10).'.tmp.php'; |
129 | $local_file = OIDplus::localpath().$tmp_filename; |
||
651 | daniel-mar | 130 | |
662 | daniel-mar | 131 | @file_put_contents($local_file, $cont); |
635 | daniel-mar | 132 | |
662 | daniel-mar | 133 | if (!file_exists($local_file) || (@file_get_contents($local_file) !== $cont)) { |
134 | throw new OIDplusException(_L('Update file could not written. Probably there are no write-permissions to the root folder.')); |
||
135 | } |
||
647 | daniel-mar | 136 | |
807 | daniel-mar | 137 | if ($update_version == 1) { |
138 | // Now call the written file |
||
139 | // Note: we may not use eval($cont) because the script uses die(), |
||
140 | // and things in the script might collide with currently (un)loaded source code files, shutdown procedues, etc. |
||
141 | $web_file = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE).$tmp_filename; // NOT canonical URL! This might fail with reverse proxies which can only be executed from outside |
||
142 | $res = url_get_contents($web_file); |
||
143 | if ($res === false) { |
||
144 | throw new OIDplusException(_L('Update-script %1 could not be executed',$web_file)); |
||
145 | } |
||
146 | return array("status" => 0, "content" => $res, "rev" => $rev); |
||
147 | } else if ($update_version == 2) { |
||
148 | // In this version, the client will call the web-update file. |
||
149 | // This has the advantage that it will also work if the system is htpasswd protected |
||
150 | return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev); |
||
662 | daniel-mar | 151 | } |
653 | daniel-mar | 152 | } |
662 | daniel-mar | 153 | else { |
716 | daniel-mar | 154 | throw new OIDplusException(_L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!')); |
662 | daniel-mar | 155 | } |
635 | daniel-mar | 156 | } |
157 | } |
||
158 | |||
159 | public function gui($id, &$out, &$handled) { |
||
160 | $parts = explode('.',$id,2); |
||
161 | if (!isset($parts[1])) $parts[1] = ''; |
||
162 | if ($parts[0] == 'oidplus:software_update') { |
||
163 | @set_time_limit(0); |
||
164 | |||
165 | $handled = true; |
||
166 | $out['title'] = _L('Software update'); |
||
801 | daniel-mar | 167 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 168 | |
169 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
800 | daniel-mar | 170 | $out['icon'] = 'img/error.png'; |
635 | daniel-mar | 171 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
172 | return; |
||
173 | } |
||
174 | |||
665 | daniel-mar | 175 | $out['text'] .= '<div id="update_versioninfo">'; |
176 | |||
635 | daniel-mar | 177 | $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>'; |
178 | |||
840 | daniel-mar | 179 | if (isset(OIDplus::getEditionInfo()['svnrepo']) && (OIDplus::getEditionInfo()['svnrepo'] != '')) { |
180 | $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co %1</code> and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['svnrepo']).'/trunk/'); |
||
181 | if (!str_starts_with(PHP_OS, 'WIN')) { |
||
182 | $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','svn update'); |
||
183 | } |
||
184 | $out['text'] .= '</p>'; |
||
699 | daniel-mar | 185 | } else { |
186 | $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','GIT').'</p>'; |
||
187 | } |
||
635 | daniel-mar | 188 | |
840 | daniel-mar | 189 | if (isset(OIDplus::getEditionInfo()['gitrepo']) && (OIDplus::getEditionInfo()['gitrepo'] != '')) { |
190 | $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Install OIDplus using the Git client in your SSH/Linux shell using the command <code>git clone %1</code> and update it regularly with the command <code>git pull</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['gitrepo'].'.git')); |
||
191 | if (!str_starts_with(PHP_OS, 'WIN')) { |
||
192 | $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','git pull'); |
||
193 | } |
||
194 | $out['text'] .= '</p>'; |
||
699 | daniel-mar | 195 | } else { |
196 | $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','SVN').'</p>'; |
||
197 | } |
||
635 | daniel-mar | 198 | |
699 | daniel-mar | 199 | if (isset(OIDplus::getEditionInfo()['downloadpage']) && (OIDplus::getEditionInfo()['downloadpage'] != '')) { |
200 | $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Install OIDplus by downloading a TAR.GZ file from %1, which contains an SVN snapshot, and extract it to your webspace. The TAR.GZ file contains a file named ".version.php" which contains the SVN revision of the snapshot. This update-tool will then try to update your files on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory. A change conflict detection is NOT implemented. It is required that the files on your webspace have create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.','<a href="'.OIDplus::getEditionInfo()['downloadpage'].'">'.parse_url(OIDplus::getEditionInfo()['downloadpage'])['host'].'</a>').'</p>'; |
||
201 | } else { |
||
202 | $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','Snapshot').'</p>'; |
||
203 | } |
||
635 | daniel-mar | 204 | |
699 | daniel-mar | 205 | |
635 | daniel-mar | 206 | $out['text'] .= '<hr>'; |
207 | |||
208 | $installType = OIDplus::getInstallType(); |
||
209 | |||
210 | if ($installType === 'ambigous') { |
||
906 | daniel-mar | 211 | $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!').'</font>'; |
665 | daniel-mar | 212 | $out['text'] .= '</div>'; |
635 | daniel-mar | 213 | } else if ($installType === 'unknown') { |
906 | daniel-mar | 214 | $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>'; |
665 | daniel-mar | 215 | $out['text'] .= '</div>'; |
662 | daniel-mar | 216 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc') || ($installType === 'svn-snapshot')) { |
635 | daniel-mar | 217 | if ($installType === 'svn-wc') { |
218 | $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>'; |
||
662 | daniel-mar | 219 | $requireInfo = _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension'); |
697 | daniel-mar | 220 | $updateCommand = $this->getSvnCommand(); |
662 | daniel-mar | 221 | } else if ($installType === 'git-wc') { |
635 | daniel-mar | 222 | $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>'; |
662 | daniel-mar | 223 | $requireInfo = _L('shell access with Git client'); |
697 | daniel-mar | 224 | $updateCommand = $this->getGitCommand(); |
662 | daniel-mar | 225 | } else if ($installType === 'svn-snapshot') { |
226 | $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with .version.php file).').'</p>'; |
||
227 | $requireInfo = ''; // unused |
||
228 | $updateCommand = ''; // unused |
||
635 | daniel-mar | 229 | } |
230 | |||
231 | $local_installation = OIDplus::getVersion(); |
||
648 | daniel-mar | 232 | $newest_version = $this->getLatestRevision(); |
635 | daniel-mar | 233 | |
234 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
||
662 | daniel-mar | 235 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br><br>'; |
635 | daniel-mar | 236 | |
237 | if (!$newest_version) { |
||
1061 | daniel-mar | 238 | if (!function_exists('curl_init')) { |
239 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl').'</font></p>'; |
||
240 | } else { |
||
241 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('Probably the ViaThinkSoft server could not be reached.').'</font></p>'; |
||
242 | } |
||
662 | daniel-mar | 243 | $out['text'] .= '</div>'; |
654 | daniel-mar | 244 | } else if (!$local_installation) { |
662 | daniel-mar | 245 | if ($installType === 'svn-snapshot') { |
246 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version.').'</font></p>'; |
||
247 | } else { |
||
248 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version. (Required: %1). Please update your system manually via the "%2" command regularly.',$requireInfo,$updateCommand).'</font></p>'; |
||
635 | daniel-mar | 249 | } |
647 | daniel-mar | 250 | $out['text'] .= '</div>'; |
997 | daniel-mar | 251 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
635 | daniel-mar | 252 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
647 | daniel-mar | 253 | $out['text'] .= '</div>'; |
635 | daniel-mar | 254 | } else { |
662 | daniel-mar | 255 | if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
256 | $out['text'] .= '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>'; |
||
257 | $out['text'] .= '<p>'._L('Alternatively, click this button to execute the command through the web-interface (command execution and write permissions required).').'</p>'; |
||
258 | } |
||
635 | daniel-mar | 259 | |
648 | daniel-mar | 260 | $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.((int)substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>'; |
635 | daniel-mar | 261 | |
662 | daniel-mar | 262 | // TODO: Open "system_file_check" without page reload. |
263 | // TODO: Only show link if the plugin is installed |
||
906 | daniel-mar | 264 | $out['text'] .= '<p><font color="red">'.mb_strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! (<a href="%1">Click here to check which files have been modified</a>) In case the update fails, you can download and extract the complete <a href="%s">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.','?goto='.urlencode('oidplus:system_file_check'),OIDplus::getEditionInfo()['downloadpage']).'</font></p>'; |
662 | daniel-mar | 265 | |
647 | daniel-mar | 266 | $out['text'] .= '</div>'; |
267 | |||
662 | daniel-mar | 268 | $out['text'] .= $this->showPreview($local_installation, $newest_version); |
635 | daniel-mar | 269 | } |
270 | } |
||
271 | } else { |
||
272 | $handled = false; |
||
273 | } |
||
274 | } |
||
275 | |||
276 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
277 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
278 | |||
800 | daniel-mar | 279 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 280 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 281 | } else { |
282 | $tree_icon = null; // default icon (folder) |
||
283 | } |
||
284 | |||
285 | $json[] = array( |
||
286 | 'id' => 'oidplus:software_update', |
||
287 | 'icon' => $tree_icon, |
||
288 | 'text' => _L('Software update') |
||
289 | ); |
||
290 | |||
291 | return true; |
||
292 | } |
||
293 | |||
294 | public function tree_search($request) { |
||
295 | return false; |
||
296 | } |
||
648 | daniel-mar | 297 | |
298 | private $releases_ser = null; |
||
299 | |||
300 | private function showChangelog($local_ver) { |
||
301 | |||
302 | try { |
||
303 | if (is_null($this->releases_ser)) { |
||
716 | daniel-mar | 304 | if (function_exists('gzdecode')) { |
305 | $url = OIDplus::getEditionInfo()['revisionlog_gz']; |
||
306 | $cont = url_get_contents($url); |
||
307 | if ($cont !== false) $cont = @gzdecode($cont); |
||
308 | } else { |
||
309 | $url = OIDplus::getEditionInfo()['revisionlog']; |
||
310 | $cont = url_get_contents($url); |
||
311 | } |
||
648 | daniel-mar | 312 | if ($cont === false) return false; |
313 | $this->releases_ser = $cont; |
||
314 | } else { |
||
315 | $cont = $this->releases_ser; |
||
316 | } |
||
317 | $content = ''; |
||
318 | $ary = @unserialize($cont); |
||
319 | if ($ary === false) return false; |
||
320 | krsort($ary); |
||
321 | foreach ($ary as $rev => $data) { |
||
997 | daniel-mar | 322 | if (version_compare("svn-$rev", $local_ver) <= 0) continue; |
648 | daniel-mar | 323 | $comment = empty($data['msg']) ? _L('No comment') : $data['msg']; |
324 | $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") "; |
||
325 | $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment)); |
||
326 | $content .= "\n"; |
||
327 | } |
||
328 | return $content; |
||
1050 | daniel-mar | 329 | } catch (\Exception $e) { |
648 | daniel-mar | 330 | return false; |
331 | } |
||
332 | |||
333 | } |
||
334 | |||
335 | private function getLatestRevision() { |
||
336 | try { |
||
337 | if (is_null($this->releases_ser)) { |
||
716 | daniel-mar | 338 | if (function_exists('gzdecode')) { |
339 | $url = OIDplus::getEditionInfo()['revisionlog_gz']; |
||
340 | $cont = url_get_contents($url); |
||
341 | if ($cont !== false) $cont = @gzdecode($cont); |
||
342 | } else { |
||
343 | $url = OIDplus::getEditionInfo()['revisionlog']; |
||
344 | $cont = url_get_contents($url); |
||
345 | } |
||
648 | daniel-mar | 346 | if ($cont === false) return false; |
347 | $this->releases_ser = $cont; |
||
348 | } else { |
||
349 | $cont = $this->releases_ser; |
||
350 | } |
||
351 | $ary = @unserialize($cont); |
||
352 | if ($ary === false) return false; |
||
353 | krsort($ary); |
||
354 | $max_rev = array_keys($ary)[0]; |
||
355 | $newest_version = 'svn-' . $max_rev; |
||
356 | return $newest_version; |
||
1050 | daniel-mar | 357 | } catch (\Exception $e) { |
648 | daniel-mar | 358 | return false; |
359 | } |
||
360 | } |
||
662 | daniel-mar | 361 | |
362 | private function showPreview($local_installation, $newest_version) { |
||
363 | $out = '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
||
364 | |||
365 | ob_start(); |
||
366 | try { |
||
367 | $cont = $this->showChangelog($local_installation); |
||
1050 | daniel-mar | 368 | } catch (\Exception $e) { |
662 | daniel-mar | 369 | $cont = _L('Error: %1',$e->getMessage()); |
370 | } |
||
371 | ob_end_clean(); |
||
372 | |||
831 | daniel-mar | 373 | $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", "$cont\n"); |
662 | daniel-mar | 374 | |
375 | $out .= '<pre id="update_infobox">'.$cont.'</pre>'; |
||
376 | |||
377 | return $out; |
||
378 | } |
||
1000 | daniel-mar | 379 | |
380 | public function implementsFeature($id) { |
||
381 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications() |
||
382 | return false; |
||
383 | } |
||
384 | |||
385 | public function getNotifications($user=null): array { |
||
386 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.8 |
||
387 | $notifications = array(); |
||
388 | if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) { |
||
389 | |||
390 | // Following code is based on the VNag plugin (admin 901) code |
||
391 | |||
392 | $installType = OIDplus::getInstallType(); |
||
393 | |||
394 | if ($installType === 'ambigous') { |
||
395 | $out_stat = 'WARN'; |
||
396 | $out_msg = _L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!'); |
||
397 | } else if ($installType === 'unknown') { |
||
398 | $out_stat = 'WARN'; |
||
399 | $out_msg = _L('The version cannot be determined, and the update needs to be applied manually!'); |
||
400 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
||
401 | $local_installation = OIDplus::getVersion(); |
||
402 | $newest_version = $this->getLatestRevision(); |
||
403 | |||
404 | $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client'); |
||
405 | $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull'; |
||
406 | |||
407 | if (!$newest_version) { |
||
408 | $out_stat = 'WARN'; |
||
1061 | daniel-mar | 409 | if (!function_exists('curl_init')) { |
410 | $out_msg = _L('OIDplus could not determine the latest version.').' '._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl'); |
||
411 | } else { |
||
412 | $out_msg = _L('OIDplus could not determine the latest version.').' '._L('Probably the ViaThinkSoft server could not be reached.'); |
||
413 | } |
||
1000 | daniel-mar | 414 | } else if (!$local_installation) { |
415 | $out_stat = 'WARN'; |
||
416 | $out_msg = _L('OIDplus could not determine its version (Required: %1). Please update your system manually via the "%2" command regularly.', $requireInfo, $updateCommand); |
||
417 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
||
418 | $out_stat = 'INFO'; |
||
419 | $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version); |
||
420 | } else { |
||
421 | $out_stat = 'WARN'; |
||
422 | $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version); |
||
423 | } |
||
424 | } else if ($installType === 'svn-snapshot') { |
||
425 | $local_installation = OIDplus::getVersion(); |
||
426 | $newest_version = $this->getLatestRevision(); |
||
427 | |||
428 | if (!$newest_version) { |
||
429 | $out_stat = 'WARN'; |
||
1061 | daniel-mar | 430 | if (!function_exists('curl_init')) { |
431 | $out_msg = _L('OIDplus could not determine the latest version.').' '._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl'); |
||
432 | } else { |
||
433 | $out_msg = _L('OIDplus could not determine the latest version.').' '._L('Probably the ViaThinkSoft server could not be reached.'); |
||
434 | } |
||
1000 | daniel-mar | 435 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
436 | $out_stat = 'INFO'; |
||
437 | $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version); |
||
438 | } else { |
||
439 | $out_stat = 'WARN'; |
||
440 | $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version); |
||
441 | } |
||
442 | } else { |
||
443 | assert(false); |
||
444 | return $notifications; |
||
445 | } |
||
446 | |||
447 | if ($out_stat != 'INFO') { |
||
448 | $out_msg = '<a '.OIDplus::gui()->link('oidplus:software_update').'>'._L('Software update').'</a>: ' . $out_msg; |
||
449 | |||
450 | $notifications[] = array($out_stat, $out_msg); |
||
451 | } |
||
452 | |||
453 | } |
||
454 | return $notifications; |
||
455 | } |
||
456 | |||
661 | daniel-mar | 457 | } |