Rev 511 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 511 | Rev 532 | ||
---|---|---|---|
Line 22... | Line 22... | ||
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 | public function action($actionID, $params) { |
|
- | 28 | if ($actionID == 'update_now') { |
|
- | 29 | @set_time_limit(0); |
|
- | 30 | ||
- | 31 | ||
- | 32 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
|
- | 33 | throw new OIDplusException(_L('You need to log in as administrator.')); |
|
- | 34 | } |
|
- | 35 | ||
- | 36 | $error = ""; |
|
- | 37 | try { |
|
- | 38 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
|
- | 39 | $svn->versionFile = 'oidplus_version.txt'; |
|
- | 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 | ob_start(); |
|
- | 53 | if (!$svn->updateWorkingCopy(OIDplus::localpath().'oidplus_version.txt', '/trunk', OIDplus::localpath(), false)) { |
|
- | 54 | $error = _L("Some updates failed. Please see details in the update protocol."); |
|
- | 55 | } |
|
- | 56 | $cont = ob_get_contents(); |
|
- | 57 | $cont = str_replace(OIDplus::localpath(), '...', $cont); |
|
- | 58 | ob_end_clean(); |
|
- | 59 | } catch (Exception $e) { |
|
- | 60 | $error = $e->getMessage(); |
|
- | 61 | } |
|
- | 62 | ||
- | 63 | if ($error != "") { |
|
- | 64 | return array("status" => -1, "error" => $error, "content" => $cont); |
|
- | 65 | } else { |
|
- | 66 | return array("status" => 0, "content" => $cont); |
|
- | 67 | } |
|
- | 68 | } |
|
- | 69 | } |
|
- | 70 | ||
27 | public function gui($id, &$out, &$handled) { |
71 | public function gui($id, &$out, &$handled) { |
28 | $parts = explode('.',$id,2); |
72 | $parts = explode('.',$id,2); |
29 | if (!isset($parts[1])) $parts[1] = ''; |
73 | if (!isset($parts[1])) $parts[1] = ''; |
30 | if ($parts[0] != 'oidplus:software_update') return; |
74 | if ($parts[0] == 'oidplus:software_update') { |
- | 75 | @set_time_limit(0); |
|
- | 76 | ||
31 | $handled = true; |
77 | $handled = true; |
32 | $out['title'] = _L('Software update'); |
78 | $out['title'] = _L('Software update'); |
33 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_big.png'; |
79 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_big.png'; |
34 | 80 | ||
35 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
81 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
36 | $out['icon'] = 'img/error_big.png'; |
82 | $out['icon'] = 'img/error_big.png'; |
37 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
83 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
38 | return; |
84 | return; |
39 | } |
85 | } |
40 | 86 | ||
- | 87 | $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>'; |
|
- | 88 | ||
41 | $out['text'] = '<p>'._L('You can perform a system update by clicking the button below.').'</p>'; |
89 | $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>'; |
- | 90 | ||
42 | $out['text'] .= '<p><input type="button" onclick="document.location=\'update/\'" value="'._L('Start update assistant').'"></p>'; |
91 | $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>'; |
- | 92 | ||
- | 93 | $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>'; |
|
- | 94 | ||
- | 95 | $out['text'] .= '<hr>'; |
|
- | 96 | ||
- | 97 | $installType = OIDplus::getInstallType(); |
|
- | 98 | ||
- | 99 | if ($installType === 'ambigous') { |
|
- | 100 | $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>'; |
|
- | 101 | } else if ($installType === 'unknown') { |
|
- | 102 | $out['text'] .= '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>'; |
|
- | 103 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
|
- | 104 | if ($installType === 'svn-wc') { |
|
- | 105 | $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>'; |
|
- | 106 | } else { |
|
- | 107 | $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>'; |
|
- | 108 | } |
|
- | 109 | ||
- | 110 | $local_installation = OIDplus::getVersion(); |
|
- | 111 | try { |
|
- | 112 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
|
- | 113 | $newest_version = 'svn-'.$svn->getVersion(); |
|
- | 114 | } catch (Exception $e) { |
|
- | 115 | $newest_version = false; |
|
- | 116 | } |
|
- | 117 | ||
- | 118 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
|
- | 119 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>'; |
|
- | 120 | ||
- | 121 | $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client'); |
|
- | 122 | $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull'; |
|
- | 123 | ||
- | 124 | if (!$newest_version) { |
|
- | 125 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>'; |
|
- | 126 | } |
|
- | 127 | else if (!$local_installation) { |
|
- | 128 | $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>'; |
|
- | 129 | } else if ($local_installation == $newest_version) { |
|
- | 130 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
|
- | 131 | } else { |
|
- | 132 | $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>'; |
|
- | 133 | ||
- | 134 | $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
|
- | 135 | ||
- | 136 | ob_start(); |
|
- | 137 | try { |
|
- | 138 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
|
- | 139 | $svn->use_cache = true; |
|
- | 140 | $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', OIDplus::localpath(), true); |
|
- | 141 | $cont = ob_get_contents(); |
|
- | 142 | $cont = str_replace(OIDplus::localpath(), '...', $cont); |
|
- | 143 | } catch (Exception $e) { |
|
- | 144 | $cont = _L('Error: %1',$e->getMessage()); |
|
- | 145 | } |
|
- | 146 | ob_end_clean(); |
|
- | 147 | ||
- | 148 | $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>'; |
|
- | 149 | } |
|
- | 150 | } else if ($installType === 'svn-snapshot') { |
|
- | 151 | $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot ZIP file with oidplus_version.txt file).').'</p>'; |
|
- | 152 | ||
- | 153 | $local_installation = OIDplus::getVersion(); |
|
- | 154 | try { |
|
- | 155 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
|
- | 156 | $newest_version = 'svn-'.$svn->getVersion(); |
|
- | 157 | } catch (Exception $e) { |
|
- | 158 | $newest_version = false; |
|
- | 159 | } |
|
- | 160 | ||
- | 161 | $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>'; |
|
- | 162 | $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>'; |
|
- | 163 | ||
- | 164 | if (!$newest_version) { |
|
- | 165 | $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>'; |
|
- | 166 | } |
|
- | 167 | else if ($local_installation == $newest_version) { |
|
- | 168 | $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>'; |
|
- | 169 | } else { |
|
- | 170 | $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>'; |
|
- | 171 | $out['text'] .= '<form method="POST" action="index.php">'; |
|
- | 172 | ||
- | 173 | $out['text'] .= '<p><input type="button" onclick="doUpdateOIDplus()" value="'._L('Update NOW').'"></p>'; |
|
- | 174 | ||
- | 175 | $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 → %2',$local_installation,$newest_version).'</h2>'; |
|
- | 176 | ||
- | 177 | ob_start(); |
|
- | 178 | try { |
|
- | 179 | $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']); |
|
- | 180 | $svn->use_cache = true; |
|
- | 181 | $svn->updateWorkingCopy(OIDplus::localpath().'/oidplus_version.txt', '/trunk', OIDplus::localpath(), true); |
|
- | 182 | $cont = ob_get_contents(); |
|
- | 183 | $cont = str_replace(OIDplus::localpath(), '...', $cont); |
|
- | 184 | } catch (Exception $e) { |
|
- | 185 | $cont = _L('Error: %1',$e->getMessage()); |
|
- | 186 | } |
|
- | 187 | ob_end_clean(); |
|
- | 188 | ||
- | 189 | $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>'; |
|
- | 190 | } |
|
- | 191 | } |
|
- | 192 | } else { |
|
- | 193 | $handled = false; |
|
- | 194 | } |
|
43 | } |
195 | } |
44 | 196 | ||
45 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
197 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
46 | if (!OIDplus::authUtils()::isAdminLoggedIn()) return false; |
198 | if (!OIDplus::authUtils()::isAdminLoggedIn()) return false; |
47 | 199 |