#! /opt/bin/dash # # os/prog/ssd/post.sh # requires setting ftl_columns = 1000 in ssd.py so FTL list will always print on one line export PATH="/opt/bin:/bin:/usr/bin" echo "Content-type: text/html\n\nssd" user=`echo "${REMOTE_USER}" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]'` if [ -z "$user" ]; then echo "Bad user: ${REMOTE_USER} -> $user"; exit 1; fi if [ -n "$HTTP_HOST" ]; then cd /os/prog/ssd || exit 1; fi # tomato = #FF6347 # lightgreen = #90EE90 # in=$(cat | egrep -v '#FF6347|#90EE90') h=$(echo "$in" | awk '{ if( $2 == "P") { print $3; exit; }}') useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}') #echo "
$in\n
" n="6"; l="30"; B="3"; p="10"; P="0/70/30" case "$h" in "log") T="log"; s="123456789";; *) T="direct"; s="123456789";; esac if [ -n "$useed" ]; then seed="$useed" msg="- seed = $seed" else x=$(perl -e "print unpack(\"C*\",$user);"); seed="${s}${x}" #echo "
s = $s, x = $x, seed = $seed
" msg="" fi echo "$user - ssd results $msg

green = correct
    red = wrong

" echo "

SSD Type $T\n\nInitial State:"

out=$(
(echo "$in"; python3 ./ssd.py -s "$seed" -T "$T" -l "$l" -B "$B" -p "$p" -n "$n" -P "$P" -C -F) |
 awk -v "B=$B" -v "p=$p" '# disp replaces blanks with "-"
 function disp(z,sep,r,s,b,i,k) { k=6; r=""; for(b=0;b ", " -\\> ", $0);
     if( v < 0) {
       if( $1 == "FTL")  { print "FTL   "; next; }
       if( $1 == "Data") { print "Data  "disp($0," "); next; }
       if( $1 == "Live") { print "Live  "disp($0," "); next; }
       print;
     }
     if( $1 == "cmd") { ++v; if( v > 0) print; }
     if( v >= 0) {
        if( $1 == "FTL") { F=""; if( $2 != "(empty)") { gsub( ":  *", ":", $0);
         F=$2; for(i=3;i<=NF;++i) F=F","$i; } }
	else if( $1 == "State") { S=""; for(i=2;i<=NF;++i) S=S""$i; }
	else if( $1 == "Data") D=disp($0,"");
	else if( $1 == "Live") { L=disp($0,"");
	 print "\n";
	 x=u["v"v"F"]; if( x == F) color="#90EE90"; else color="#FF6347";
          if( x == "") x = " "
          print "";
	 x=u["v"v"S"]; if( x == S) color="#90EE90"; else color="#FF6347";
          if( x == "") x = " "
          print "";
	 x=u["v"v"D"]; if( x == D) color="#90EE90"; else color="#FF6347";
          if( x == "") x = " "
          print "";
	 x=u["v"v"L"]; if( x == L) color="#90EE90"; else color="#FF6347";
          if( x == "") x = " "
          print "";
         print "
FTL   "x"
State   "x"
Data   "x"
Live   "x"
"; } } }' ) if [ -z "$useed" ]; then bad=$(echo "$out" | grep "#FF6347" | wc -l) good=$(echo "$out" | grep "#90EE90" | wc -l) log=$(echo "$in" | tr -dc '\-+,:[:alnum:]') echo "$(date) $user ${T}: good $good bad $bad in: $log" >> log fi echo "\n$out
"