Subversion Repositories oidplus

Rev

Rev 294 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
139 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
 
360 daniel-mar 20
// TODO: Translate
21
 
139 daniel-mar 22
require_once __DIR__ . '/../../../includes/oidplus.inc.php';
23
 
24
ob_start(); // allow cookie headers to be sent
25
 
26
header('Content-Type:text/html; charset=UTF-8');
27
 
28
OIDplus::init(true);
29
 
30
ob_start();
31
 
32
$step = 1;
33
$errors_happened = false;
157 daniel-mar 34
$edits_possible = true;
139 daniel-mar 35
 
36
?><!DOCTYPE html>
37
<html lang="en">
38
 
39
<head>
157 daniel-mar 40
        <title>OIDplus Setup</title>
41
        <meta name="robots" content="noindex">
42
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
139 daniel-mar 43
        <link rel="stylesheet" href="../../../setup/setup.css">
163 daniel-mar 44
        <?php
261 daniel-mar 45
        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
163 daniel-mar 46
        ?>
157 daniel-mar 47
        <script src="https://www.google.com/recaptcha/api.js"></script>
163 daniel-mar 48
        <?php
49
        }
50
        ?>
139 daniel-mar 51
</head>
52
 
53
<body>
54
 
157 daniel-mar 55
<h1>OIDplus Setup - Initial Settings</h1>
139 daniel-mar 56
 
270 daniel-mar 57
<p>If you can read this, then your database login credentials are correct.</p>
139 daniel-mar 58
 
59
<p>The following settings need to be configured once.<br>
270 daniel-mar 60
After setup is complete, you can change all these settings
61
through the admin login area, if necessary.</p>
139 daniel-mar 62
 
270 daniel-mar 63
<form method="POST" action="oobe.php">
139 daniel-mar 64
<input type="hidden" name="sent" value="1">
65
 
157 daniel-mar 66
<?php
261 daniel-mar 67
if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
157 daniel-mar 68
        echo '<p><u>Step '.($step++).': Solve CAPTCHA</u></p>';
69
        echo '<noscript>';
70
        echo '<p><font color="red">You need to enable JavaScript to solve the CAPTCHA.</font></p>';
71
        echo '</noscript>';
261 daniel-mar 72
        echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
157 daniel-mar 73
        echo '<p>Before logging in, please solve the following CAPTCHA</p>';
294 daniel-mar 74
        echo '<p>If the CAPTCHA does not work (e.g. because of wrong keys, please run <a href="<?php echo OIDplus::getSystemUrl(); ?>setup/">setup part 1</a> again or edit userdata/baseconfig/config.inc.php).</p>';
261 daniel-mar 75
        echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
157 daniel-mar 76
 
77
        if (isset($_REQUEST['sent'])) {
261 daniel-mar 78
                $secret=OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', '');
157 daniel-mar 79
                $response=$_POST["g-recaptcha-response"];
80
                $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
81
                $captcha_success=json_decode($verify);
82
                if ($captcha_success->success==false) {
360 daniel-mar 83
                        echo '<p><font color="red"><b>CAPTCHA not successfully verified</b></font></p>';
157 daniel-mar 84
                        $errors_happened = true;
85
                        $edits_possible = false;
86
                }
87
        }
88
}
89
?>
90
 
292 daniel-mar 91
<p><u>Step <?php echo $step++; ?>: Authenticate</u></p>
139 daniel-mar 92
 
93
<p>Please enter the administrator password you have entered before.</p>
94
 
227 daniel-mar 95
<p><input type="password" name="admin_password" value=""> (<a href="<?php echo OIDplus::getSystemUrl(); ?>setup/">Forgot?</a>) <?php
139 daniel-mar 96
 
97
if (isset($_REQUEST['sent'])) {
157 daniel-mar 98
        if (!OIDplusAuthUtils::adminCheckPassword($_REQUEST['admin_password'])) {
139 daniel-mar 99
                $errors_happened = true;
157 daniel-mar 100
                $edits_possible = false;
139 daniel-mar 101
                echo '<font color="red"><b>Wrong password</b></font>';
102
        }
103
}
104
 
105
?></p>
106
 
157 daniel-mar 107
<?php
108
#------------------------
109
$do_edits = isset($_REQUEST['sent']) && $edits_possible;;
110
#------------------------
111
 
292 daniel-mar 112
# ---
139 daniel-mar 113
 
