diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 8d4ae411..888a6fdc 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -1102,10 +1102,6 @@ includes/ ├── CoreUtilities.php # ~135 статических методов -> proxy к core/ и domain/ ├── StreamingUtilities.php # ~66 статических методов -> proxy к streaming/ ├── ts.php # Timeshift утилиты -├── bootstrap/ # Старые файлы инициализации admin -│ ├── admin_bootstrap.php -│ ├── admin_runtime.php -│ └── admin_session.php ├── api/ # API-обработчики │ ├── admin/ │ └── reseller/ @@ -1200,7 +1196,6 @@ LB_DIRS_TO_REMOVE := \ bin/nginx/conf/codes \ includes/api \ includes/libs/resources \ - includes/bootstrap \ domain/User \ domain/Device \ domain/Auth \ diff --git a/Makefile b/Makefile index 305bb22e..fc29be60 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,6 @@ LB_DIRS_TO_REMOVE := \ bin/nginx/conf/codes \ includes/api \ includes/libs/resources \ - includes/bootstrap \ domain/User \ domain/Device \ domain/Auth \ diff --git a/docs/en/builds/build_system.md b/docs/en/builds/build_system.md index 4de93ae3..54e73b98 100644 --- a/docs/en/builds/build_system.md +++ b/docs/en/builds/build_system.md @@ -82,7 +82,6 @@ After copying, admin-specific content is **removed** from the LB build: | `resources/langs/` | Admin UI language files | | `includes/api/` | Admin API routes | | `includes/libs/resources/` | Admin resource libraries | -| `includes/bootstrap/` | Admin bootstrap | | `domain/User/` | User management | | `domain/Device/` | Device registration | | `domain/Auth/` | Auth management (panel auth) | diff --git a/docs/ru/builds/build_system.md b/docs/ru/builds/build_system.md index 59baf248..d8a9ed27 100644 --- a/docs/ru/builds/build_system.md +++ b/docs/ru/builds/build_system.md @@ -82,7 +82,6 @@ signals/ streaming/ tmp/ www/ | `resources/langs/` | Языковые ресурсы | | `includes/api/` | Маршруты админ API | | `includes/libs/resources/` | Библиотеки ресурсов админки | -| `includes/bootstrap/` | Бутстрап админки | | `domain/User/` | Управление пользователями | | `domain/Device/` | Регистрация устройств | | `domain/Auth/` | Авторизация (панельная) | diff --git a/src/bootstrap.php b/src/bootstrap.php index e7700b1c..f12d459e 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -186,6 +186,7 @@ class XC_Bootstrap { self::initAdminAPI(); self::initTranslator(); self::registerAdminShutdown(); + self::initAdminGlobals(); break; } @@ -574,6 +575,56 @@ class XC_Bootstrap { } } + /** + * Инициализация admin-глобалов: MobileDetect, таймауты, серверы, + * протокол, admin_constants. + * + * Логика из includes/bootstrap/admin_runtime.php (post-bootstrap block) + * + includes/bootstrap/admin_bootstrap.php (admin_constants.php). + */ + private static function initAdminGlobals(): void { + global $rDetect, $rMobile, $rTimeout, $rSQLTimeout, $rProtocol, + $allServers, $rServers, $rSettings, $rProxyServers, + $rPermissions, $language, $allowedLangs; + + if (!defined('SERVER_ID')) { + define('SERVER_ID', intval(ConfigReader::get('server_id'))); + } + + require_once INCLUDES_PATH . 'libs/mobiledetect.php'; + $rDetect = new \Mobile_Detect(); + $rMobile = $rDetect->isMobile(); + + $rTimeout = 15; + $rSQLTimeout = 10; + set_time_limit($rTimeout); + ini_set('mysql.connect_timeout', (string) $rSQLTimeout); + ini_set('max_execution_time', (string) $rTimeout); + ini_set('default_socket_timeout', (string) $rTimeout); + + $rProtocol = self::detectProtocol(); + $allServers = ServerRepository::getAllSimple(); + $rServers = ServerRepository::getStreamingSimple($rPermissions); + $rSettings = SettingsManager::getAll(); + $rProxyServers = ServerRepository::getProxySimple($rPermissions); + + $language = Translator::class; + $allowedLangs = $language::available(); + + require_once MAIN_HOME . 'resources/data/admin_constants.php'; + } + + /** + * Определить HTTP-протокол (http/https). + * + * Перенесено из includes/admin.php (issecure + getProtocol). + */ + private static function detectProtocol(): string { + $https = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; + $port443 = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443; + return ($https || $port443) ? 'https' : 'http'; + } + // ───────────────────────────────────────────────────────── // Вспомогательные статусные константы (из admin.php) // ───────────────────────────────────────────────────────── diff --git a/src/includes/admin.php b/src/includes/admin.php index 18f8c43d..65af2cd5 100644 --- a/src/includes/admin.php +++ b/src/includes/admin.php @@ -5,8 +5,8 @@ global $db, $rSettings, $rMobile, $rServers, $rProxyServers, $rDetect, $rTimeout, $rProtocol, $allServers, $rPermissions, $language, $allowedLangs, $_INFO; -require_once __DIR__ . '/bootstrap/admin_bootstrap.php'; -bootstrapAdminInclude(); +require_once __DIR__ . '/../bootstrap.php'; +XC_Bootstrap::boot(XC_Bootstrap::CONTEXT_ADMIN); if (is_array($rServers)) { uasort( diff --git a/src/includes/bootstrap/admin_bootstrap.php b/src/includes/bootstrap/admin_bootstrap.php deleted file mode 100644 index c80c2025..00000000 --- a/src/includes/bootstrap/admin_bootstrap.php +++ /dev/null @@ -1,14 +0,0 @@ - 0, - 'STATUS_SUCCESS' => 1, - 'STATUS_SUCCESS_MULTI' => 2, - 'STATUS_CODE_LENGTH' => 3, - 'STATUS_NO_SOURCES' => 4, - 'STATUS_DISABLED' => 5, - 'STATUS_NOT_ADMIN' => 6, - 'STATUS_INVALID_EMAIL' => 7, - 'STATUS_INVALID_PASSWORD' => 8, - 'STATUS_INVALID_IP' => 9, - 'STATUS_INVALID_PLAYLIST' => 10, - 'STATUS_INVALID_NAME' => 11, - 'STATUS_INVALID_CAPTCHA' => 12, - 'STATUS_INVALID_CODE' => 13, - 'STATUS_INVALID_DATE' => 14, - 'STATUS_INVALID_FILE' => 15, - 'STATUS_INVALID_GROUP' => 16, - 'STATUS_INVALID_DATA' => 17, - 'STATUS_INVALID_DIR' => 18, - 'STATUS_INVALID_MAC' => 19, - 'STATUS_EXISTS_CODE' => 20, - 'STATUS_EXISTS_NAME' => 21, - 'STATUS_EXISTS_USERNAME' => 22, - 'STATUS_EXISTS_MAC' => 23, - 'STATUS_EXISTS_SOURCE' => 24, - 'STATUS_EXISTS_IP' => 25, - 'STATUS_EXISTS_DIR' => 26, - 'STATUS_SUCCESS_REPLACE' => 27, - 'STATUS_FLUSH' => 28, - 'STATUS_TOO_MANY_RESULTS' => 29, - 'STATUS_SPACE_ISSUE' => 30, - 'STATUS_INVALID_USER' => 31, - 'STATUS_CERTBOT' => 32, - 'STATUS_CERTBOT_INVALID' => 33, - 'STATUS_INVALID_INPUT' => 34, - 'STATUS_NOT_RESELLER' => 35, - 'STATUS_NO_TRIALS' => 36, - 'STATUS_INSUFFICIENT_CREDITS' => 37, - 'STATUS_INVALID_PACKAGE' => 38, - 'STATUS_INVALID_TYPE' => 39, - 'STATUS_INVALID_USERNAME' => 40, - 'STATUS_INVALID_SUBRESELLER' => 41, - 'STATUS_NO_DESCRIPTION' => 42, - 'STATUS_NO_KEY' => 43, - 'STATUS_EXISTS_HMAC' => 44, - 'STATUS_CERTBOT_RUNNING' => 45, - 'STATUS_RESERVED_CODE' => 46, - 'STATUS_NO_TITLE' => 47, - 'STATUS_NO_SOURCE' => 48 - ); - - foreach ($rStatusMap as $rStatusConst => $rStatusValue) { - if (!defined($rStatusConst)) { - define($rStatusConst, $rStatusValue); - } - } - } -} - -if (!function_exists('bootstrapAdminRuntime')) { - function bootstrapAdminRuntime() { - global $_INFO; - global $db; - global $rDetect; - global $rMobile; - global $rTimeout; - global $rSQLTimeout; - global $rProtocol; - global $allServers; - global $rServers; - global $rSettings; - global $rProxyServers; - global $rPermissions; - global $language; - global $allowedLangs; - - $rBootstrapped = false; - require_once MAIN_HOME . 'bootstrap.php'; - if (class_exists('XC_Bootstrap') && defined('XC_Bootstrap::CONTEXT_ADMIN')) { - try { - XC_Bootstrap::boot(XC_Bootstrap::CONTEXT_ADMIN); - $rBootstrapped = true; - } catch (Throwable $e) { - $rBootstrapped = false; - } - } - - if (!$rBootstrapped) { - require_once MAIN_HOME . 'autoload.php'; - require_once MAIN_HOME . 'core/Init/LegacyInitializer.php'; - require_once MAIN_HOME . 'core/Database/DatabaseHandler.php'; - require_once INCLUDES_PATH . 'reseller_api.php'; - require_once INCLUDES_PATH . 'libs/Translator.php'; - $db = new DatabaseHandler($_INFO['username'], $_INFO['password'], $_INFO['database'], $_INFO['hostname'], $_INFO['port']); - DatabaseFactory::set($db); - LegacyInitializer::initCore(); - // Admin user info (formerly API::$rUserInfo) - if (isset($_SESSION['hash'])) { - $GLOBALS['rAdminUserInfo'] = UserRepository::getRegisteredUserById($_SESSION['hash']); - } - ResellerAPI::init(); - RedisManager::ensureConnected(); - register_shutdown_function(function () { - global $db; - if (is_object($db)) { - $db->close_mysql(); - } - }); - - $language = Translator::class; - $language::init(MAIN_HOME . 'resources/langs/'); - } - - if (defined('SERVER_ID') === false) { - define('SERVER_ID', intval(ConfigReader::get('server_id'))); - } - - require_once INCLUDES_PATH . 'libs/mobiledetect.php'; - $rDetect = new Mobile_Detect(); - $rMobile = $rDetect->isMobile(); - $rTimeout = 15; - $rSQLTimeout = 10; - set_time_limit($rTimeout); - ini_set('mysql.connect_timeout', $rSQLTimeout); - ini_set('max_execution_time', $rTimeout); - ini_set('default_socket_timeout', $rTimeout); - - $rProtocol = getProtocol(); - $allServers = ServerRepository::getAllSimple(); - $rServers = ServerRepository::getStreamingSimple($rPermissions); - $rSettings = SettingsManager::getAll(); - $rProxyServers = ServerRepository::getProxySimple($rPermissions); - - $language = Translator::class; - $allowedLangs = $language::available(); - } -} diff --git a/src/includes/bootstrap/admin_session.php b/src/includes/bootstrap/admin_session.php deleted file mode 100644 index fae55c3e..00000000 --- a/src/includes/bootstrap/admin_session.php +++ /dev/null @@ -1,12 +0,0 @@ -