From 41fa7fe9ed84c4b8989f622fb532722b7f39ad72 Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Sun, 1 Mar 2026 19:07:42 -0500 Subject: refactor: src/ --- src/font.php | 44 ++++ src/fonts.php | 49 ++++ src/index.php | 693 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/upload.php | 66 +++++ src/uploads/.htaccess | 2 + 5 files changed, 854 insertions(+) create mode 100644 src/font.php create mode 100644 src/fonts.php create mode 100644 src/index.php create mode 100644 src/upload.php create mode 100644 src/uploads/.htaccess diff --git a/src/font.php b/src/font.php new file mode 100644 index 0000000..de39569 --- /dev/null +++ b/src/font.php @@ -0,0 +1,44 @@ + 'font/ttf', + 'otf' => 'font/otf', + 'woff' => 'font/woff', + 'woff2' => 'font/woff2', + default => 'application/octet-stream', +}; + +header("Content-Type: $mime"); +header('Cache-Control: public, max-age=31536000, immutable'); +header('Content-Length: ' . filesize($file)); +readfile($file); diff --git a/src/fonts.php b/src/fonts.php new file mode 100644 index 0000000..1959f51 --- /dev/null +++ b/src/fonts.php @@ -0,0 +1,49 @@ +/dev/null'); +if (!$output) { + echo json_encode([]); + exit; +} + +$lines = array_filter(explode("\n", trim($output))); +$fonts = []; +$seen = []; + +foreach ($lines as $line) { + $parts = explode('|', $line, 2); + if (count($parts) < 2) continue; + + /* take first family name (some entries are comma-separated) */ + $families = explode(',', $parts[0]); + $family = trim($families[0]); + + if (empty($family) || isset($seen[$family])) continue; + + $file = trim($parts[1]); + if (!file_exists($file)) continue; + + $seen[$family] = true; + + $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); + $format = match ($ext) { + 'ttf' => 'truetype', + 'otf' => 'opentype', + 'woff' => 'woff', + 'woff2' => 'woff2', + default => 'truetype', + }; + + $fonts[] = [ + 'family' => $family, + 'file' => base64_encode($file), + 'format' => $format, + ]; +} + +usort($fonts, fn($a, $b) => strcasecmp($a['family'], $b['family'])); +echo json_encode($fonts); diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..062d80e --- /dev/null +++ b/src/index.php @@ -0,0 +1,693 @@ + + + + + + + + sent-web + + + + + + +
+

sent-web

+

suckless's sent tool ported to the very sucky web world

+
+ +
+
+ + + +
+ + + +
+
+ + + +
+ + + +
+

F5 to present · Esc to exit · ← → h l j k space enter to navigate

+
+ + +
+
+
+ + + + \ No newline at end of file diff --git a/src/upload.php b/src/upload.php new file mode 100644 index 0000000..62db139 --- /dev/null +++ b/src/upload.php @@ -0,0 +1,66 @@ + 'Method not allowed']); + exit; +} + +if (!isset($_FILES['image']) || $_FILES['image']['error'] !== UPLOAD_ERR_OK) { + $code = $_FILES['image']['error'] ?? 'unknown'; + http_response_code(400); + echo json_encode(['error' => "Upload failed (code: $code)"]); + exit; +} + +$file = $_FILES['image']; +$allowed = [ + 'image/png', 'image/jpeg', 'image/gif', + 'image/webp', 'image/svg+xml', 'image/bmp', +]; + +$finfo = finfo_open(FILEINFO_MIME_TYPE); +$mime = finfo_file($finfo, $file['tmp_name']); +finfo_close($finfo); + +if (!in_array($mime, $allowed, true)) { + http_response_code(400); + echo json_encode(['error' => "Invalid file type: $mime"]); + exit; +} + +$ext = match ($mime) { + 'image/png' => 'png', + 'image/jpeg' => 'jpg', + 'image/gif' => 'gif', + 'image/webp' => 'webp', + 'image/svg+xml' => 'svg', + 'image/bmp' => 'bmp', + default => 'bin', +}; + +/* generate safe filename */ +$basename = pathinfo($file['name'], PATHINFO_FILENAME); +$basename = preg_replace('/[^a-zA-Z0-9_-]/', '_', $basename); +$basename = substr($basename, 0, 64); +$filename = $basename . '_' . bin2hex(random_bytes(4)) . '.' . $ext; + +$uploadDir = __DIR__ . '/uploads'; +if (!is_dir($uploadDir)) { + mkdir($uploadDir, 0755, true); +} + +$dest = $uploadDir . '/' . $filename; +if (!move_uploaded_file($file['tmp_name'], $dest)) { + http_response_code(500); + echo json_encode(['error' => 'Failed to save file']); + exit; +} + +echo json_encode([ + 'filename' => $filename, + 'url' => 'uploads/' . $filename, +]); diff --git a/src/uploads/.htaccess b/src/uploads/.htaccess new file mode 100644 index 0000000..2cf2ddc --- /dev/null +++ b/src/uploads/.htaccess @@ -0,0 +1,2 @@ +# prevent PHP execution in uploads directory +php_flag engine off -- cgit v1.2.3