diff options
-rw-r--r-- | search_cgi | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/search_cgi b/search_cgi new file mode 100644 index 0000000..624ad2e --- /dev/null +++ b/search_cgi @@ -0,0 +1,31 @@ +#!/bin/sh + +echo "Content-type: text/html\n\n" + +query="${QUERY_STRING}" + + +echo "<html><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/\%20/ /g') + res=$(./search_repo ./ $search ) + if [ -z "$res" ]; then + echo "<p>No results for \"$search\":" + exit 0; + else + echo "<p>Results for \"$search\"" + for r in $res; do + echo "<div><a href=\"$r\" target='new'>$r</a></div>\n" + done + fi +fi |