#! /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\n
relocation"
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 "VA | PA |
"; } {
# 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 ""v" | "va" | ";
x=u["v"v"v"]; if( x != "" && x == pa) color="#90EE90"; else color="#FF6347";
print " "x" |
"; ++v;
}}} END { min_bounds = max+1; max_base = p-min_bounds;
print "min bounds | ";
x=u["v8v"]; if( x != "" && x == min_bounds) color="#90EE90"; else color="#FF6347";
print " "x" |
";
print "max base | ";
x=u["v9v"]; if( x != "" && x == max_base) color="#90EE90"; else color="#FF6347";
print " "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 good $good bad $bad in: $log" >> log
fi
echo "$out
"