Subversion Repositories oidplus

Rev

Rev 1033 | Rev 1055 | 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. ob_start(); // allow cookie headers to be sent
  27.  
  28. header('Content-Type:text/html; charset=UTF-8');
  29.  
  30. OIDplus::init(true);
  31. set_exception_handler(array(OIDplusGui::class, 'html_exception_handler'));
  32.  
  33. if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminOOBE', false)) {
  34.         throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
  35. }
  36.  
  37. ob_start();
  38.  
  39. $step = 1;
  40. $errors_happened = false;
  41. $edits_possible = true;
  42.  
  43. echo '<!DOCTYPE html>';
  44. echo '<html lang="'.substr(OIDplus::getCurrentLang(),0,2).'">';
  45.  
  46. echo '<head>';
  47. echo '  <title>'._L('OIDplus Setup').'</title>';
  48. echo '  <meta name="robots" content="noindex">';
  49. echo '  <meta name="viewport" content="width=device-width, initial-scale=1.0">';
  50. echo '  <script src="../../../../oidplus.min.js.php"></script>';
  51. echo '  <script src="../../../../polyfill.min.js.php"></script>';
  52. echo '  <link rel="stylesheet" href="../../../../setup/setup.min.css.php">';
  53. echo '  <link rel="shortcut icon" type="image/x-icon" href="../../../../favicon.ico.php">';
  54. echo '</head>';
  55.  
  56. echo '<body>';
  57.  
  58. echo '<h1>'._L('OIDplus Setup - Initial Settings').'</h1>';
  59.  
  60. OIDplus::handleLangArgument();
  61. echo OIDplus::gui()->getLanguageBox(null, false);
  62.  
  63. echo '<p>'._L('If you can read this, then your database login credentials are correct.').'</p>';
  64.  
  65. 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>';
  66.  
  67. echo '<form method="POST" action="oobe.php">';
  68. echo '<input type="hidden" name="sent" value="1">';
  69.  
  70. if (OIDplus::getActiveCaptchaPlugin()->isVisible()) echo '<p><u>'._L('Step %1: Solve CAPTCHA',$step++).'</u></p>';
  71. if (isset($_POST['sent'])) {
  72.         try {
  73.                 OIDplus::getActiveCaptchaPlugin()->captchaVerify($_POST);
  74.         } catch (\Exception $e) {
  75.                 echo '<p><font color="red"><b>'.htmlentities($e->getMessage()).'</b></font></p>';
  76.                 $errors_happened = true;
  77.                 $edits_possible = false;
  78.         }
  79. }
  80. 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'));
  81.  
  82. echo '<p><u>'._L('Step %1: Authenticate',$step++).'</u></p>';
  83.  
  84. if (OIDplus::authUtils()->isAdminLoggedIn()) {
  85.  
  86.         echo '<p><font color="green">You are already logged in as administrator.</font></p>';
  87.  
  88. } else {
  89.  
  90.         echo '<p>'._L('Please enter the administrator password you have entered before.').'</p>';
  91.  
  92.         echo '<p><input type="password" name="admin_password" value=""> (<a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Forgot password?').'</a>) ';
  93.  
  94.         if (isset($_POST['sent'])) {
  95.                 if (!OIDplus::authUtils()->adminCheckPassword(isset($_POST['admin_password']) ? $_POST['admin_password'] : '')) {
  96.                         $errors_happened = true;
  97.                         $edits_possible = false;
  98.                         echo '<font color="red"><b>'._L('Wrong password').'</b></font>';
  99.                 }
  100.         }
  101.  
  102.         echo '</p>';
  103. }
  104.  
  105. #------------------------
  106. $do_edits = isset($_POST['sent']) && $edits_possible;;
  107. #------------------------
  108.  
  109. # ---
  110.  
  111. function step_admin_email($step, $do_edits, &$errors_happened) {
  112.         echo '<p><u>'._L('Step %1: Please enter the email address of the system administrator',$step).'</u></p>';
  113.         echo '<input type="text" name="admin_email" value="';
  114.  
  115.         $msg = '';
  116.         if (isset($_POST['sent'])) {
  117.                 echo htmlentities(isset($_POST['admin_email']) ? $_POST['admin_email'] : '');
  118.                 if ($do_edits) {
  119.                         try {
  120.                                 OIDplus::config()->setValue('admin_email', isset($_POST['admin_email']) ? $_POST['admin_email'] : '');
  121.                         } catch (\Exception $e) {
  122.                                 $msg = $e->getMessage();
  123.                                 $errors_happened = true;
  124.                         }
  125.                 }
  126.         } else {
  127.                 echo htmlentities(OIDplus::config()->getValue('admin_email'));
  128.         }
  129.  
  130.         echo '" size="25"> <font color="red"><b>'.$msg.'</b></font>';
  131. }
  132. step_admin_email($step++, $do_edits, $errors_happened);
  133.  
  134. # ---
  135.  
  136. function step_system_title($step, $do_edits, &$errors_happened) {
  137.         echo '<p><u>'._L('Step %1: What title should your Registration Authority / OIDplus instance have?',$step).'</u></p>';
  138.         echo '<input type="text" name="system_title" value="';
  139.  
  140.         $msg = '';
  141.         if (isset($_POST['sent'])) {
  142.                 echo htmlentities(isset($_POST['system_title']) ? $_POST['system_title'] : '');
  143.                 if ($do_edits) {
  144.                         try {
  145.                                 OIDplus::config()->setValue('system_title', isset($_POST['system_title']) ? $_POST['system_title'] : '');
  146.                         } catch (\Exception $e) {
  147.                                 $msg = $e->getMessage();
  148.                                 $errors_happened = true;
  149.                         }
  150.                 }
  151.         } else {
  152.                 echo htmlentities(OIDplus::config()->getValue('system_title'));
  153.         }
  154.  
  155.         echo '" size="50"> <font color="red"><b>'.$msg.'</b></font>';
  156. }
  157. step_system_title($step++, $do_edits, $errors_happened);
  158.  
  159. # ---
  160.  
  161. foreach (OIDplus::getAllPlugins() as $plugin) {
  162.         if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) {
  163.                 $plugin->oobeEntry($step++, $do_edits, $errors_happened);
  164.         }
  165. }
  166.  
  167. # ---
  168.  
  169. echo '<p><u>'._L('Step %1: Save settings and start OIDplus',$step).'</u></p>';
  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.  
  177.         echo '<p><u>'._L('Your OIDplus system ID (derived from the public key) is:').'</u></p>';
  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.  
  185.         echo '<p><u>'._L('Your public key is:').'</u></p>';
  186.  
  187.         $val = OIDplus::getSystemPublicKey();
  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();
  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.         OIDplus::invoke_shutdown();
  211.         echo $cont;
  212. }
  213.