Subversion Repositories oidplus

Rev

Rev 635 | Rev 709 | 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">';
46
echo '  <link rel="stylesheet" href="../../../../setup/setup.min.css.php">';
47
echo '  <link rel="shortcut icon" type="image/x-icon" href="../../../../favicon.ico.php">';
702 daniel-mar 48
echo OIDplus::getActiveCaptchaPlugin()->captchaDomHead();
635 daniel-mar 49
echo '</head>';
50
 
51
echo '<body>';
52
 
53
echo '<h1>'._L('OIDplus Setup - Initial Settings').'</h1>';
54
 
55
OIDplus::handleLangArgument();
56
echo OIDplus::gui()->getLanguageBox(null, false);
57
 
58
echo '<p>'._L('If you can read this, then your database login credentials are correct.').'</p>';
59
 
60
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>';
61
 
62
echo '<form method="POST" action="oobe.php">';
63
echo '<input type="hidden" name="sent" value="1">';
64
 
702 daniel-mar 65
if (OIDplus::getActiveCaptchaPlugin()::id() !== 'None') {
635 daniel-mar 66
        echo '<p><u>'._L('Step %1: Solve CAPTCHA',$step++).'</u></p>';
67
        if (isset($_REQUEST['sent'])) {
702 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>';
635 daniel-mar 72
                        $errors_happened = true;
73
                        $edits_possible = false;
74
                }
75
        }
702 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().'setup/','userdata/baseconfig/config.inc.php'));
635 daniel-mar 77
}
78
 
79
echo '<p><u>'._L('Step %1: Authenticate',$step++).'</u></p>';
80
 
81
if (OIDplus::authUtils()->isAdminLoggedIn()) {
82
 
83
        echo '<p><font color="green">You are already logged in as administrator.</font></p>';
84
 
85
} else {
86
 
87
        echo '<p>'._L('Please enter the administrator password you have entered before.').'</p>';
88
 
89
        echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath().'setup/">'._L('Forgot password?').'</a>) ';
90
 
91
        if (isset($_REQUEST['sent'])) {
92
                if (!OIDplus::authUtils()->adminCheckPassword(isset($_REQUEST['admin_password']) ? $_REQUEST['admin_password'] : '')) {
93
                        $errors_happened = true;
94
                        $edits_possible = false;
95
                        echo '<font color="red"><b>'._L('Wrong password').'</b></font>';
96
                }
97
        }
98
 
99
        echo '</p>';
100
}
101
 
102
#------------------------
103
$do_edits = isset($_REQUEST['sent']) && $edits_possible;;
104
#------------------------
105
 
106
# ---
107
 
108
function step_admin_email($step, $do_edits, &$errors_happened) {
109
        echo '<p><u>'._L('Step %1: Please enter the email address of the system administrator',$step).'</u></p>';
110
        echo '<input type="text" name="admin_email" value="';
111
 
112
        $msg = '';
113
        if (isset($_REQUEST['sent'])) {
114
                echo htmlentities(isset($_REQUEST['admin_email']) ? $_REQUEST['admin_email'] : '');
115
                if ($do_edits) {
116
                        try {
117
                                OIDplus::config()->setValue('admin_email', isset($_REQUEST['admin_email']) ? $_REQUEST['admin_email'] : '');
118
                        } catch (Exception $e) {
119
                                $msg = $e->getMessage();
120
                                $errors_happened = true;
121
                        }
122
                }
123
        } else {
124
                echo htmlentities(OIDplus::config()->getValue('admin_email'));
125
        }
126
 
127
        echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>';
128
}
129
step_admin_email($step++, $do_edits, $errors_happened);
130
 
131
# ---
132
 
133
function step_system_title($step, $do_edits, &$errors_happened) {
134
        echo '<p><u>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</u></p>';
135
        echo '<input type="text" name="system_title" value="';
136
 
137
        $msg = '';
138
        if (isset($_REQUEST['sent'])) {
139
                echo htmlentities(isset($_REQUEST['system_title']) ? $_REQUEST['system_title'] : '');
140
                if ($do_edits) {
141
                        try {
142
                                OIDplus::config()->setValue('system_title', isset($_REQUEST['system_title']) ? $_REQUEST['system_title'] : '');
143
                        } catch (Exception $e) {
144
                                $msg = $e->getMessage();
145
                                $errors_happened = true;
146
                        }
147
                }
148
        } else {
149
                echo htmlentities(OIDplus::config()->getValue('system_title'));
150
        }
151
 
152
        echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>';
153
}
154
step_system_title($step++, $do_edits, $errors_happened);
155
 
156
# ---
157
 
158
foreach (OIDplus::getPagePlugins() as $plugin) {
159
        if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) {
160
                $plugin->oobeEntry($step++, $do_edits, $errors_happened);
161
        }
162
}
163
 
164
# ---
165
 
166
echo '<p><u>'._L('Step %1: Save settings and start OIDplus',$step).'</u></p>';
167
echo '<input type="submit" value="'._L('Save and start OIDplus!').'">';
168
echo '</form>';
169
 
170
$pki_status = OIDplus::getPkiStatus();
171
 
172
if ($pki_status) {
173
 
174
        echo '<p><u>'._L('Your OIDplus system ID (derived from the public key) is:').'</u></p>';
175
 
176
        echo '<b>';
177
        $sysid_oid = OIDplus::getSystemId(true);
178
        if (!$sysid_oid) $sysid_oid = _L('Unknown!');
179
        echo htmlentities($sysid_oid);
180
        echo '</b>';
181
 
182
        echo '<p><u>'._L('Your public key is:').'</u></p>';
183
 
184
        $val = OIDplus::config()->getValue('oidplus_public_key');
185
        if ($val) {
186
                echo '<pre>'.htmlentities($val).'</pre>';
187
        } else {
188
                echo '<p>'._L('Private/Public key creation failed').'</p>';
189
        }
190
 
191
}
192
 
193
echo '<br><br><br>'; // because of iPhone Safari
194
 
195
echo '</body>';
196
 
197
echo '</html>';
198
 
199
$cont = ob_get_contents();
200
ob_end_clean();
201
 
202
if ($do_edits && !$errors_happened)  {
203
        OIDplus::config()->setValue('oobe_main_done', '1');
204
        header('Location:../../../../');
205
} else {
206
        echo $cont;
207
}