#! /opt/bin/dash # # os/prog/relocation/post.sh export PATH="/opt/bin:/bin:/usr/bin" #echo "Content-type: text/plain\n"; in=$(cat); echo "in = \"$in\""; exit echo "Content-type: text/html\n\nrelocation" 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/relocation || exit 1; fi # tomato = #FF6347 # lightgreen = #90EE90 # in=$(cat | egrep -v '#FF6347|#90EE90') useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}') n="8"; a="2048"; p="32768"; s="123456789" 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 - relocation results $msg

green = correct
    red = wrong

" #echo "

"
#python3 ./relocation.py -s "$seed" -n "$n" -a "$a" -p "$p" -c |
# sed -e 's/) / /' -e 's/)$//'
#echo "
" out=$( (echo "$in"; python3 ./relocation.py -s "$seed" -n "$n" -a "$a" -p "$p" -c | sed -e 's/) / /' -e 's/)$//') | awk -v "p=$p" 'BEGIN { v=0; max=0; print ""; print ""; } { # each line of user input from relocation-post looks like: U name value if( $1 != "") { if( $1 == "U") u[$2]=$3; else if( $1 == "VA") { va=$5; if( va > max) max = va; pa=$10; if( pa == "") pa=0; print ""; x=u["v"v"v"]; if( x != "" && x == pa) color="#90EE90"; else color="#FF6347"; print ""; ++v; }}} END { min_bounds = max+1; max_base = p-min_bounds; print ""; x=u["v8v"]; if( x != "" && x == min_bounds) color="#90EE90"; else color="#FF6347"; print ""; print ""; x=u["v9v"]; if( x != "" && x == max_base) color="#90EE90"; else color="#FF6347"; print ""; }' ) 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 good $good bad $bad in: $log" >> log fi echo "$out
  #  VAPA
"v"   "va"   "x"
min bounds   "x"
max base   "x"
"