summaryrefslogtreecommitdiff
path: root/search_cgi
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2020-01-08 10:34:12 +0000
committerKatolaZ <katolaz@freaknet.org>2020-01-08 10:34:12 +0000
commit8545883d676207a4f0ed01079aa8fccfa1e31c7a (patch)
treed285e569630b8c06d1c3fef99feb1f017d66dfeb /search_cgi
parentce8cebeec1ab8f7d391629d059d7620d6bcc2ec1 (diff)
add search_cgi example
Diffstat (limited to 'search_cgi')
-rw-r--r--search_cgi31
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