Subversion Repositories oidplus

Rev

Rev 509 | 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
 
165 daniel-mar 20
declare(ticks=1);
21
 
493 daniel-mar 22
@set_time_limit(0);
172 daniel-mar 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>
504 daniel-mar 32
<html lang="<?php echo substr(OIDplus::getCurrentLang(),0,2); ?>">
163 daniel-mar 33
 
34
<head>
360 daniel-mar 35
        <title><?php echo _L('OIDplus Update'); ?></title>
163 daniel-mar 36
        <meta name="robots" content="noindex">
37
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
364 daniel-mar 38
        <link rel="stylesheet" href="../setup/setup.min.css.php">
504 daniel-mar 39
        <link rel="shortcut icon" type="image/x-icon" href="../favicon.ico.php">
163 daniel-mar 40
        <?php
261 daniel-mar 41
        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
163 daniel-mar 42
        ?>
43
        <script src="https://www.google.com/recaptcha/api.js"></script>
44
        <?php
45
        }
46
        ?>
47
</head>
48
 
49
<body>
50
 
51
<?php
52
 
360 daniel-mar 53
echo '<h1>'._L('Update OIDplus').'</h1>';
54
 
163 daniel-mar 55
if (isset($_REQUEST['update_now'])) {
261 daniel-mar 56
        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
57
                $secret = OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', '');
163 daniel-mar 58
                $response = $_POST["g-recaptcha-response"];
59
                $verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
60
                $captcha_success = json_decode($verify);
61
        }
261 daniel-mar 62
        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false) && ($captcha_success->success==false)) {
360 daniel-mar 63
                echo '<p><font color="red"><b>'._L('CAPTCHA not successfully verified').'</b></font></p>';
64
                echo '<p><a href="index.php">'._L('Try again').'</a></p>';
163 daniel-mar 65
        } else {
415 daniel-mar 66
                if (!OIDplus::authUtils()->adminCheckPassword($_REQUEST['admin_password'])) {
360 daniel-mar 67
                        echo '<p><font color="red"><b>'._L('Wrong password').'</b></font></p>';
68
                        echo '<p><a href="index.php">'._L('Try again').'</a></p>';
163 daniel-mar 69
                } else {
360 daniel-mar 70
                        echo '<h2>'._L('Updating ...').'</h2>';
303 daniel-mar 71
 
72
                        ob_start();
492 daniel-mar 73
                        try {
74
                                $svn = new phpsvnclient(OIDPLUS_REPO);
75
                                $svn->versionFile = 'oidplus_version.txt';
505 daniel-mar 76
 
77
                                // We are caching the changed file logs here only in the preview mode.
78
                                // Reason: We want to avoid that the "update/" page becomes an
79
                                // DoS attack vector if there hasn't been an update for a long time,
80
                                // and the list is very large.
81
                                // But we don't want to use cache in the real update, because
82
                                // otherwise it might break the system if an update is made
83
                                // while the ViaThinkSoft server is down (because the file list
84
                                // is cached, and therefore "delete" actions can be made, while
85
                                // adding/downloading does not work)
86
                                $svn->use_cache = false;
87
 
492 daniel-mar 88
                                $svn->updateWorkingCopy(realpath(__DIR__.'/../oidplus_version.txt'), '/trunk', dirname(__DIR__), false);
315 daniel-mar 89
 
492 daniel-mar 90
                                $cont = ob_get_contents();
91
                                $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
92
                        } catch (Exception $e) {
93
                                $cont = _L('Error: %1',$e->getMessage());
94
                        }
303 daniel-mar 95
                        ob_end_clean();
96
 
97
                        echo '<pre>'.$cont.'</pre>';
98
 
509 daniel-mar 99
                        echo '<p><input type="button" onclick="document.location=\'index.php\'" value="'._L('Go back to update page').'"></p>';
506 daniel-mar 100
 
163 daniel-mar 101
                        echo '<hr>';
102
                }
103
        }
104
 
