Subversion Repositories oidplus

Rev

Rev 206 | 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. ?><!DOCTYPE html>
  35. <html lang="en">
  36.  
  37. <head>
  38.         <title>OIDplus Setup</title>
  39.         <meta name="robots" content="noindex">
  40.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  41.         <link rel="stylesheet" href="../../../setup/setup.css">
  42.         <?php
  43.         if (RECAPTCHA_ENABLED) {
  44.         ?>
  45.         <script src="https://www.google.com/recaptcha/api.js"></script>
  46.         <?php
  47.         }
  48.         ?>
  49. </head>
  50.  
  51. <body>
  52.  
  53. <h1>OIDplus Setup - Initial Settings</h1>
  54.  
  55. <p>Your database settings are correct.</p>
  56.  
  57. <p>The following settings need to be configured once.<br>
  58. After setup is complete, you can change all these settings if required.</p>
  59.  
  60. <form method="POST" action="registration.php">
  61. <input type="hidden" name="sent" value="1">
  62.  
  63. <?php
  64. if (RECAPTCHA_ENABLED) {
  65.         echo '<p><u>Step '.($step++).': Solve CAPTCHA</u></p>';
  66.         echo '<noscript>';
  67.         echo '<p><font color="red">You need to enable JavaScript to solve the CAPTCHA.</font></p>';
  68.         echo '</noscript>';
  69.         echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>';
  70.         echo '<p>Before logging in, please solve the following CAPTCHA</p>';
  71.         echo '<p>If the CAPTCHA does not work (e.g. because of wrong keys, please run <a href="<?php echo OIDplus::getSystemUrl(); ?>setup/">setup part 1</a> again or edit includes/config.inc.php).</p>';
  72.         echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>';
  73.  
  74.         if (isset($_REQUEST['sent'])) {
  75.                 $secret=RECAPTCHA_PRIVATE;
  76.                 $response=$_POST["g-recaptcha-response"];
  77.                 $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
  78.                 $captcha_success=json_decode($verify);
  79.                 if ($captcha_success->success==false) {
  80.                         echo '<p><font color="red"><b>CAPTCHA not sucessfully verified</b></font></p>';
  81.                         $errors_happened = true;
  82.                         $edits_possible = false;
  83.                 }
  84.         }
  85. }
  86. ?>
  87.  
  88. <p><u>Step <?php echo $step++; ?>: Authentificate</u></p>
  89.  
  90. <p>Please enter the administrator password you have entered before.</p>
  91.  
  92. <p><input type="password" name="admin_password" value=""> (<a href="<?php echo OIDplus::getSystemUrl(); ?>setup/">Forgot?</a>) <?php
  93.  
  94. if (isset($_REQUEST['sent'])) {
  95.         if (!OIDplusAuthUtils::adminCheckPassword($_REQUEST['admin_password'])) {
  96.                 $errors_happened = true;
  97.                 $edits_possible = false;
  98.                 echo '<font color="red"><b>Wrong password</b></font>';
  99.         }
  100. }
  101.  
  102. ?></p>
  103.  
  104. <?php
  105. #------------------------
  106. $do_edits = isset($_REQUEST['sent']) && $edits_possible;;
  107. #------------------------
  108. ?>
  109.  
  110. <p><u>Step <?php echo $step++; ?>: Please enter the email address of the system administrator</u></p>
  111.  
  112. <input type="text" name="admin_email" value="<?php
  113.  
  114. $msg = '';
  115. if (isset($_REQUEST['sent'])) {
  116.         echo htmlentities($_REQUEST['admin_email']);
  117.         if ($do_edits) {
  118.                 try {
  119.                         OIDplus::config()->setValue('admin_email', $_REQUEST['admin_email']);
  120.                 } catch (Exception $e) {
  121.                         $msg = $e->getMessage();
  122.                         $errors_happened = true;
  123.                 }
  124.         }
  125. } else {
  126.         echo htmlentities(OIDplus::config()->getValue('admin_email'));
  127. }
  128.  
  129. ?>" size="25"><?php echo ' <font color="red"><b>'.$msg.'</b></font>'; ?>
  130.  
  131. <p><u>Step <?php echo $step++; ?>: What title should your Registration Authority / OIDplus instance have?</u></p>
  132.  
  133. <input type="text" name="system_title" value="<?php
  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. ?>" size="50"><?php echo ' <font color="red"><b>'.$msg.'</b></font>'; ?>
  151.  
  152. <p><u>Step <?php echo $step++; ?>: Enable/Disable object type plugins</u></p>
  153.  
  154. <p>Which object types do you want to manage using OIDplus?</p>
  155.  
  156. <?php
  157.  
  158. $enabled_ary = array();
  159.  
  160. foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  161.         echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
  162.         if (isset($_REQUEST['sent'])) {
  163.                 if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
  164.                         echo ' checked';
  165.                         $enabled_ary[] = $ot::ns();
  166.                 }
  167.         } else {
  168.                 echo ' checked';
  169.         }
  170.         echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
  171. }
  172.  
  173. foreach (OIDplus::getDisabledObjectTypes() as $ot) {
  174.         echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
  175.         if (isset($_REQUEST['sent'])) {
  176.                 if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
  177.                         echo ' checked';
  178.                         $enabled_ary[] = $ot::ns();
  179.                 }
  180.         } else {
  181.                 echo ''; // <-- difference
  182.         }
  183.         echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
  184. }
  185.  
  186. $msg = '';
  187. if ($do_edits) {
  188.         try {
  189.                 OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
  190.         } catch (Exception $e) {
  191.                 $msg = $e->getMessage();
  192.                 $errors_happened = true;
  193.         }
  194. }
  195.  
  196. echo ' <font color="red"><b>'.$msg.'</b></font>';
  197.  
  198. echo '<p><u>Step '.($step++).': System registration and automatic Publishing</u></p>';
  199.  
  200. echo file_get_contents(__DIR__ . '/info.tpl');
  201.  
  202. if (!function_exists('openssl_sign')) {
  203.         echo '<p>OpenSSL plugin is missing in PHP. You cannot register your OIDplus instance.</p>';
  204. } else {
  205.  
  206.         echo '<p>Privacy level:</p><select name="reg_privacy" id="reg_privacy">';
  207.  
  208.         # ---
  209.  
  210.         echo '<option value="0"';
  211.         if (isset($_REQUEST['sent'])) {
  212.                 if (isset($_REQUEST['reg_privacy']) && ($_REQUEST['reg_privacy'] == 0)) echo ' selected';
  213.         } else {
  214.                 if ((OIDplus::config()->getValue('reg_privacy') == 0) || !OIDplus::config()->getValue('reg_wizard_done')) {
  215.                         echo ' selected';
  216.                 } else {
  217.                         echo '';
  218.                 }
  219.         }
  220.         echo '>0 = Register to directory service and automatically publish RA/OID data at oid-info.com</option>';
  221.  
  222.         # ---
  223.  
  224.         echo '<option value="1"';
  225.         if (isset($_REQUEST['sent'])) {
  226.                 if (isset($_REQUEST['reg_privacy']) && ($_REQUEST['reg_privacy'] == 1)) echo ' selected';
  227.         } else {
  228.                 if ((OIDplus::config()->getValue('reg_privacy') == 1)) {
  229.                         echo ' selected';
  230.                 } else {
  231.                         echo '';
  232.                 }
  233.         }
  234.         echo '>1 = Only register to directory service</option>';
  235.  
  236.         # ---
  237.  
  238.         echo '<option value="2"';
  239.         if (isset($_REQUEST['sent'])) {
  240.                 if (isset($_REQUEST['reg_privacy']) && ($_REQUEST['reg_privacy'] == 2)) echo ' selected';
  241.         } else {
  242.                 if ((OIDplus::config()->getValue('reg_privacy') == 2)) {
  243.                         echo ' selected';
  244.                 } else {
  245.                         echo '';
  246.                 }
  247.         }
  248.         echo '>2 = Hide system</option>';
  249.  
  250.         # ---
  251.  
  252.         echo '</select>';
  253.  
  254.         $msg = '';
  255.         if ($do_edits) {
  256.                 try {
  257.                         OIDplus::config()->setValue('reg_privacy', $_REQUEST['reg_privacy']);
  258.                 } catch (Exception $e) {
  259.                         $msg = $e->getMessage();
  260.                         $errors_happened = true;
  261.                 }
  262.         }
  263.         echo ' <font color="red"><b>'.$msg.'</b></font>';
  264.  
  265.         echo '<p><i>Privacy information:</i> This setting can always be changed in the administrator login / control panel.</p>';
  266.         // TODO: describe what data is transmitted or link to a privacy statement
  267. }
  268.  
  269. ?>
  270.  
  271. <p><u>Submit</u></p>
  272.  
  273. <input type="submit" value="Save and start OIDplus!">
  274.  
  275. </form>
  276.  
  277. <?php
  278.  
  279. if (function_exists('openssl_sign')) {
  280.  
  281. ?>
  282.  
  283. <p><u>Your OIDplus system ID (derived from the public key) is:</u></p>
  284.  
  285. 1.3.6.1.4.1.37476.30.9.<b><?php
  286. echo htmlentities(OIDplus::getSystemId());
  287. ?></b>
  288.  
  289. <p><u>Your public key is</u></p>
  290.  
  291. <?php
  292.  
  293. echo '<pre>'.htmlentities(OIDplus::config()->getValue('oidplus_public_key')).'</pre>';
  294.  
  295. }
  296.  
  297. ?>
  298.  
  299. </body>
  300.  
  301. </html>
  302.  
  303. <?php
  304.  
  305. $cont = ob_get_contents();
  306. ob_end_clean();
  307.  
  308. if ($do_edits && !$errors_happened)  {
  309.         OIDplus::config()->setValue('reg_wizard_done', '1');
  310.         header('Location:../../../');
  311. } else {
  312.         echo $cont;
  313. }
  314.