From 10105172df6def5e5a7410119302a701fd9ca7ec Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Fri, 10 Jan 2020 06:41:25 +0000 Subject: search by URL, description, or content in search_cgi --- search_cgi | 127 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 24 deletions(-) (limited to 'search_cgi') diff --git a/search_cgi b/search_cgi index 425ce55..68031bb 100755 --- a/search_cgi +++ b/search_cgi @@ -1,35 +1,114 @@ #!/bin/sh -echo "Content-type: text/html\n\n" +##func +printlines (){ + echo "\n" +} -query="${QUERY_STRING}" -echo "" -echo "
Search for:
" -echo "" -echo "" -echo "
" +printf "Content-type: text/html\n\n" +query=$(echo "${QUERY_STRING}" | sed -E 's/[\$^?<>@;\*`\|]//g') -terms=$(echo "${query}" | tr '&' '\n' | grep -E "^query" | sed -E 's/^query=//') +##func +print_head(){ + echo "" + echo "
Search for:
" + echo "
" + echo "
in: url" + echo "description" + echo "readme" + echo "all" + echo "
" + echo "" + echo "
" -if [ -z "$terms" ]; then - exit 0 -else +} + +##func +print_foot(){ + echo "" +} + +terms=$(echo "${query}" | tr '&' '\n' | grep -E "^query=" | sed -E 's/^query=//') +qtype=$(echo "${query}" | tr '&' '\n' | grep -E "^type=" | sed -E 's/^type=//') + +print_head + +if [ -n "$terms" ]; then search=$(echo "$terms" | sed -E 's/\+/ /g') - res=$(./search_repo ./ $search ) - if [ -z "$res" ]; then - echo "

No results for \"$search\":" - exit 0; - else - echo "

Results for \"$search\"" - echo "

" + numres=0 + lines=$(./search_repo ./ "$search" 2>&1 ) + for line in $lines; do + case "$line" in + "--URL") + #echo "$line
" + if [ "$qtype" = "url" -o "$qtype" = "all" ]; then + curstr="url" + else + curstr="" + fi + ;; + + "--DESCR") + if [ -n "$curstr" ]; then + if [ -n "$results" ]; then + printf "
%s results in repo %s
\n" $numres $curstr + printlines "$results" + else + printf "
No results in repo %s
\n" $curstr + fi + fi + results="" + numres=0 + if [ "$qtype" = "descr" -o "$qtype" = "all" ]; then + curstr="description" + else + curstr="" + fi + ;; + + "--README") + #echo "$line
" + if [ -n "$curstr" ]; then + if [ -n "$results" ]; then + printf "
%s results in repo %s
\n" $numres $curstr + printlines "$results" + else + printf "
No results in repo %s
\n" $curstr + fi + fi + results="" + numres=0 + if [ "$qtype" = "read" -o "$qtype" = "all" ]; then + curstr="readme" + else + curstr="" + fi + ;; + + *) + numres=$(($((numres)) + 1)) + results="$results $line" + ;; + esac + done + if [ -n "$curstr" ]; then + if [ -n "$results" ]; then + printf "
%s results in readme files
\n" $numres + printlines $results + else + printf "
No results in readme files
\n" $curstr + fi fi fi + +print_foot -- cgit v1.2.3