Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2021 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
 
20
require_once __DIR__ . '/../../../../includes/oidplus.inc.php';
21
 
22
ob_start(); // allow cookie headers to be sent
23
 
24
header('Content-Type:text/html; charset=UTF-8');
25
 
26
OIDplus::init(true);
27
set_exception_handler(array('OIDplusGui', 'html_exception_handler'));
28
 
29
if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminOOBE', false)) {
30
        throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
31
}
32
 
33
ob_start();
34
 
35
$step = 1;
36
$errors_happened = false;
37
$edits_possible = true;
38
 
39
echo '<!DOCTYPE html>';
40
echo '<html lang="'.substr(OIDplus::getCurrentLang(),0,2).'">';
41
 
42
echo '<head>';
43
echo '  <title>'._L('OIDplus Setup').'</title>';
44
echo '  <meta name="robots" content="noindex">';
45
echo '  <meta name="viewport" content="width=device-width, initial-scale=1.0">';
1018 daniel-mar 46
echo '  <script src="../../../../oidplus.min.js.php"></script>';
47
echo '  <script src="../../../../polyfill.min.js.php"></script>';
635 daniel-mar 48
echo '  <link rel="stylesheet" href="../../../../setup/setup.min.css.php">';
49
echo '  <link rel="shortcut icon" type="image/x-icon" href="../../../../favicon.ico.php">';
50
echo '</head>';
51
 
52
echo '<body>';
53
 
54
echo '<h1>'._L('OIDplus Setup - Initial Settings').'</h1>';
55
 
56
OIDplus::handleLangArgument();
57
echo OIDplus::gui()->getLanguageBox(null, false);
58
 
59
echo '<p>'._L('If you can read this, then your database login credentials are correct.').'</p>';
60
 
61
echo '<p>'._L('The following settings need to be configured once.<br>After setup is complete, you can change all these settings through the admin login area, if necessary.').'</p>';
62
 
63
echo '<form method="POST" action="oobe.php">';
64
echo '<input type="hidden" name="sent" value="1">';
65
 
