#! /opt/bin/dash # # os/prog/paging-linear-translate/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\npaging-linear-translate" 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/paging-linear-translate || 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; }}') #echo "
$in\n
" #exit n="10"; a="1m"; p="64m"; P="64k"; u="70"; 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 - paging-linear-translate results $msg

green = correct
    red = wrong

" #echo "

"
#python3 ./paging-linear-translate.py -s "$seed" -n "$n" -P "$P" -p "$p" -a "$a" -u "$u" -v -c
# sed -e 's/) / /' -e 's/)$//'
#echo "
" out=$( (echo "$in"; python3 ./paging-linear-translate.py -s "$seed" -n "$n" -P "$P" -p "$p" -a "$a" -u "$u" -v -c) | awk 'function hex(h) { if( index(h,"0x") == 1) h=substr(h,3); # remove leading 0x while(length(h)>8 && index(h,"0") == 1) h=substr(h,2); # remove excess leading zeros while(length(h)<8) h = "0"h; return "0x"h; } # add leading zeros to make length 8 BEGIN { v=0; print ""; print ""; } { # each line of user input from paging-linear-translate-post looks like: U name value if( $1 != "") { if( $1 == "U") u[$2]=$3; else if( $1 == "VA") { va=$2; pa=$6; if( pa == "Invalid") pa="0x00000000"; else pa=hex(pa); print ""; x=u["v"v"v"]; if( x != "" && hex(x) == pa) color="#90EE90"; else color="#FF6347"; print ""; ++v; }}}' ) 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"
"