Rev 504 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
139 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
139 | daniel-mar | 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); |
||
440 | daniel-mar | 27 | set_exception_handler(array('OIDplusGui', 'html_exception_handler')); |
139 | daniel-mar | 28 | |
29 | ob_start(); |
||
30 | |||
31 | $step = 1; |
||
32 | $errors_happened = false; |
||
157 | daniel-mar | 33 | $edits_possible = true; |
139 | daniel-mar | 34 | |
362 | daniel-mar | 35 | echo '<!DOCTYPE html>'; |
504 | daniel-mar | 36 | echo '<html lang="'.substr(OIDplus::getCurrentLang(),0,2).'">'; |
139 | daniel-mar | 37 | |
362 | daniel-mar | 38 | echo '<head>'; |
39 | echo ' <title>'._L('OIDplus Setup').'</title>'; |
||
40 | echo ' <meta name="robots" content="noindex">'; |
||
41 | echo ' <meta name="viewport" content="width=device-width, initial-scale=1.0">'; |
||
364 | daniel-mar | 42 | echo ' <link rel="stylesheet" href="../../../setup/setup.min.css.php">'; |
504 | daniel-mar | 43 | echo ' <link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico.php">'; |
362 | daniel-mar | 44 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) { |
45 | echo ' <script src="https://www.google.com/recaptcha/api.js"></script>'; |
||
46 | } |
||
47 | echo '</head>'; |
||
139 | daniel-mar | 48 | |
362 | daniel-mar | 49 | echo '<body>'; |
139 | daniel-mar | 50 | |
362 | daniel-mar | 51 | echo '<h1>'._L('OIDplus Setup - Initial Settings').'</h1>'; |
139 | daniel-mar | 52 | |
362 | daniel-mar | 53 | OIDplus::handleLangArgument(); |
54 | echo OIDplusGui::getLanguageBox(null, false); |
||
139 | daniel-mar | 55 | |
362 | daniel-mar | 56 | echo '<p>'._L('If you can read this, then your database login credentials are correct.').'</p>'; |
139 | daniel-mar | 57 | |
362 | daniel-mar | 58 | 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>'; |
139 | daniel-mar | 59 | |
362 | daniel-mar | 60 | echo '<form method="POST" action="oobe.php">'; |
61 | echo '<input type="hidden" name="sent" value="1">'; |
||
62 | |||
261 | daniel-mar | 63 | if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) { |
362 | daniel-mar | 64 | echo '<p><u>'._L('Step %1: Solve CAPTCHA',$step++).'</u></p>'; |
157 | daniel-mar | 65 | echo '<noscript>'; |
362 | daniel-mar | 66 | echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>'; |
157 | daniel-mar | 67 | echo '</noscript>'; |
261 | daniel-mar | 68 | echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>'; |
362 | daniel-mar | 69 | echo '<p>'._L('Before logging in, please solve the following CAPTCHA').'</p>'; |
496 | daniel-mar | 70 | echo '<p>'._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').'</p>'; |
261 | daniel-mar | 71 | echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>'; |
157 | daniel-mar | 72 | |
73 | if (isset($_REQUEST['sent'])) { |
||
261 | daniel-mar | 74 | $secret=OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', ''); |
157 | daniel-mar | 75 | $response=$_POST["g-recaptcha-response"]; |
76 | $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}"); |
||
77 | $captcha_success=json_decode($verify); |
||
78 | if ($captcha_success->success==false) { |
||
360 | daniel-mar | 79 | echo '<p><font color="red"><b>CAPTCHA not successfully verified</b></font></p>'; |
157 | daniel-mar | 80 | $errors_happened = true; |
81 | $edits_possible = false; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
362 | daniel-mar | 86 | echo '<p><u>'._L('Step %1: Authenticate',$step++).'</u></p>'; |
139 | daniel-mar | 87 | |
415 | daniel-mar | 88 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
139 | daniel-mar | 89 | |
415 | daniel-mar | 90 | echo '<p><font color="green">You are already logged in as administrator.</font></p>'; |
139 | daniel-mar | 91 | |
415 | daniel-mar | 92 | } else { |
93 | |||
94 | echo '<p>'._L('Please enter the administrator password you have entered before.').'</p>'; |
||
95 | |||
496 | daniel-mar | 96 | echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath().'setup/">'._L('Forgot password?').'</a>) '; |
415 | daniel-mar | 97 | |
98 | if (isset($_REQUEST['sent'])) { |
||
99 | if (!OIDplus::authUtils()->adminCheckPassword($_REQUEST['admin_password'])) { |
||
100 | $errors_happened = true; |
||
101 | $edits_possible = false; |
||
102 | echo '<font color="red"><b>'._L('Wrong password').'</b></font>'; |
||
103 | } |
||
139 | daniel-mar | 104 | } |
415 | daniel-mar | 105 | |
106 | echo '</p>'; |
||
139 | daniel-mar | 107 | } |
108 | |||
157 | daniel-mar | 109 | #------------------------ |
110 | $do_edits = isset($_REQUEST['sent']) && $edits_possible;; |
||
111 | #------------------------ |
||
112 | |||
292 | daniel-mar | 113 | # --- |
139 | daniel-mar | 114 | |
292 | daniel-mar | 115 | function step_admin_email($step, $do_edits, &$errors_happened) { |
362 | daniel-mar | 116 | echo '<p><u>'._L('Step %1: Please enter the email address of the system administrator',$step).'</u></p>'; |
292 | daniel-mar | 117 | echo '<input type="text" name="admin_email" value="'; |
139 | daniel-mar | 118 | |
292 | daniel-mar | 119 | $msg = ''; |
139 | daniel-mar | 120 | if (isset($_REQUEST['sent'])) { |
292 | daniel-mar | 121 | echo htmlentities($_REQUEST['admin_email']); |
122 | if ($do_edits) { |
||
123 | try { |
||
124 | OIDplus::config()->setValue('admin_email', $_REQUEST['admin_email']); |
||
125 | } catch (Exception $e) { |
||
126 | $msg = $e->getMessage(); |
||
127 | $errors_happened = true; |
||
128 | } |
||
139 | daniel-mar | 129 | } |
130 | } else { |
||
292 | daniel-mar | 131 | echo htmlentities(OIDplus::config()->getValue('admin_email')); |
139 | daniel-mar | 132 | } |
133 | |||
292 | daniel-mar | 134 | echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>'; |
139 | daniel-mar | 135 | } |
292 | daniel-mar | 136 | step_admin_email($step++, $do_edits, $errors_happened); |
139 | daniel-mar | 137 | |
292 | daniel-mar | 138 | # --- |
139 | daniel-mar | 139 | |
292 | daniel-mar | 140 | function step_system_title($step, $do_edits, &$errors_happened) { |
362 | daniel-mar | 141 | echo '<p><u>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</u></p>'; |
292 | daniel-mar | 142 | echo '<input type="text" name="system_title" value="'; |
139 | daniel-mar | 143 | |
292 | daniel-mar | 144 | $msg = ''; |
139 | daniel-mar | 145 | if (isset($_REQUEST['sent'])) { |
292 | daniel-mar | 146 | echo htmlentities($_REQUEST['system_title']); |
147 | if ($do_edits) { |
||
148 | try { |
||
149 | OIDplus::config()->setValue('system_title', $_REQUEST['system_title']); |
||
150 | } catch (Exception $e) { |
||
151 | $msg = $e->getMessage(); |
||
152 | $errors_happened = true; |
||
153 | } |
||
139 | daniel-mar | 154 | } |
155 | } else { |
||
292 | daniel-mar | 156 | echo htmlentities(OIDplus::config()->getValue('system_title')); |
139 | daniel-mar | 157 | } |
158 | |||
292 | daniel-mar | 159 | echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>'; |
160 | } |
||
161 | step_system_title($step++, $do_edits, $errors_happened); |
||
139 | daniel-mar | 162 | |
292 | daniel-mar | 163 | # --- |
139 | daniel-mar | 164 | |
292 | daniel-mar | 165 | foreach (OIDplus::getPagePlugins() as $plugin) { |
166 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) { |
||
167 | $plugin->oobeEntry($step++, $do_edits, $errors_happened); |
||
139 | daniel-mar | 168 | } |
169 | } |
||
170 | |||
292 | daniel-mar | 171 | # --- |
139 | daniel-mar | 172 | |
362 | daniel-mar | 173 | echo '<p><u>'._L('Step %1: Save settings and start OIDplus',$step).'</u></p>'; |
174 | echo '<input type="submit" value="'._L('Save and start OIDplus!').'">'; |
||
292 | daniel-mar | 175 | echo '</form>'; |
139 | daniel-mar | 176 | |
292 | daniel-mar | 177 | $pki_status = OIDplus::getPkiStatus(); |
139 | daniel-mar | 178 | |
239 | daniel-mar | 179 | if ($pki_status) { |
139 | daniel-mar | 180 | |
362 | daniel-mar | 181 | echo '<p><u>'._L('Your OIDplus system ID (derived from the public key) is:').'</u></p>'; |
139 | daniel-mar | 182 | |
362 | daniel-mar | 183 | echo '<b>'; |
184 | $sysid_oid = OIDplus::getSystemId(true); |
||
185 | if (!$sysid_oid) $sysid_oid = _L('Unknown!'); |
||
186 | echo htmlentities($sysid_oid); |
||
187 | echo '</b>'; |
||
139 | daniel-mar | 188 | |
362 | daniel-mar | 189 | echo '<p><u>'._L('Your public key is:').'</u></p>'; |
139 | daniel-mar | 190 | |
362 | daniel-mar | 191 | $val = OIDplus::config()->getValue('oidplus_public_key'); |
192 | if ($val) { |
||
193 | echo '<pre>'.htmlentities($val).'</pre>'; |
||
194 | } else { |
||
195 | echo '<p>'._L('Private/Public key creation failed').'</p>'; |
||
196 | } |
||
139 | daniel-mar | 197 | |
198 | } |
||
199 | |||
379 | daniel-mar | 200 | echo '<br><br><br>'; // because of iPhone Safari |
362 | daniel-mar | 201 | |
292 | daniel-mar | 202 | echo '</body>'; |
139 | daniel-mar | 203 | |
292 | daniel-mar | 204 | echo '</html>'; |
139 | daniel-mar | 205 | |
206 | $cont = ob_get_contents(); |
||
207 | ob_end_clean(); |
||
208 | |||
209 | if ($do_edits && !$errors_happened) { |
||
362 | daniel-mar | 210 | OIDplus::config()->setValue('oobe_main_done', '1'); |
139 | daniel-mar | 211 | header('Location:../../../'); |
212 | } else { |
||
213 | echo $cont; |
||
379 | daniel-mar | 214 | } |