Subversion Repositories oidplus

Rev

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