| | <?php |
| | |
| | $VCSKY_BASE_URL = "https://cdn.dos.zone/vcsky/"; |
| | $BR_BASE_URL = "https://br.cdn.dos.zone/vcsky/"; |
| | $BASE_PATH = '/reVCDOS'; |
| | $DIST_PATH = __DIR__ . '/dist'; |
| |
|
| | |
| |
|
| | |
| | function build_url($base, $path) { |
| | $query = $_SERVER['QUERY_STRING']; |
| | $url = rtrim($base, '/') . '/' . ltrim($path, '/'); |
| | if ($query) { |
| | $url .= '?' . $query; |
| | } |
| | return $url; |
| | } |
| |
|
| | |
| | function proxy_request($url) { |
| | $ch = curl_init($url); |
| | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']); |
| |
|
| | |
| | $headers = []; |
| | foreach (getallheaders() as $key => $value) { |
| | if (!in_array(strtolower($key), ['host', 'content-length'])) { |
| | $headers[] = "$key: $value"; |
| | } |
| | } |
| | $headers[] = "Cross-Origin-Opener-Policy: same-origin"; |
| | $headers[] = "Cross-Origin-Embedder-Policy: require-corp"; |
| | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| |
|
| | |
| | if (!in_array($_SERVER['REQUEST_METHOD'], ['GET', 'HEAD'])) { |
| | curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input')); |
| | } |
| |
|
| | curl_setopt($ch, CURLOPT_HEADER, true); |
| | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| |
|
| | $response = curl_exec($ch); |
| | $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
| |
|
| | $header_text = substr($response, 0, $header_size); |
| | $body = substr($response, $header_size); |
| |
|
| | foreach (explode("\r\n", $header_text) as $header) { |
| | if ($header && stripos($header, 'Content-Length') === false) { |
| | header($header, false); |
| | } |
| | } |
| |
|
| | echo $body; |
| | curl_close($ch); |
| | } |
| |
|
| | |
| | $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
| |
|
| | |
| | if (preg_match('#^' . $BASE_PATH . '/vcsky/(.*)#', $uri, $matches)) { |
| | $url = build_url($VCSKY_BASE_URL, $matches[1]); |
| | proxy_request($url); |
| | exit; |
| | } |
| |
|
| | |
| | if (preg_match('#^' . $BASE_PATH . '/vcbr/(.*)#', $uri, $matches)) { |
| | $url = build_url($BR_BASE_URL, $matches[1]); |
| | proxy_request($url); |
| | exit; |
| | } |
| |
|
| |
|
| | |
| | if (strpos($uri, $BASE_PATH) === 0) { |
| | $relativePath = substr($uri, strlen($BASE_PATH)); |
| | if ($relativePath === '' || $relativePath === '/') { |
| | $relativePath = '/index.html'; |
| | } |
| |
|
| | $localFile = realpath($DIST_PATH . $relativePath); |
| |
|
| | |
| | if ($localFile && is_file($localFile) && str_starts_with($localFile, realpath($DIST_PATH))) { |
| | |
| | $ext = pathinfo($localFile, PATHINFO_EXTENSION); |
| | switch (strtolower($ext)) { |
| | case 'js': |
| | $mimeType = 'application/javascript'; |
| | break; |
| | case 'css': |
| | $mimeType = 'text/css'; |
| | break; |
| | case 'html': |
| | case 'htm': |
| | $mimeType = 'text/html'; |
| | break; |
| | case 'json': |
| | $mimeType = 'application/json'; |
| | break; |
| | case 'wasm': |
| | $mimeType = 'application/wasm'; |
| | break; |
| | default: |
| | $mimeType = mime_content_type($localFile) ?: 'application/octet-stream'; |
| | } |
| |
|
| | header("Content-Type: $mimeType"); |
| | header("Cross-Origin-Opener-Policy: same-origin"); |
| | header("Cross-Origin-Embedder-Policy: require-corp"); |
| | readfile($localFile); |
| | exit; |
| | } |
| |
|
| | |
| | if (str_ends_with($uri, '/') || preg_match('/\.html$/', $uri)) { |
| | $indexFile = $DIST_PATH . '/index.html'; |
| | if (is_file($indexFile)) { |
| | header("Content-Type: text/html"); |
| | header("Cross-Origin-Opener-Policy: same-origin"); |
| | header("Cross-Origin-Embedder-Policy: require-corp"); |
| | readfile($indexFile); |
| | exit; |
| | } |
| | } |
| | } |
| |
|
| | |
| | http_response_code(404); |
| | echo "Not Found"; |
| |
|