diff --git a/404.png b/404.png new file mode 100644 index 0000000..53d7869 Binary files /dev/null and b/404.png differ diff --git a/api.php b/api.php index c49604a..9444fab 100644 --- a/api.php +++ b/api.php @@ -1,8 +1,5 @@ - -{ - "posts": [ -intval($res["PostID"]), "username"=>$res["Username"], "time"=>$res["Time"], "message"=>str_replace("\r", "", $res["Message"]), "imageURL"=>test_input($res["ImageURL"]))); } + +echo json_encode(array("posts"=>$posts), JSON_PRETTY_PRINT); ?> - ] -} diff --git a/creds.php b/creds.php index 8ecdac6..45b0edc 100644 --- a/creds.php +++ b/creds.php @@ -1,9 +1,10 @@ diff --git a/css/style.css b/css/style.css index 7fc6a07..1b72da1 100644 --- a/css/style.css +++ b/css/style.css @@ -1,16 +1,57 @@ +/* colorscheme independent rules */ body { - background-color: #D0D0D0; font-family: monospace; + margin: 0; + padding: 0; + padding-bottom: 5px; + width: 70%; + margin: auto; + box-shadow: 0px 0px 15px #000000; +} +@media screen and (max-width: 1200px) { + body { + width: 80%; + } +} +@media screen and (max-width: 900px) { + body { + width: 100%; + } +} +img.image { + max-width: 100%; } table, th, td { - border: 1px solid #000000; - background-color: #EEEEEE; font-size: 10pt; margin: auto; } +input { + font-family: monospace; +} +.navbar { + padding: 3px; + font-size: 15pt; +} .logotable { border: 0px; - background-color: #D0D0D0; +} +span.message { + white-space: pre-line; + text-overflow: ellipsis; + overflow-wrap: break-word; + max-width: 100%; +} +hr { + border: 0px none #000000; + border-top: 1px solid #EEEEEE; + margin: 5px; +} +div.message { + margin: 5px; + padding: 5px; + width: fit-content; + max-width: 100%; + display: block; } .center { margin: auto; @@ -18,36 +59,167 @@ table, th, td { .text-center { text-align: center !important; } -.navbar { - border: 1px solid #000000; - background-color: #EEEEEE; - padding: 3px; -} a { text-decoration: none; + transition: 0.1s; +} +.navbar { + border: 0; + position: -webkit-sticky; /* safari */ + position: sticky; + top: 0; + box-shadow: 0px 0px 5px #000000; + height: fit-content; + padding: 0; +} +.navbutton { + border-top: 0px; + border-bottom: 0px; + height: 100%; + padding: 5px; + padding-top: 0px; + padding-bottom: 0px; + transition: 0.1s; + vertical-align: middle; } -span#id { - color: #2c49c9 !important; +/* light theme fallback */ +html { + background-color: #c0c0c0; } -span#name{ +body { + background-color: #D0D0D0; +} +table, th, td { + border: 1px solid #000000; + background-color: #EEEEEE; +} +.navbar { + border-bottom: 1px solid #000000; + background-color: #EEEEEE; +} +.navbutton { + color: #000000; + border: 1px solid #000000; +} +.navbutton:hover { + color: #ffffff; + background-color: #000000; +} +.navbutton:first-of-type:not(#floatright) { + border-left: 1px solid #000000; + border-right: 0px; +} +.navbutton:last-of-type#floatright { + border-left: 0px solid #000000; + border-right: 1px solid #000000; +} +.logotable { + background-color: #D0D0D0; +} + +span.id { + color: #2c49c9; +} +span.name{ color: #1c8757; } -span#date { +span.date { color: #727272; } -span#message { - color: #000000; - white-space: pre-line; - text-overflow: ellipsis; - overflow-wrap: break-word; - max-width: 100%; +a.sharebutton { + color: #727272; } -div#message { +a.sharebutton:hover { + color: #000000; +} +span.you { + color: #373737; +} +span.message { + color: #000000; +} +div.message { background-color: #EEEEEE; border: 1px solid #000000; - padding: 5px; - width: fit-content; - max-width: 100%; - display: block; +} +textarea, input { + background-color: #ffffff; + border: 1px solid #000000; + color: #000000; +} + +/* dark theme */ +@media (prefers-color-scheme: dark) { + html { + background-color: #101010; + } + body { + background-color: #141414; + color: #ffffff; + } + a { + color: #4fb1dc; + } + a:hover { + color: #89cff0; + } + table, th, td { + border: 1px solid #111111; + background-color: #1f1f1f; + } + .navbar { + border-bottom: 1px solid #111111; + background-color: #1f1f1f; + } + .navbutton { + color: #ffffff; + border: 1px solid #111111; + } + .navbutton:hover { + color: #000000; + background-color: #ffffff; + } + .navbutton:first-of-type:not(#floatright) { + border-left: 1px solid #111111; + border-right: 0px; + } + .navbutton:last-of-type#floatright { + border-left: 0px solid #111111; + border-right: 1px solid #111111; + } + .logotable { + background-color: #00000000; + } + + span.id { + color: #1f8fb9; + } + span.name{ + color: #55bb84; + } + span.date { + color: #727272; + } + a.sharebutton { + color: #727272; + } + a.sharebutton:hover { + color: #ffffff; + } + span.you { + color: #c0c0c0; + } + span.message { + color: #ffffff; + } + div.message { + background-color: #1f1f1f; + border: 1px solid #111111; + } + textarea, input { + background-color: #1f1f1f; + border: 1px solid #111111; + color: #ffffff; + } } diff --git a/image_proxy.php b/image_proxy.php new file mode 100644 index 0000000..5506aa1 --- /dev/null +++ b/image_proxy.php @@ -0,0 +1,54 @@ + $lh) return false; + return substr($haystack, 0, $ln) == $needle; +} + +$i = @$_GET["i"]; +if (!isset($_GET["i"])) { + http_response_code(400); + die("no image url"); +} +$c = curl_init($i); +curl_setopt($c, CURLOPT_FOLLOWLOCATION, false); + +$clear = false; +$buffer = array(); +curl_setopt($c, CURLOPT_HEADERFUNCTION, function($c, $h) { + global $clear, $buffer; + if (!$clear) { + if (str_starts_with(strtolower($h), "content-type:")) { + $i = explode(" ", str_replace("\r\n", "", $h)); + if (str_starts_with($i[count($i) - 1], "image/")) { + $clear = true; + for($j = 0; $j < count($buffer); $j++) { + header($buffer[$j]); + } + header($h); + } elseif (str_starts_with($i[count($i) - 1], "video/")) { + header("Location: /rautafarmi/video-file.png"); + die(); + } else { + http_response_code(302); + header("Location: /rautafarmi/404.png"); + die(); + } + } + else array_push($buffer, $h); + } + else header($h); + return strlen($h); +}); +curl_exec($c); +if (curl_error($c) != "") { + http_response_code(302); + header("Location: /rautafarmi/404.png"); +} +curl_close($c); diff --git a/index.php b/index.php index 548ec79..bdb32a7 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,20 @@ + + +
@@ -13,6 +29,12 @@ + + + +
image URL + +
action @@ -26,19 +48,28 @@ "; - echo "".$res['PostID']." "; + echo "
"; + echo " ".$res['PostID']." "; if(empty($res['Username'])) { - echo "Anonymous "; + echo "Anonymous"; } else { - echo "".$res['Username']." "; + echo "".$res['Username'].""; } - echo "".$res['Time']."
"; - echo "".$res['Message'].""; - echo "

"; + echo " "; + if($_SERVER["HTTP_X_FORWARDED_FOR"] == $res["IP"]) { + echo "(you) "; + } + /*echo "
";*/ + echo "
"; + /*echo "
";*/ + if(! empty($res['ImageURL'])) { + echo "
"; + } + echo "".htmlspecialchars($res['Message']).""; + echo ""; } ?> diff --git a/messages.txt b/messages.txt index 896175d..d589297 100644 --- a/messages.txt +++ b/messages.txt @@ -1,7 +1,7 @@ Hello! If you are reading this message, it means you are using an outdated rautafarmi client. As of 2022-09-07, rautafarmi has stopped using the old messages.txt method for retrieving messages. -An alternative will be released soon. To continue using the original rautafarmi, set your instance to +New clients should add support for the JSON API. To continue using the original rautafarmi, set your instance to https://donut.gq/old-rautafarmi. --jornmann, donut.gq and rautafarmi sysop diff --git a/oldapi.php b/oldapi.php new file mode 100644 index 0000000..674f60a --- /dev/null +++ b/oldapi.php @@ -0,0 +1,39 @@ + +{ + "posts": [ + + ] +} diff --git a/oldindex.php b/oldindex.php new file mode 100644 index 0000000..c037ba7 --- /dev/null +++ b/oldindex.php @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + +
username + 30 char limit +
message + +
image URL + +
action + +
+ +
+
+"; + echo " ".$res['PostID']." "; + if(empty($res['Username'])) { + echo "Anonymous"; + } else { + echo "".$res['Username'].""; + } + echo " "; + if($_SERVER["HTTP_X_FORWARDED_FOR"] == $res["IP"]) { + echo "(you) "; + } + /*echo "
";*/ + echo "".$res['Time']."
"; + /*echo "
";*/ + if(! empty($res['ImageURL'])) { + echo "
"; + } + echo "".htmlspecialchars($res['Message']).""; + echo "
"; +} +?> + + diff --git a/post.php b/post.php index af48fbd..02cd3f7 100644 --- a/post.php +++ b/post.php @@ -1,22 +1,45 @@ you have been banned from posting on rautafarmi!"; +$backbutton = "
[ back ]"; + if(isset($_POST['message'])) { $username = mysqli_real_escape_string($mysqli, $_POST['username']); $message = mysqli_real_escape_string($mysqli, $_POST['message']); + $imgurl = mysqli_real_escape_string($mysqli, $_POST['imgurl']); if(empty($message)) { - die("cannot post empty message!"); + die("cannot post empty message!".$backbutton); } - $mysqli->query("INSERT INTO posts (username, message, ip) VALUES('" . $username . "', '" . $message . "', '" . $_SERVER["HTTP_X_FORWARDED_FOR"] . "')"); + if($_SERVER["HTTP_X_FORWARDED_FOR"] == "37.139.53.81") { + die($banmessage."

Reason: spam

.$backbutton"); + } + + if($username == "Crytoinimi") { + die($banmessage."

Reason: spam

.$backbutton"); + } + if($username == "Tookdono") { + echo "

success

"; + echo "

done

"; + header("Location: index.php"); + exit(); + } + + $mysqli->query("INSERT INTO posts (username, message, ip, imageurl) VALUES('" . $username . "', '" . $message . "', '" . $_SERVER["HTTP_X_FORWARDED_FOR"] . "', '" . $imgurl . "')"); + //$stmt->bind_param("sis", $username, $message); + //$stmt->execute(); echo "

success

"; header("Location: index.php"); +} else { + echo "

fail! no message!

"; } -echo "

done

"; ?> diff --git a/schema.sql b/schema.sql index 386048a..44804b4 100644 --- a/schema.sql +++ b/schema.sql @@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS posts ( Username VARCHAR(30), IP VARCHAR(100) NOT NULL, Time TIMESTAMP, - Message VARCHAR(1000) + Message VARCHAR(1000), + ImageURL VARCHAR(100) ); diff --git a/templates/footer.php b/templates/footer.php index 7bd0e82..70f2efb 100644 --- a/templates/footer.php +++ b/templates/footer.php @@ -1,9 +1,9 @@
-

made with love, php, blood, sweat, and tears. lots of tears.

-

-

(c) donut.gq and contributors 2022

+

[ api ] [ e-mail ] [ privacy policy ]

+

(c) donut.gq 2022

+ diff --git a/templates/header.php b/templates/header.php index 6f3c79e..ee72da9 100644 --- a/templates/header.php +++ b/templates/header.php @@ -7,12 +7,12 @@ +
diff --git a/video-file.png b/video-file.png new file mode 100644 index 0000000..1d41b08 Binary files /dev/null and b/video-file.png differ