Subversion Repositories oidplus

Rev

Rev 440 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

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