Subversion Repositories oidplus

Rev

Rev 493 | 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
 
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>
32
<html lang="en">
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">
163 daniel-mar 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
<?php
51
 
360 daniel-mar 52
echo '<h1>'._L('Update OIDplus').'</h1>';
53
 
163 daniel-mar 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)) {
360 daniel-mar 62
                echo '<p><font color="red"><b>'._L('CAPTCHA not successfully verified').'</b></font></p>';
63
                echo '<p><a href="index.php">'._L('Try again').'</a></p>';
163 daniel-mar 64
        } else {
415 daniel-mar 65
                if (!OIDplus::authUtils()->adminCheckPassword($_REQUEST['admin_password'])) {
360 daniel-mar 66
                        echo '<p><font color="red"><b>'._L('Wrong password').'</b></font></p>';
67
                        echo '<p><a href="index.php">'._L('Try again').'</a></p>';
163 daniel-mar 68
                } else {
360 daniel-mar 69
                        echo '<h2>'._L('Updating ...').'</h2>';
303 daniel-mar 70
 
71
                        ob_start();
492 daniel-mar 72
                        try {
73
                                $svn = new phpsvnclient(OIDPLUS_REPO);
74
                                $svn->versionFile = 'oidplus_version.txt';
75
                                $svn->updateWorkingCopy(realpath(__DIR__.'/../oidplus_version.txt'), '/trunk', dirname(__DIR__), false);
315 daniel-mar 76
 
492 daniel-mar 77
                                $cont = ob_get_contents();
78
                                $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
79
                        } catch (Exception $e) {
80
                                $cont = _L('Error: %1',$e->getMessage());
81
                        }
303 daniel-mar 82
                        ob_end_clean();
83
 
84
                        echo '<pre>'.$cont.'</pre>';
85
 
360 daniel-mar 86
                        echo '<p><a href="index.php">'._L('Back to update page').'</a></p>';
163 daniel-mar 87
                        echo '<hr>';
88
                }
89
        }
90
 
