#!/bin/sh ##func printlines (){ echo "<ul>\n" l=$(echo "$@" | tr ' ' '\n') for r in $l; do echo "<li><div><a href=\"$r\" target='new'>$r</a></div></li>\n" done echo "</ul>\n" } printf "Content-type: text/html\n\n" query=$(echo "${QUERY_STRING}" | sed -E 's/[\$^?<>@;\*`\|]//g') ##func print_head(){ 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 "<div><input type='text' name='query'></input></div>" echo "<div>in: <input type='radio' name='type' value='url' checked>url</input>" echo "<input type='radio' name='type' value='descr'>description</input>" echo "<input type='radio' name='type' value='read'>readme</input>" echo "<input type='radio' name='type' value='all'>all</input>" echo "</div>" echo "<input type='submit' value='Search!'></input>" echo "</form>" } ##func print_foot(){ echo "</body></html>" } 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') numres=0 lines=$(./search_repo ./ "$search" 2>&1 ) for line in $lines; do case "$line" in "--URL") #echo "$line<br>" if [ "$qtype" = "url" -o "$qtype" = "all" ]; then curstr="url" else curstr="" fi ;; "--DESCR") if [ -n "$curstr" ]; then if [ -n "$results" ]; then printf "<div>%s results in repo %s</div>\n" $numres $curstr printlines "$results" else printf "<div>No results in repo %s</div>\n" $curstr fi fi results="" numres=0 if [ "$qtype" = "descr" -o "$qtype" = "all" ]; then curstr="description" else curstr="" fi ;; "--README") #echo "$line<br>" if [ -n "$curstr" ]; then if [ -n "$results" ]; then printf "<div>%s results in repo %s</div>\n" $numres $curstr printlines "$results" else printf "<div>No results in repo %s</div>\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 "<div>%s results in readme files</div>\n" $numres printlines $results else printf "<div>No results in readme files </div>\n" $curstr fi fi fi print_foot