#! /opt/bin/dash # # os/prog/raid/post.sh # uses non-standard -d,--dups option to avoid duplicate addresses export PATH="/opt/bin:/bin:/usr/bin" echo "Content-type: text/html\n\nraid" 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/raid || 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
" #exit n="6"; R="25" case "$h" in "L1R") p="L1R"; L="1"; r="-r"; s="123456789";; "L1") p="L1"; L="1"; r=""; s="123456789";; "L0R") p="L0R"; L="0"; r="-r"; s="123456789";; *) p="L0"; L="0"; r=""; 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 - raid results $msg

green = correct
    red = wrong

4 disks: RAID Level $L

" #echo "

"
#python3 ./raid.py -d -s "$seed" -n "$n" -R "$R" -L "$L" "$r" -c | egrep '^(LOGICAL|  read)'
#echo "
" out=$( (echo "$in"; python3 ./raid.py -d -s "$seed" -n "$n" -R "$R" -L "$L" "$r" -c) | awk -v "r=$r" 'BEGIN { v=0; print ""; if(r=="") print ""; else print ""; } { # user input: U name value # raid.py input: LOGICAL READ from addr:4205 size:4096 # or: read [disk 1, offset 1051] if( $1 != "") { if( $1 == "U") u[$2]=$3; else if( $1 == "LOGICAL") { split($4,t,":"); a=t[2]; } else if( $1 == "read") { d=$3; o=$5; gsub(/[^[:digit:]]/,"",d); gsub(/[^[:digit:]]/,"",o); if(r=="") { print ""; x=u["v"v"d"]; if( x != "" && x == d) color="#90EE90"; else color="#FF6347"; print ""; x=u["v"v"o"]; if( x != "" && x == o) color="#90EE90"; else color="#FF6347"; print ""; } else { print ""; x=u["v"v"a"]; if( x != "" && x == a) color="#90EE90"; else color="#FF6347"; print ""; } 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 ${p}: good $good bad $bad in: $log" >> log fi echo "$out
AddressDiskOffset
DiskOffsetAddress
"a""x""x"
"d""o""x"
"