<?php
	// This is just a dummy implementation during the development of the GTK+3 GUI


if ($_SERVER['HTTP_X_TOKEN'] != "123456") {
	http_response_code(403);
	die("Invalid token.\n");
}

$id = $_GET['id'];
preg_match("/^[A-Za-z0-9]{6,10}$/", $id, $matches);
if (!$matches) {
	http_response_code(400);
	die ("Invalid tag ID.");
}

// $id is now safe to use

if (isset($_GET['meta'])) {
	if ($id == "BF09CE") {
		?>
		{
			"title" : "Cute Wifi Cat",
			"description" : "802.11nya~",
			"comment" : "It's mewine!"
		}
		<?php
	} else if ($id == "BE6200") {
		?>
		{
			"title" : "Crazy Stuff",
			"description" : "It blinks. Or explodes.",
			"comment" : "Like the kittens."
		}
		<?php
	} else {
		http_response_code(400);
		?>
		{
			"title" : "INVALID",
			"description" : "INVALID",
			"comment" : "INVALID"
		}
		<?php
	}
} else if (isset($_GET['image'])) {
	header('Content-Type: image/png');
	$fn = "img/$id.png";
	if (file_exists($fn)) {
		readfile($fn);
	} else {
		http_response_code(404);
		die ("Image not found.");
	}
} else {
	http_response_code(400);
	die("Invalid request.");
}
?>