Subversion Repositories oidplus

Rev

Rev 164 | 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
 
163 daniel-mar 22
include __DIR__ . '/../includes/oidplus.inc.php';
23
include __DIR__ . '/../includes/config.inc.php';
24
include __DIR__ . '/phpsvnclient.inc.php';
165 daniel-mar 25
require_once __DIR__ . '/vnag_framework.inc.php';
163 daniel-mar 26
 
27
define('OIDPLUS_REPO', 'https://svn.viathinksoft.com/svn/oidplus');
28
 
29
?><!DOCTYPE html>
30
<html lang="en">
31
 
32
<head>
33
        <title>OIDplus Update</title>
34
        <meta name="robots" content="noindex">
35
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
36
        <link rel="stylesheet" href="../setup/setup.css">
37
        <?php
38
        if (RECAPTCHA_ENABLED) {
39
        ?>
40
        <script src="https://www.google.com/recaptcha/api.js"></script>
41
        <?php
42
        }
43
        ?>
44
</head>
45
 
46
<body>
47
 
48
<h1>Update OIDplus</h1>
49
 
50
<?php
51
 
52
if (isset($_REQUEST['update_now'])) {
53
        if (RECAPTCHA_ENABLED) {
54
                $secret = RECAPTCHA_PRIVATE;
55
                $response = $_POST["g-recaptcha-response"];
56
                $verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
57
                $captcha_success = json_decode($verify);
58
        }
59
        if (RECAPTCHA_ENABLED && ($captcha_success->success==false)) {
60
                echo '<p><font color="red"><b>CAPTCHA not sucessfully verified</b></font></p>';
61
                echo '<p><a href="index.php">Try again</a></p>';
62
        } else {
63
                if (!OIDplusAuthUtils::adminCheckPassword($_REQUEST['admin_password'])) {
64
                        echo '<p><font color="red"><b>Wrong password</b></font></p>';
65
                        echo '<p><a href="index.php">Try again</a></p>';
66
                } else {
67
                        $svn = new phpsvnclient('https://svn.viathinksoft.com/svn/oidplus');
68
                        $svn->versionFile = 'oidplus_version.txt';
69
                        echo '<h2>Updating ...</h2>';
70
                        echo '<pre>';
164 daniel-mar 71
                        $svn->updateWorkingCopy('/trunk', dirname(__DIR__), false);
163 daniel-mar 72
                        echo '</pre>';
73
                        echo '<p><a href="index.php">Back to update page</a></p>';
74
                        echo '<hr>';
75
                }
76
        }
77
 
78
} else {
79
 
165 daniel-mar 80
        class VNagMonitorDummy extends VNag {
81
                private $status;
82
                private $content;
83
 
84
                public function __construct($status, $content) {
85
                        parent::__construct();
86
                        $this->status = $status;
87
                        $this->content = $content;
88
                }
89
 
90
                protected function cbRun($optional_args=array()) {
91
                        $this->setStatus($this->status);
92
                        $this->setHeadline($this->content);
93
                }
94
        }
95
 
163 daniel-mar 96
        ?>
97
 
98
        <p><u>There are two possibilities how to keep OIDplus up-to-date:</u></p>
99
 
100
        <p><b>Method A</b>: Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co <?php echo OIDPLUS_REPO; ?></code>
101
        and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and also check for
102
        conflicts. Highly recommended if you have a Shell/SSH access to your webspace!</p>
103
 
104
        <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.
105
        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
106
        on-the-fly by downloading them from the ViaThinkSoft SVN repository directly in your webspace (using PHP). It is required that the files on your webspace have
107
        create/write/delete permissions. Only recommended if you have no access to SSH/Linux shell.</p>
108
 
109
        <hr>
110
 
111
        <?php
112
 
113
        $svn_wc_exists = is_dir(__DIR__ . '/../.svn');
114
        $snapshot_exists = file_exists(__DIR__ . '/../oidplus_version.txt');
115
 
116
        if ($svn_wc_exists && $snapshot_exists) {
117
                echo '<font color="red">ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!</font>';
165 daniel-mar 118
                $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!");
119
                $job->http_visual_output = false;
120
                $job->run();
121
                unset($job);
163 daniel-mar 122
        } else if (!$svn_wc_exists && !$snapshot_exists) {
123
                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 124
                $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!");
125
                $job->http_visual_output = false;
126
                $job->run();
127
                unset($job);
163 daniel-mar 128
        } else if ($svn_wc_exists) {
129
                echo '<p>You are using <b>method A</b> (SVN working copy).</p>';
130
 
131
                $local_installation = OIDplus::getVersion();
132
                $svn = new phpsvnclient(OIDPLUS_REPO);
133
                $newest_version     = 'svn-'.$svn->getVersion();
134
 
135
                echo 'Local installation: ' . $local_installation.'<br>';
136
                echo 'Latest published version: ' . $newest_version.'<br>';
137
 
138
                if ($local_installation == $newest_version) {
139
                        echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>';
165 daniel-mar 140
                        $job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)");
141
                        $job->http_visual_output = false;
142
                        $job->run();
143
                        unset($job);
163 daniel-mar 144
                } else {
145
                        echo '<p><font color="blue">Please enter <code>svn update</code> into the SSH shell to update OIDplus to the latest version.</font></p>';
165 daniel-mar 146
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)");
147
                        $job->http_visual_output = false;
148
                        $job->run();
149
                        unset($job);
163 daniel-mar 150
                }
