Subversion Repositories oidplus

Rev

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