1016 daniel-mar 66
if (OIDplus::getActiveCaptchaPlugin()->isVisible()) echo '<p><u>'._L('Step %1: Solve CAPTCHA',$step++).'</u></p>';
1033 daniel-mar 67
if (isset($_POST['sent'])) {
709 daniel-mar 68
        try {
69
                OIDplus::getActiveCaptchaPlugin()->captchaVerify($_POST);
70
        } catch (Exception $e) {
71
                echo '<p><font color="red"><b>'.htmlentities($e->getMessage()).'</b></font></p>';
72
                $errors_happened = true;
73
                $edits_possible = false;
635 daniel-mar 74
        }
75
}
801 daniel-mar 76
echo OIDplus::getActiveCaptchaPlugin()->captchaGenerate(_L('Before logging in, please solve the following CAPTCHA'), _L('If the CAPTCHA does not work (e.g. because of wrong keys, please run <a href="%1">setup part 1</a> again or edit %2 manually).',OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/','userdata/baseconfig/config.inc.php'));
635 daniel-mar 77
 
78
echo '<p><u>'._L('Step %1: Authenticate',$step++).'</u></p>';
79
 
80
if (OIDplus::authUtils()->isAdminLoggedIn()) {
81
 
82
        echo '<p><font color="green">You are already logged in as administrator.</font></p>';
83
 
84
} else {
85
 
86
        echo '<p>'._L('Please enter the administrator password you have entered before.').'</p>';
87
 
801 daniel-mar 88
        echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Forgot password?').'</a>) ';
635 daniel-mar 89
 
1033 daniel-mar 90
        if (isset($_POST['sent'])) {
91
                if (!OIDplus::authUtils()->adminCheckPassword(isset($_POST['admin_password']) ? $_POST['admin_password'] : '')) {
635 daniel-mar 92
                        $errors_happened = true;
93
                        $edits_possible = false;
94
                        echo '<font color="red"><b>'._L('Wrong password').'</b></font>';
95
                }
96
        }
97
 
98
        echo '</p>';
99
}
100
 
101
#------------------------
1033 daniel-mar 102
$do_edits = isset($_POST['sent']) && $edits_possible;;
635 daniel-mar 103
#------------------------
104
 
105
# ---
106
 
107
function step_admin_email($step, $do_edits, &$errors_happened) {
108
        echo '<p><u>'._L('Step %1: Please enter the email address of the system administrator',$step).'</u></p>';
109
        echo '<input type="text" name="admin_email" value="';
110
 
111
        $msg = '';
1033 daniel-mar 112
        if (isset($_POST['sent'])) {
113
                echo htmlentities(isset($_POST['admin_email']) ? $_POST['admin_email'] : '');
635 daniel-mar 114
                if ($do_edits) {
115
                        try {
1033 daniel-mar 116
                                OIDplus::config()->setValue('admin_email', isset($_POST['admin_email']) ? $_POST['admin_email'] : '');
635 daniel-mar 117
                        } catch (Exception $e) {
118
                                $msg = $e->getMessage();
119
                                $errors_happened = true;
120
                        }
121
                }
122
        } else {
123
                echo htmlentities(OIDplus::config()->getValue('admin_email'));
124
        }
125
 
126
        echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>';
127
}
128
step_admin_email($step++, $do_edits, $errors_happened);
129
 
130
# ---
131
 
132
function step_system_title($step, $do_edits, &$errors_happened) {
133
        echo '<p><u>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</u></p>';
134
        echo '<input type="text" name="system_title" value="';
135
 
136
        $msg = '';
1033 daniel-mar 137
        if (isset($_POST['sent'])) {
138
                echo htmlentities(isset($_POST['system_title']) ? $_POST['system_title'] : '');
635 daniel-mar 139
                if ($do_edits) {
140
                        try {
1033 daniel-mar 141
                                OIDplus::config()->setValue('system_title', isset($_POST['system_title']) ? $_POST['system_title'] : '');
635 daniel-mar 142
                        } catch (Exception $e) {
143
                                $msg = $e->getMessage();
144
                                $errors_happened = true;
145
                        }
146
                }
147
        } else {
148
                echo htmlentities(OIDplus::config()->getValue('system_title'));
149
        }
150
 
151
        echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>';
152
}
153
step_system_title($step++, $do_edits, $errors_happened);
154
 
155
# ---
156
 
1005 daniel-mar 157
foreach (OIDplus::getAllPlugins() as $plugin) {
635 daniel-mar 158
        if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) {
159
                $plugin->oobeEntry($step++, $do_edits, $errors_happened);
160
        }
161
}
162
 
163
# ---
164
 
165
echo '<p><u>'._L('Step %1: Save settings and start OIDplus',$step).'</u></p>';
166
echo '<input type="submit" value="'._L('Save and start OIDplus!').'">';
167
echo '</form>';
168
 
169
$pki_status = OIDplus::getPkiStatus();
170
 
171
if ($pki_status) {
172
 
173
        echo '<p><u>'._L('Your OIDplus system ID (derived from the public key) is:').'</u></p>';
174
 
175
        echo '<b>';
176
        $sysid_oid = OIDplus::getSystemId(true);
177
        if (!$sysid_oid) $sysid_oid = _L('Unknown!');
178
        echo htmlentities($sysid_oid);
179
        echo '</b>';
180
 
181
        echo '<p><u>'._L('Your public key is:').'</u></p>';
182
 
830 daniel-mar 183
        $val = OIDplus::getSystemPublicKey();
635 daniel-mar 184
        if ($val) {
185
                echo '<pre>'.htmlentities($val).'</pre>';
186
        } else {
187
                echo '<p>'._L('Private/Public key creation failed').'</p>';
188
        }
189
 
190
}
191
 
192
echo '<br><br><br>'; // because of iPhone Safari
193
 
194
echo '</body>';
195
 
196
echo '</html>';
197
 
198
$cont = ob_get_contents();
199
ob_end_clean();
200
 
201
if ($do_edits && !$errors_happened)  {
202
        OIDplus::config()->setValue('oobe_main_done', '1');
1005 daniel-mar 203
        OIDplus::invoke_shutdown();
635 daniel-mar 204
        header('Location:../../../../');
205
} else {
1005 daniel-mar 206
        OIDplus::invoke_shutdown();
635 daniel-mar 207
        echo $cont;
208
}