Subversion Repositories oidplus

Rev

Rev 1056 | Rev 1130 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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. use ViaThinkSoft\OIDplus\OIDplus;
  21. use ViaThinkSoft\OIDplus\OIDplusGui;
  22. use ViaThinkSoft\OIDplus\OIDplusException;
  23.  
  24. require_once __DIR__ . '/../../../../includes/oidplus.inc.php';
  25.  
  26. set_exception_handler(array(OIDplusGui::class, 'html_exception_handler'));
  27.  
  28. ob_start(); // allow cookie headers to be sent
  29.  
  30. header('Content-Type:text/html; charset=UTF-8');
  31.  
  32. OIDplus::init(true);
  33. set_exception_handler(array(OIDplusGui::class, 'html_exception_handler'));
  34.  
  35. if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminOOBE', false)) {
  36.         throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
  37. }
  38.  
  39. OIDplus::handleLangArgument();
  40.  
  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.  
  54. if (OIDplus::getActiveCaptchaPlugin()->isVisible()) echo '<h2>'._L('Step %1: Solve CAPTCHA',$step++).'</h2>';
  55. if (isset($_POST['sent'])) {
  56.         try {
  57.                 OIDplus::getActiveCaptchaPlugin()->captchaVerify($_POST);
  58.         } catch (\Exception $e) {
  59.                 echo '<p><font color="red"><b>'.htmlentities($e->getMessage()).'</b></font></p>';
  60.                 $errors_happened = true;
  61.                 $edits_possible = false;
  62.         }
  63. }
  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'));
  65.  
  66. echo '<h2>'._L('Step %1: Authenticate',$step++).'</h2>';
  67.  
  68. if (OIDplus::authUtils()->isAdminLoggedIn()) {
  69.  
  70.         echo '<p><font color="green">'._L('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.  
  76.         echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Forgot password?').'</a>) ';
  77.  
  78.         if (isset($_POST['sent'])) {
  79.                 if (!OIDplus::authUtils()->adminCheckPassword(isset($_POST['admin_password']) ? $_POST['admin_password'] : '')) {
  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. #------------------------
  90. $do_edits = isset($_POST['sent']) && $edits_possible;
  91. #------------------------
  92.  
  93. # ---
  94.  
  95. function step_admin_email($step, $do_edits, &$errors_happened) {
  96.         echo '<h2>'._L('Step %1: Please enter the email address of the system administrator',$step).'</h2>';
  97.         echo '<input type="text" name="admin_email" value="';
  98.  
  99.         $msg = '';
  100.         if (isset($_POST['sent'])) {
  101.                 echo htmlentities(isset($_POST['admin_email']) ? $_POST['admin_email'] : '');
  102.                 if ($do_edits) {
  103.                         try {
  104.                                 OIDplus::config()->setValue('admin_email', isset($_POST['admin_email']) ? $_POST['admin_email'] : '');
  105.                         } catch (\Exception $e) {
  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) {
  121.         echo '<h2>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</h2>';
  122.         echo '<input type="text" name="system_title" value="';
  123.  
  124.         $msg = '';
  125.         if (isset($_POST['sent'])) {
  126.                 echo htmlentities(isset($_POST['system_title']) ? $_POST['system_title'] : '');
  127.                 if ($do_edits) {
  128.                         try {
  129.                                 OIDplus::config()->setValue('system_title', isset($_POST['system_title']) ? $_POST['system_title'] : '');
  130.                         } catch (\Exception $e) {
  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.  
  145. foreach (OIDplus::getAllPlugins() as $plugin) {
  146.         if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) {
  147.                 $plugin->oobeEntry($step++, $do_edits, $errors_happened); /** @phpstan-ignore-line */
  148.         }
  149. }
  150.  
  151. # ---
  152.  
  153. echo '<h2>'._L('Step %1: Save settings and start OIDplus',$step).'</h2>';
  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.  
  161.         echo '<h2>'._L('Your OIDplus system ID (derived from the public key) is:').'</h2>';
  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.  
  169.         echo '<h2>'._L('Your public key is:').'</h2>';
  170.  
  171.         $val = OIDplus::getSystemPublicKey();
  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');
  191.         OIDplus::invoke_shutdown();
  192.         header('Location:../../../../');
  193. } else {
  194.         $page_title_1 = _L('OIDplus Setup');
  195.         $page_title_2 = _L('Initial settings');
  196.         $static_icon = 'img/main_icon.png';
  197.         $static_content = $cont;
  198.         $extra_head_tags = array();
  199.         $extra_head_tags[] = '<meta name="robots" content="noindex">';
  200.  
  201.         $cont = OIDplus::gui()->showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags);
  202.  
  203.         OIDplus::invoke_shutdown();
  204.  
  205.         echo $cont;
  206. }
  207.