closes #175 added alternative environment configuration
This commit is contained in:
@@ -11,11 +11,46 @@ namespace Controller;
|
||||
use DB;
|
||||
use DB\SQL;
|
||||
use DB\SQL\MySQL as MySQL;
|
||||
|
||||
use lib\Config;
|
||||
use Model;
|
||||
|
||||
class Setup extends Controller {
|
||||
|
||||
/**
|
||||
* required environment variables
|
||||
* @var array
|
||||
*/
|
||||
protected $environmentVars = [
|
||||
'TYPE',
|
||||
'BASE',
|
||||
'URL',
|
||||
'DEBUG',
|
||||
'DB_DNS',
|
||||
'DB_NAME',
|
||||
'DB_USER',
|
||||
'DB_PASS',
|
||||
'DB_CCP_DNS',
|
||||
'DB_CCP_NAME',
|
||||
'DB_CCP_USER',
|
||||
'DB_CCP_PASS',
|
||||
'CCP_CREST_URL',
|
||||
'SSO_CCP_URL',
|
||||
'SSO_CCP_CLIENT_ID',
|
||||
'SSO_CCP_SECRET_KEY',
|
||||
'CCP_XML',
|
||||
'SMTP_HOST',
|
||||
'SMTP_PORT',
|
||||
'SMTP_SCHEME',
|
||||
'SMTP_USER',
|
||||
'SMTP_PASS',
|
||||
'SMTP_FROM',
|
||||
'SMTP_ERROR'
|
||||
];
|
||||
|
||||
/**
|
||||
* required database setup
|
||||
* @var array
|
||||
*/
|
||||
protected $databases = [
|
||||
'PF' => [
|
||||
'info' => [],
|
||||
@@ -104,7 +139,7 @@ class Setup extends Controller {
|
||||
* works as dispatcher for setup functions
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function init($f3){
|
||||
public function init(\Base $f3){
|
||||
$params = $f3->get('GET');
|
||||
|
||||
// enables automatic column fix
|
||||
@@ -128,22 +163,69 @@ class Setup extends Controller {
|
||||
$fixColumns = true;
|
||||
}
|
||||
|
||||
// set server information for page render
|
||||
// set template data ----------------------------------------------------------------
|
||||
// set environment information
|
||||
$f3->set('environmentInformation', $this->getEnvironmentInformation($f3));
|
||||
|
||||
// set server information
|
||||
$f3->set('serverInformation', $this->getServerInformation($f3));
|
||||
|
||||
// set requirement check information for page render
|
||||
// set requirement check information
|
||||
$f3->set('checkRequirements', $this->checkRequirements($f3));
|
||||
|
||||
// set database connection information for page render
|
||||
// set database connection information
|
||||
$f3->set('checkDatabase', $this->checkDatabase($f3, $fixColumns));
|
||||
}
|
||||
|
||||
/**
|
||||
* set environment information
|
||||
* @param \Base $f3
|
||||
* @return array
|
||||
*/
|
||||
protected function getEnvironmentInformation(\Base $f3){
|
||||
$environmentData = [];
|
||||
// exclude some sensitive data (e.g. database, passwords)
|
||||
$excludeVars = ['DB_DNS', 'DB_NAME', 'DB_USER',
|
||||
'DB_PASS', 'DB_CCP_DNS', 'DB_CCP_NAME',
|
||||
'DB_CCP_USER', 'DB_CCP_PASS'
|
||||
];
|
||||
|
||||
// obscure some values
|
||||
$obscureVars = ['SSO_CCP_CLIENT_ID', 'SSO_CCP_SECRET_KEY', 'SMTP_PASS'];
|
||||
|
||||
foreach($this->environmentVars as $var){
|
||||
if( !in_array($var, $excludeVars) ){
|
||||
$value = Config::getEnvironmentData($var);
|
||||
$check = true;
|
||||
|
||||
if(is_null($value)){
|
||||
// variable missing
|
||||
$check = false;
|
||||
$value = '[missing]';
|
||||
}elseif( in_array($var, $obscureVars)){
|
||||
$length = strlen($value);
|
||||
$hideChars = ($length < 10) ? $length : 10;
|
||||
$value = substr_replace($value, str_repeat('.', 3), -$hideChars);
|
||||
$value .= ' [' . $length . ']';
|
||||
}
|
||||
|
||||
$environmentData[$var] = [
|
||||
'label' => $var,
|
||||
'value' => ((empty($value)) ? ' ' : $value),
|
||||
'check' => $check
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $environmentData;
|
||||
}
|
||||
|
||||
/**
|
||||
* get server information
|
||||
* @param \Base $f3
|
||||
* @return array
|
||||
*/
|
||||
protected function getServerInformation($f3){
|
||||
protected function getServerInformation(\Base $f3){
|
||||
$serverInfo = [
|
||||
'time' => [
|
||||
'label' => 'Time',
|
||||
@@ -180,7 +262,7 @@ class Setup extends Controller {
|
||||
* @param \Base $f3
|
||||
* @return array
|
||||
*/
|
||||
protected function checkRequirements($f3){
|
||||
protected function checkRequirements(\Base $f3){
|
||||
|
||||
|
||||
// server type ------------------------------------------------------------------
|
||||
@@ -291,7 +373,7 @@ class Setup extends Controller {
|
||||
* @param bool|false $exec
|
||||
* @return array
|
||||
*/
|
||||
protected function checkDatabase($f3, $exec = false){
|
||||
protected function checkDatabase(\Base $f3, $exec = false){
|
||||
|
||||
foreach($this->databases as $dbKey => $dbData){
|
||||
|
||||
@@ -575,7 +657,7 @@ class Setup extends Controller {
|
||||
* @param $db
|
||||
* @return array
|
||||
*/
|
||||
protected function checkDBConfig($f3, $db){
|
||||
protected function checkDBConfig(\Base $f3, $db){
|
||||
|
||||
// some db like "Maria DB" have some strange version strings....
|
||||
$dbVersionString = $db->version();
|
||||
|
||||
Reference in New Issue
Block a user