diff options
author | KatolaZ <[email protected]> | 2020-01-08 10:34:12 +0000 |
---|---|---|
committer | KatolaZ <[email protected]> | 2020-01-08 10:34:12 +0000 |
commit | 8545883d676207a4f0ed01079aa8fccfa1e31c7a (patch) | |
tree | d285e569630b8c06d1c3fef99feb1f017d66dfeb | |
parent | ce8cebeec1ab8f7d391629d059d7620d6bcc2ec1 (diff) |
add search_cgi example
-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 |