summaryrefslogtreecommitdiff
path: root/search_cgi
blob: 425ce55387d4c62b8419f036b71e870b72280d3b (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
#!/bin/sh

echo "Content-type: text/html\n\n"

query="${QUERY_STRING}"

echo "<html><head><style type='text/css'>"
echo "body{padding: 20px; margin: 40px auto;line-height: 1.6;font-size: 18px; color:#444;}"
echo "</style></head>"
echo "<body><div>Search for: </div><form method='GET' action='/cgi-bin/search_cgi'>"
echo "<input type='text' name='query'></input>"
echo "<input type='submit' value='Search!'></input>"
echo "</form>"


terms=$(echo "${query}" | tr '&' '\n' | grep -E "^query" | sed -E 's/^query=//')


if [ -z "$terms" ]; then 
	exit 0
else
	search=$(echo "$terms" | sed -E 's/\+/ /g')
	res=$(./search_repo ./ $search )
	if [ -z "$res" ]; then 
		echo "<p>No results for \"$search\":"
		exit 0;
	else
		echo "<p>Results for \"$search\""
		echo "<ul>\n"
		for r in $res; do 
			echo "<li><div><a href=\"$r\" target='new'>$r</a></div></li>\n"
		done
		echo "</ul>"
	fi
fi