From 4d690992ac0d37cba31c996de2916d0ed570ddb5 Mon Sep 17 00:00:00 2001 From: slawkens1 Date: Sun, 24 Dec 2017 13:00:14 +0100 Subject: [PATCH] * switch to 0.7.5-dev * fix when config.local.php doesn't exist * fix when reinstalling aac with samples already installed * some optimisations to installation script * forgot to fclose on config.local.php --- common.php | 2 +- index.php | 4 +++- install/index.php | 38 +++++++++++++++++++++++++++----- install/steps/3-requirements.php | 2 +- install/steps/4-config.php | 2 +- install/steps/5-database.php | 17 +++++++++----- install/steps/7-finish.php | 15 ++++++++++++- system/locale/en/install.php | 2 +- system/locale/pl/install.php | 2 +- 9 files changed, 67 insertions(+), 17 deletions(-) diff --git a/common.php b/common.php index 12772148..5b83224e 100644 --- a/common.php +++ b/common.php @@ -26,7 +26,7 @@ session_start(); define('MYAAC', true); -define('MYAAC_VERSION', '0.7.4'); +define('MYAAC_VERSION', '0.7.5-dev'); define('DATABASE_VERSION', 20); define('TABLE_PREFIX', 'myaac_'); define('START_TIME', microtime(true)); diff --git a/index.php b/index.php index fee0c8e7..a7a9b0d4 100644 --- a/index.php +++ b/index.php @@ -56,7 +56,9 @@ else if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|php| exit; } -require_once(BASE . 'config.local.php'); +if(file_exists(BASE . 'config.local.php')) + require_once(BASE . 'config.local.php'); + if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed'])) { header('Location: ' . BASE_URL . 'install/'); diff --git a/install/index.php b/install/index.php index 22c87b3d..b0017236 100644 --- a/install/index.php +++ b/install/index.php @@ -5,7 +5,9 @@ require('../common.php'); require(SYSTEM . 'functions.php'); require(BASE . 'install/includes/functions.php'); require(BASE . 'install/includes/locale.php'); -require(BASE . 'config.local.php'); + +if(file_exists(BASE . 'config.local.php')) + require(BASE . 'config.local.php'); // twig require_once LIBS . 'Twig/Autoloader.php'; @@ -31,15 +33,31 @@ if(!in_array($step, $steps)) // check if step is valid die('ERROR: Unknown step.'); $errors = array(); -if($step == 'database') -{ - foreach($_POST['vars'] as $key => $value) - { +if($step == 'database') { + foreach($_SESSION as $key => $value) { + if(strpos($key, 'var_') === false || strpos($key, 'account') !== false || strpos($key, 'password') !== false) { + continue; + } + + $key = str_replace('var_', '', $key); if($key != 'usage' && empty($value)) { $errors[] = $locale['please_fill_all']; break; } + 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] != '/') + $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)) { $errors[] = $locale['step_config_mail_admin_error']; @@ -56,6 +74,16 @@ if($step == 'database') $step = 'config'; } } +else if($step == 'admin') { + $config_failed = true; + if(file_exists(BASE . 'config.local.php') && isset($config['installed']) && $config['installed'] && isset($_SESSION['saved'])) { + $config_failed = false; + } + + if($config_failed) { + $step = 'database'; + } +} else if($step == 'finish') { // password $password = $_SESSION['var_password']; diff --git a/install/steps/3-requirements.php b/install/steps/3-requirements.php index bec5ee1c..bb25d230 100644 --- a/install/steps/3-requirements.php +++ b/install/steps/3-requirements.php @@ -23,7 +23,7 @@ $failed = false; // start validating version_check($locale['step_requirements_php_version'], (PHP_VERSION_ID >= 50300), PHP_VERSION); -foreach(array('config.local.php', 'images/guilds', 'images/houses', 'images/gallery') as $value) +foreach(array('images/guilds', 'images/houses', 'images/gallery') as $value) { $perms = (int) substr(decoct(fileperms(BASE . $value)), 2); version_check($locale['step_requirements_write_perms'] . ': ' . $value, $perms >= 660); diff --git a/install/steps/4-config.php b/install/steps/4-config.php index 56aaa0d1..6a2d8257 100644 --- a/install/steps/4-config.php +++ b/install/steps/4-config.php @@ -9,7 +9,7 @@ $clients_list = array( 770, 772, 780, - 7920, + 792, 800, 810, 821, diff --git a/install/steps/5-database.php b/install/steps/5-database.php index 5ab0fb23..bd6efdba 100644 --- a/install/steps/5-database.php +++ b/install/steps/5-database.php @@ -13,6 +13,8 @@ if(!isset($_SESSION['var_server_path'])) { if(!$error) { $content = " $value) { if(strpos($key, 'var_') !== false) @@ -221,7 +223,7 @@ if(!$error) { } } - if(!$error && (!isset($_SESSION['saved']))) { + if(!$error) { $content .= '$config[\'installed\'] = true;'; $content .= PHP_EOL; @@ -243,16 +245,21 @@ if(!$error) { $content .= '$config[\'session_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';'; $content .= PHP_EOL; $content .= '$config[\'cache_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';'; - $content .= PHP_EOL; + + $saved = true; + if(!$error) { + $saved = file_put_contents(BASE . 'config.local.php', $content); + } - $file = fopen(BASE . 'config.local.php', 'a+'); - if($file) { + if($saved) { if(!$error) { - fwrite($file, $content); $_SESSION['saved'] = true; } } else { + $_SESSION['config_content'] = $content; + unset($_SESSION['saved']); + $locale['step_database_error_file'] = str_replace('$FILE$', '' . BASE . 'config.local.php', $locale['step_database_error_file']); warning($locale['step_database_error_file'] . '
'); diff --git a/install/steps/7-finish.php b/install/steps/7-finish.php index 7e41f44d..a7ada911 100644 --- a/install/steps/7-finish.php +++ b/install/steps/7-finish.php @@ -192,13 +192,26 @@ else { error(Spells::getLastError()); } + if(count($highscores_ignored_ids) == 0) { + $query = $db->query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . ") ORDER BY `id`;"); + + $highscores_ignored_ids = array(); + if($query->rowCount() > 0) { + foreach($query->fetchAll() as $result) + $highscores_ignored_ids[] = $result['id']; + } + else { + $highscores_ignored_ids[] = 0; + } + } + $content = PHP_EOL; $content .= '$config[\'highscores_ids_hidden\'] = array(' . implode(', ', $highscores_ignored_ids) . ');'; - $content .= PHP_EOL; $file = fopen(BASE . 'config.local.php', 'a+'); if($file) { fwrite($file, $content); + fclose($file); } else { $locale['step_database_error_file'] = str_replace('$FILE$', '' . BASE . 'config.local.php', $locale['step_database_error_file']); diff --git a/system/locale/en/install.php b/system/locale/en/install.php index 383cebb1..410c0d52 100644 --- a/system/locale/en/install.php +++ b/system/locale/en/install.php @@ -58,7 +58,7 @@ $locale['step_database'] = 'Import schema'; $locale['step_database_title'] = 'Import MySQL schema'; $locale['step_database_importing'] = 'Your database is MySQL. Importing schema now...'; $locale['step_database_error_path'] = 'Please specify server path.'; -$locale['step_database_error_config'] = 'Cannot find config file. Is your server path correct? Go back and check again.'; +$locale['step_database_error_config'] = 'Cannot find config.lua file. Is your server path correct? Go back and check again.'; $locale['step_database_error_database_empty'] = 'Cannot determine database type from config.lua. Your OTS is unsupported by this AAC.'; $locale['step_database_error_only_mysql'] = 'This AAC supports only MySQL. From your config file it seems that your OTS is using: $DATABASE_TYPE$ database. Please change your database to MySQL and then follow the installation again.'; $locale['step_database_error_table'] = 'Table $TABLE$ doesn\'t exist. Please import your OTS database schema first.'; diff --git a/system/locale/pl/install.php b/system/locale/pl/install.php index 98ef31d0..c76fd526 100644 --- a/system/locale/pl/install.php +++ b/system/locale/pl/install.php @@ -58,7 +58,7 @@ $locale['step_database'] = 'Baza Danych'; $locale['step_database_title'] = 'Baza MySQL'; $locale['step_database_importing'] = 'Twoja baza to MySQL. Importowanie schematu...'; $locale['step_database_error_path'] = 'Proszę podać ścieżkę do serwera.'; -$locale['step_database_error_config'] = 'Nie można znaleźć pliku config. Jest Twoja ścieżka do katalogu serwera poprawna? Wróć się i sprawdź ponownie.'; +$locale['step_database_error_config'] = 'Nie można znaleźć pliku config.lua. Czy ścieżka do katalogu serwera jest poprawna? Wróć się i sprawdź ponownie.'; $locale['step_database_error_database_empty'] = 'Nie można wykryć typu bazy danych z pliku config.lua. Prawdopodobnie Twój OTS nie jest wspierany przez ten AAC.'; $locale['step_database_error_only_mysql'] = 'Ten AAC wspiera tylko bazy danych MySQL. Z Twojego pliku config wynika, że Twój serwera używa bazy: $DATABASE_TYPE$. Proszę zmienić typ bazy na MySQL i ponownie przystąpić do instalacji.'; $locale['step_database_error_table'] = 'Tabela $TABLE$ nie istnieje. Proszę najpierw zaimportować schemat bazy danych serwera OTS.';