'text/javascript', 'mjs' => 'text/javascript', 'css' => 'text/css', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'webp' => 'image/webp', 'svg' => 'image/svg+xml', 'woff' => 'font/woff', 'woff2' => 'font/woff2', 'ttf' => 'font/ttf', 'ico' => 'image/x-icon']; $type = $types[strtolower(pathinfo($file, PATHINFO_EXTENSION))] ?? null; if ($type === null) { missing(); } } elseif (preg_match('~^/admin(?:/[A-Za-z0-9_-]+)*/?$~D', $path)) { $file = $preview . '/index.html'; $type = 'text/html; charset=utf-8'; } else { missing(); } if (!is_file($file)) { missing(); } header('Content-Type: ' . $type); if ($method !== 'HEAD') { readfile($file); } exit; } // 不透传任意磁盘路径、安装器、测试脚本或 PHP 文件。 if (!in_array($method, ['GET', 'POST', 'OPTIONS'], true) || !preg_match('~^/adminapi/[A-Za-z][A-Za-z0-9_.]*/[A-Za-z][A-Za-z0-9_]*$~D', $path)) { missing(); } $root = $project . '/server'; if (!is_file($root . '/vendor/autoload.php') || !is_file($root . '/config/install.lock')) { http_response_code(503); header('Content-Type: application/json; charset=utf-8'); echo '{"code":0,"msg":"原项目服务尚未配置","data":{}}'; exit; } require $root . '/vendor/autoload.php'; $_SERVER['SCRIPT_FILENAME'] = $public . '/index.php'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHP_SELF'] = '/index.php'; $_SERVER['PATH_INFO'] = $path; foreach (['HTTP_X_FORWARDED_HOST', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_REAL_IP'] as $key) { unset($_SERVER[$key]); } $application = new class($root . DIRECTORY_SEPARATOR) extends think\App { public function loadEnv(string $envName = ''): void { parent::loadEnv($envName); $this->env->set('APP_DEBUG', false); $this->env->set('LOCAL_DEBUG_LOGIN_SKIP_PASSWORD', false); } }; $application->initialize(); $application->request->setPathinfo(ltrim($path, '/')); $http = $application->http; $response = $http->run(); $response->send(); $http->end($response);