summaryrefslogtreecommitdiffstats
path: root/api/php/api.php
blob: 1140dde28f878797f118d1435738a2c973050672 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?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 = "anonymous";
			} 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 (empty($_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");
			}
			$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(
				"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))
			i));
			$response = file_put_contents($commentsfile, $cm, 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.");
			}
			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;
	}
?>