91
} else {
92
 
165 daniel-mar 93
        class VNagMonitorDummy extends VNag {
94
                private $status;
95
                private $content;
96
 
97
                public function __construct($status, $content) {
98
                        parent::__construct();
99
                        $this->status = $status;
100
                        $this->content = $content;
101
                }
102
 
103
                protected function cbRun($optional_args=array()) {
104
                        $this->setStatus($this->status);
105
                        $this->setHeadline($this->content);
106
                }
107
        }
108
 
486 daniel-mar 109
        echo '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
163 daniel-mar 110
 
360 daniel-mar 111
        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 112
 
486 daniel-mar 113
        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 114
 
486 daniel-mar 115
        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>';
116
 
360 daniel-mar 117
        echo '<hr>';
163 daniel-mar 118
 
486 daniel-mar 119
        $installType = OIDplus::getInstallType();
163 daniel-mar 120
 
486 daniel-mar 121
        if ($installType === 'ambigous') {
122
                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>';
123
                $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 124
                $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 125
                $job->run();
126
                unset($job);
486 daniel-mar 127
        } else if ($installType === 'unknown') {
128
                echo '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
129
                $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 130
                $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 131
                $job->run();
132
                unset($job);
486 daniel-mar 133
        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
134
                if ($installType === 'svn-wc') {
135
                        echo '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
136
                } else {
137
                        echo '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
138
                }
163 daniel-mar 139
 
140
                $local_installation = OIDplus::getVersion();
492 daniel-mar 141
                try {
142
                        $svn = new phpsvnclient(OIDPLUS_REPO);
143
                        $newest_version = 'svn-'.$svn->getVersion();
144
                } catch (Exception $e) {
145
                        $newest_version = false;
146
                }
316 daniel-mar 147
 
360 daniel-mar 148
                echo _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
149
                echo _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
163 daniel-mar 150
 
486 daniel-mar 151
                $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
152
                $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
153
 
492 daniel-mar 154
                if (!$newest_version) {
155
                        echo '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
156
                }
157
                else if (!$local_installation) {
486 daniel-mar 158
                        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 159
 
486 daniel-mar 160
                        $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 161
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
162
                        $job->run();
163
                        unset($job);
239 daniel-mar 164
                } else if ($local_installation == $newest_version) {
360 daniel-mar 165
                        echo '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
172 daniel-mar 166
 
360 daniel-mar 167
                        $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 168
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 169
                        $job->run();
170
                        unset($job);
163 daniel-mar 171
                } else {
486 daniel-mar 172
                        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 173
 
360 daniel-mar 174
                        echo '<h2>'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
303 daniel-mar 175
 
176
                        ob_start();
492 daniel-mar 177
                        try {
178
                                $svn = new phpsvnclient(OIDPLUS_REPO);
179
                                $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', realpath(__DIR__.'/../'), true);
180
                                $cont = ob_get_contents();
181
                                $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
182
                        } catch (Exception $e) {
183
                                $cont = _L('Error: %1',$e->getMessage());
184
                        }
303 daniel-mar 185
                        ob_end_clean();
172 daniel-mar 186
 
303 daniel-mar 187
                        echo '<pre>'.$cont.'</pre>';
188
 
360 daniel-mar 189
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus is outdated. ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
251 daniel-mar 190
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 191
                        $job->run();
192
                        unset($job);
163 daniel-mar 193
                }
486 daniel-mar 194
        } else if ($installType === 'svn-snapshot') {
195
                echo '<p>'._L('You are using <b>method C</b> (Snapshot ZIP file with oidplus_version.txt file).').'</p>';
163 daniel-mar 196
 
197
                $local_installation = OIDplus::getVersion();
492 daniel-mar 198
                try {
199
                        $svn = new phpsvnclient(OIDPLUS_REPO);
200
                        $newest_version = 'svn-'.$svn->getVersion();
201
                } catch (Exception $e) {
202
                        $newest_version = false;
203
                }
163 daniel-mar 204
 
492 daniel-mar 205
                echo _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
206
                echo _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
163 daniel-mar 207
 
492 daniel-mar 208
                if (!$newest_version) {
209
                        echo '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
210
                }
211
                else if ($local_installation == $newest_version) {
360 daniel-mar 212
                        echo '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
172 daniel-mar 213
 
360 daniel-mar 214
                        $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 215
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 216
                        $job->run();
217
                        unset($job);
163 daniel-mar 218
                } else {
360 daniel-mar 219
                        echo '<p><font color="blue">'._L('To update your OIDplus system, please enter the administrator password and click the button "Update NOW".').'</font></p>';
220
                        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 221
                        echo '<form method="POST" action="index.php">';
222
 
261 daniel-mar 223
                        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
163 daniel-mar 224
                                echo '<noscript>';
360 daniel-mar 225
                                echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>';
163 daniel-mar 226
                                echo '</noscript>';
261 daniel-mar 227
                                echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
228
                                echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
163 daniel-mar 229
                        }
230
 
231
                        echo '<input type="hidden" name="update_now" value="1">';
232
                        echo '<input type="password" name="admin_password">';
360 daniel-mar 233
                        echo '<input type="submit" value="'._L('Update NOW').'">';
163 daniel-mar 234
                        echo '</form>';
172 daniel-mar 235
 
360 daniel-mar 236
                        echo '<h2>'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
303 daniel-mar 237
 
238
                        ob_start();
492 daniel-mar 239
                        try {
240
                                $svn = new phpsvnclient(OIDPLUS_REPO);
241
                                $svn->updateWorkingCopy(realpath(__DIR__.'/../oidplus_version.txt'), '/trunk', realpath(__DIR__.'/../'), true);
242
                                $cont = ob_get_contents();
243
                                $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
244
                        } catch (Exception $e) {
245
                                $cont = _L('Error: %1',$e->getMessage());
246
                        }
303 daniel-mar 247
                        ob_end_clean();
172 daniel-mar 248
 
303 daniel-mar 249
                        echo '<pre>'.$cont.'</pre>';
250
 
360 daniel-mar 251
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus is outdated. ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
251 daniel-mar 252
                        $job->http_visual_output = VNag::OUTPUT_NEVER;
165 daniel-mar 253
                        $job->run();
254
                        unset($job);
163 daniel-mar 255
                }
256
        }
257
 
258
        echo '<hr>';
259
 
360 daniel-mar 260
        echo '<p><input type="button" onclick="document.location=\'../\'" value="'._L('Go back to OIDplus').'"></p>';
165 daniel-mar 261
 
360 daniel-mar 262
        echo '<br><h2>'._L('File Completeness Check').'</h2>';
306 daniel-mar 263
 
360 daniel-mar 264
        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 265
 
360 daniel-mar 266
        echo '<p>'._L('Please enter your administrator password to run the tool.').'</p>';
350 daniel-mar 267
 
306 daniel-mar 268
        echo '<form method="POST" action="check.php">';
269
        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
270
                echo '<noscript>';
360 daniel-mar 271
                echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>';
306 daniel-mar 272
                echo '</noscript>';
273
                echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
274
                echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
275
        }
276
        if (!isset($local_installation)) $local_installation = 'svn-';
277
        echo '<input type="hidden" name="svn_version" value="'.(substr($local_installation,strlen('svn-'))).'">';
278
        echo '<input type="password" name="admin_password">';
360 daniel-mar 279
        echo '<input type="submit" value="'._L('Check').'">';
280
        echo '<p>'._L('Attention: This will take some time!').'</p>';
306 daniel-mar 281
        echo '</form>';
282
 
360 daniel-mar 283
        echo '<h2>'._L('VNag integration').'</h2>';
306 daniel-mar 284
 
360 daniel-mar 285
        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 286
}
287
 
288
?>
289
 
290
</body>
486 daniel-mar 291
</html>