Subversion Repositories oidplus

Rev

Rev 1321 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. originHeaders(); // This is important so that http://.../setup/ can query https://.../setup/ in order to do an SSL availability check
  28.  
  29. const BASECONFIG_FILE_OLD = 'includes/config.inc.php';
  30. const BASECONFIG_FILE_NEW = 'userdata/baseconfig/config.inc.php';
  31. $existing_config = '';
  32. if (file_exists(__DIR__.'/../'.BASECONFIG_FILE_OLD)) $existing_config = BASECONFIG_FILE_OLD;
  33. if (file_exists(__DIR__.'/../'.BASECONFIG_FILE_NEW)) $existing_config = BASECONFIG_FILE_NEW;
  34. $already_setup = $existing_config != '';
  35.  
  36. OIDplus::handleLangArgument();
  37.  
  38. ob_start();
  39.  
  40. echo '<noscript>';
  41. echo '<h2>'._L('Please enable JavaScript in order to use setup!').'</h2>';
  42. echo '</noscript>';
  43.  
  44. echo '<span id="setupPageContent" style="display:None">';
  45.  
  46. echo '<p>';
  47. if ($already_setup) {
  48.         echo _L('This assistant will help you updating the file <b>%1</b>.',$existing_config);
  49. } else {
  50.         echo _L('Thank you very much for choosing OIDplus!');
  51.         echo ' ';
  52.         echo _L('This setup assistant will help you creating the file <b>%1</b>.',$existing_config);
  53. }
  54. echo ' ';
  55. echo _L('However, it does not automatically write to this file. Instead, you need to copy-paste the contents into the file.');
  56. echo ' ';
  57. if ($already_setup) {
  58.         echo _L('Later, you can change the config file by hand, or run this assistant again.');
  59. } else {
  60.         echo _L('Once OIDplus setup is finished, you can change the config file by hand, or run this setup assistant again.');
  61. }
  62. echo '</p>';
  63.  
  64. echo '<h2 id="systemCheckCaption" style="display:none">'._L('System check').'</h2>';
  65. echo '<div id="dirAccessWarning"></div>';
  66.  
  67. echo '<div id="step1">';
  68. echo '<h2>'._L('Step %1: Enter setup information',1).'</h2>';
  69.  
  70. // ----------------------------------------
  71.  
  72. echo '<h3>'._L('Administrator password').'</h3>';
  73.  
  74. echo '<form id="step1_form">';
  75. 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>';
  76. 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>';
  77.  
  78. // ----------------------------------------
  79.  
  80. echo '<h3>'._L('Database connectivity').'</h3>';
  81.  
  82. if (file_exists(__DIR__ . '/../doc/database_connectivity_diagram.png')) {
  83.         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>';
  84. }
  85.  
  86. echo _L('Database plugin').': <select name="db_plugin" onChange="dbplugin_changed()" id="db_plugin">';
  87.  
  88. OIDplus::registerAllPlugins('database', OIDplusDatabasePlugin::class, array(OIDplus::class,'registerDatabasePlugin'));
  89. foreach (OIDplus::getDatabasePlugins() as $plugin) {
  90.         $selected = $plugin::id() == 'MySQL' ? ' selected="true"' : '';
  91.         echo '<option value="'.htmlentities($plugin::id()).'"'.$selected.'>'.htmlentities($plugin::id()).'</option>';
  92. }
  93.  
  94. echo '</select>';
  95.  
  96. echo '<div style="margin-left:50px">';
  97.  
  98. OIDplus::registerAllPlugins('sqlSlang', OIDplusSqlSlangPlugin::class, array(OIDplus::class,'registerSqlSlangPlugin'));
  99. $sql_slang_selection = array();
  100. foreach (OIDplus::getSqlSlangPlugins() as $plugin) {
  101.         $slang_id = $plugin::id();
  102.         $pluginManifest = $plugin->getManifest();
  103.         $human_friendly_name = empty($pluginManifest->getName()) ? get_class($plugin) : $pluginManifest->getName();
  104.         $sql_slang_selection[] = '<option value="'.$slang_id.'">'.$human_friendly_name.'</option>';
  105. }
  106. $sql_slang_selection = implode("\n", $sql_slang_selection);
  107.  
  108. $found_db_plugins = 0;
  109. //OIDplus::registerAllPlugins('database', OIDplusDatabasePlugin::class, array(OIDplus::class,'registerDatabasePlugin'));
  110. foreach (OIDplus::getDatabasePlugins() as $plugin) {
  111.         $found_db_plugins++;
  112.         $cont = $plugin->setupHTML();
  113.         $cont = str_replace('<!-- %SQL_SLANG_SELECTION% -->', $sql_slang_selection, $cont);
  114.         echo $cont;
  115. }
  116.  
  117. if ($found_db_plugins == 0) {
  118.         echo '<p><font color="red">'._L('ERROR: No database plugins were found! You CANNOT use OIDplus without database connection.').'</font></p>';
  119. }
  120.  
  121. echo '</div>';
  122.  
  123. 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>';
  124.  
  125. // ----------------------------------------
  126.  
  127. echo '<h3>'._L('CAPTCHA').'</h3>';
  128.  
  129. // TODO: Add a small explanation here, in case somebody does not know what CAPTCHA is
  130.  
  131. echo _L('CAPTCHA plugin').': <select name="captcha_plugin" onChange="captchaplugin_changed()" id="captcha_plugin">';
  132.  
  133. OIDplus::registerAllPlugins('captcha', OIDplusCaptchaPlugin::class, array(OIDplus::class,'registerCaptchaPlugin'));
  134. foreach (OIDplus::getCaptchaPlugins() as $plugin) {
  135.         $selected = strtolower($plugin::id()) === strtolower('None') ? ' selected="true"' : ''; // select "None" by default
  136.         echo '<option value="'.htmlentities($plugin::id()).'"'.$selected.'>'.htmlentities($plugin::id()).'</option>';
  137. }
  138.  
  139. echo '</select>';
  140.  
  141. echo '<div style="margin-left:50px">';
  142.  
  143. $found_captcha_plugins = 0;
  144. foreach (OIDplus::getCaptchaPlugins() as $plugin) {
  145.         $found_captcha_plugins++;
  146.         $cont = $plugin->setupHTML();
  147.         echo $cont;
  148. }
  149.  
  150. if ($found_captcha_plugins == 0) {
  151.         echo '<p><font color="red">'._L('ERROR: No CAPTCHA plugins were found! You CANNOT use OIDplus without the "%1" CAPTCHA plugin.','None').'</font></p>';
  152. }
  153.  
  154. echo '</div>';
  155.  
  156. // ----------------------------------------
  157.  
  158. $is_ssl = OIDplus::isSSL();
  159. echo '<h3>'._L('Secure connection (HTTPS)').'</h3>';
  160. echo '<p>'._L('Enforcement of a secure connection:').'<br><select name="enforce_ssl" id="enforce_ssl" onchange="rebuild()">';
  161. echo '<option value="OIDplus::ENFORCE_SSL_NO">'._L('No SSL available (don\'t redirect)').'</option>';
  162. echo '<option value="OIDplus::ENFORCE_SSL_YES"'.($is_ssl ? ' selected' : '').'>'._L('Enforce SSL (always redirect)').'</option>';
  163. echo '<option value="OIDplus::ENFORCE_SSL_AUTO"'.(!$is_ssl ? ' selected' : '').'>'._L('Intelligent SSL detection (redirect if port 443 is open)').'</option>';
  164. echo '</select></p>';
  165.  
  166. // ----------------------------------------
  167.  
  168. echo '<h3>'._L('Public URL of this system (Canonical URL)').'</h3>';
  169.  
  170. 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>';
  171.  
  172. // ----------------------------------------
  173.  
  174. echo '</form>';
  175. echo '</div>';
  176.  
  177. echo '<div id="step2">';
  178. echo '<h2>'._L('Step %1: Initialize database',2).'</h2>';
  179. if ($already_setup) {
  180.         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>';
  181. }
  182. echo '<div id="step2_inner">';
  183. echo '<p>'._L('Please import one of the following SQL dumps in your database:').'</p>';
  184. echo '<p><ul>';
  185. 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>';
  186. 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>';
  187. echo '</ul></p>';
  188. echo '<p><font color="red">'._L('Warning: Existing OIDplus data will be deleted during the initialization of the database.').'</font></p>';
  189. echo '</div>';
  190. if ($already_setup) {
  191.         echo '<script>';
  192.         echo '$("#step2_enable").click(function() {';
  193.         echo '    if ($(this).is(":checked")) {';
  194.         echo '        $("#step2_inner").show();';
  195.         echo '    } else {';
  196.         echo '        $("#step2_inner").hide();';
  197.         echo '    }';
  198.         echo '});';
  199.         echo '$("#step2_inner").hide();';
  200.         echo '</script>';
  201. }
  202. echo '</div>';
  203.  
  204. // ----------------------------------------
  205.  
  206. echo '<div id="step3">';
  207. echo '<h2>'._L('Step %1: Save %2 file',3,$existing_config).'</h2>';
  208. echo '<p>'._L('Save following contents into the file <b>%1</b>',$existing_config).'</p>';
  209. echo '<code><font color="darkblue"><div id="config"></div></font></code><br>';
  210. echo '<p><input type="button" value="'._L('Copy to clipboard').'" onClick="copyToClipboard(config)"></p>';
  211. echo '</div>';
  212.  
  213. // ----------------------------------------
  214.  
  215. echo '<div id="step4">';
  216. echo '<h2>'._L('Step %1: After you have updated the file...',4).'</h2>';
  217. if (is_dir(__DIR__.'/../plugins/viathinksoft/adminPages/050_oobe/')) {
  218.         if ($already_setup) {
  219.                 echo '<p><input type="button" onclick="window.location.href=\'../plugins/viathinksoft/adminPages/050_oobe/oobe.php\'" value="'._L('Check connection and modify initial settings').'"></p>';
  220.                 echo '<p><input type="button" onclick="window.location.href=\'../\'" value="'._L('Check connection and start OIDplus').'"></p>';
  221.         } else {
  222.                 echo '<p><input type="button" onclick="window.location.href=\'../plugins/viathinksoft/adminPages/050_oobe/oobe.php\'" value="'._L('Check connection and go to initial settings').'"></p>';
  223.         }
  224. } else {
  225.         echo '<p><input type="button" onclick="window.location.href=\'../\'" value="'._L('Check connection and start OIDplus').'"></p>';
  226. }
  227. echo '</div>';
  228.  
  229. echo '<span id="footer_warn"></span>';
  230.  
  231. echo '<br><br>'; // because of iPhone Safari
  232.  
  233. echo '</span>';
  234.  
  235. echo '<script> $("#setupPageContent")[0].style.display = "Block"; </script>';
  236.  
  237. # ---
  238.  
  239. $page_title_1 = _L('OIDplus Setup');
  240. $page_title_2 = _L('Configuration File Generator');
  241. $static_icon = 'img/main_icon.png';
  242. $static_content = ob_get_contents();
  243. if (!$static_content) $static_content = '';
  244. $extra_head_tags = array();
  245. $extra_head_tags[] = '<meta name="robots" content="noindex">';
  246. $extra_head_tags[] = '<link rel="stylesheet" href="setup.min.css.php">';
  247. $extra_head_tags[] = '<script src="setup.min.js.php" type="text/javascript"></script>';
  248. ob_end_clean();
  249.  
  250. $cont = OIDplus::gui()->showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags);
  251.  
  252. OIDplus::invoke_shutdown();
  253.  
  254. echo $cont;
  255.