improved DB connection setup

improved config (*.ini) file loading (merged ini files by "include")
added MySQL "values" check to /setup process
added HTML "title" tags for each "view"
This commit is contained in:
Exodus4D
2016-01-11 20:21:32 +01:00
parent 6e978545e9
commit 577605940e
14 changed files with 157 additions and 106 deletions

View File

@@ -9,13 +9,12 @@ Mapping tool for [*EVE ONLINE*](https://www.eveonline.com)
- Licence [MIT](http://opensource.org/licenses/MIT)
##### IMPORTANT Information:
**The setup and installation process in ``v.0.0.17`` and is not backwards compatible with previous beta releases (check wiki)!**
**The setup and installation process in ``1.0.0RC1`` and is not backwards compatible with previous beta releases (check wiki)!**
**This project is still in beta phase and is not officially released!
Feel free to check the code for bugs and security issues.
Issues should be reported in the [Issue](https://github.com/exodus4d/pathfinder/issues) section.**
**Feel free to check the code for bugs and security issues.
Issues should be reported in the [Issue](https://github.com/exodus4d/pathfinder/issues) section.**
If you are looking for installation help, please check the [wiki](https://github.com/exodus4d/pathfinder/wiki) (DRAFT).
If you are looking for installation help, please check the [wiki](https://github.com/exodus4d/pathfinder/wiki).
More information will be added once the beta is over and the first stable build is released.
## Project structure
@@ -26,9 +25,11 @@ More information will be added once the beta is over and the first stable build
|-- lib --> "Fat Free Framework"
|-- main --> "PATHFINDER" root
|-- config.ini --> config "f3" framework
|-- cron.ini --> config cronjobs
|-- pathfinder.ini --> config pathfinder
|-- routes.ini --> config routes
|-- cron.ini --> config - cronjobs
|-- environment.ini --> config - system environment
|-- pathfinder.ini --> config - pathfinder
|-- requirements.ini --> config - system requirements
|-- routes.ini --> config - routes
|-- (0755) export --> DB export data
|-- sql --> static DB data for import (pathfinder.sql)
|-- (0755) favicon --> Favicons

View File

@@ -37,3 +37,11 @@ AUTOLOAD = app/main/
; path to favicons folder
FAVICON = /favicon
; load additional config files
[configs]
app/routes.ini = true
app/environment.ini = true
app/pathfinder.ini = true
app/requirements.ini = true
app/cron.ini = true

View File

@@ -16,11 +16,14 @@ class AppController extends Controller {
* @param $f3
*/
public function showLandingpage($f3) {
// page title
$f3->set('pageTitle', 'Login');
// main page content
$f3->set('pageContent', $f3->get('PATHFINDER.VIEW.LANDINGPAGE'));
// body element class
$this->f3->set('bodyClass', 'pf-body pf-landing');
$f3->set('bodyClass', 'pf-body pf-landing');
// landing page is always IGB trusted
$f3->set('trusted', 1);

View File

@@ -260,39 +260,43 @@ class Controller {
/**
* get some server information
* @return array
* @param int $ttl cache time (default: 1h)
* @return object
*/
static function getServerData(){
static function getServerData($ttl = 3600){
$f3 = \Base::instance();
$cacheKey = 'PF_SERVER_INFO';
if( !$f3->exists($cacheKey) ){
$serverData = (object) [];
$serverData->type = '???';
$serverData->version = '???';
$serverData->requiredVersion = '???';
$serverData->type = 'unknown';
$serverData->version = 'unknown';
$serverData->requiredVersion = 'unknown';
$serverData->phpInterfaceType = php_sapi_name();
if(strpos('nginx', strtolower($_SERVER['SERVER_SOFTWARE']) ) !== 1){
if(strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'nginx' ) !== false){
// Nginx server
$serverSoftwareArgs = explode('/', strtolower( $_SERVER['SERVER_SOFTWARE']) );
$serverData->type = reset($serverSoftwareArgs);
$serverData->version = end($serverSoftwareArgs);
$serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.NGINX.VERSION');
}elseif(strpos('apache', strtolower($_SERVER['SERVER_SOFTWARE']) ) !== 1){
}elseif(strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache' ) !== false){
// Apache server
$matches = preg_split('/[\s,\/ ]+/', strtolower( apache_get_version() ) );
if(count($matches)){
$serverData->type = $matches[0];
$serverData->type = 'apache';
$serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.APACHE.VERSION');
// try to get the apache version...
if(function_exists('apache_get_version')){
// function does not exists if PHP is running as CGI/FPM module!
$matches = preg_split('/[\s,\/ ]+/', strtolower( apache_get_version() ) );
if(count($matches) > 1){
$serverData->version = $matches[1];
}
}
$serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.APACHE.VERSION');
}
// cache data for one day
$f3->set($cacheKey, $serverData, 60 * 60 * 24);
$f3->set($cacheKey, $serverData, $ttl);
}
return $f3->get($cacheKey);
@@ -368,7 +372,6 @@ class Controller {
if( $f3->exists($environmentKey) ){
$data = $f3->get($environmentKey);
}
return $data;
}
@@ -390,6 +393,22 @@ class Controller {
return self::getEnvironment() == 'PRODUCTION';
}
/**
* get required MySQL variable value
* @param $key
* @return mixed|null
*/
static function getRequiredMySqlVariables($key){
$f3 = \Base::instance();
$requiredMySqlVarKey = 'REQUIREMENTS[MYSQL][VARS][' . $key . ']';
$data = null;
if( $f3->exists($requiredMySqlVarKey) ){
$data = $f3->get($requiredMySqlVarKey);
}
return $data;
}
/**
* get a program URL by alias
* -> if no $alias given -> get "default" route (index.php)
@@ -475,7 +494,7 @@ class Controller {
/**
* Callback for framework "unload"
* -> config.ini
* check -> config.ini
*/
public function unload($f3){
return true;

View File

@@ -12,16 +12,20 @@ class MapController extends \Controller\AccessController {
public function showMap($f3) {
// page title
$f3->set('pageTitle', 'Maps');
// main page content
$f3->set('pageContent', false);
// body element class
$this->f3->set('bodyClass', 'pf-body');
$f3->set('bodyClass', 'pf-body');
// set trust attribute to template
$this->f3->set('trusted', (int)self::isIGBTrusted());
$f3->set('trusted', (int)self::isIGBTrusted());
// JS main file
$this->f3->set('jsView', 'mappage');
$f3->set('jsView', 'mappage');
}
}

View File

@@ -79,15 +79,15 @@ class Setup extends Controller {
* @param $f3
*/
function beforeroute($f3) {
// load "requirements" info in "setup" route only
$f3->config('app/requirements.ini');
// body element class
$f3->set('bodyClass', 'pf-body pf-landing');
// page title
$f3->set('pageTitle', 'Setup');
// main page content
$f3->set('pageContent', $f3->get('PATHFINDER.VIEW.SETUP'));
// body element class
$f3->set('bodyClass', 'pf-body pf-landing');
// js path (build/minified or raw uncompressed files)
$f3->set('pathJs', 'public/js/' . $f3->get('PATHFINDER.VERSION') );
}
@@ -185,32 +185,36 @@ class Setup extends Controller {
// server type ------------------------------------------------------------------
$serverData = self::getServerData();
$serverData = self::getServerData(0);
$checkRequirements = [
'servertype' => [
'serverType' => [
'label' => 'Server type',
'version' => $serverData->type,
'check' => true
],
'serverversion' => [
'serverVersion' => [
'label' => 'Server version',
'required' => $serverData->requiredVersion,
'version' => $serverData->version,
'check' => version_compare( $serverData->version, $serverData->requiredVersion, '>=')
'check' => version_compare( $serverData->version, $serverData->requiredVersion, '>='),
'tooltip' => 'If not specified, please check your \'ServerTokens\' server config. (not critical)'
],
'phpInterface' => [
'label' => 'PHP interface type',
'version' => $serverData->phpInterfaceType,
'check' => empty($serverData->phpInterfaceType) ? false : true
],
'php' => [
'label' => 'PHP',
'required' => $f3->get('REQUIREMENTS.PHP.VERSION'),
'version' => phpversion(),
'prefix' => 'v.',
'check' => version_compare( phpversion(), $f3->get('REQUIREMENTS.PHP.VERSION'), '>=')
],
'pcre' => [
'label' => 'PCRE',
'required' => $f3->get('REQUIREMENTS.PHP.PCRE_VERSION'),
'version' => strstr(PCRE_VERSION, ' ', true),
'prefix' => 'v.',
'check' => version_compare( strstr(PCRE_VERSION, ' ', true), $f3->get('REQUIREMENTS.PHP.PCRE_VERSION'), '>=')
],
'gd' => [
@@ -228,9 +232,14 @@ class Setup extends Controller {
];
if($serverData->type != 'nginx'){
// default msg if module status not available
$modNotFoundMsg = 'Module status can not be identified. '
. 'This can happen if PHP runs as \'FastCGI\'. Please check manual! ';
// mod_rewrite check ------------------------------------------------------------
$modRewriteCheck = false;
$modRewriteVersion = 'disabled';
$modRewriteTooltip = false;
if(function_exists('apache_get_modules')){
if(in_array('mod_rewrite',apache_get_modules())){
$modRewriteCheck = true;
@@ -238,19 +247,22 @@ class Setup extends Controller {
}
}else{
// e.g. Nginx server
$modRewriteVersion = '???';
$modRewriteVersion = 'unknown';
$modRewriteTooltip = $modNotFoundMsg;
}
$checkRequirements['mod_rewrite'] = [
'label' => 'mod_rewrite',
'required' => 'enabled',
'version' => $modRewriteVersion,
'check' => $modRewriteCheck
'check' => $modRewriteCheck,
'tooltip' => $modRewriteTooltip
];
// mod_headers check ------------------------------------------------------------
$modHeadersCheck = false;
$modHeadersVersion = 'disabled';
$modHeadersTooltip = false;
if(function_exists('apache_get_modules')){
if(in_array('mod_headers',apache_get_modules())){
$modHeadersCheck = true;
@@ -258,14 +270,16 @@ class Setup extends Controller {
}
}else{
// e.g. Nginx server
$modHeadersVersion = '???';
$modHeadersVersion = 'unknown';
$modHeadersTooltip = $modNotFoundMsg;
}
$checkRequirements['mod_headers'] = [
'label' => 'mod_headers',
'required' => 'enabled',
'version' => $modHeadersVersion,
'check' => $modHeadersCheck
'check' => $modHeadersCheck,
'tooltip' => $modHeadersTooltip
];
}
@@ -290,7 +304,7 @@ class Setup extends Controller {
// DB connection status
$dbConnected = false;
// DB type (e.g. MySql,..)
$dbDriver = '???';
$dbDriver = 'unknown';
// enable database ::setup() function in UI
$dbSetupEnable = false;
// check of everything is OK (connection, tables, columns, indexes,..)
@@ -554,7 +568,7 @@ class Setup extends Controller {
// some db like "Maria DB" have some strange version strings....
$dbVersionString = $db->version();
$dbVersionParts = explode('-', $dbVersionString);
$dbVersion = '???';
$dbVersion = 'unknown';
foreach($dbVersionParts as $dbVersionPart){
// check if this is a valid version number
// hint: MariaDB´s version is always the last valid version number...
@@ -566,23 +580,27 @@ class Setup extends Controller {
$dbConfig = [
'version' => [
'label' => 'DB version',
'required' => 'v.' . $f3->get('REQUIREMENTS.MYSQL.VERSION'),
'version' => 'v.' . $dbVersion,
'required' => $f3->get('REQUIREMENTS.MYSQL.VERSION'),
'version' => $dbVersion,
'check' => version_compare($dbVersion, $f3->get('REQUIREMENTS.MYSQL.VERSION'), '>=' )
]
];
// get specific MySQL config Value
$getDBConfigValue = function($db, $param){
$result = $db->exec('SELECT @@' . $param);
return !empty($result)? reset(reset($result)) : '???';
$result = $db->exec([
//"USE " . $db->name(),
"SHOW VARIABLES LIKE '" . strtolower($param) . "'"
]);
$tmpResult = reset($result);
return !empty($result)? end($tmpResult) : 'unknown';
};
$mySQLConfigParams = $f3->get('REQUIREMENTS.MYSQL.OPTIONS');
$mySQLConfigParams = $f3->get('REQUIREMENTS.MYSQL.VARS');
foreach($mySQLConfigParams as $param => $requiredValue){
$value = $getDBConfigValue($db, $param);
$dbConfig[] = [
'label' => $param,
'label' => strtolower($param),
'required' => $requiredValue,
'version' => $value,
'check' => !empty($requiredValue) ? ($requiredValue == $value) : true
@@ -605,6 +623,13 @@ class Setup extends Controller {
$checkTables = [];
if($db){
// set/change default "character set" and "collation"
$db->exec('ALTER DATABASE ' . $db->name()
. ' CHARACTER SET ' . self::getRequiredMySqlVariables('CHARACTER_SET_DATABASE')
. ' COLLATE ' . self::getRequiredMySqlVariables('COLLATION_DATABASE')
);
// setup tables
foreach($this->databases[$dbKey]['models'] as $modelClass){
$checkTables[] = call_user_func($modelClass . '::setup');
}

View File

@@ -30,34 +30,31 @@ class Database extends \Prefab {
// "Hive" Key for DB storage
$dbHiveKey = $this->getDbHiveKey($database);
if($database === 'CCP'){
// CCP DB
$dns = Controller\Controller::getEnvironmentData('DB_CCP_DNS');
$name = Controller\Controller::getEnvironmentData('DB_CCP_NAME');
$user = Controller\Controller::getEnvironmentData('DB_CCP_USER');
$password = Controller\Controller::getEnvironmentData('DB_CCP_PASS');
}else{
// Pathfinder(PF) DB
$dns = Controller\Controller::getEnvironmentData('DB_DNS');
$name = Controller\Controller::getEnvironmentData('DB_NAME');
$user = Controller\Controller::getEnvironmentData('DB_USER');
$password = Controller\Controller::getEnvironmentData('DB_PASS');
}
// check if DB connection already exists
if(
!$f3->exists( $dbHiveKey ) ||
$name !== $f3->get( $dbHiveKey )->name()
){
if( !$f3->exists( $dbHiveKey ) ){
if($database === 'CCP'){
// CCP DB
$dns = Controller\Controller::getEnvironmentData('DB_CCP_DNS');
$name = Controller\Controller::getEnvironmentData('DB_CCP_NAME');
$user = Controller\Controller::getEnvironmentData('DB_CCP_USER');
$password = Controller\Controller::getEnvironmentData('DB_CCP_PASS');
}else{
// Pathfinder(PF) DB
$dns = Controller\Controller::getEnvironmentData('DB_DNS');
$name = Controller\Controller::getEnvironmentData('DB_NAME');
$user = Controller\Controller::getEnvironmentData('DB_USER');
$password = Controller\Controller::getEnvironmentData('DB_PASS');
}
$db = $this->connect($dns, $name, $user, $password);
if( !is_null($db) ){
// set DB timezone to UTC +00:00 (eve server time)
$db->exec('SET @@session.time_zone = "+00:00";');
// disable innoDB schema (relevant vor MySql 5.5)
// not necessary for MySql > v.5.6
// $db->exec('SET GLOBAL innodb_stats_on_metadata = OFF;');
// set default storage engine
$db->exec('SET @@session.default_storage_engine = "' .
Controller\Controller::getRequiredMySqlVariables('DEFAULT_STORAGE_ENGINE') . '"');
// store DB object
$f3->set($dbHiveKey, $db);

View File

@@ -36,7 +36,7 @@ INVITE_LIMIT = 50
; View ============================================================================================
[PATHFINDER.VIEW]
; static page temaplates
; static page templates
INDEX = templates/view/index.html
SETUP = templates/view/setup.html
LANDINGPAGE = templates/view/landingpage.html

View File

@@ -10,7 +10,7 @@ NGINX.VERSION = 1.9
[REQUIREMENTS.PHP]
; recommended is >= 5.6
VERSION = 5.4
VERSION = 5.6
; "Perl-Compatible Regular Expressions"
; usually shipped with PHP package,
@@ -22,9 +22,16 @@ PCRE_VERSION = 8.02
; newer "deviation" of MySQL like "MariaDB" > 10.1 are recommended
VERSION = 5.6
[REQUIREMENTS.MYSQL.OPTIONS]
STORAGE_ENGINE = InnoDB
CHARACTER_SET_SERVER = utf8
FOREIGN_KEY_CHECKS = 1
[REQUIREMENTS.MYSQL.VARS]
; MySql variables. Values are auto. set as 'SESSION' vars
; https://dev.mysql.com/doc/refman/5.5/en/show-variables.html
DEFAULT_STORAGE_ENGINE = InnoDB
CHARACTER_SET_DATABASE = utf8
CHARACTER_SET_CLIENT = utf8
CHARACTER_SET_RESULTS = utf8
CHARACTER_SET_CONNECTION = utf8
COLLATION_DATABASE = utf8_general_ci
COLLATION_CONNECTION = utf8_general_ci
FOREIGN_KEY_CHECKS = ON

View File

@@ -4,18 +4,6 @@ $f3 = require('app/lib/base.php');
// load main config
$f3->config('app/config.ini');
// load route config
$f3->config('app/routes.ini');
// load environment config
$f3->config('app/environment.ini');
// load pathfinder config
$f3->config('app/pathfinder.ini');
// load cron config
$f3->config('app/cron.ini');
// set base dir
$f3->set('BASE', \Controller\Controller::getEnvironmentData('BASE'));

View File

@@ -3,8 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="cache-control" content="public">
@@ -32,7 +31,7 @@
<meta name="keywords" content="eve,wormhole,mapping,tool,mmo,space,game,igb">
<meta name="author" content="Exodus 4D">
<title>Pathfinder</title>
<title>Pathfinder - {{ @pageTitle}}</title>
<meta property="og:title" content="EVE ONLINE mapping tool">
<meta property="og:site_name" content="PATHFINDER">
@@ -43,14 +42,13 @@
<meta property="og:description" content="PATHFINDER is an 'open source' mapping tool for EVE ONLINE,
primarily developed to enrich the gameplay of small scale PvP and PvE.">
<!-- Chrome, Firefox OS and Opera -->
{* Chrome, Firefox OS and Opera *}
<meta name="theme-color" content="#2b2b2b">
<!-- Windows Phone -->
{* Windows Phone *}
<meta name="msapplication-navbutton-color" content="#2b2b2b">
<!-- iOS Safari -->
{* iOS Safari *}
<meta name="apple-mobile-web-app-status-bar-style" content="#2b2b2b">
<link rel="stylesheet" type="text/css" media="screen" href="/public/css/pathfinder.css?{{ @PATHFINDER.VERSION }}">
</head>

View File

@@ -69,10 +69,7 @@
</false>
</check>
{* login form*}
{* login form *}
<section id="pf-landing-login">
<div class="container">
<div class="row text-center">

View File

@@ -131,21 +131,26 @@
<tbody>
<repeat group="{{ @checkRequirements }}" value="{{ @requirement }}">
<tr>
<td>{{@requirement.label}}</td>
<td>
{{@requirement.label}}
<check if="{{ @requirement.tooltip }}">
<i class="fa fa-fw fa-question-circle" title="{{ @requirement.tooltip }}"></i>
</check>
</td>
<td class="text-right">
<check if="{{ @requirement.required }}">
<kbd>{{@requirement.prefix}}{{@requirement.required}}</kbd>
<kbd>{{@requirement.required}}</kbd>
</check>
</td>
<td class="text-right">
<check if="{{ @requirement.check }}">
<true>
<kbd class="txt-color txt-color-success">{{@requirement.prefix}}{{@requirement.version}}</kbd>
<kbd class="txt-color txt-color-success">{{@requirement.version}}</kbd>
</true>
<false>
<kbd class="txt-color txt-color-warning">{{@requirement.prefix}}{{@requirement.version}}</kbd>
<kbd class="txt-color txt-color-warning">{{@requirement.version}}</kbd>
{* Check failed *}
<set requirementsFulfilled="Missing feature" />
<set requirementsFulfilled="Warnings" />
</false>
</check>
</td>

View File

@@ -55,7 +55,6 @@ em{
@extend .txt-color-gray;
@include transition( color 0.08s ease-out );
&:hover{
@extend .txt-color-blue;
}