151
 
152
        } else if ($snapshot_exists) {
153
                echo '<p>You are using <b>method B</b> (Snapshot ZIP file with oidplus_version.txt file).</p>';
154
 
155
                $local_installation = OIDplus::getVersion();
156
                $svn = new phpsvnclient(OIDPLUS_REPO);
157
                $newest_version     = 'svn-'.$svn->getVersion();
158
 
159
                echo 'Local installation: ' . $local_installation.'<br>';
160
                echo 'Latest published version: ' . $newest_version.'<br>';
161
 
162
                if ($local_installation == $newest_version) {
163
                        echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>';
165 daniel-mar 164
                        $job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)");
165
                        $job->http_visual_output = false;
166
                        $job->run();
167
                        unset($job);
163 daniel-mar 168
                } else {
169
                        echo '<p><font color="blue">To update your OIDplus installation, please enter your password and click the button "Update NOW".</font></p>';
170
                        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>';
171
                        echo '<form method="POST" action="index.php">';
172
 
173
                        if (RECAPTCHA_ENABLED) {
174
                                echo '<noscript>';
175
                                echo '<p><font color="red">You need to enable JavaScript to solve the CAPTCHA.</font></p>';
176
                                echo '</noscript>';
177
                                echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>';
178
                                echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>';
179
                        }
180
 
181
                        echo '<input type="hidden" name="update_now" value="1">';
182
                        echo '<input type="password" name="admin_password">';
183
                        echo '<input type="submit" value="Update NOW">';
184
                        echo '</form>';
185
                        echo '<h2>Preview</h2>';
186
                        $svn = new phpsvnclient('https://svn.viathinksoft.com/svn/oidplus');
187
                        $svn->versionFile = 'oidplus_version.txt';
188
                        echo '<pre>';
164 daniel-mar 189
                        $svn->updateWorkingCopy('/trunk', dirname(__DIR__), true);
163 daniel-mar 190
                        echo '</pre>';
165 daniel-mar 191
                        $job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)");
192
                        $job->http_visual_output = false;
193
                        $job->run();
194
                        unset($job);
163 daniel-mar 195
                }
196
        }
197
 
198
        echo '<hr>';
199
 
200
        echo '<p><input type="button" onclick="document.location=\'../\'" value="Go back to OIDplus"></p>';
165 daniel-mar 201
 
202
        echo '<br><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 203
}
204
 
205
?>
206
 
207
</body>
208
</html>