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