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