Rev 303 | 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 |
||
5 | * Copyright 2019 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 | |||
165 | daniel-mar | 20 | declare(ticks=1); |
21 | |||
172 | daniel-mar | 22 | set_time_limit(0); |
23 | |||
250 | daniel-mar | 24 | require_once __DIR__ . '/../includes/oidplus.inc.php'; |
25 | |||
280 | daniel-mar | 26 | // Note: we don't want to use OIDplus::init() in this updater (it should be independent as much as possible) |
294 | daniel-mar | 27 | OIDplus::baseConfig(); // This call will redirect to setup if userdata/baseconfig/config.inc.php is missing |
174 | daniel-mar | 28 | |
163 | daniel-mar | 29 | define('OIDPLUS_REPO', 'https://svn.viathinksoft.com/svn/oidplus'); |
30 | |||
31 | ?><!DOCTYPE html> |
||
32 | <html lang="en"> |
||
33 | |||
34 | <head> |
||
35 | <title>OIDplus Update</title> |
||
36 | <meta name="robots" content="noindex"> |
||
37 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||
38 | <link rel="stylesheet" href="../setup/setup.css"> |
||
39 | <?php |
||
261 | daniel-mar | 40 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) { |
163 | daniel-mar | 41 | ?> |
42 | <script src="https://www.google.com/recaptcha/api.js"></script> |
||
43 | <?php |
||
44 | } |
||
45 | ?> |
||
46 | </head> |
||
47 | |||
48 | <body> |
||
49 | |||
50 | <h1>Update OIDplus</h1> |
||
51 | |||
52 | <?php |
||
53 | |||
54 | if (isset($_REQUEST['update_now'])) { |
||
261 | daniel-mar | 55 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) { |
56 | $secret = OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', ''); |
||
163 | daniel-mar | 57 | $response = $_POST["g-recaptcha-response"]; |
58 | $verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}"); |
||
59 | $captcha_success = json_decode($verify); |
||
60 | } |
||
261 | daniel-mar | 61 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false) && ($captcha_success->success==false)) { |
163 | daniel-mar | 62 | echo '<p><font color="red"><b>CAPTCHA not sucessfully verified</b></font></p>'; |
63 | echo '<p><a href="index.php">Try again</a></p>'; |
||
64 | } else { |
||
65 | if (!OIDplusAuthUtils::adminCheckPassword($_REQUEST['admin_password'])) { |
||
66 | echo '<p><font color="red"><b>Wrong password</b></font></p>'; |
||
67 | echo '<p><a href="index.php">Try again</a></p>'; |
||
68 | } else { |
||
69 | $svn = new phpsvnclient('https://svn.viathinksoft.com/svn/oidplus'); |
||
70 | $svn->versionFile = 'oidplus_version.txt'; |
||
71 | echo '<h2>Updating ...</h2>'; |
||
303 | daniel-mar | 72 | |
73 | ob_start(); |
||
177 | daniel-mar | 74 | $svn->updateWorkingCopy(dirname(__DIR__).'/oidplus_version.txt', '/trunk', dirname(__DIR__), false); |
303 | daniel-mar | 75 | $cont = ob_get_contents(); |
76 | $cont = str_replace(realpath(dirname(__DIR__)), '...', $cont); |
||
77 | ob_end_clean(); |
||
78 | |||
79 | echo '<pre>'.$cont.'</pre>'; |
||
80 | |||
163 | daniel-mar | 81 | echo '<p><a href="index.php">Back to update page</a></p>'; |
82 | echo '<hr>'; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | } else { |
||
87 | |||
165 | daniel-mar | 88 | class VNagMonitorDummy extends VNag { |
89 | private $status; |
||
90 | private $content; |
||
91 | |||
92 | public function __construct($status, $content) { |
||
93 | parent::__construct(); |
||
94 | $this->status = $status; |
||
95 | $this->content = $content; |
||
96 | } |
||
97 | |||
98 | protected function cbRun($optional_args=array()) { |
||
99 | $this->setStatus($this->status); |
||
100 | $this->setHeadline($this->content); |
||
101 | } |
||
102 | } |
||
103 | |||
163 | daniel-mar | 104 | ?> |
105 | |||
106 | <p><u>There are two possibilities how to keep OIDplus up-to-date:</u></p> |
||
107 | |||
261 | daniel-mar | 108 | <p><b>Method A</b>: Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co <?php echo htmlentities(OIDPLUS_REPO); ?>/trunk</code> |
163 | daniel-mar | 109 | and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and also check for |
110 | conflicts. Highly recommended if you have a Shell/SSH access to your webspace!</p> |
||
111 | |||
112 | <p><b>Method B:</b> Install OIDplus by downloading a ZIP file from www.viathinksoft.com, which contains a SVN snapshot, and extract it to your webspace. |
||
113 | 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 |
||
186 | daniel-mar | 114 | on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory. |
115 | A change conflict detection is NOT implemented. |
||
116 | It is required that the files on your webspace have |
||
171 | daniel-mar | 117 | create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.</p> |
163 | daniel-mar | 118 | |
119 | <hr> |
||
120 | |||
121 | <?php |
||
122 | |||
294 | daniel-mar | 123 | $svn_wc_exists = is_dir(OIDplus::basePath().'/.svn'); |
124 | $snapshot_exists = file_exists(OIDplus::basePath().'/oidplus_version.txt'); |
||
163 | daniel-mar | 125 | |
126 | if ($svn_wc_exists && $snapshot_exists) { |
||
127 | echo '<font color="red">ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!</font>'; |
||
165 | daniel-mar | 128 | $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!"); |
251 | daniel-mar | 129 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
165 | daniel-mar | 130 | $job->run(); |
131 | unset($job); |
||
163 | daniel-mar | 132 | } else if (!$svn_wc_exists && !$snapshot_exists) { |
133 | echo '<font color="red">ERROR: Neither oidplus_version.txt, nor .svn directory exist! Therefore, the version cannot be determined and the update needs to be applied manually!</font>'; |
||
165 | daniel-mar | 134 | $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "Neither oidplus_version.txt, nor .svn directory exist! Therefore, the version cannot be determined and the update needs to be applied manually!"); |
251 | daniel-mar | 135 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
165 | daniel-mar | 136 | $job->run(); |
137 | unset($job); |
||
163 | daniel-mar | 138 | } else if ($svn_wc_exists) { |
139 | echo '<p>You are using <b>method A</b> (SVN working copy).</p>'; |
||
140 | |||
141 | $local_installation = OIDplus::getVersion(); |
||
142 | $svn = new phpsvnclient(OIDPLUS_REPO); |
||
172 | daniel-mar | 143 | $newest_version = 'svn-'.$svn->getVersion(); |
239 | daniel-mar | 144 | |
145 | echo 'Local installation: ' . ($local_installation ? $local_installation : 'unknown') . '<br>'; |
||
146 | echo 'Latest published version: ' . ($newest_version ? $newest_version : 'unknown') . '<br>'; |
||
163 | daniel-mar | 147 | |
239 | daniel-mar | 148 | if (!$local_installation) { |
149 | echo '<p><font color="red">The system could not determine the version of your system. (Required: svnupdate shell access or SQLite3). Please update your system manually via the SVN "update" command regularly.</font></p>'; |
||
251 | daniel-mar | 150 | |
151 | $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'The system could not determine the version of your system. (Required: svnupdate shell access or SQLite3). Please update your system manually via the SVN "update" command regularly.'); |
||
152 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
||
153 | $job->run(); |
||
154 | unset($job); |
||
239 | daniel-mar | 155 | } else if ($local_installation == $newest_version) { |
163 | daniel-mar | 156 | echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>'; |
172 | daniel-mar | 157 | |
165 | daniel-mar | 158 | $job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)"); |
251 | daniel-mar | 159 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
165 | daniel-mar | 160 | $job->run(); |
161 | unset($job); |
||
163 | daniel-mar | 162 | } else { |
163 | echo '<p><font color="blue">Please enter <code>svn update</code> into the SSH shell to update OIDplus to the latest version.</font></p>'; |
||
172 | daniel-mar | 164 | |
186 | daniel-mar | 165 | echo '<h2>Preview of update '.$local_installation.' → '.$newest_version.'</h2>'; |
172 | daniel-mar | 166 | $svn = new phpsvnclient(OIDPLUS_REPO); |
303 | daniel-mar | 167 | |
168 | ob_start(); |
||
172 | daniel-mar | 169 | $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', dirname(__DIR__), true); |
303 | daniel-mar | 170 | $cont = ob_get_contents(); |
171 | $cont = str_replace(realpath(dirname(__DIR__)), '...', $cont); |
||
172 | ob_end_clean(); |
||
172 | daniel-mar | 173 | |
303 | daniel-mar | 174 | echo '<pre>'.$cont.'</pre>'; |
175 | |||
165 | daniel-mar | 176 | $job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)"); |
251 | daniel-mar | 177 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
165 | daniel-mar | 178 | $job->run(); |
179 | unset($job); |
||
163 | daniel-mar | 180 | } |
181 | } else if ($snapshot_exists) { |
||
182 | echo '<p>You are using <b>method B</b> (Snapshot ZIP file with oidplus_version.txt file).</p>'; |
||
183 | |||
184 | $local_installation = OIDplus::getVersion(); |
||
185 | $svn = new phpsvnclient(OIDPLUS_REPO); |
||
172 | daniel-mar | 186 | $newest_version = 'svn-'.$svn->getVersion(); |
163 | daniel-mar | 187 | |
188 | echo 'Local installation: ' . $local_installation.'<br>'; |
||
189 | echo 'Latest published version: ' . $newest_version.'<br>'; |
||
190 | |||
191 | if ($local_installation == $newest_version) { |
||
192 | echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>'; |
||
172 | daniel-mar | 193 | |
165 | daniel-mar | 194 | $job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)"); |
251 | daniel-mar | 195 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
165 | daniel-mar | 196 | $job->run(); |
197 | unset($job); |
||
163 | daniel-mar | 198 | } else { |
199 | echo '<p><font color="blue">To update your OIDplus installation, please enter your password and click the button "Update NOW".</font></p>'; |
||
200 | echo '<p><font color="red">WARNING: Please make a backup of your files before updating. In case of an error, the OIDplus installation (including this update-assistant) might become unavailable. Also, since the web-update does not contain collission-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost!</font></p>'; |
||
201 | echo '<form method="POST" action="index.php">'; |
||
202 | |||
261 | daniel-mar | 203 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) { |
163 | daniel-mar | 204 | echo '<noscript>'; |
205 | echo '<p><font color="red">You need to enable JavaScript to solve the CAPTCHA.</font></p>'; |
||
206 | echo '</noscript>'; |
||
261 | daniel-mar | 207 | echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>'; |
208 | echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>'; |
||
163 | daniel-mar | 209 | } |
210 | |||
211 | echo '<input type="hidden" name="update_now" value="1">'; |
||
212 | echo '<input type="password" name="admin_password">'; |
||
213 | echo '<input type="submit" value="Update NOW">'; |
||
214 | echo '</form>'; |
||
172 | daniel-mar | 215 | |
186 | daniel-mar | 216 | echo '<h2>Preview of update '.$local_installation.' → '.$newest_version.'</h2>'; |
172 | daniel-mar | 217 | $svn = new phpsvnclient(OIDPLUS_REPO); |
303 | daniel-mar | 218 | |
219 | ob_start(); |
||
172 | daniel-mar | 220 | $svn->updateWorkingCopy(dirname(__DIR__).'/oidplus_version.txt', '/trunk', dirname(__DIR__), true); |
303 | daniel-mar | 221 | $cont = ob_get_contents(); |
222 | $cont = str_replace(realpath(dirname(__DIR__)), '...', $cont); |
||
223 | ob_end_clean(); |
||
172 | daniel-mar | 224 | |
303 | daniel-mar | 225 | echo '<pre>'.$cont.'</pre>'; |
226 | |||
165 | daniel-mar | 227 | $job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)"); |
251 | daniel-mar | 228 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
165 | daniel-mar | 229 | $job->run(); |
230 | unset($job); |
||
163 | daniel-mar | 231 | } |
232 | } |
||
233 | |||
234 | echo '<hr>'; |
||
235 | |||
236 | echo '<p><input type="button" onclick="document.location=\'../\'" value="Go back to OIDplus"></p>'; |
||
165 | daniel-mar | 237 | |
306 | daniel-mar | 238 | echo '<br><h2>File Completeness Check</h2>'; |
239 | |||
240 | echo '<p>With this optional tool, you can check if your OIDplus installation is complete and no files are missing.</p>'; |
||
241 | |||
242 | echo '<form method="POST" action="check.php">'; |
||
243 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) { |
||
244 | echo '<noscript>'; |
||
245 | echo '<p><font color="red">You need to enable JavaScript to solve the CAPTCHA.</font></p>'; |
||
246 | echo '</noscript>'; |
||
247 | echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>'; |
||
248 | echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>'; |
||
249 | } |
||
250 | if (!isset($local_installation)) $local_installation = 'svn-'; |
||
251 | echo '<input type="hidden" name="svn_version" value="'.(substr($local_installation,strlen('svn-'))).'">'; |
||
252 | echo '<input type="password" name="admin_password">'; |
||
253 | echo '<input type="submit" value="Check">'; |
||
254 | echo '<p>Attention: This will take some time!</p>'; |
||
255 | echo '</form>'; |
||
256 | |||
257 | echo '<h2>VNag integration</h2>'; |
||
258 | |||
259 | echo '<p>Did you know that this page contains an invisible VNag tag? You can watch this page using the "webreader" plugin of VNag, and then monitor it with any Nagios compatible software! <a href="https://www.viathinksoft.com/projects/vnag">More information</a>.</p>'; |
||
163 | daniel-mar | 260 | } |
261 | |||
262 | ?> |
||
263 | |||
264 | </body> |
||
265 | </html> |