105
} else {
106
 
165 daniel-mar 107
        class VNagMonitorDummy extends VNag {
108
                private $status;
109
                private $content;
110
 
111
                public function __construct($status, $content) {
112
                        parent::__construct();
113
                        $this->status = $status;
114
                        $this->content = $content;
115
                }
116
 
117
                protected function cbRun($optional_args=array()) {
118
                        $this->setStatus($this->status);
119
                        $this->setHeadline($this->content);
120
                }
121
        }
122
 
486 daniel-mar 123
        echo '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
163 daniel-mar 124
 
360 daniel-mar 125
        echo '<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(OIDPLUS_REPO).'/trunk').'</p>';
163 daniel-mar 126
 
486 daniel-mar 127
        echo '<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>';
163 daniel-mar 128
 
486 daniel-mar 129
        echo '<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>';
130
 
360 daniel-mar 131
        echo '<hr>';
163 daniel-mar 132
 
486 daniel-mar 133
        $installType = OIDplus::getInstallType();
163 daniel-mar 134
 
486 daniel-mar 135
        if ($installType === 'ambigous') {
136
                echo '<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>';
137
                $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, 'Multiple version files/directories (oidplus_version.txt, .git and .svn) are existing! Therefore, the version is ambiguous!'); // do not translate
251 daniel-mar 138
                $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 139
                $job->run();
140
                unset($job);
486 daniel-mar 141
        } else if ($installType === 'unknown') {
142
                echo '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
143
                $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, 'The version cannot be determined, and the update needs to be applied manually!'); // do not translate
251 daniel-mar 144
                $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 145
                $job->run();
146
                unset($job);
486 daniel-mar 147
        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
148
                if ($installType === 'svn-wc') {
149
                        echo '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
150
                } else {
151
                        echo '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
152
                }
163 daniel-mar 153
 
154
                $local_installation = OIDplus::getVersion();
492 daniel-mar 155
                try {
156
                        $svn = new phpsvnclient(OIDPLUS_REPO);
157
                        $newest_version = 'svn-'.$svn->getVersion();
158
                } catch (Exception $e) {
159
                        $newest_version = false;
160
                }
316 daniel-mar 161
 
360 daniel-mar 162
                echo _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
163
                echo _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
163 daniel-mar 164
 
486 daniel-mar 165
                $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
166
                $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
167
 
492 daniel-mar 168
                if (!$newest_version) {
169
                        echo '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
170
                }