292 daniel-mar 114
function step_admin_email($step, $do_edits, &$errors_happened) {
115
        echo "<p><u>Step $step: Please enter the email address of the system administrator</u></p>";
116
        echo '<input type="text" name="admin_email" value="';
139 daniel-mar 117
 
292 daniel-mar 118
        $msg = '';
139 daniel-mar 119
        if (isset($_REQUEST['sent'])) {
292 daniel-mar 120
                echo htmlentities($_REQUEST['admin_email']);
121
                if ($do_edits) {
122
                        try {
123
                                OIDplus::config()->setValue('admin_email', $_REQUEST['admin_email']);
124
                        } catch (Exception $e) {
125
                                $msg = $e->getMessage();
126
                                $errors_happened = true;
127
                        }
139 daniel-mar 128
                }
129
        } else {
292 daniel-mar 130
                echo htmlentities(OIDplus::config()->getValue('admin_email'));
139 daniel-mar 131
        }
132
 
292 daniel-mar 133
        echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>';
139 daniel-mar 134
}
292 daniel-mar 135
step_admin_email($step++, $do_edits, $errors_happened);
139 daniel-mar 136
 
292 daniel-mar 137
# ---
139 daniel-mar 138
 
292 daniel-mar 139
function step_system_title($step, $do_edits, &$errors_happened) {
140
        echo "<p><u>Step $step: What title should your Registration Authority / OIDplus instance have?</u></p>";
141
        echo '<input type="text" name="system_title" value="';
139 daniel-mar 142
 
292 daniel-mar 143
        $msg = '';
139 daniel-mar 144
        if (isset($_REQUEST['sent'])) {
292 daniel-mar 145
                echo htmlentities($_REQUEST['system_title']);
146
                if ($do_edits) {
147
                        try {
148
                                OIDplus::config()->setValue('system_title', $_REQUEST['system_title']);
149
                        } catch (Exception $e) {
150
                                $msg = $e->getMessage();
151
                                $errors_happened = true;
152
                        }
139 daniel-mar 153
                }
154
        } else {
292 daniel-mar 155
                echo htmlentities(OIDplus::config()->getValue('system_title'));
139 daniel-mar 156
        }
157
 
292 daniel-mar 158
        echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>';
159
}
160
step_system_title($step++, $do_edits, $errors_happened);
139 daniel-mar 161
 
292 daniel-mar 162
# ---
139 daniel-mar 163
 
292 daniel-mar 164
foreach (OIDplus::getPagePlugins() as $plugin) {
165
        if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) {
166
                $plugin->oobeEntry($step++, $do_edits, $errors_happened);
139 daniel-mar 167
        }
168
}
169
 
292 daniel-mar 170
# ---
139 daniel-mar 171
 
292 daniel-mar 172
echo '<p><u>Submit</u></p>';
173
echo '<input type="submit" value="Save and start OIDplus!">';
174
echo '</form>';
139 daniel-mar 175
 
292 daniel-mar 176
$pki_status = OIDplus::getPkiStatus();
139 daniel-mar 177
 
239 daniel-mar 178
if ($pki_status) {
139 daniel-mar 179
 
292 daniel-mar 180
echo '<p><u>Your OIDplus system ID (derived from the public key) is:</u></p>';
139 daniel-mar 181
 
292 daniel-mar 182
echo '<b>';
239 daniel-mar 183
$sysid_oid = OIDplus::getSystemId(true);
360 daniel-mar 184
if (!$sysid_oid) $sysid_oid = _L('Unknown!');
239 daniel-mar 185
echo htmlentities($sysid_oid);
292 daniel-mar 186
echo '</b>';
139 daniel-mar 187
 
292 daniel-mar 188
echo '<p><u>Your public key is</u></p>';
139 daniel-mar 189
 
239 daniel-mar 190
$val = OIDplus::config()->getValue('oidplus_public_key');
191
if ($val) {
192
        echo '<pre>'.htmlentities($val).'</pre>';
193
} else {
194
        echo '<p>Private/Public key creation failed</p>';
195
}
139 daniel-mar 196
 
197
}
198
 
292 daniel-mar 199
echo '</body>';
139 daniel-mar 200
 
292 daniel-mar 201
echo '</html>';
139 daniel-mar 202
 
203
$cont = ob_get_contents();
204
ob_end_clean();
205
 
206
if ($do_edits && !$errors_happened)  {
207
        OIDplus::config()->setValue('reg_wizard_done', '1');
208
        header('Location:../../../');
209
} else {
210
        echo $cont;
360 daniel-mar 211
}