From 6528a4a60c64807c3e22ff90384e87cd434e238d Mon Sep 17 00:00:00 2001
From: slawkens1
Date: Mon, 25 Dec 2017 12:40:41 +0100
Subject: [PATCH] * 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
---
TODO | 2 +-
install/index.php | 62 +++++++++++++-----
install/steps/1-welcome.php | 2 +-
install/steps/4-config.php | 69 +-------------------
install/steps/5-database.php | 13 ++--
install/steps/7-finish.php | 3 +
system/clients.conf.php | 78 +++++++++++++++++++++++
system/init.php | 3 +-
system/locale/en/install.php | 4 ++
system/templates/install.config.html.twig | 16 +++++
10 files changed, 158 insertions(+), 94 deletions(-)
create mode 100644 system/clients.conf.php
diff --git a/TODO b/TODO
index 804cca81..36f2381d 100644
--- a/TODO
+++ b/TODO
@@ -31,7 +31,7 @@ At any time between (version not specified):
* update account.management 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
+ * new cache engine - plain php, is good with pure php 7.0+ and opcache
* 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
* database towns table support for TFS 1.3
\ No newline at end of file
diff --git a/install/index.php b/install/index.php
index b0017236..10e7bf6e 100644
--- a/install/index.php
+++ b/install/index.php
@@ -5,6 +5,7 @@ require('../common.php');
require(SYSTEM . 'functions.php');
require(BASE . 'install/includes/functions.php');
require(BASE . 'install/includes/locale.php');
+require(SYSTEM . 'clients.conf.php');
if(file_exists(BASE . 'config.local.php'))
require(BASE . 'config.local.php');
@@ -19,20 +20,39 @@ $twig = new Twig_Environment($twig_loader, array(
'auto_reload' => true
));
-if(isset($_POST['vars']))
-{
- foreach($_POST['vars'] as $key => $value)
- $_SESSION['var_' . $key] = $value;
-}
-
-// step
+// load installation status
$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');
if(!in_array($step, $steps)) // check if step is valid
die('ERROR: Unknown step.');
+$install_status['step'] = $step;
$errors = array();
+
if($step == 'database') {
foreach($_SESSION as $key => $value) {
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);
- if($key != 'usage' && empty($value))
- {
+
+ if($key != 'usage' && empty($value)) {
$errors[] = $locale['please_fill_all'];
break;
}
- else if($key == 'server_path')
- {
+ else if($key == 'server_path') {
$config['server_path'] = $value;
// 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'] .= '/';
+ }
if(!file_exists($config['server_path'] . 'config.lua')) {
$errors[] = $locale['step_database_error_config'];
break;
}
}
- else if($key == 'mail_admin' && !Validator::email($value))
- {
+ else if($key == 'mail_admin' && !Validator::email($value)) {
$errors[] = $locale['step_config_mail_admin_error'];
break;
}
- else if($key == 'mail_address' && !Validator::email($value))
- {
+ else if($key == 'mail_address' && !Validator::email($value)) {
$errors[] = $locale['step_config_mail_address_error'];
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)) {
@@ -117,6 +143,10 @@ else if($step == 'finish') {
}
}
+if(empty($errors)) {
+ file_put_contents(CACHE . 'install.txt', serialize($install_status));
+}
+
$error = false;
clearstatcache();
diff --git a/install/steps/1-welcome.php b/install/steps/1-welcome.php
index 8a38e8ce..54391e9e 100644
--- a/install/steps/1-welcome.php
+++ b/install/steps/1-welcome.php
@@ -1,6 +1,6 @@
' . $locale['already_installed'] . '
';
}
else {
diff --git a/install/steps/4-config.php b/install/steps/4-config.php
index 6a2d8257..201ca089 100644
--- a/install/steps/4-config.php
+++ b/install/steps/4-config.php
@@ -1,74 +1,8 @@
render('install.config.html.twig', array(
'clients' => $clients,
+ 'timezones' => DateTimeZone::listIdentifiers(),
'locale' => $locale,
'session' => $_SESSION,
'errors' => isset($errors) ? $errors : null,
diff --git a/install/steps/5-database.php b/install/steps/5-database.php
index bd6efdba..4ededff0 100644
--- a/install/steps/5-database.php
+++ b/install/steps/5-database.php
@@ -15,6 +15,10 @@ if(!$error) {
$content .= PHP_EOL;
$content .= '// place for your configuration directives, so you can later easily update myaac';
$content .= PHP_EOL;
+ $content .= '$config[\'installed\'] = true;';
+ $content .= PHP_EOL;
+ $content .= '$config[\'mail_enabled\'] = true;';
+ $content .= PHP_EOL;
foreach($_SESSION as $key => $value)
{
if(strpos($key, 'var_') !== false)
@@ -23,14 +27,14 @@ if(!$error) {
{
$value = str_replace("\\", "/", $value);
if($value[strlen($value) - 1] != '/')
- $value .= "/";
+ $value .= '/';
}
if($key == 'var_usage') {
$content .= '$config[\'anonymous_usage_statistics\'] = ' . ((int)$value == 1 ? 'true' : 'false') . ';';
$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 .= PHP_EOL;
}
@@ -224,11 +228,6 @@ 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'])) {
error($locale['step_config_mail_admin_error']);
$error = true;
diff --git a/install/steps/7-finish.php b/install/steps/7-finish.php
index a7ada911..abe40914 100644
--- a/install/steps/7-finish.php
+++ b/install/steps/7-finish.php
@@ -235,6 +235,9 @@ else {
unset($_SESSION[$key]);
}
unset($_SESSION['saved']);
+ if(file_exists(CACHE . 'install.txt')) {
+ unlink(CACHE . 'install.txt');
+ }
}
}
?>
\ No newline at end of file
diff --git a/system/clients.conf.php b/system/clients.conf.php
new file mode 100644
index 00000000..74c8bf27
--- /dev/null
+++ b/system/clients.conf.php
@@ -0,0 +1,78 @@
+
+ * @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,
+);
+?>
diff --git a/system/init.php b/system/init.php
index 938a43fa..8833b95a 100644
--- a/system/init.php
+++ b/system/init.php
@@ -14,8 +14,7 @@ if(file_exists(BASE . 'config.local.php')) // user customizations
require(BASE . 'config.local.php');
if(!isset($config['installed']) || !$config['installed']) {
- header('Location: ' . BASE_URL);
- die('AAC has not been installed yet or there was error during installation. Please install again.');
+ die('MyAAC has not been installed yet or there was error during installation. Please install again.');
}
date_default_timezone_set($config['date_timezone']);
diff --git a/system/locale/en/install.php b/system/locale/en/install.php
index 410c0d52..fa5fddad 100644
--- a/system/locale/en/install.php
+++ b/system/locale/en/install.php
@@ -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_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_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_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_desc'] = 'Allow MyAAC to report anonymous usage statistics? The data is sent only once per 30 days and is fully confidential.';
diff --git a/system/templates/install.config.html.twig b/system/templates/install.config.html.twig
index 874e1d5e..6f881bf1 100644
--- a/system/templates/install.config.html.twig
+++ b/system/templates/install.config.html.twig
@@ -15,6 +15,22 @@
{% endfor %}
+
+
+
+
+
+ |
+
+ {{ locale.step_config_timezone_desc }}
+ |
+
|