summaryrefslogtreecommitdiff
path: root/src/font.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/font.php')
-rw-r--r--src/font.php50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/font.php b/src/font.php
deleted file mode 100644
index d12ceb8..0000000
--- a/src/font.php
+++ /dev/null
@@ -1,50 +0,0 @@
1<?php
2/* font.php — serve font files from the server's font directories */
3
4$encoded = $_GET['f'] ?? '';
5if (empty($encoded)) {
6 http_response_code(400);
7 exit('Missing parameter');
8}
9
10$file = base64_decode($encoded, true);
11if ($file === false || !file_exists($file)) {
12 http_response_code(404);
13 exit('Font not found');
14}
15
16$real = realpath($file);
17$allowed = ['/usr/share/fonts', '/usr/local/share/fonts'];
18
19foreach (glob('/home/*', GLOB_ONLYDIR) as $home) {
20 $allowed[] = $home . '/.local/share/fonts';
21 $allowed[] = $home . '/.fonts';
22}
23
24$ok = false;
25
26foreach ($allowed as $dir) {
27 if (str_starts_with($real, realpath($dir) ?: $dir)) {
28 $ok = true;
29 break;
30 }
31}
32
33if (!$ok) {
34 http_response_code(403);
35 exit('Access denied');
36}
37
38$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
39$mime = match ($ext) {
40 'ttf' => 'font/ttf',
41 'otf' => 'font/otf',
42 'woff' => 'font/woff',
43 'woff2' => 'font/woff2',
44 default => 'application/octet-stream',
45};
46
47header("Content-Type: $mime");
48header('Cache-Control: public, max-age=31536000, immutable');
49header('Content-Length: ' . filesize($file));
50readfile($file);