Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
82 daniel-mar 1
<?php
2
 
360 daniel-mar 3
/*
4
 * OIDplus 2.0
1321 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
360 daniel-mar 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
 
1050 daniel-mar 20
use ViaThinkSoft\OIDplus\OIDplus;
21
use ViaThinkSoft\OIDplus\OIDplusDatabasePlugin;
22
use ViaThinkSoft\OIDplus\OIDplusSqlSlangPlugin;
23
use ViaThinkSoft\OIDplus\OIDplusCaptchaPlugin;
24
 
236 daniel-mar 25
require_once __DIR__ . '/../includes/oidplus.inc.php';
82 daniel-mar 26
 
1434 daniel-mar 27
originHeaders(); // This is important so that http://.../setup/ can query https://.../setup/ in order to do an SSL availability check
28
 
1116 daniel-mar 29
const BASECONFIG_FILE_OLD = 'includes/config.inc.php';
30
const BASECONFIG_FILE_NEW = 'userdata/baseconfig/config.inc.php';
1055 daniel-mar 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 != '';
1030 daniel-mar 35
 
362 daniel-mar 36
OIDplus::handleLangArgument();
2 daniel-mar 37
 
1055 daniel-mar 38
ob_start();
2 daniel-mar 39
 
561 daniel-mar 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
 
1030 daniel-mar 46
echo '<p>';
47
if ($already_setup) {
1055 daniel-mar 48
        echo _L('This assistant will help you updating the file <b>%1</b>.',$existing_config);
1030 daniel-mar 49
} else {
50
        echo _L('Thank you very much for choosing OIDplus!');
51
        echo ' ';
1055 daniel-mar 52
        echo _L('This setup assistant will help you creating the file <b>%1</b>.',$existing_config);
1030 daniel-mar 53
}
54
echo ' ';
1084 daniel-mar 55
echo _L('However, it does not automatically write to this file. Instead, you need to copy-paste the contents into the file.');
1031 daniel-mar 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
}
1030 daniel-mar 62
echo '</p>';
299 daniel-mar 63
 
362 daniel-mar 64
echo '<h2 id="systemCheckCaption" style="display:none">'._L('System check').'</h2>';
65
echo '<div id="dirAccessWarning"></div>';
301 daniel-mar 66
 
362 daniel-mar 67
echo '<div id="step1">';
68
echo '<h2>'._L('Step %1: Enter setup information',1).'</h2>';
299 daniel-mar 69
 
702 daniel-mar 70
// ----------------------------------------
71
 
362 daniel-mar 72
echo '<h3>'._L('Administrator password').'</h3>';
299 daniel-mar 73
 
362 daniel-mar 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>';
299 daniel-mar 77
 
702 daniel-mar 78
// ----------------------------------------
79
 
362 daniel-mar 80
echo '<h3>'._L('Database connectivity').'</h3>';
157 daniel-mar 81
 
479 daniel-mar 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
}
157 daniel-mar 85
 
362 daniel-mar 86
echo _L('Database plugin').': <select name="db_plugin" onChange="dbplugin_changed()" id="db_plugin">';
150 daniel-mar 87
 
1050 daniel-mar 88
OIDplus::registerAllPlugins('database', OIDplusDatabasePlugin::class, array(OIDplus::class,'registerDatabasePlugin'));
380 daniel-mar 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>';
236 daniel-mar 92
}
93
 
362 daniel-mar 94
echo '</select>';
150 daniel-mar 95
 
362 daniel-mar 96
echo '<div style="margin-left:50px">';
150 daniel-mar 97
 
1050 daniel-mar 98
OIDplus::registerAllPlugins('sqlSlang', OIDplusSqlSlangPlugin::class, array(OIDplus::class,'registerSqlSlangPlugin'));
274 daniel-mar 99
$sql_slang_selection = array();
380 daniel-mar 100
foreach (OIDplus::getSqlSlangPlugins() as $plugin) {
101
        $slang_id = $plugin::id();
102
        $pluginManifest = $plugin->getManifest();
502 daniel-mar 103
        $human_friendly_name = empty($pluginManifest->getName()) ? get_class($plugin) : $pluginManifest->getName();
380 daniel-mar 104
        $sql_slang_selection[] = '<option value="'.$slang_id.'">'.$human_friendly_name.'</option>';
274 daniel-mar 105
}
106
$sql_slang_selection = implode("\n", $sql_slang_selection);
107
 
305 daniel-mar 108
$found_db_plugins = 0;
1050 daniel-mar 109
//OIDplus::registerAllPlugins('database', OIDplusDatabasePlugin::class, array(OIDplus::class,'registerDatabasePlugin'));
380 daniel-mar 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;
277 daniel-mar 115
}
116
 
305 daniel-mar 117
if ($found_db_plugins == 0) {
362 daniel-mar 118
        echo '<p><font color="red">'._L('ERROR: No database plugins were found! You CANNOT use OIDplus without database connection.').'</font></p>';
150 daniel-mar 119
}
120
 
362 daniel-mar 121
echo '</div>';
150 daniel-mar 122
 
362 daniel-mar 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>';
150 daniel-mar 124
 
702 daniel-mar 125
// ----------------------------------------
150 daniel-mar 126
 
702 daniel-mar 127
echo '<h3>'._L('CAPTCHA').'</h3>';
128
 
703 daniel-mar 129
// TODO: Add a small explanation here, in case somebody does not know what CAPTCHA is
130
 
702 daniel-mar 131
echo _L('CAPTCHA plugin').': <select name="captcha_plugin" onChange="captchaplugin_changed()" id="captcha_plugin">';
132
 
1050 daniel-mar 133
OIDplus::registerAllPlugins('captcha', OIDplusCaptchaPlugin::class, array(OIDplus::class,'registerCaptchaPlugin'));
702 daniel-mar 134
foreach (OIDplus::getCaptchaPlugins() as $plugin) {
1020 daniel-mar 135
        $selected = strtolower($plugin::id()) === strtolower('None') ? ' selected="true"' : ''; // select "None" by default
702 daniel-mar 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
 
974 daniel-mar 158
$is_ssl = OIDplus::isSSL();
159
echo '<h3>'._L('Secure connection (HTTPS)').'</h3>';
985 daniel-mar 160
echo '<p>'._L('Enforcement of a secure connection:').'<br><select name="enforce_ssl" id="enforce_ssl" onchange="rebuild()">';
974 daniel-mar 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>';
362 daniel-mar 164
echo '</select></p>';
1020 daniel-mar 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
 
362 daniel-mar 174
echo '</form>';
175
echo '</div>';
157 daniel-mar 176
 
362 daniel-mar 177
echo '<div id="step2">';
178
echo '<h2>'._L('Step %1: Initialize database',2).'</h2>';
1030 daniel-mar 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>';
362 daniel-mar 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>';
1030 daniel-mar 188
echo '<p><font color="red">'._L('Warning: Existing OIDplus data will be deleted during the initialization of the database.').'</font></p>';
362 daniel-mar 189
echo '</div>';
1030 daniel-mar 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>';
157 daniel-mar 203
 
702 daniel-mar 204
// ----------------------------------------
205
 
362 daniel-mar 206
echo '<div id="step3">';
1055 daniel-mar 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>';
1073 daniel-mar 209
echo '<code><font color="darkblue"><div id="config"></div></font></code><br>';
982 daniel-mar 210
echo '<p><input type="button" value="'._L('Copy to clipboard').'" onClick="copyToClipboard(config)"></p>';
362 daniel-mar 211
echo '</div>';
157 daniel-mar 212
 
702 daniel-mar 213
// ----------------------------------------
214
 
362 daniel-mar 215
echo '<div id="step4">';
1055 daniel-mar 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
        }
1030 daniel-mar 224
} else {
1055 daniel-mar 225
        echo '<p><input type="button" onclick="window.location.href=\'../\'" value="'._L('Check connection and start OIDplus').'"></p>';
1030 daniel-mar 226
}
362 daniel-mar 227
echo '</div>';
157 daniel-mar 228
 
1057 daniel-mar 229
echo '<span id="footer_warn"></span>';
230
 
1055 daniel-mar 231
echo '<br><br>'; // because of iPhone Safari
366 daniel-mar 232
 
561 daniel-mar 233
echo '</span>';
1057 daniel-mar 234
 
561 daniel-mar 235
echo '<script> $("#setupPageContent")[0].style.display = "Block"; </script>';
236
 
1055 daniel-mar 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();
1143 daniel-mar 243
if (!$static_content) $static_content = '';
1055 daniel-mar 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
 
1056 daniel-mar 250
$cont = OIDplus::gui()->showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags);
251
 
1055 daniel-mar 252
OIDplus::invoke_shutdown();
253
 
1056 daniel-mar 254
echo $cont;