Rev 635 | Rev 648 | 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 | |
647 | daniel-mar | 37 | $url = "https://www.oidplus.com/updates/update_".($rev-1)."_to_".($rev).".txt"; // TODO: in consts.ini |
38 | $cont = @file_get_contents($url); |
||
635 | daniel-mar | 39 | |
647 | daniel-mar | 40 | if ($cont === false) throw new OIDplusException(_L("Update could not be downloaded from ViaThinkSoft server. Please try again later.")); |
41 | file_put_contents(OIDplus::localpath().'update.tmp.php', $cont); |
||
635 | daniel-mar | 42 | |
647 | daniel-mar | 43 | # TODO: instead use cURL? |
44 | // Note: we may not use eval() because script uses die() |
||
45 | $cont = @file_get_contents(OIDplus::webpath().'update.tmp.php'); |
||
46 | if ($cont === false) throw new OIDplusException(_L("Failed to execute update-script. Probably file_get_contents() may not open URLs!")); |
||
47 | |||
48 | return array("status" => 0, "content" => $cont); |
||
635 | daniel-mar | 49 | } |
50 | } |
||
51 | |||
52 | public function gui($id, &$out, &$handled) { |
||
53 | $parts = explode('.',$id,2); |
||
54 | if (!isset($parts[1])) $parts[1] = ''; |
||
55 | if ($parts[0] == 'oidplus:software_update') { |
||
56 | @set_time_limit(0); |
||
57 | |||
58 | $handled = true; |
||
59 | $out['title'] = _L('Software update'); |
||
60 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_big.png'; |
||
61 | |||
62 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
63 | $out['icon'] = 'img/error_big.png'; |
||
64 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>'; |
||
69 | |||
70 | $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>'; |
||
71 | |||
72 | $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>'; |
||
73 | |||
74 | $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>'; |
||
75 | |||
76 | $out['text'] .= '<hr>'; |
||
77 | |||
78 | $installType = OIDplus::getInstallType(); |
||
79 | |||
80 | if ($installType === 'ambigous') { |
||
81 | $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>'; |
||
82 | } else if ($installType === 'unknown') { |
||
83 | $out['text'] .= '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>'; |
||
84 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
||
85 | if ($installType === 'svn-wc') { |
||
86 | $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>'; |
||
87 | } else { |
||
88 | $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>'; |
||
89 | } |
||
90 | |||
91 | $local_installation = OIDplus::getVersion(); |
||
92 | try { |
||
93 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
||
94 | $newest_version = 'svn-'.$svn->getVersion(); |
||
95 | } catch (Exception $e) { |
||
96 | $newest_version = false; |
||
97 | } |
||
98 | |||
99 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
||
100 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>'; |
||
101 | |||
102 | $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client'); |
||
103 | $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull'; |
||
104 | |||
105 | if (!$newest_version) { |
||
106 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>'; |
||
107 | } |
||
108 | else if (!$local_installation) { |
||
109 | $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>'; |
||
110 | } else if ($local_installation == $newest_version) { |
||
111 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
||
112 | } else { |
||
113 | $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>'; |
||
114 | |||
115 | $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
||
116 | |||
647 | daniel-mar | 117 | // TODO: Completely remove PHP SVN client and instead get log files hard coded from VTS |
635 | daniel-mar | 118 | ob_start(); |
119 | try { |
||
120 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
||
121 | $svn->use_cache = true; |
||
122 | $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', OIDplus::localpath(), true); |
||
123 | $cont = ob_get_contents(); |
||
124 | $cont = str_replace(OIDplus::localpath(), '...', $cont); |
||
125 | } catch (Exception $e) { |
||
126 | $cont = _L('Error: %1',$e->getMessage()); |
||
127 | } |
||
128 | ob_end_clean(); |
||
129 | |||
130 | $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", $cont); |
||
131 | |||
132 | $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>'; |
||
133 | } |
||
134 | } else if ($installType === 'svn-snapshot') { |
||
647 | daniel-mar | 135 | $out['text'] .= '<div id="update_versioninfo">'; |
136 | |||
635 | daniel-mar | 137 | $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with oidplus_version.txt file).').'</p>'; |
138 | |||
139 | $local_installation = OIDplus::getVersion(); |
||
140 | try { |
||
141 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
||
142 | $newest_version = 'svn-'.$svn->getVersion(); |
||
143 | } catch (Exception $e) { |
||
144 | $newest_version = false; |
||
145 | } |
||
146 | |||
147 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
||
148 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>'; |
||
149 | |||
150 | if (!$newest_version) { |
||
151 | $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 | 152 | $out['text'] .= '</div>'; |
635 | daniel-mar | 153 | } |
154 | else if ($local_installation == $newest_version) { |
||
155 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
||
647 | daniel-mar | 156 | $out['text'] .= '</div>'; |
635 | daniel-mar | 157 | } else { |
158 | $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>'; |
||
159 | $out['text'] .= '<form method="POST" action="index.php">'; |
||
160 | |||
647 | daniel-mar | 161 | $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.(substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>'; |
635 | daniel-mar | 162 | |
647 | daniel-mar | 163 | $out['text'] .= '</div>'; |
164 | |||
635 | daniel-mar | 165 | $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
166 | |||
167 | ob_start(); |
||
168 | try { |
||
169 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
||
170 | $svn->use_cache = true; |
||
171 | $svn->updateWorkingCopy(OIDplus::localpath().'/oidplus_version.txt', '/trunk', OIDplus::localpath(), true); |
||
172 | $cont = ob_get_contents(); |
||
173 | $cont = str_replace(OIDplus::localpath(), '...', $cont); |
||
174 | } catch (Exception $e) { |
||
175 | $cont = _L('Error: %1',$e->getMessage()); |
||
176 | } |
||
177 | ob_end_clean(); |
||
178 | |||
179 | $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", $cont); |
||
180 | |||
181 | $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>'; |
||
182 | } |
||
183 | } |
||
184 | } else { |
||
185 | $handled = false; |
||
186 | } |
||
187 | } |
||
188 | |||
189 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
190 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
191 | |||
192 | if (file_exists(__DIR__.'/treeicon.png')) { |
||
193 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
||
194 | } else { |
||
195 | $tree_icon = null; // default icon (folder) |
||
196 | } |
||
197 | |||
198 | $json[] = array( |
||
199 | 'id' => 'oidplus:software_update', |
||
200 | 'icon' => $tree_icon, |
||
201 | 'text' => _L('Software update') |
||
202 | ); |
||
203 | |||
204 | return true; |
||
205 | } |
||
206 | |||
207 | public function tree_search($request) { |
||
208 | return false; |
||
209 | } |
||
210 | } |