diff --git a/database.sql b/database.sql index 64097a8..a522e38 100644 --- a/database.sql +++ b/database.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1:3306 --- Generation Time: Mar 08, 2025 at 06:43 AM +-- Generation Time: Mar 08, 2025 at 05:27 PM -- Server version: 11.4.3-MariaDB-1 -- PHP Version: 8.3.11 @@ -31,7 +31,8 @@ CREATE TABLE `colors` ( `id` int(11) NOT NULL, `name` text NOT NULL, `color` char(6) NOT NULL, - `timestamp` int(11) NOT NULL + `timestamp` int(11) NOT NULL, + `hostname` char(64) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; -- diff --git a/webroot/assets/delete.svg b/webroot/assets/delete.svg new file mode 100644 index 0000000..1866557 --- /dev/null +++ b/webroot/assets/delete.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/webroot/delete.php b/webroot/delete.php new file mode 100644 index 0000000..a3278a2 --- /dev/null +++ b/webroot/delete.php @@ -0,0 +1,16 @@ +prepare("DELETE FROM colors WHERE id = :id AND hostname = :hostname"); +$stmt->bindParam(':id', $id); +$stmt->bindParam(':hostname', $hostname); +$stmt->execute(); + +header("Location: /"); \ No newline at end of file diff --git a/webroot/index.php b/webroot/index.php index 19ebf14..6eb83ee 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -10,7 +10,7 @@ $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); usort($result, function($a, $b) { - return strtotime($b['timestamp']) - strtotime($a['timestamp']); + return strcmp($b['timestamp'], $a['timestamp']); }); $lastInsertId = $_GET['highlight'] ?? null; @@ -47,6 +47,12 @@ $lastInsertId = $_GET['highlight'] ?? null; border: 2px solid #006eff } + .color { + width: 128px; + height: 128px; + border-radius: 5px; + } + .used-text { display: none; color: red; @@ -55,19 +61,36 @@ $lastInsertId = $_GET['highlight'] ?? null; @@ -94,11 +119,13 @@ $lastInsertId = $_GET['highlight'] ?? null;

Name your own color!

-

This color has already been named!

+

This color has already been named!

+

This name has already been used!

- + +
@@ -106,9 +133,12 @@ $lastInsertId = $_GET['highlight'] ?? null;

Colors that were named

"; - echo "
"; + echo "
time() - 10) ? " highlight" : "") . "\">"; + echo "
"; echo "

" . htmlspecialchars(base64_decode($row['name'])) . " • #". $row["color"] ."

"; + if ($row['hostname'] == hash('sha256', $_SERVER["HTTP_CF_CONNECTING_IP"])) { + echo "\"Delete\""; + } echo "
"; } ?> diff --git a/webroot/upload.php b/webroot/upload.php index dad2829..1f09953 100644 --- a/webroot/upload.php +++ b/webroot/upload.php @@ -3,6 +3,7 @@ include __DIR__ . "/config/captcha.php"; include __DIR__ . "/incl/db.php"; $time = time(); +$hostname = hash('sha256', $_SERVER["HTTP_CF_CONNECTING_IP"]); if ($_SERVER['REQUEST_METHOD'] === 'POST') { @@ -66,10 +67,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } - $stmt = $conn->prepare("INSERT INTO colors (color, name, timestamp) VALUES (:color, :name, :time)"); + $stmt = $conn->prepare("SELECT name FROM colors WHERE name = :name"); + $stmt->bindParam(':name', $name); + $stmt->execute(); + + if ($stmt->rowCount() > 0) { + echo "Name already taken"; + exit; + } + + $stmt = $conn->prepare("INSERT INTO colors (color, name, timestamp, hostname) VALUES (:color, :name, :time, :hostname)"); $stmt->bindParam(':color', $color); $stmt->bindParam(':name', $name); $stmt->bindParam(':time', $time); + $stmt->bindParam(':hostname', $hostname); $stmt->execute(); $lastInsertId = $conn->lastInsertId(); header("Location: /?highlight=$lastInsertId");