-
Notifications
You must be signed in to change notification settings - Fork 0
/
403.php
120 lines (111 loc) · 2.99 KB
/
403.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
$volume = listVolumeContent();
$templateValues = [
$_SERVER['SERVER_SIGNATURE'],
getenv('USER_ID') . ':' . getenv('USER_GID'),
exec('whoami'),
implode('</code></li><li><code>', $volume),
];
$responseCode = 403;
$template = <<<'HTML'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>
<body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
%s
<hr>
<details>
<summary>Technical details</summary>
<h2>Technical details</h2>
<p>uid/gid: <code>%s</code></p>
<p>user: <code>%s</code></p>
<p>Volume contents:</p>
<ul>
<li><code>%s</code></li>
</ul>
</details>
</body>
</html>
HTML;
function listVolumeContent(): array
{
$files = [];
$folders = [];
$iterator = new FilesystemIterator(
'/var/www/www/api/data/',
FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_FILENAME
);
foreach ($iterator as $file) {
$type = $file->getType();
switch ($type) {
case 'dir':
$filename = $file->getFilename() . '/';
$folders[] = $filename;
break;
case 'link':
$filename = $file->getFilename() . ' -> ' . readlink($file->getPathname());
$files[] = $filename;
break;
case 'file':
default:
$filename = $file->getFilename();
$files[] = $filename;
break;
}
}
sort($folders);
sort($files);
return array_merge($folders, $files);
}
if (
$_SERVER['REQUEST_URI'] === '/' && ! file_exists('/var/www/www/api/data/generated.html')
) {
$responseCode = 200;
$template = <<<'HTML'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html lang="en">
<head>
<title>Welcome to SimplyCode</title>
</head>
<body>
<h1>Welcome to SimplyCode!</h1>
<p>
This looks like your first visit.
<strong>Go to <a href="https://tutorial.dev.muze.nl/">https://tutorial.dev.muze.nl/</a> and read "Your first application: TodoMVC" to learn about SimplyCode.</strong>
<strong>Go to <a href="%s">%s</a> to start building something awesome.</strong>
<!-- @TODO: Update the link to the turorial or reference to help the user when available
See: https://github.com/SimplyEdit/simplycode-docker/issues/12
-->
</p>
<hr>
%s
<hr>
<details>
<summary>Technical details</summary>
<h2>Technical details</h2>
<p>uid/gid: <code>%s</code></p>
<p>user: <code>%s</code></p>
<p>Volume contents:</p>
<ul>
<li><code>%s</code></li>
</ul>
</details>
</body>
</html>
HTML;
$templateValues = array_merge([],
[
"{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}/simplycode",
'/simplycode',
],
$templateValues
);
}
http_response_code($responseCode);
header('Content-Type: text/html');
vprintf($template, $templateValues);