Subversion Repositories oidplus

Rev

Rev 559 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
163 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
163 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPageAdminSoftwareUpdate extends OIDplusPagePluginAdmin {
23
 
163 daniel-mar 24
        public function init($html=true) {
25
        }
26
 
532 daniel-mar 27
        public function action($actionID, $params) {
28
                if ($actionID == 'update_now') {
29
                        @set_time_limit(0);
30
 
31
 
549 daniel-mar 32
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
559 daniel-mar 33
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
532 daniel-mar 34
                        }
35
 
554 daniel-mar 36
                        ob_start();
532 daniel-mar 37
                        $error = "";
38
                        try {
39
                                $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
40
 
41
                                // We are caching the changed file logs here only in the preview mode.
42
                                // Reason: We want to avoid that the "update/" page becomes an
43
                                // DoS attack vector if there hasn't been an update for a long time,
44
                                // and the list is very large.
45
                                // But we don't want to use cache in the real update, because
46
                                // otherwise it might break the system if an update is made
47
                                // while the ViaThinkSoft server is down (because the file list
48
                                // is cached, and therefore "delete" actions can be made, while
49
                                // adding/downloading does not work)
50
                                $svn->use_cache = false;
51
 
52
                                if (!$svn->updateWorkingCopy(OIDplus::localpath().'oidplus_version.txt', '/trunk', OIDplus::localpath(), false)) {
53
                                        $error = _L("Some updates failed. Please see details in the update protocol.");
54
                                }
55
                        } catch (Exception $e) {
56
                                $error = $e->getMessage();
57
                        }
554 daniel-mar 58
                        $cont = ob_get_contents();
59
                        $cont = str_replace(OIDplus::localpath(), '...', $cont);
60
                        ob_end_clean();
532 daniel-mar 61
 
62
                        if ($error != "") {
63
                                return array("status" => -1, "error" => $error, "content" => $cont);
64
                        } else {
65
                                return array("status" => 0, "content" => $cont);
66
                        }
67
                }
68
        }
69
 
163 daniel-mar 70
        public function gui($id, &$out, &$handled) {
71
                $parts = explode('.',$id,2);
72
                if (!isset($parts[1])) $parts[1] = '';
532 daniel-mar 73
                if ($parts[0] == 'oidplus:software_update') {
74
                        @set_time_limit(0);
163 daniel-mar 75
 
532 daniel-mar 76
                        $handled = true;
77
                        $out['title'] = _L('Software update');
78
                        $out['icon']  = OIDplus::webpath(__DIR__).'icon_big.png';
79
 
549 daniel-mar 80
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
532 daniel-mar 81
                                $out['icon'] = 'img/error_big.png';
559 daniel-mar 82
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
532 daniel-mar 83
                                return;
84
                        }
85
 
86
                        $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
87
 
88
                        $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>';
89
 
90
                        $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>';
91
 
92
                        $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Install OIDplus by downloading a ZIP file from www.viathinksoft.com, which contains an SVN snapshot, and extract it to your webspace. The ZIP 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>';
93
 
94
                        $out['text'] .= '<hr>';
95
 
96
                        $installType = OIDplus::getInstallType();
97
 
98
                        if ($installType === 'ambigous') {
99
                                $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>';
100
                        } else if ($installType === 'unknown') {
101
                                $out['text'] .= '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
102
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
103
                                if ($installType === 'svn-wc') {
104
                                        $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
105
                                } else {
106
                                        $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
107
                                }
108
 
109
                                $local_installation = OIDplus::getVersion();
110
                                try {
111
                                        $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
112
                                        $newest_version = 'svn-'.$svn->getVersion();
113
                                } catch (Exception $e) {
114
                                        $newest_version = false;
115
                                }
116
 
117
                                $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
118
                                $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
119
 
120
                                $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
121
                                $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
122
 
123
                                if (!$newest_version) {
124
                                        $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
125
                                }
126
                                else if (!$local_installation) {
127
                                        $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>';
128
                                } else if ($local_installation == $newest_version) {
129
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
130
                                } else {
131
                                        $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>';
132
 
133
                                        $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
134
 
135
                                        ob_start();
136
                                        try {
137
                                                $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
138
                                                $svn->use_cache = true;
139
                                                $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', OIDplus::localpath(), true);
140
                                                $cont = ob_get_contents();
141
                                                $cont = str_replace(OIDplus::localpath(), '...', $cont);
142
                                        } catch (Exception $e) {
143
                                                $cont = _L('Error: %1',$e->getMessage());
144
                                        }
145
                                        ob_end_clean();
146
 
147
                                        $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>';
148
                                }
149
                        } else if ($installType === 'svn-snapshot') {
150
                                $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot ZIP file with oidplus_version.txt file).').'</p>';
151
 
152
                                $local_installation = OIDplus::getVersion();
153
                                try {
154
                                        $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
155
                                        $newest_version = 'svn-'.$svn->getVersion();
156
                                } catch (Exception $e) {
157
                                        $newest_version = false;
158
                                }
159
 
160
                                $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
161
                                $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
162
 
163
                                if (!$newest_version) {
164
                                        $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
165
                                }
166
                                else if ($local_installation == $newest_version) {
167
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
168
                                } else {
169
                                        $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 ZIP file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.').'</font></p>';
170
                                        $out['text'] .= '<form method="POST" action="index.php">';
171
 
549 daniel-mar 172
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus()" value="'._L('Update NOW').'"></p>';
532 daniel-mar 173
 
174
                                        $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
175
 
176
                                        ob_start();
177
                                        try {
178
                                                $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
179
                                                $svn->use_cache = true;
180
                                                $svn->updateWorkingCopy(OIDplus::localpath().'/oidplus_version.txt', '/trunk', OIDplus::localpath(), true);
181
                                                $cont = ob_get_contents();
182
                                                $cont = str_replace(OIDplus::localpath(), '...', $cont);
183
                                        } catch (Exception $e) {
184
                                                $cont = _L('Error: %1',$e->getMessage());
185
                                        }
186
                                        ob_end_clean();
187
 
188
                                        $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>';
189
                                }
190
                        }
191
                } else {
192
                        $handled = false;
163 daniel-mar 193
                }
194
        }
195
 
196
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
549 daniel-mar 197
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
360 daniel-mar 198
 
163 daniel-mar 199
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 200
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
163 daniel-mar 201
                } else {
202
                        $tree_icon = null; // default icon (folder)
203
                }
204
 
205
                $json[] = array(
206
                        'id' => 'oidplus:software_update',
207
                        'icon' => $tree_icon,
360 daniel-mar 208
                        'text' => _L('Software update')
163 daniel-mar 209
                );
210
 
211
                return true;
212
        }
213
 
214
        public function tree_search($request) {
215
                return false;
216
        }
532 daniel-mar 217
}