Rev 648 | Rev 651 | 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 |
||
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
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 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminSoftwareUpdate extends OIDplusPagePluginAdmin { |
||
23 | |||
24 | public function init($html=true) { |
||
25 | } |
||
26 | |||
27 | public function action($actionID, $params) { |
||
28 | if ($actionID == 'update_now') { |
||
647 | daniel-mar | 29 | @set_time_limit(0); |
635 | daniel-mar | 30 | |
31 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
32 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
||
33 | } |
||
34 | |||
647 | daniel-mar | 35 | $rev = $params['rev']; |
635 | daniel-mar | 36 | |
650 | daniel-mar | 37 | if (function_exists('gzdecode')) { |
38 | $url = "https://www.oidplus.com/updates/update_".($rev-1)."_to_".($rev).".txt.gz"; // TODO: in consts.ini |
||
39 | $cont = @file_get_contents($url); |
||
40 | if ($cont !== false) $cont = @gzdecode($cont); |
||
41 | } else { |
||
42 | $url = "https://www.oidplus.com/updates/update_".($rev-1)."_to_".($rev).".txt"; // TODO: in consts.ini |
||
43 | $cont = @file_get_contents($url); |
||
44 | } |
||
635 | daniel-mar | 45 | |
647 | daniel-mar | 46 | if ($cont === false) throw new OIDplusException(_L("Update could not be downloaded from ViaThinkSoft server. Please try again later.")); |
650 | daniel-mar | 47 | |
647 | daniel-mar | 48 | file_put_contents(OIDplus::localpath().'update.tmp.php', $cont); |
635 | daniel-mar | 49 | |
647 | daniel-mar | 50 | # TODO: instead use cURL? |
51 | // Note: we may not use eval() because script uses die() |
||
52 | $cont = @file_get_contents(OIDplus::webpath().'update.tmp.php'); |
||
53 | if ($cont === false) throw new OIDplusException(_L("Failed to execute update-script. Probably file_get_contents() may not open URLs!")); |
||
54 | |||
55 | return array("status" => 0, "content" => $cont); |
||
635 | daniel-mar | 56 | } |
57 | } |
||
58 | |||
59 | public function gui($id, &$out, &$handled) { |
||
60 | $parts = explode('.',$id,2); |
||
61 | if (!isset($parts[1])) $parts[1] = ''; |
||
62 | if ($parts[0] == 'oidplus:software_update') { |
||
63 | @set_time_limit(0); |
||
64 | |||
65 | $handled = true; |
||
66 | $out['title'] = _L('Software update'); |
||
67 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_big.png'; |
||
68 | |||
69 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
70 | $out['icon'] = 'img/error_big.png'; |
||
71 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
||
72 | return; |
||
73 | } |
||
74 | |||
75 | $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>'; |
||
76 | |||
77 | $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. Highly recommended if you have a Shell/SSH access to your webspace!',htmlentities(parse_ini_file(__DIR__.'/consts.ini')['svn']).'/trunk').'</p>'; |
||
78 | |||
79 | $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. Highly recommended if you have a Shell/SSH access to your webspace!','https://github.com/danielmarschall/oidplus.git').'</p>'; |
||
80 | |||
81 | $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Install OIDplus by downloading a TAR.GZ file from www.viathinksoft.com, which contains an SVN snapshot, and extract it to your webspace. The TAR.GZ file contains a file named "oidplus_version.txt" 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.').'</p>'; |
||
82 | |||
83 | $out['text'] .= '<hr>'; |
||
84 | |||
85 | $installType = OIDplus::getInstallType(); |
||
86 | |||
87 | if ($installType === 'ambigous') { |
||
88 | $out['text'] .= '<font color="red">'.strtoupper(_L('Error')).': '._L('Multiple version files/directories (oidplus_version.txt, .git and .svn) are existing! Therefore, the version is ambiguous!').'</font>'; |
||
89 | } else if ($installType === 'unknown') { |
||
90 | $out['text'] .= '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>'; |
||
91 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
||
92 | if ($installType === 'svn-wc') { |
||
93 | $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>'; |
||
94 | } else { |
||
95 | $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>'; |
||
96 | } |
||
97 | |||
98 | $local_installation = OIDplus::getVersion(); |
||
648 | daniel-mar | 99 | $newest_version = $this->getLatestRevision(); |
635 | daniel-mar | 100 | |
101 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
||
102 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>'; |
||
103 | |||
104 | $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client'); |
||
105 | $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull'; |
||
106 | |||
107 | if (!$newest_version) { |
||
108 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>'; |
||
109 | } |
||
110 | else if (!$local_installation) { |
||
111 | $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>'; |
||
112 | } else if ($local_installation == $newest_version) { |
||
113 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
||
114 | } else { |
||
115 | $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>'; |
||
116 | |||
117 | $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
||
118 | |||
119 | ob_start(); |
||
120 | try { |
||
648 | daniel-mar | 121 | $cont = $this->showChangelog($local_installation); |
635 | daniel-mar | 122 | } catch (Exception $e) { |
123 | $cont = _L('Error: %1',$e->getMessage()); |
||
124 | } |
||
125 | ob_end_clean(); |
||
126 | |||
127 | $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", $cont); |
||
128 | |||
129 | $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>'; |
||
130 | } |
||
131 | } else if ($installType === 'svn-snapshot') { |
||
647 | daniel-mar | 132 | $out['text'] .= '<div id="update_versioninfo">'; |
133 | |||
635 | daniel-mar | 134 | $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with oidplus_version.txt file).').'</p>'; |
135 | |||
136 | $local_installation = OIDplus::getVersion(); |
||
648 | daniel-mar | 137 | $newest_version = $this->getLatestRevision(); |
635 | daniel-mar | 138 | |
139 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
||
140 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>'; |
||
141 | |||
142 | if (!$newest_version) { |
||
143 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>'; |
||
647 | daniel-mar | 144 | $out['text'] .= '</div>'; |
635 | daniel-mar | 145 | } |
146 | else if ($local_installation == $newest_version) { |
||
147 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
||
647 | daniel-mar | 148 | $out['text'] .= '</div>'; |
635 | daniel-mar | 149 | } else { |
150 | $out['text'] .= '<p><font color="red">'.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! In case the update fails, you can download and extract the complete <a href="https://www.viathinksoft.com/projects/oidplus">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.').'</font></p>'; |
||
151 | $out['text'] .= '<form method="POST" action="index.php">'; |
||
152 | |||
648 | daniel-mar | 153 | $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 | 154 | |
647 | daniel-mar | 155 | $out['text'] .= '</div>'; |
156 | |||
635 | daniel-mar | 157 | $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
158 | |||
159 | ob_start(); |
||
160 | try { |
||
648 | daniel-mar | 161 | $cont = $this->showChangelog($local_installation); |
635 | daniel-mar | 162 | } catch (Exception $e) { |
163 | $cont = _L('Error: %1',$e->getMessage()); |
||
164 | } |
||
165 | ob_end_clean(); |
||
166 | |||
167 | $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", $cont); |
||
168 | |||
169 | $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>'; |
||
170 | } |
||
171 | } |
||
172 | } else { |
||
173 | $handled = false; |
||
174 | } |
||
175 | } |
||
176 | |||
177 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
178 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
179 | |||
180 | if (file_exists(__DIR__.'/treeicon.png')) { |
||
181 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
||
182 | } else { |
||
183 | $tree_icon = null; // default icon (folder) |
||
184 | } |
||
185 | |||
186 | $json[] = array( |
||
187 | 'id' => 'oidplus:software_update', |
||
188 | 'icon' => $tree_icon, |
||
189 | 'text' => _L('Software update') |
||
190 | ); |
||
191 | |||
192 | return true; |
||
193 | } |
||
194 | |||
195 | public function tree_search($request) { |
||
196 | return false; |
||
197 | } |
||
648 | daniel-mar | 198 | |
199 | private $releases_ser = null; |
||
200 | |||
201 | private function showChangelog($local_ver) { |
||
202 | |||
203 | try { |
||
204 | if (is_null($this->releases_ser)) { |
||
205 | $url = "https://www.oidplus.com/updates/releases.ser"; // TODO: in consts.ini |
||
206 | $cont = @file_get_contents($url); |
||
207 | if ($cont === false) return false; |
||
208 | $this->releases_ser = $cont; |
||
209 | } else { |
||
210 | $cont = $this->releases_ser; |
||
211 | } |
||
212 | $content = ''; |
||
213 | $ary = @unserialize($cont); |
||
214 | if ($ary === false) return false; |
||
215 | krsort($ary); |
||
216 | foreach ($ary as $rev => $data) { |
||
217 | if ($rev <= substr($local_ver,4)) continue; |
||
218 | $comment = empty($data['msg']) ? _L('No comment') : $data['msg']; |
||
219 | $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") "; |
||
220 | $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment)); |
||
221 | $content .= "\n"; |
||
222 | } |
||
223 | return $content; |
||
224 | } catch (Exception $e) { |
||
225 | return false; |
||
226 | } |
||
227 | |||
228 | } |
||
229 | |||
230 | private function getLatestRevision() { |
||
231 | try { |
||
232 | if (is_null($this->releases_ser)) { |
||
233 | $url = "https://www.oidplus.com/updates/releases.ser"; // TODO: in consts.ini |
||
234 | $cont = @file_get_contents($url); |
||
235 | if ($cont === false) return false; |
||
236 | $this->releases_ser = $cont; |
||
237 | } else { |
||
238 | $cont = $this->releases_ser; |
||
239 | } |
||
240 | $ary = @unserialize($cont); |
||
241 | if ($ary === false) return false; |
||
242 | krsort($ary); |
||
243 | $max_rev = array_keys($ary)[0]; |
||
244 | $newest_version = 'svn-' . $max_rev; |
||
245 | return $newest_version; |
||
246 | } catch (Exception $e) { |
||
247 | return false; |
||
248 | } |
||
249 | } |
||
635 | daniel-mar | 250 | } |