summaryrefslogtreecommitdiffstats
path: root/kratek.sh
blob: f298b206b93820b74356215454221b300fd28470 (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
67
68
69
70
71
72
#!/bin/sh
f="`cut -d/ -f2 <<<"$DOCUMENT_URI" | head -n1`"
k="`tr "&"  "\n" <<<"$QUERY_STRING" | grep -m1 '^k=' | cut -d= -f2 | head -n1`"
d="`tr "&" "\n" <<<"$QUERY_STRING" | grep -m1 '^d=' | cut -d= -f2 | head -n1`"
if [ x"$f" = x ]
then
	true
else
	k="$f"
fi
if grep '^[[:alnum:]]*$' <<<"$k" > /dev/null && grep '^[[:alnum:]]*$' <<<"$d" > /dev/null
then
	r="`grep --text ^"$k"\\\\s /tmp/db 2> /dev/null | cut -f2 | head -n1`"
else
	b=1
fi
if [ x = x"$f" ]
then
	if [ x = x"$k" ] && [ x = x"$d" ]
	then
		echo Status: 200
		echo Content-Type: text/html
		echo
		echo "<form><label for=k>kratek</label><input id=k name=k><label for=d>dolg</label><input id=d name=d><input type=submit></form><a href=//splet.sijanec.eu>moja spletna stran</a>"
		echo
	else
		if [ x"$r" = x ]
		then
			if [ x$b = x1 ]
			then
				echo Status: 400
				echo Content-Type: text/plain
				echo
				echo 400
				echo 'grep ^[[:alnum:]]*$ <<<"$x"'
				echo
			else
				echo "$k	$d" >> /tmp/db
				echo Status: 201
				echo Content-Type: text/plain
				echo
			fi
		else
			echo Status: 409
			echo Content-Type: text/plain
			echo
			echo 409
			echo '[ x"`grep --text ^"$k"$ db | cut -f2^`" = x ]'
			echo "$r"
		fi
	fi
else
	if [ x"$r" = x ]
	then
		echo Status: 404
		echo Content-Type: text/plain
		echo
		echo 404
		echo 'grep --text ^"$k"$ db | cut -f2'
		echo f: "$f"
		echo k: "$k"
		echo d: "$d"
		echo
	else
		echo Status: 301
		echo Content-Type: text/plain
		echo Location: "$r"
		echo
		echo "$r"
		echo
	fi
fi