File: //srv/admin/htdocs/_util.php
<?php
define('INTERNAL_PORT', 5081);
define('RUN_PATH', '/srv/run');
define('DATA_DISK_MNT', '/srv/data');
define('DEFAULT_VHOST_PATH', DATA_DISK_MNT . '/web/vhosts/default');
define('GIT_REPOSITORIES_PATH', DATA_DISK_MNT . '/vcs/git');
define('CUSTOM_ADMIN_PATH', DATA_DISK_MNT . '/web/customadmin');
define('GIBIBYTE', (1024 * 1024 * 1024));
function data_disk_total_space()
{
return disk_total_space(DATA_DISK_MNT) / GIBIBYTE;
}
function data_disk_free_space()
{
return disk_free_space(DATA_DISK_MNT) / GIBIBYTE;
}
function is_php_running()
{
return file_exists(RUN_PATH . '/php/www.sock');
}
function is_nodejs_running()
{
return file_exists(RUN_PATH . '/nodejs');
}
function is_python_running()
{
return file_exists(RUN_PATH . '/uwsgi/.python')
|| file_exists(DEFAULT_VHOST_PATH . '/wsgi.py');
}
function is_ruby_running()
{
return file_exists(RUN_PATH . '/uwsgi/.ruby')
|| file_exists(DEFAULT_VHOST_PATH . '/config.ru');
}
function is_mysql_running()
{
return file_exists(RUN_PATH . '/mysqld');
}
function is_postgres_running()
{
return file_exists(RUN_PATH . '/pgsql');
}
function is_mongodb_running()
{
return file_exists(RUN_PATH . '/mongodb');
}
function has_git_repositories()
{
$results = glob(GIT_REPOSITORIES_PATH . '/*.git', GLOB_ONLYDIR);
return ($results !== false && !empty($results));
}
function custom_admin_exists($filename)
{
return file_exists(CUSTOM_ADMIN_PATH . '/' . $filename);
}
function is_internal()
{
return $_SERVER['SERVER_PORT'] == INTERNAL_PORT;
}
function header_file()
{
if (!is_internal() && custom_admin_exists('header.php')) {
return CUSTOM_ADMIN_PATH. '/header.php';
}
return '_header.php';
}
function footer_file()
{
if (!is_internal() && custom_admin_exists('footer.php')) {
return CUSTOM_ADMIN_PATH. '/footer.php';
}
return '_footer.php';
}
function css_path()
{
if (!is_internal() && custom_admin_exists('simplehosting.css')) {
return '/customadmin/simplehosting.css';
}
return '/css/screen-default.css';
}
function favicon_path()
{
if (!is_internal() && custom_admin_exists('favicon.ico')) {
return '/customadmin/favicon.ico';
}
return '/favicon.ico';
}
function phpmyadmin_version()
{
if (PHP_VERSION_ID >= 70205) { // PHP >= 7.2.5
return '5.2';
}
elseif (PHP_VERSION_ID >= 50500) { // PHP 5.5 to 7.4
return '4.9'; // (LTS)
}
else { // PHP 5.4 and older
return '4.4'; // (EOL)
}
}
function phppgadmin_version() {
if (PHP_VERSION_ID >= 70200)
return "7.13"; // PHP >= 7.2
else
return "5.6"; // PHP <= 7.1
}
?>