Subversion Repositories oidplus

Rev

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