-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.php
More file actions
48 lines (46 loc) · 1.79 KB
/
index.php
File metadata and controls
48 lines (46 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use RingCentral\Psr7\Response;
function handler($request, $context): Response
{
$host = "hz.mofangdegisn.cn";
$root_dir = '/mnt/auto/wordpress'; // nas dir
$uri = $request->getAttribute("requestURI");
$uriArr = explode("?", $uri);
// default php / or /wp-admin/
if (preg_match('#/$#', $uriArr[0]) && !(strpos($uri, '.php'))) {
$uriArr[0] .= "index.php";
$uri = implode($uriArr);
}
//php script
if (preg_match('#\.php.*#', $uri)) {
try{
$resp = $GLOBALS['fcPhpCgiProxy']->requestPhpCgi(
$request, $root_dir, "index.php",
['HTTP_HOST' => $host, 'SERVER_NAME' => $host, 'SERVER_PORT' => '80'],
['debug_show_cgi_params' => true, 'readWriteTimeout' => 15000]
);
return $resp;
} catch (Exception $e){
$GLOBALS['fcPhpCgiProxy'] = new \ServerlessFC\PhpCgiProxy();
$resp = $GLOBALS['fcPhpCgiProxy']->requestPhpCgi(
$request, $root_dir, "index.php",
['HTTP_HOST' => $host, 'SERVER_NAME' => $host, 'SERVER_PORT' => '80'],
['debug_show_cgi_params' => true, 'readWriteTimeout' => 15000]
);
return $resp;
}
} else {
// static files, js, css, jpg ...
$filename = $root_dir . explode("?", $uri)[0];
$filename = rawurldecode($filename);
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$headers = [
'Content-Type' => $GLOBALS['fcPhpCgiProxy']->getMimeType($filename),
'Cache-Control' => "max-age=8640000",
'Accept-Ranges' => 'bytes',
];
return new Response(200, $headers, $contents);
}
}