* ask user for timezone on install

* remember status of the installation
* moved clients list to the new file
* verify if client and timezone is correct on install
This commit is contained in:
slawkens1 2017-12-25 12:40:41 +01:00
parent 4d690992ac
commit 6528a4a60c
10 changed files with 158 additions and 94 deletions

2
TODO
View File

@ -31,7 +31,7 @@ At any time between (version not specified):
* update account.management page to be more realistic (like on tibia.com) * update account.management page to be more realistic (like on tibia.com)
* update guilds page to be more realistic (like on tibia.com) * update guilds page to be more realistic (like on tibia.com)
* possibility to add extra cache engines with plugins * possibility to add extra cache engines with plugins
* new cache engine - plain php, is good with pure php 7.0+ and opcache
* preferably configurable (enable/disable) forum TinyMCE editor * preferably configurable (enable/disable) forum TinyMCE editor
* new cache engine - plain php, is good with pure php 7.0+ and opcache
* OTAdmin support in Admin Panel * OTAdmin support in Admin Panel
* database towns table support for TFS 1.3 * database towns table support for TFS 1.3

View File

@ -5,6 +5,7 @@ require('../common.php');
require(SYSTEM . 'functions.php'); require(SYSTEM . 'functions.php');
require(BASE . 'install/includes/functions.php'); require(BASE . 'install/includes/functions.php');
require(BASE . 'install/includes/locale.php'); require(BASE . 'install/includes/locale.php');
require(SYSTEM . 'clients.conf.php');
if(file_exists(BASE . 'config.local.php')) if(file_exists(BASE . 'config.local.php'))
require(BASE . 'config.local.php'); require(BASE . 'config.local.php');
@ -19,20 +20,39 @@ $twig = new Twig_Environment($twig_loader, array(
'auto_reload' => true 'auto_reload' => true
)); ));
if(isset($_POST['vars'])) // load installation status
{
foreach($_POST['vars'] as $key => $value)
$_SESSION['var_' . $key] = $value;
}
// step
$step = isset($_POST['step']) ? $_POST['step'] : 'welcome'; $step = isset($_POST['step']) ? $_POST['step'] : 'welcome';
$install_status = array();
if(file_exists(CACHE . 'install.txt')) {
$install_status = unserialize(file_get_contents(CACHE . 'install.txt'));
if(!isset($_POST['step'])) {
$step = isset($install_status['step']) ? $install_status['step'] : '';
}
}
if(isset($_POST['vars']))
{
foreach($_POST['vars'] as $key => $value) {
$_SESSION['var_' . $key] = $value;
$install_status[$key] = $value;
}
}
else {
foreach($install_status as $key => $value) {
$_SESSION['var_' . $key] = $value;
}
}
// step verify
$steps = array(1 => 'welcome', 2 => 'license', 3 => 'requirements', 4 => 'config', 5 => 'database', 6 => 'admin', 7 => 'finish'); $steps = array(1 => 'welcome', 2 => 'license', 3 => 'requirements', 4 => 'config', 5 => 'database', 6 => 'admin', 7 => 'finish');
if(!in_array($step, $steps)) // check if step is valid if(!in_array($step, $steps)) // check if step is valid
die('ERROR: Unknown step.'); die('ERROR: Unknown step.');
$install_status['step'] = $step;
$errors = array(); $errors = array();
if($step == 'database') { if($step == 'database') {
foreach($_SESSION as $key => $value) { foreach($_SESSION as $key => $value) {
if(strpos($key, 'var_') === false || strpos($key, 'account') !== false || strpos($key, 'password') !== false) { if(strpos($key, 'var_') === false || strpos($key, 'account') !== false || strpos($key, 'password') !== false) {
@ -40,34 +60,40 @@ if($step == 'database') {
} }
$key = str_replace('var_', '', $key); $key = str_replace('var_', '', $key);
if($key != 'usage' && empty($value))
{ if($key != 'usage' && empty($value)) {
$errors[] = $locale['please_fill_all']; $errors[] = $locale['please_fill_all'];
break; break;
} }
else if($key == 'server_path') else if($key == 'server_path') {
{
$config['server_path'] = $value; $config['server_path'] = $value;
// take care of trailing slash at the end // take care of trailing slash at the end
if($config['server_path'][strlen($config['server_path']) - 1] != '/') if($config['server_path'][strlen($config['server_path']) - 1] != '/') {
$config['server_path'] .= '/'; $config['server_path'] .= '/';
}
if(!file_exists($config['server_path'] . 'config.lua')) { if(!file_exists($config['server_path'] . 'config.lua')) {
$errors[] = $locale['step_database_error_config']; $errors[] = $locale['step_database_error_config'];
break; break;
} }
} }
else if($key == 'mail_admin' && !Validator::email($value)) else if($key == 'mail_admin' && !Validator::email($value)) {
{
$errors[] = $locale['step_config_mail_admin_error']; $errors[] = $locale['step_config_mail_admin_error'];
break; break;
} }
else if($key == 'mail_address' && !Validator::email($value)) else if($key == 'mail_address' && !Validator::email($value)) {
{
$errors[] = $locale['step_config_mail_address_error']; $errors[] = $locale['step_config_mail_address_error'];
break; break;
} }
else if($key == 'timezone' && !in_array($value, DateTimeZone::listIdentifiers())) {
$errors[] = $locale['step_config_timezone_error'];
break;
}
else if($key == 'client' && !in_array($value, $config['clients'])) {
$errors[] = $locale['step_config_client_error'];
break;
}
} }
if(!empty($errors)) { if(!empty($errors)) {
@ -117,6 +143,10 @@ else if($step == 'finish') {
} }
} }
if(empty($errors)) {
file_put_contents(CACHE . 'install.txt', serialize($install_status));
}
$error = false; $error = false;
clearstatcache(); clearstatcache();

View File

@ -1,6 +1,6 @@
<?php <?php
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['saved'])) { if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['saved']) && !isset($install_status['step'])) {
echo '<p class="warning">' . $locale['already_installed'] . '</p>'; echo '<p class="warning">' . $locale['already_installed'] . '</p>';
} }
else { else {

View File

@ -1,74 +1,8 @@
<?php <?php
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$clients_list = array(
710,
740,
750,
760,
770,
772,
780,
792,
800,
810,
821,
822,
831,
840,
841,
842,
850,
852,
853,
854,
855,
857,
860,
870,
900,
910,
920,
930,
940,
942,
944,
946,
950,
952,
953,
954,
960,
970,
980,
1000,
1010,
1021,
1031,
1034,
1041,
1050,
1053,
1054,
1058,
1075,
1077,
1079,
1080,
1090,
1093,
1094,
1095,
1096,
1097,
1098,
1100,
);
$clients = array(); $clients = array();
foreach($clients_list as $client) { foreach($config['clients'] as $client) {
$client_version = (string)($client / 100); $client_version = (string)($client / 100);
if(strpos($client_version, '.') == false) if(strpos($client_version, '.') == false)
$client_version .= '.0'; $client_version .= '.0';
@ -78,6 +12,7 @@ foreach($clients_list as $client) {
echo $twig->render('install.config.html.twig', array( echo $twig->render('install.config.html.twig', array(
'clients' => $clients, 'clients' => $clients,
'timezones' => DateTimeZone::listIdentifiers(),
'locale' => $locale, 'locale' => $locale,
'session' => $_SESSION, 'session' => $_SESSION,
'errors' => isset($errors) ? $errors : null, 'errors' => isset($errors) ? $errors : null,

View File

@ -15,6 +15,10 @@ if(!$error) {
$content .= PHP_EOL; $content .= PHP_EOL;
$content .= '// place for your configuration directives, so you can later easily update myaac'; $content .= '// place for your configuration directives, so you can later easily update myaac';
$content .= PHP_EOL; $content .= PHP_EOL;
$content .= '$config[\'installed\'] = true;';
$content .= PHP_EOL;
$content .= '$config[\'mail_enabled\'] = true;';
$content .= PHP_EOL;
foreach($_SESSION as $key => $value) foreach($_SESSION as $key => $value)
{ {
if(strpos($key, 'var_') !== false) if(strpos($key, 'var_') !== false)
@ -23,14 +27,14 @@ if(!$error) {
{ {
$value = str_replace("\\", "/", $value); $value = str_replace("\\", "/", $value);
if($value[strlen($value) - 1] != '/') if($value[strlen($value) - 1] != '/')
$value .= "/"; $value .= '/';
} }
if($key == 'var_usage') { if($key == 'var_usage') {
$content .= '$config[\'anonymous_usage_statistics\'] = ' . ((int)$value == 1 ? 'true' : 'false') . ';'; $content .= '$config[\'anonymous_usage_statistics\'] = ' . ((int)$value == 1 ? 'true' : 'false') . ';';
$content .= PHP_EOL; $content .= PHP_EOL;
} }
else if($key != 'var_account' && $key != 'var_account_id' && $key != 'var_password') { else if($key != 'var_account' && $key != 'var_account_id' && $key != 'var_password' && $key != 'var_step') {
$content .= '$config[\'' . str_replace('var_', '', $key) . '\'] = \'' . $value . '\';'; $content .= '$config[\'' . str_replace('var_', '', $key) . '\'] = \'' . $value . '\';';
$content .= PHP_EOL; $content .= PHP_EOL;
} }
@ -224,11 +228,6 @@ if(!$error) {
} }
if(!$error) { if(!$error) {
$content .= '$config[\'installed\'] = true;';
$content .= PHP_EOL;
$content .= '$config[\'mail_enabled\'] = true;';
$content .= PHP_EOL;
if(!Validator::email($_SESSION['var_mail_admin'])) { if(!Validator::email($_SESSION['var_mail_admin'])) {
error($locale['step_config_mail_admin_error']); error($locale['step_config_mail_admin_error']);
$error = true; $error = true;

View File

@ -235,6 +235,9 @@ else {
unset($_SESSION[$key]); unset($_SESSION[$key]);
} }
unset($_SESSION['saved']); unset($_SESSION['saved']);
if(file_exists(CACHE . 'install.txt')) {
unlink(CACHE . 'install.txt');
}
} }
} }
?> ?>

78
system/clients.conf.php Normal file
View File

@ -0,0 +1,78 @@
<?php
/**
* List of clients
*
* @package MyAAC
* @author Slawkens <slawkens@gmail.com>
* @copyright 2017 MyAAC
* @link http://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
$config['clients'] = array(
710,
740,
750,
760,
770,
772,
780,
792,
800,
810,
821,
822,
831,
840,
841,
842,
850,
852,
853,
854,
855,
857,
860,
870,
900,
910,
920,
930,
940,
942,
944,
946,
950,
952,
953,
954,
960,
970,
980,
1000,
1010,
1021,
1031,
1034,
1041,
1050,
1053,
1054,
1058,
1075,
1077,
1079,
1080,
1090,
1093,
1094,
1095,
1096,
1097,
1098,
1100,
);
?>

View File

@ -14,8 +14,7 @@ if(file_exists(BASE . 'config.local.php')) // user customizations
require(BASE . 'config.local.php'); require(BASE . 'config.local.php');
if(!isset($config['installed']) || !$config['installed']) { if(!isset($config['installed']) || !$config['installed']) {
header('Location: ' . BASE_URL); die('MyAAC has not been installed yet or there was error during installation. Please install again.');
die('AAC has not been installed yet or there was error during installation. Please install again.');
} }
date_default_timezone_set($config['date_timezone']); date_default_timezone_set($config['date_timezone']);

View File

@ -48,8 +48,12 @@ $locale['step_config_mail_admin_error'] = 'Admin E-Mail is not correct.';
$locale['step_config_mail_address'] = 'Server E-Mail'; $locale['step_config_mail_address'] = 'Server E-Mail';
$locale['step_config_mail_address_desc'] = 'Address which will be used for outgoing emails (from:), for example no-reply@your-server.org'; $locale['step_config_mail_address_desc'] = 'Address which will be used for outgoing emails (from:), for example no-reply@your-server.org';
$locale['step_config_mail_address_error'] = 'Server E-Mail is not correct.'; $locale['step_config_mail_address_error'] = 'Server E-Mail is not correct.';
$locale['step_config_timezone'] = 'Timezone';
$locale['step_config_timezone_desc'] = 'Used for date functions';
$locale['step_config_timezone_error'] = 'Timezone is not correct.';
$locale['step_config_client'] = 'Client version'; $locale['step_config_client'] = 'Client version';
$locale['step_config_client_desc'] = 'Used for download page and some templates'; $locale['step_config_client_desc'] = 'Used for download page and some templates';
$locale['step_config_client_error'] = 'Client is not correct.';
$locale['step_config_usage'] = 'Usage Statistics'; $locale['step_config_usage'] = 'Usage Statistics';
$locale['step_config_usage_desc'] = 'Allow MyAAC to report anonymous usage statistics? The data is sent only once per 30 days and is fully confidential.'; $locale['step_config_usage_desc'] = 'Allow MyAAC to report anonymous usage statistics? The data is sent only once per 30 days and is fully confidential.';

View File

@ -15,6 +15,22 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr>
<td>
<label for="vars_date_timezone">
<span>{{ locale.step_config_timezone }}</span>
</label>
<br/>
<select name="vars[date_timezone]" id="vars_date_timezone">
{% for timezone in timezones %}
<option value="{{ timezone }}"{% if (session['var_date_timezone'] is not null and session['var_date_timezone'] == timezone) or (session['var_date_timezone'] is null and timezone == 'Europe/Berlin') %} selected{% endif %}>{{ timezone }}</option>
{% endfor %}
</select>
</td>
<td>
<em>{{ locale.step_config_timezone_desc }}</em>
</td>
</tr>
<tr> <tr>
<td> <td>
<label for="vars_client"> <label for="vars_client">