Subversion Repositories oidplus

Rev

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