Subversion Repositories oidplus

Rev

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