171
                else if (!$local_installation) {
486 daniel-mar 172
                        echo '<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>';
251 daniel-mar 173
 
486 daniel-mar 174
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus could not determine its version. Please update your system manually via the "'.$updateCommand.'" command regularly.'); // do not translate
251 daniel-mar 175
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
176
                        $job->run();
177
                        unset($job);
239 daniel-mar 178
                } else if ($local_installation == $newest_version) {
360 daniel-mar 179
                        echo '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
172 daniel-mar 180
 
360 daniel-mar 181
                        $job = new VNagMonitorDummy(VNag::STATUS_OK, 'You are using the latest version of OIDplus ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
251 daniel-mar 182
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 183
                        $job->run();
184
                        unset($job);
163 daniel-mar 185
                } else {
486 daniel-mar 186
                        echo '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
172 daniel-mar 187
 
360 daniel-mar 188
                        echo '<h2>'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
303 daniel-mar 189
 
190
                        ob_start();
492 daniel-mar 191
                        try {
192
                                $svn = new phpsvnclient(OIDPLUS_REPO);
505 daniel-mar 193
                                $svn->use_cache = true;
492 daniel-mar 194
                                $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', realpath(__DIR__.'/../'), true);
195
                                $cont = ob_get_contents();
196
                                $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
197
                        } catch (Exception $e) {
198
                                $cont = _L('Error: %1',$e->getMessage());
199
                        }
303 daniel-mar 200
                        ob_end_clean();
172 daniel-mar 201
 
303 daniel-mar 202
                        echo '<pre>'.$cont.'</pre>';
203
 
360 daniel-mar 204
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus is outdated. ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
251 daniel-mar 205
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 206
                        $job->run();
207
                        unset($job);
163 daniel-mar 208
                }
486 daniel-mar 209
        } else if ($installType === 'svn-snapshot') {
210
                echo '<p>'._L('You are using <b>method C</b> (Snapshot ZIP file with oidplus_version.txt file).').'</p>';
163 daniel-mar 211
 
212
                $local_installation = OIDplus::getVersion();
492 daniel-mar 213
                try {
214
                        $svn = new phpsvnclient(OIDPLUS_REPO);
215
                        $newest_version = 'svn-'.$svn->getVersion();
216
                } catch (Exception $e) {
217
                        $newest_version = false;
218
                }
163 daniel-mar 219
 
492 daniel-mar 220
                echo _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
221
                echo _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
163 daniel-mar 222
 
492 daniel-mar 223
                if (!$newest_version) {
224
                        echo '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
225
                }
226
                else if ($local_installation == $newest_version) {
360 daniel-mar 227
                        echo '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
172 daniel-mar 228
 
360 daniel-mar 229
                        $job = new VNagMonitorDummy(VNag::STATUS_OK, 'You are using the latest version of OIDplus ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
251 daniel-mar 230
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 231
                        $job->run();
232
                        unset($job);
163 daniel-mar 233
                } else {
360 daniel-mar 234
                        echo '<p><font color="blue">'._L('To update your OIDplus system, please enter the administrator password and click the button "Update NOW".').'</font></p>';
235
                        echo '<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", this should be safe.').'</font></p>';
163 daniel-mar 236
                        echo '<form method="POST" action="index.php">';
237
 
261 daniel-mar 238
                        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
163 daniel-mar 239
                                echo '<noscript>';
360 daniel-mar 240
                                echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>';
163 daniel-mar 241
                                echo '</noscript>';
261 daniel-mar 242
                                echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
243
                                echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
163 daniel-mar 244
                        }
245
 
246
                        echo '<input type="hidden" name="update_now" value="1">';
247
                        echo '<input type="password" name="admin_password">';
360 daniel-mar 248
                        echo '<input type="submit" value="'._L('Update NOW').'">';
163 daniel-mar 249
                        echo '</form>';
172 daniel-mar 250
 
360 daniel-mar 251
                        echo '<h2>'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
303 daniel-mar 252
 
253
                        ob_start();
492 daniel-mar 254
                        try {
255
                                $svn = new phpsvnclient(OIDPLUS_REPO);
505 daniel-mar 256
                                $svn->use_cache = true;
492 daniel-mar 257
                                $svn->updateWorkingCopy(realpath(__DIR__.'/../oidplus_version.txt'), '/trunk', realpath(__DIR__.'/../'), true);
258
                                $cont = ob_get_contents();
259
                                $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
260
                        } catch (Exception $e) {
261
                                $cont = _L('Error: %1',$e->getMessage());
262
                        }
303 daniel-mar 263
                        ob_end_clean();
172 daniel-mar 264
 
303 daniel-mar 265
                        echo '<pre>'.$cont.'</pre>';
266
 
360 daniel-mar 267
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus is outdated. ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
251 daniel-mar 268
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 269
                        $job->run();
270
                        unset($job);
163 daniel-mar 271
                }
272
        }
273
 
274
        echo '<hr>';
275
 
360 daniel-mar 276
        echo '<p><input type="button" onclick="document.location=\'../\'" value="'._L('Go back to OIDplus').'"></p>';
165 daniel-mar 277
 
360 daniel-mar 278
        echo '<br><h2>'._L('File Completeness Check').'</h2>';
306 daniel-mar 279
 
360 daniel-mar 280
        echo '<p>'._L('With this optional tool, you can check if your OIDplus installation is complete and no files are missing.').'</p>';
306 daniel-mar 281
 
360 daniel-mar 282
        echo '<p>'._L('Please enter your administrator password to run the tool.').'</p>';
350 daniel-mar 283
 
306 daniel-mar 284
        echo '<form method="POST" action="check.php">';
285
        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
286
                echo '<noscript>';
360 daniel-mar 287
                echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>';
306 daniel-mar 288
                echo '</noscript>';
289
                echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
290
                echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
291
        }
292
        if (!isset($local_installation)) $local_installation = 'svn-';
293
        echo '<input type="hidden" name="svn_version" value="'.(substr($local_installation,strlen('svn-'))).'">';
294
        echo '<input type="password" name="admin_password">';
360 daniel-mar 295
        echo '<input type="submit" value="'._L('Check').'">';
296
        echo '<p>'._L('Attention: This will take some time!').'</p>';
306 daniel-mar 297
        echo '</form>';
298
 
360 daniel-mar 299
        echo '<h2>'._L('VNag integration').'</h2>';
306 daniel-mar 300
 
360 daniel-mar 301
        echo '<p>'._L('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 302
}
303
 
304
?>
305
 
306
</body>
486 daniel-mar 307
</html>