Rev 1131 | Rev 1189 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1131 | Rev 1143 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1; |
20 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1; |
21 | use ViaThinkSoft\OIDplus\OIDplus; |
21 | use ViaThinkSoft\OIDplus\OIDplus; |
22 | use ViaThinkSoft\OIDplus\OIDplusGui; |
22 | use ViaThinkSoft\OIDplus\OIDplusGui; |
23 | use ViaThinkSoft\OIDplus\OIDplusException; |
23 | use ViaThinkSoft\OIDplus\OIDplusException; |
24 | 24 | ||
25 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
25 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
26 | 26 | ||
27 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
27 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
28 | 28 | ||
29 | ob_start(); // allow cookie headers to be sent |
29 | ob_start(); // allow cookie headers to be sent |
30 | 30 | ||
31 | header('Content-Type:text/html; charset=UTF-8'); |
31 | header('Content-Type:text/html; charset=UTF-8'); |
32 | 32 | ||
33 | OIDplus::init(true); |
33 | OIDplus::init(true); |
34 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
34 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
35 | 35 | ||
36 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminOOBE', false)) { |
36 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminOOBE', false)) { |
37 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
37 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
38 | } |
38 | } |
39 | 39 | ||
40 | OIDplus::handleLangArgument(); |
40 | OIDplus::handleLangArgument(); |
41 | 41 | ||
42 | ob_start(); |
42 | ob_start(); |
43 | 43 | ||
44 | $step = 1; |
44 | $step = 1; |
45 | $errors_happened = false; |
45 | $errors_happened = false; |
46 | $edits_possible = true; |
46 | $edits_possible = true; |
47 | 47 | ||
48 | echo '<p>'._L('If you can read this, then your database login credentials are correct.').'</p>'; |
48 | echo '<p>'._L('If you can read this, then your database login credentials are correct.').'</p>'; |
49 | 49 | ||
50 | 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 | 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>'; |
51 | 51 | ||
52 | echo '<form method="POST" action="oobe.php">'; |
52 | echo '<form method="POST" action="oobe.php">'; |
53 | echo '<input type="hidden" name="sent" value="1">'; |
53 | echo '<input type="hidden" name="sent" value="1">'; |
54 | 54 | ||
55 | if (OIDplus::getActiveCaptchaPlugin()->isVisible()) echo '<h2>'._L('Step %1: Solve CAPTCHA',$step++).'</h2>'; |
55 | if (OIDplus::getActiveCaptchaPlugin()->isVisible()) echo '<h2>'._L('Step %1: Solve CAPTCHA',$step++).'</h2>'; |
56 | if (isset($_POST['sent'])) { |
56 | if (isset($_POST['sent'])) { |
57 | try { |
57 | try { |
58 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($_POST); |
58 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($_POST); |
59 | } catch (\Exception $e) { |
59 | } catch (\Exception $e) { |
60 | echo '<p><font color="red"><b>'.htmlentities($e->getMessage()).'</b></font></p>'; |
60 | echo '<p><font color="red"><b>'.htmlentities($e->getMessage()).'</b></font></p>'; |
61 | $errors_happened = true; |
61 | $errors_happened = true; |
62 | $edits_possible = false; |
62 | $edits_possible = false; |
63 | } |
63 | } |
64 | } |
64 | } |
65 | 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')); |
65 | 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')); |
66 | 66 | ||
67 | echo '<h2>'._L('Step %1: Authenticate',$step++).'</h2>'; |
67 | echo '<h2>'._L('Step %1: Authenticate',$step++).'</h2>'; |
68 | 68 | ||
69 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
69 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
70 | 70 | ||
71 | echo '<p><font color="green">'._L('You are already logged in as administrator.').'</font></p>'; |
71 | echo '<p><font color="green">'._L('You are already logged in as administrator.').'</font></p>'; |
72 | 72 | ||
73 | } else { |
73 | } else { |
74 | 74 | ||
75 | echo '<p>'._L('Please enter the administrator password you have entered before.').'</p>'; |
75 | echo '<p>'._L('Please enter the administrator password you have entered before.').'</p>'; |
76 | 76 | ||
77 | echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Forgot password?').'</a>) '; |
77 | echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Forgot password?').'</a>) '; |
78 | 78 | ||
79 | if (isset($_POST['sent'])) { |
79 | if (isset($_POST['sent'])) { |
80 | if (!OIDplus::authUtils()->adminCheckPassword($_POST['admin_password'] ?? '')) { |
80 | if (!OIDplus::authUtils()->adminCheckPassword($_POST['admin_password'] ?? '')) { |
81 | $errors_happened = true; |
81 | $errors_happened = true; |
82 | $edits_possible = false; |
82 | $edits_possible = false; |
83 | echo '<font color="red"><b>'._L('Wrong password').'</b></font>'; |
83 | echo '<font color="red"><b>'._L('Wrong password').'</b></font>'; |
84 | } |
84 | } |
85 | } |
85 | } |
86 | 86 | ||
87 | echo '</p>'; |
87 | echo '</p>'; |
88 | } |
88 | } |
89 | 89 | ||
90 | #------------------------ |
90 | #------------------------ |
91 | $do_edits = isset($_POST['sent']) && $edits_possible; |
91 | $do_edits = isset($_POST['sent']) && $edits_possible; |
92 | #------------------------ |
92 | #------------------------ |
93 | 93 | ||
94 | # --- |
94 | # --- |
95 | 95 | ||
96 | /** |
96 | /** |
97 | * @param int $step |
97 | * @param int $step |
98 | * @param bool $do_edits |
98 | * @param bool $do_edits |
99 | * @param bool $errors_happened |
99 | * @param bool $errors_happened |
100 | * @return void |
100 | * @return void |
101 | * @throws OIDplusException |
101 | * @throws OIDplusException |
102 | * @throws \ViaThinkSoft\OIDplus\OIDplusConfigInitializationException |
102 | * @throws \ViaThinkSoft\OIDplus\OIDplusConfigInitializationException |
103 | */ |
103 | */ |
104 | function step_admin_email(int $step, bool $do_edits, bool &$errors_happened) { |
104 | function step_admin_email(int $step, bool $do_edits, bool &$errors_happened) { |
105 | echo '<h2>'._L('Step %1: Please enter the email address of the system administrator',$step).'</h2>'; |
105 | echo '<h2>'._L('Step %1: Please enter the email address of the system administrator',$step).'</h2>'; |
106 | echo '<input type="text" name="admin_email" value="'; |
106 | echo '<input type="text" name="admin_email" value="'; |
107 | 107 | ||
108 | $msg = ''; |
108 | $msg = ''; |
109 | if (isset($_POST['sent'])) { |
109 | if (isset($_POST['sent'])) { |
110 | echo htmlentities($_POST['admin_email'] ?? ''); |
110 | echo htmlentities($_POST['admin_email'] ?? ''); |
111 | if ($do_edits) { |
111 | if ($do_edits) { |
112 | try { |
112 | try { |
113 | OIDplus::config()->setValue('admin_email', $_POST['admin_email'] ?? ''); |
113 | OIDplus::config()->setValue('admin_email', $_POST['admin_email'] ?? ''); |
114 | } catch (\Exception $e) { |
114 | } catch (\Exception $e) { |
115 | $msg = $e->getMessage(); |
115 | $msg = $e->getMessage(); |
116 | $errors_happened = true; |
116 | $errors_happened = true; |
117 | } |
117 | } |
118 | } |
118 | } |
119 | } else { |
119 | } else { |
120 | echo htmlentities(OIDplus::config()->getValue('admin_email')); |
120 | echo htmlentities(OIDplus::config()->getValue('admin_email')); |
121 | } |
121 | } |
122 | 122 | ||
123 | echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>'; |
123 | echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>'; |
124 | } |
124 | } |
125 | step_admin_email($step++, $do_edits, $errors_happened); |
125 | step_admin_email($step++, $do_edits, $errors_happened); |
126 | 126 | ||
127 | # --- |
127 | # --- |
128 | 128 | ||
129 | /** |
129 | /** |
130 | * @param int $step |
130 | * @param int $step |
131 | * @param bool $do_edits |
131 | * @param bool $do_edits |
132 | * @param bool $errors_happened |
132 | * @param bool $errors_happened |
133 | * @return void |
133 | * @return void |
134 | * @throws OIDplusException |
134 | * @throws OIDplusException |
135 | * @throws \ViaThinkSoft\OIDplus\OIDplusConfigInitializationException |
135 | * @throws \ViaThinkSoft\OIDplus\OIDplusConfigInitializationException |
136 | */ |
136 | */ |
137 | function step_system_title(int $step, bool $do_edits, bool &$errors_happened) { |
137 | function step_system_title(int $step, bool $do_edits, bool &$errors_happened) { |
138 | echo '<h2>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</h2>'; |
138 | echo '<h2>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</h2>'; |
139 | echo '<input type="text" name="system_title" value="'; |
139 | echo '<input type="text" name="system_title" value="'; |
140 | 140 | ||
141 | $msg = ''; |
141 | $msg = ''; |
142 | if (isset($_POST['sent'])) { |
142 | if (isset($_POST['sent'])) { |
143 | echo htmlentities($_POST['system_title'] ?? ''); |
143 | echo htmlentities($_POST['system_title'] ?? ''); |
144 | if ($do_edits) { |
144 | if ($do_edits) { |
145 | try { |
145 | try { |
146 | OIDplus::config()->setValue('system_title', $_POST['system_title'] ?? ''); |
146 | OIDplus::config()->setValue('system_title', $_POST['system_title'] ?? ''); |
147 | } catch (\Exception $e) { |
147 | } catch (\Exception $e) { |
148 | $msg = $e->getMessage(); |
148 | $msg = $e->getMessage(); |
149 | $errors_happened = true; |
149 | $errors_happened = true; |
150 | } |
150 | } |
151 | } |
151 | } |
152 | } else { |
152 | } else { |
153 | echo htmlentities(OIDplus::config()->getValue('system_title')); |
153 | echo htmlentities(OIDplus::config()->getValue('system_title')); |
154 | } |
154 | } |
155 | 155 | ||
156 | echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>'; |
156 | echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>'; |
157 | } |
157 | } |
158 | step_system_title($step++, $do_edits, $errors_happened); |
158 | step_system_title($step++, $do_edits, $errors_happened); |
159 | 159 | ||
160 | # --- |
160 | # --- |
161 | 161 | ||
162 | foreach (OIDplus::getAllPlugins() as $plugin) { |
162 | foreach (OIDplus::getAllPlugins() as $plugin) { |
163 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1) { |
163 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1) { |
164 | $plugin->oobeEntry($step++, $do_edits, $errors_happened); |
164 | $plugin->oobeEntry($step++, $do_edits, $errors_happened); |
165 | } |
165 | } |
166 | } |
166 | } |
167 | 167 | ||
168 | # --- |
168 | # --- |
169 | 169 | ||
170 | echo '<h2>'._L('Step %1: Save settings and start OIDplus',$step).'</h2>'; |
170 | echo '<h2>'._L('Step %1: Save settings and start OIDplus',$step).'</h2>'; |
171 | echo '<input type="submit" value="'._L('Save and start OIDplus!').'">'; |
171 | echo '<input type="submit" value="'._L('Save and start OIDplus!').'">'; |
172 | echo '</form>'; |
172 | echo '</form>'; |
173 | 173 | ||
174 | $pki_status = OIDplus::getPkiStatus(); |
174 | $pki_status = OIDplus::getPkiStatus(); |
175 | 175 | ||
176 | if ($pki_status) { |
176 | if ($pki_status) { |
177 | 177 | ||
178 | echo '<h2>'._L('Your OIDplus system ID (derived from the public key) is:').'</h2>'; |
178 | echo '<h2>'._L('Your OIDplus system ID (derived from the public key) is:').'</h2>'; |
179 | 179 | ||
180 | echo '<b>'; |
180 | echo '<b>'; |
181 | $sysid_oid = OIDplus::getSystemId(true); |
181 | $sysid_oid = OIDplus::getSystemId(true); |
182 | if (!$sysid_oid) $sysid_oid = _L('Unknown!'); |
182 | if (!$sysid_oid) $sysid_oid = _L('Unknown!'); |
183 | echo htmlentities($sysid_oid); |
183 | echo htmlentities($sysid_oid); |
184 | echo '</b>'; |
184 | echo '</b>'; |
185 | 185 | ||
186 | echo '<h2>'._L('Your public key is:').'</h2>'; |
186 | echo '<h2>'._L('Your public key is:').'</h2>'; |
187 | 187 | ||
188 | $val = OIDplus::getSystemPublicKey(); |
188 | $val = OIDplus::getSystemPublicKey(); |
189 | if ($val) { |
189 | if ($val) { |
190 | echo '<pre>'.htmlentities($val).'</pre>'; |
190 | echo '<pre>'.htmlentities($val).'</pre>'; |
191 | } else { |
191 | } else { |
192 | echo '<p>'._L('Private/Public key creation failed').'</p>'; |
192 | echo '<p>'._L('Private/Public key creation failed').'</p>'; |
193 | } |
193 | } |
194 | 194 | ||
195 | } |
195 | } |
196 | 196 | ||
197 | echo '<br><br><br>'; // because of iPhone Safari |
197 | echo '<br><br><br>'; // because of iPhone Safari |
198 | 198 | ||
199 | echo '</body>'; |
199 | echo '</body>'; |
200 | 200 | ||
201 | echo '</html>'; |
201 | echo '</html>'; |
202 | 202 | ||
203 | $cont = ob_get_contents(); |
203 | $cont = ob_get_contents(); |
- | 204 | if (!$cont) $cont = ''; |
|
204 | ob_end_clean(); |
205 | ob_end_clean(); |
205 | 206 | ||
206 | if ($do_edits && !$errors_happened) { |
207 | if ($do_edits && !$errors_happened) { |
207 | OIDplus::config()->setValue('oobe_main_done', '1'); |
208 | OIDplus::config()->setValue('oobe_main_done', '1'); |
208 | OIDplus::invoke_shutdown(); |
209 | OIDplus::invoke_shutdown(); |
209 | header('Location:../../../../'); |
210 | header('Location:../../../../'); |
210 | } else { |
211 | } else { |
211 | $page_title_1 = _L('OIDplus Setup'); |
212 | $page_title_1 = _L('OIDplus Setup'); |
212 | $page_title_2 = _L('Initial settings'); |
213 | $page_title_2 = _L('Initial settings'); |
213 | $static_icon = 'img/main_icon.png'; |
214 | $static_icon = 'img/main_icon.png'; |
214 | $static_content = $cont; |
215 | $static_content = $cont; |
215 | $extra_head_tags = array(); |
216 | $extra_head_tags = array(); |
216 | $extra_head_tags[] = '<meta name="robots" content="noindex">'; |
217 | $extra_head_tags[] = '<meta name="robots" content="noindex">'; |
217 | 218 | ||
218 | $cont = OIDplus::gui()->showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags); |
219 | $cont = OIDplus::gui()->showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags); |
219 | 220 | ||
220 | OIDplus::invoke_shutdown(); |
221 | OIDplus::invoke_shutdown(); |
221 | 222 | ||
222 | echo $cont; |
223 | echo $cont; |
223 | } |
224 | } |
224 | 225 |