<?php
// pisal bom v PHPju, ker se mi res ne da zajebavat s Cjem
$commentsfile = "comments.yml";
switch ($_REQUEST["m"]) {
case "commentreply":
if (empty($_REQUEST['vzdevek'])) {
$vzdevek = "anonimnež";
} else {
$vzdevek = $_REQUEST['vzdevek'];
}
if (empty($_REQUEST['message'])) {
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Niste vnesli sporočila.");
}
if ($_REQUEST['submit'] != 'Objavi!') {
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Izgleda, kakor da avtomatizirate zahteve. Koda napake: fuckoff");
}
if (empty($_REQUEST['parent'])) {
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. V zahtevi ni določeno, na kaj odgovarjate.");
}
if ($_REQUEST["is-submitter-human"] != "true") {
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Izgleda, kakor da avtomatizirate zahteve. Koda napake: jebise");
}
if (strpos(@file_get_contents("b.txt"), "\n" . explode(".", $_SERVER["REMOTE_ADDR"])[0] . "." . explode($_SERVER["REMOTE_ADDR"])[1] . "\t") !== FALSE) {
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Izgleda, da ste na /16 črnem seznamu. Kontaktirajte me.");
}
$sporocilo = $_REQUEST['message'];
$parent = $_REQUEST['parent'];
if (strlen($sporocilo) > 1024 || strlen($parent) > 7+1+256+1+19 || strlen($vzdevek) > 256) {
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Preveč besedila - vzdevek je lahko dolg 256, sporočilo pa 1024 znakov.");
}
$datum = date("Y-m-d H:i:s");
$cm = yaml_emit(array(array(
"author" => $vzdevek,
"date" => $datum,
"message" => $sporocilo,
"parent" => $parent,
"ip" => $_SERVER['REMOTE_ADDR'],
"addedby" => "PHP API 0.0.0",
"nonce" => hash('sha256', $vzdevek."|".$datum."|".random_bytes(69))
)), YAML_UTF8_ENCODING, YAML_LN_BREAK);
$cmarray = explode("\n", $cm);
array_shift($cmarray); array_pop($cmarray); array_pop($cmarray);
$cs = implode("\n", $cmarray)."\n";
$response = file_put_contents($commentsfile, $cs, FILE_APPEND); // pri append ni locka
if ($response === FALSE) {
http_response_code(500);
header("Content-Type: text/plain");
exit("500: Napaka. Komentarja ni uspelo zapisati.");
} else {
http_response_code(201);
header("Content-Type: text/plain");
exit("201: Uspelo! Komentar objavljen.");
}
break;
case "commentedit":
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Urejanje komentarjev še ni izdelano. Napišite elektronsko sporočilo na anton+blog@sijanec.eu.");
break;
default:
http_response_code(400);
header("Content-Type: text/plain");
exit("400: Napaka. Izbrali ste neobstoječo API metodo.");
break;
}
?>