summaryrefslogtreecommitdiff
path: root/livewatch/livewatch.c
blob: 52c2ad29cfdeab0313bc1cb22e7fe929cdff638a (plain)
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
/* $Id$ */

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
valid(char *s)
{
	char	hex[] = "0123456789abcdef";

	if (strlen(s) != 32)
		return 0;

	do
		if (!strchr(hex, *s))
			return 0;
	while (*++s);

	return 1;
}

int
main()
{
	char	*s, *p;

	if (!(s = getenv("QUERY_STRING")))
		errx(1, "not a CGI context");

	printf("Content-type: text/html\r\n\r\n");

	if ((s = strstr(s, "key="))) {
		if ((p = strchr(s, '&')))
			*p = '\0';

		s += 4;
		if (valid(s))
			printf("%s", s);
	} else
		printf("Alles OK");
		
	return 0;
}