diff options
| author | ilotterytea <iltsu@alright.party> | 2025-06-04 20:12:57 +0400 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-06-04 20:19:46 +0400 |
| commit | 28658d12a464777b50c789c2e9c3f86ce8f07da0 (patch) | |
| tree | f1249ca0feade00fa95f39ba195056623ae920b2 | |
| parent | 8245832be8470f20091eb71946fdeff3cab79aa7 (diff) | |
feat: report system
| -rw-r--r-- | public/index.php | 7 | ||||
| -rw-r--r-- | public/report.php | 106 | ||||
| -rw-r--r-- | public/static/style.css | 5 |
3 files changed, 117 insertions, 1 deletions
diff --git a/public/index.php b/public/index.php index 09ab602..42f82e3 100644 --- a/public/index.php +++ b/public/index.php @@ -143,6 +143,11 @@ if (FILE_CATALOG_FANCY_VIEW && strlen(substr($_SERVER['PHP_SELF'], strlen('/inde <?php endif; ?> </div> <div class="grow row gap-8 justify-end align-center" id="file-tab-buttons"> + <?php if (FILE_REPORT): ?> + <a href="/report.php?f=<?= $file['id'] ?>.<?= $file['extension'] ?>"> + <button>Report</button> + </a> + <?php endif; ?> <a href="<?= $file['full_url'] ?>"> <button>Full size</button> </a> @@ -273,7 +278,7 @@ if (FILE_CATALOG_FANCY_VIEW && strlen(substr($_SERVER['PHP_SELF'], strlen('/inde <script> // adding deletion button const files = JSON.parse(localStorage.getItem('uploaded_files') ?? '[]'); - const file = files.find§((x) => x.id === '<?= $file['id'] ?>'); + const file = files.find((x) => x.id === '<?= $file['id'] ?>'); console.log(file); if (file && file.urls && file.urls.deletion_url) { const buttons = document.getElementById('file-tab-buttons'); diff --git a/public/report.php b/public/report.php new file mode 100644 index 0000000..ef1def6 --- /dev/null +++ b/public/report.php @@ -0,0 +1,106 @@ +<?php +include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/partials.php'; +include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php'; + +if (!FILE_REPORT) { + http_response_code(403); + exit('No reports allowed!'); +} + +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (!isset($_POST['id'], $_POST['reason'])) { + http_response_code(400); + exit('Not enough data.'); + } + + $file_id = $_POST['id']; + $file_id = explode('.', $file_id); + $file_ext = $file_id[1]; + $file_id = $file_id[0]; + + if (!is_file(FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_ext}")) { + http_response_code(404); + exit('Invalid file.'); + } + + $reason = trim($_POST['reason'] ?? ''); + + if (empty($reason)) { + http_response_code(400); + exit('Report reason is empty'); + } + + $email = $_POST['email'] ?? '(Anonymous)'; + if (empty($email)) { + $email = '(Anonymous)'; + } + + if (!is_dir(FILE_REPORT_DIRECTORY) && !mkdir(FILE_REPORT_DIRECTORY, 0777, true)) { + http_response_code(500); + exit('Failed to create a folder for reports. Try again later.'); + } + + do { + $report_id = generate_random_char_sequence(FILE_ID_CHARACTERS, 16); + } while (is_file(FILE_REPORT_DIRECTORY . "/{$report_id}.txt")); + + $contents = "File ID: {$file_id}.{$file_ext} +Feedback Email: {$email} + +Reason: +{$reason}"; + + if (!file_put_contents(FILE_REPORT_DIRECTORY . "/{$report_id}.txt", $contents)) { + http_response_code(500); + exit("Failed to save the report. Try again later!"); + } + + json_response(['id' => $report_id], 'Sent!', 201); + exit(); +} + +$file_id = $_GET['f'] ?? ''; + +if (!is_file(FILE_UPLOAD_DIRECTORY . "/{$file_id}")) { + $file_id = null; +} + +?> +<html> + +<head> + <title>Report - <?= INSTANCE_NAME ?></title> + <link rel="stylesheet" href="/static/style.css"> + <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> +</head> + +<body> + <main> + <?php html_mini_navbar() ?> + <h1>Report a file</h1> + <hr> + <form action="/report.php" method="post"> + <table class="vertical"> + <tr> + <th>File ID with extension:</th> + <td><input type="text" name="id" value="<?= $file_id ?>" placeholder="XXXXX.png" required></td> + </tr> + <tr> + <th>What is wrong with that file?</th> + <td><textarea name="reason" placeholder="..." required></textarea></td> + </tr> + <tr> + <th>Feedback E-Mail:</th> + <td><input type="email" name="email" placeholder="Optional"></td> + </tr> + <tr> + <th></th> + <td><button type="submit">Send</button></td> + </tr> + </table> + </form> + </main> +</body> + +</html>
\ No newline at end of file diff --git a/public/static/style.css b/public/static/style.css index f22bac2..7cb8b0a 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -65,6 +65,11 @@ table.vertical { border-spacing: 8px; } +table.vertical th { + text-align: end; + vertical-align: top; +} + /** FORM */ button[type=submit] { background: linear-gradient(0deg, var(--box-tab-background), var(--background)); |
