#!/bin/bash echo "Content-type: text/plain" echo "" # get form data: pattern=....&excludeList=...&includeList=... export stdin="$(cat)" # when pattern has 3 or more dots, safari may pass an extended ascii sequence # if so, convert that sequence to 3 dots ... # https://www.w3schools.com/tags/ref_urlencode.ASP # search for %E2%80%A6 threeDots=`printf "\342\200\246"` stdin=`echo $stdin | sed "s+$threeDots+...+g" ` # now perform input validation illegal=`echo "$stdin" | sed -e 's+[A-Za-z=& .%0-9]*++g'` if [ ! -z "$illegal" ] then #tmp=`mktemp`.wordle.log #echo "`date`: error: illegal character(s); stdin = $stdin" >> $tmp #echo "error: illegal character(s): $illegal ... see also $tmp" echo "" echo "error: illegal character(s): $illegal" echo "" #echo "stdin = ($stdin)" #echo "" # echo $stdin | sed "s+$threeDots+...+g" #echo "" #echo "$stdin" | od -cv #echo "" #echo "$stdin" | od -v -t x1 echo "" exit 0 fi # construct variables from input for kv in `echo $stdin | sed -e 's+&+ +g'` do eval "$kv" done # echo stdin = $stdin # echo pattern = $pattern # echo excludeList = $excludeList # echo includeList = $includeList #################################### if [ ! -z "$excludeList" ] then # open bracket, ^ symbol, char list (with ws or %20 removed), close bracket key=`echo $excludeList | sed -e "s+^.+[^&+g" -e 's+%20++g' -e "s+[ ]*++g" -e "s+$+]+g" ` # replace "." in pattern with above key pattern=`echo $pattern | sed -e "s+\.+$key+g"` fi #################################### tmp=`mktemp` cat /usr/share/dict/words | egrep -v "[A-Z]" | egrep "^${pattern}$" > $tmp #################################### if [ -z "$includeList" ] then # if include list is empty, then return early cat $tmp else # convert %20 to space, so we can grep for each letter individually for letter in `echo $includeList | sed -e 's+%20+ +g'` do cat $tmp | egrep "$letter" > $tmp.2 mv $tmp.2 $tmp done cat $tmp fi # cleanup /bin/rm -f $tmp