summaryrefslogtreecommitdiff
path: root/livewatch/livewatch.c
blob: 35f957179d830c95fbae31caa99a424aa929b04b (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
/* $Id$ */

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

int
valid(char *s)
{
	int	i;

	for (i = 32; *s; i--, s++)
		if (!isascii(*s) || !isxdigit(*s))
			return 0;

	return !i;
}

int
main()
{
	char	*answer = "Alles OK";
	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="))) {
		s += 4;
		p = strchr(s, '&');
		if (p)
			*p = '\0';
		if (valid(s))
			answer = s;
	}

	printf("%s", answer);
		
	return 0;
}