2016-10-09 16:47:49 +00:00
|
|
|
<?PHP
|
2016-11-06 12:36:07 +00:00
|
|
|
// Measure time
|
2016-10-11 13:45:21 +00:00
|
|
|
$TIME_START = microtime(true);
|
2016-10-09 16:47:49 +00:00
|
|
|
|
2017-09-09 08:40:07 +00:00
|
|
|
// Start session
|
|
|
|
session_start();
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
// Turn on all PHP errors
|
2016-11-06 12:36:07 +00:00
|
|
|
error_reporting(-1);
|
2016-10-09 16:47:49 +00:00
|
|
|
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
// Shorten DNS timeouts for gethostbyname in case DNS server is down
|
|
|
|
putenv('RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1');
|
|
|
|
|
|
|
|
|
2020-11-07 09:37:04 +00:00
|
|
|
$DEVILBOX_VERSION = 'v1.7.3';
|
2020-11-08 10:03:40 +00:00
|
|
|
$DEVILBOX_DATE = '2020-11-08';
|
2017-05-06 09:14:01 +00:00
|
|
|
$DEVILBOX_API_PAGE = 'devilbox-api/status.json';
|
|
|
|
|
2016-11-06 12:36:07 +00:00
|
|
|
//
|
|
|
|
// Set Directories
|
|
|
|
//
|
|
|
|
$CONF_DIR = dirname(__FILE__);
|
2017-05-06 09:14:01 +00:00
|
|
|
$LIB_DIR = $CONF_DIR . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR .'lib';
|
|
|
|
$VEN_DIR = $CONF_DIR . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR .'vendor';
|
2016-11-06 12:36:07 +00:00
|
|
|
$LOG_DIR = dirname(dirname($CONF_DIR)) . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'devilbox';
|
2016-10-09 16:47:49 +00:00
|
|
|
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
//
|
|
|
|
// Load Base classes
|
|
|
|
//
|
|
|
|
require $LIB_DIR . DIRECTORY_SEPARATOR . 'container' . DIRECTORY_SEPARATOR .'BaseClass.php';
|
|
|
|
require $LIB_DIR . DIRECTORY_SEPARATOR . 'container' . DIRECTORY_SEPARATOR .'BaseInterface.php';
|
2016-11-06 12:57:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-06 12:36:07 +00:00
|
|
|
//
|
|
|
|
// Set Docker addresses
|
|
|
|
//
|
2017-05-06 09:14:01 +00:00
|
|
|
$DNS_HOST_NAME = 'bind';
|
2016-11-06 12:36:07 +00:00
|
|
|
$PHP_HOST_NAME = 'php';
|
2017-05-06 09:14:01 +00:00
|
|
|
$HTTPD_HOST_NAME = 'httpd';
|
2016-11-15 18:39:34 +00:00
|
|
|
$MYSQL_HOST_NAME = 'mysql';
|
2017-05-06 09:14:01 +00:00
|
|
|
$PGSQL_HOST_NAME = 'pgsql';
|
|
|
|
$REDIS_HOST_NAME = 'redis';
|
2017-05-20 18:12:31 +00:00
|
|
|
$MEMCD_HOST_NAME = 'memcd';
|
2017-05-22 21:20:20 +00:00
|
|
|
$MONGO_HOST_NAME = 'mongo';
|
2016-10-09 16:47:49 +00:00
|
|
|
|
2016-11-15 18:39:34 +00:00
|
|
|
|
2016-11-06 12:36:07 +00:00
|
|
|
//
|
2017-05-06 09:14:01 +00:00
|
|
|
// Lazy Container Loader
|
2016-11-06 12:36:07 +00:00
|
|
|
//
|
2017-05-06 09:14:01 +00:00
|
|
|
function loadFile($class, $base_path) {
|
|
|
|
static $_LOADED_FILE;
|
2017-04-19 17:48:44 +00:00
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
if (isset($_LOADED_FILE[$class])) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-19 17:48:44 +00:00
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
require $base_path . DIRECTORY_SEPARATOR . $class . '.php';
|
|
|
|
$_LOADED_FILE[$class] = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
function loadClass($class) {
|
2017-04-19 17:48:44 +00:00
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
static $_LOADED_LIBS;
|
2017-04-19 17:48:44 +00:00
|
|
|
|
|
|
|
if (isset($_LOADED_LIBS[$class])) {
|
|
|
|
return $_LOADED_LIBS[$class];
|
|
|
|
} else {
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
$lib_dir = $GLOBALS['LIB_DIR'];
|
|
|
|
$cnt_dir = $GLOBALS['LIB_DIR'] . DIRECTORY_SEPARATOR . 'container';
|
|
|
|
|
|
|
|
switch($class) {
|
|
|
|
//
|
|
|
|
// Lib Classes
|
|
|
|
//
|
2017-04-19 17:48:44 +00:00
|
|
|
case 'Logger':
|
2017-05-06 09:14:01 +00:00
|
|
|
loadFile($class, $lib_dir);
|
2017-04-19 17:48:44 +00:00
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Logger::getInstance();
|
|
|
|
break;
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
case 'Html':
|
|
|
|
loadFile($class, $lib_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Html::getInstance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Helper':
|
|
|
|
loadFile($class, $lib_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Helper::getInstance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Docker Container Classes
|
|
|
|
//
|
|
|
|
case 'Php':
|
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Php::getInstance($GLOBALS['PHP_HOST_NAME']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Dns':
|
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Dns::getInstance($GLOBALS['DNS_HOST_NAME']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Httpd':
|
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Httpd::getInstance($GLOBALS['HTTPD_HOST_NAME']);
|
2017-04-19 17:48:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Mysql':
|
2017-05-06 09:14:01 +00:00
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Mysql::getInstance($GLOBALS['MYSQL_HOST_NAME'], array(
|
|
|
|
'user' => 'root',
|
|
|
|
'pass' => loadClass('Helper')->getEnv('MYSQL_ROOT_PASSWORD')
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Pgsql':
|
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Pgsql::getInstance($GLOBALS['PGSQL_HOST_NAME'], array(
|
|
|
|
'user' => loadClass('Helper')->getEnv('PGSQL_ROOT_USER'),
|
|
|
|
'pass' => loadClass('Helper')->getEnv('PGSQL_ROOT_PASSWORD'),
|
|
|
|
'db' => 'postgres'
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Redis':
|
2018-08-11 11:50:21 +00:00
|
|
|
|
|
|
|
// Check if redis is using a password
|
|
|
|
$REDIS_ROOT_PASSWORD = '';
|
|
|
|
|
|
|
|
$_REDIS_ARGS = loadClass('Helper')->getEnv('REDIS_ARGS');
|
|
|
|
$_REDIS_PASS = preg_split("/--requirepass\s+/", $_REDIS_ARGS);
|
|
|
|
if (is_array($_REDIS_PASS) && count($_REDIS_PASS)) {
|
|
|
|
// In case the option is specified multiple times, use the last effective one.
|
|
|
|
$_REDIS_PASS = $_REDIS_PASS[count($_REDIS_PASS)-1];
|
|
|
|
if (strlen($_REDIS_PASS) > 0) {
|
|
|
|
$REDIS_ROOT_PASSWORD = $_REDIS_PASS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
loadFile($class, $cnt_dir);
|
2018-08-11 11:50:21 +00:00
|
|
|
if ($REDIS_ROOT_PASSWORD == '') {
|
2018-07-05 21:50:24 +00:00
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']);
|
2018-08-11 11:50:21 +00:00
|
|
|
} else {
|
2018-07-05 21:50:24 +00:00
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME'], array(
|
2018-08-11 11:50:21 +00:00
|
|
|
'pass' => $REDIS_ROOT_PASSWORD,
|
2018-07-05 21:50:24 +00:00
|
|
|
));
|
|
|
|
}
|
2017-04-19 17:48:44 +00:00
|
|
|
break;
|
|
|
|
|
2017-05-06 09:14:01 +00:00
|
|
|
case 'Memcd':
|
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Memcd::getInstance($GLOBALS['MEMCD_HOST_NAME']);
|
2017-04-19 17:48:44 +00:00
|
|
|
break;
|
|
|
|
|
2017-05-22 21:20:20 +00:00
|
|
|
case 'Mongo':
|
|
|
|
loadFile($class, $cnt_dir);
|
|
|
|
$_LOADED_LIBS[$class] = \devilbox\Mongo::getInstance($GLOBALS['MONGO_HOST_NAME']);
|
|
|
|
break;
|
|
|
|
|
2017-04-23 11:20:32 +00:00
|
|
|
// Get optional docker classes
|
2017-04-19 17:48:44 +00:00
|
|
|
default:
|
2018-08-11 11:50:21 +00:00
|
|
|
// Unknown class
|
2017-05-06 09:14:01 +00:00
|
|
|
exit('Class does not exist: '.$class);
|
2017-04-19 17:48:44 +00:00
|
|
|
}
|
|
|
|
return $_LOADED_LIBS[$class];
|
|
|
|
}
|
|
|
|
}
|