Subversion Repositories oidplus

Rev

Rev 1031 | 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 - 2022 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\OIDplusDatabasePlugin;
  22. use ViaThinkSoft\OIDplus\OIDplusSqlSlangPlugin;
  23. use ViaThinkSoft\OIDplus\OIDplusCaptchaPlugin;
  24.  
  25. require_once __DIR__ . '/../includes/oidplus.inc.php';
  26.  
  27. define('BASECONFIG_FILE', 'userdata/baseconfig/config.inc.php');
  28. $already_setup = file_exists(__DIR__.'/../'.BASECONFIG_FILE);
  29.  
  30. OIDplus::handleLangArgument();
  31.  
  32. echo '<!DOCTYPE html>';
  33. echo '<html lang="'.substr(OIDplus::getCurrentLang(),0,2).'">';
  34.  
  35. echo '<head>';
  36. echo '  <title>'._L('OIDplus Setup').'</title>';
  37. echo '  <meta name="robots" content="noindex">';
  38. echo '  <meta name="viewport" content="width=device-width, initial-scale=1.0">';
  39. echo '  <link rel="stylesheet" href="setup.min.css.php">';
  40. echo '  <link rel="shortcut icon" type="image/x-icon" href="../favicon.ico.php">';
  41. echo '  <script src="setup.min.js.php" type="text/javascript"></script>';
  42. echo '</head>';
  43.  
  44. echo '<body>';
  45.  
  46. echo '<h1>'._L('OIDplus Setup - Configuration File Generator').'</h1>';
  47.  
  48. echo '<noscript>';
  49. echo '<h2>'._L('Please enable JavaScript in order to use setup!').'</h2>';
  50. echo '</noscript>';
  51.  
  52. echo '<span id="setupPageContent" style="display:None">';
  53.  
  54. echo OIDplus::gui()->getLanguageBox(null, false);
  55.  
  56. echo '<p>';
  57. if ($already_setup) {
  58.         echo _L('This assistant will help you updating the file <b>%1</b>.',BASECONFIG_FILE);
  59. } else {
  60.         echo _L('Thank you very much for choosing OIDplus!');
  61.         echo ' ';
  62.         echo _L('This setup assistant will help you creating the file <b>%1</b>.',BASECONFIG_FILE);
  63. }
  64. echo ' ';
  65. echo _L('This assistant does not automatically write to this file. Instead, you need to copy-paste the contents into the file.');
  66. echo ' ';
  67. if ($already_setup) {
  68.         echo _L('Later, you can change the config file by hand, or run this assistant again.');
  69. } else {
  70.         echo _L('Once OIDplus setup is finished, you can change the config file by hand, or run this setup assistant again.');
  71. }
  72. echo '</p>';
  73.  
  74. echo '<h2 id="systemCheckCaption" style="display:none">'._L('System check').'</h2>';
  75. echo '<div id="dirAccessWarning"></div>';
  76.  
  77. echo '<div id="step1">';
  78. echo '<h2>'._L('Step %1: Enter setup information',1).'</h2>';
  79.  
  80. // ----------------------------------------
  81.  
  82. echo '<h3>'._L('Administrator password').'</h3>';
  83.  
  84. echo '<form id="step1_form">';
  85. echo '<p>'._L('Which admin password do you want?').'<br><input id="admin_password" type="password" autocomplete="new-password" onkeypress="rebuild()" onkeyup="rebuild()"> <span id="password_warn"></span></p>';
  86. echo '<p>'._L('Please repeat the password input:').'<br><input id="admin_password2" type="password" autocomplete="new-password" onkeypress="rebuild()" onkeyup="rebuild()"> <span id="password_warn2"></span></p>';
  87.  
  88. // ----------------------------------------
  89.  
  90. echo '<h3>'._L('Database connectivity').'</h3>';
  91.  
  92. if (file_exists(__DIR__ . '/../doc/database_connectivity_diagram.png')) {
  93.         echo '<p><a href="../doc/database_connectivity_diagram.png" target="_blank"><img src="../doc/database_connectivity_diagram.png" width="20%" alt="'._L('Database connectivity diagram').'" title="'._L('Database connectivity diagram').'"></a></p>';
  94. }
  95.  
  96. echo _L('Database plugin').': <select name="db_plugin" onChange="dbplugin_changed()" id="db_plugin">';
  97.  
  98. OIDplus::registerAllPlugins('database', OIDplusDatabasePlugin::class, array(OIDplus::class,'registerDatabasePlugin'));
  99. foreach (OIDplus::getDatabasePlugins() as $plugin) {
  100.         $selected = $plugin::id() == 'MySQL' ? ' selected="true"' : '';
  101.         echo '<option value="'.htmlentities($plugin::id()).'"'.$selected.'>'.htmlentities($plugin::id()).'</option>';
  102. }
  103.  
  104. echo '</select>';
  105.  
  106. echo '<div style="margin-left:50px">';
  107.  
  108. OIDplus::registerAllPlugins('sqlSlang', OIDplusSqlSlangPlugin::class, array(OIDplus::class,'registerSqlSlangPlugin'));
  109. $sql_slang_selection = array();
  110. foreach (OIDplus::getSqlSlangPlugins() as $plugin) {
  111.         $slang_id = $plugin::id();
  112.         $pluginManifest = $plugin->getManifest();
  113.         $human_friendly_name = empty($pluginManifest->getName()) ? get_class($plugin) : $pluginManifest->getName();
  114.         $sql_slang_selection[] = '<option value="'.$slang_id.'">'.$human_friendly_name.'</option>';
  115. }
  116. $sql_slang_selection = implode("\n", $sql_slang_selection);
  117.  
  118. $found_db_plugins = 0;
  119. //OIDplus::registerAllPlugins('database', OIDplusDatabasePlugin::class, array(OIDplus::class,'registerDatabasePlugin'));
  120. foreach (OIDplus::getDatabasePlugins() as $plugin) {
  121.         $found_db_plugins++;
  122.         $cont = $plugin->setupHTML();
  123.         $cont = str_replace('<!-- %SQL_SLANG_SELECTION% -->', $sql_slang_selection, $cont);
  124.         echo $cont;
  125. }
  126.  
  127. if ($found_db_plugins == 0) {
  128.         echo '<p><font color="red">'._L('ERROR: No database plugins were found! You CANNOT use OIDplus without database connection.').'</font></p>';
  129. }
  130.  
  131. echo '</div>';
  132.  
  133. echo '<p>'._L('Table name prefix (e.g. <b>oidplus_</b>)').':<br><input id="tablename_prefix" type="text" value="oidplus_" onkeypress="rebuild()" onkeyup="rebuild()"></p>';
  134.  
  135. // ----------------------------------------
  136.  
  137. echo '<h3>'._L('CAPTCHA').'</h3>';
  138.  
  139. // TODO: Add a small explanation here, in case somebody does not know what CAPTCHA is
  140.  
  141. echo _L('CAPTCHA plugin').': <select name="captcha_plugin" onChange="captchaplugin_changed()" id="captcha_plugin">';
  142.  
  143. OIDplus::registerAllPlugins('captcha', OIDplusCaptchaPlugin::class, array(OIDplus::class,'registerCaptchaPlugin'));
  144. foreach (OIDplus::getCaptchaPlugins() as $plugin) {
  145.         $selected = strtolower($plugin::id()) === strtolower('None') ? ' selected="true"' : ''; // select "None" by default
  146.         echo '<option value="'.htmlentities($plugin::id()).'"'.$selected.'>'.htmlentities($plugin::id()).'</option>';
  147. }
  148.  
  149. echo '</select>';
  150.  
  151. echo '<div style="margin-left:50px">';
  152.  
  153. $found_captcha_plugins = 0;
  154. foreach (OIDplus::getCaptchaPlugins() as $plugin) {
  155.         $found_captcha_plugins++;
  156.         $cont = $plugin->setupHTML();
  157.         echo $cont;
  158. }
  159.  
  160. if ($found_captcha_plugins == 0) {
  161.         echo '<p><font color="red">'._L('ERROR: No CAPTCHA plugins were found! You CANNOT use OIDplus without the "%1" CAPTCHA plugin.','None').'</font></p>';
  162. }
  163.  
  164. echo '</div>';
  165.  
  166. // ----------------------------------------
  167.  
  168. $is_ssl = OIDplus::isSSL();
  169. echo '<h3>'._L('Secure connection (HTTPS)').'</h3>';
  170. echo '<p>'._L('Enforcement of a secure connection:').'<br><select name="enforce_ssl" id="enforce_ssl" onchange="rebuild()">';
  171. echo '<option value="OIDplus::ENFORCE_SSL_NO">'._L('No SSL available (don\'t redirect)').'</option>';
  172. echo '<option value="OIDplus::ENFORCE_SSL_YES"'.($is_ssl ? ' selected' : '').'>'._L('Enforce SSL (always redirect)').'</option>';
  173. echo '<option value="OIDplus::ENFORCE_SSL_AUTO"'.(!$is_ssl ? ' selected' : '').'>'._L('Intelligent SSL detection (redirect if port 443 is open)').'</option>';
  174. echo '</select></p>';
  175.  
  176. // ----------------------------------------
  177.  
  178. echo '<h3>'._L('Public URL of this system (Canonical URL)').'</h3>';
  179.  
  180. echo '<p><input id="canonical_url" type="text" value="'.htmlentities(OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL)).'" onkeypress="rebuild()" onkeyup="rebuild()" style="width:550px"></p>';
  181.  
  182. // ----------------------------------------
  183.  
  184. echo '</form>';
  185. echo '</div>';
  186.  
  187. echo '<div id="step2">';
  188. echo '<h2>'._L('Step %1: Initialize database',2).'</h2>';
  189. if ($already_setup) {
  190.         echo '<p><input type="checkbox" id="step2_enable"> <label for="step2_enable"><font color="red">'._L('Re-Install database (all data will be deleted)').'</font></label></p>';
  191. }
  192. echo '<div id="step2_inner">';
  193. echo '<p>'._L('Please import one of the following SQL dumps in your database:').'</p>';
  194. echo '<p><ul>';
  195. echo '  <li><a href="struct_empty.sql.php" id="struct_1" target="_blank">'._L('Empty OIDplus database without example data').'</a><span id="struct_cli_1"></span><br><br></li>';
  196. echo '  <li><a href="struct_with_examples.sql.php" id="struct_2" target="_blank">'._L('OIDplus database with example data').'</a><span id="struct_cli_2"></span><br><br></li>';
  197. echo '</ul></p>';
  198. echo '<p><font color="red">'._L('Warning: Existing OIDplus data will be deleted during the initialization of the database.').'</font></p>';
  199. echo '</div>';
  200. if ($already_setup) {
  201.         echo '<script>';
  202.         echo '$("#step2_enable").click(function() {';
  203.         echo '    if ($(this).is(":checked")) {';
  204.         echo '        $("#step2_inner").show();';
  205.         echo '    } else {';
  206.         echo '        $("#step2_inner").hide();';
  207.         echo '    }';
  208.         echo '});';
  209.         echo '$("#step2_inner").hide();';
  210.         echo '</script>';
  211. }
  212. echo '</div>';
  213.  
  214. // ----------------------------------------
  215.  
  216. echo '<div id="step3">';
  217. echo '<h2>'._L('Step %1: Save %2 file',3,BASECONFIG_FILE).'</h2>';
  218. echo '<p>'._L('Save following contents into the file <b>%1</b>',BASECONFIG_FILE).'</p>';
  219. echo '<code><font color="darkblue"><div id="config"></div></font></code>';
  220. echo '<p><input type="button" value="'._L('Copy to clipboard').'" onClick="copyToClipboard(config)"></p>';
  221. echo '</div>';
  222.  
  223. // ----------------------------------------
  224.  
  225. echo '<div id="step4">';
  226. if ($already_setup) {
  227.         echo '<h2>'._L('Step %1: Start OIDplus',4).'</h2>';
  228. } else {
  229.         echo '<h2>'._L('Step %1: Continue to next step',4).'</h2>';
  230. }
  231. echo '<p><input type="button" onclick="window.location.href=\'../\'" value="'._L('Continue').'"></p>';
  232. echo '</div>';
  233.  
  234. echo '<br><br><br>'; // because of iPhone Safari
  235.  
  236. echo '</span>';
  237. echo '<script> $("#setupPageContent")[0].style.display = "Block"; </script>';
  238.  
  239. echo '</body>';
  240. echo '</html>';
  241.