#! /opt/bin/dash
#
# os/prog/vsfs/post.sh
# requires change from end='' to end=' ' in five places in vsfs.py,
# and change to show the data value when writing data
export PATH="/opt/bin:/bin:/usr/bin"
echo "Content-type: text/html\n\n
vsfs"
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/vsfs || 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"; i="8"; d="8"
case "$h" in
"state") p="state"; r="-r"; s="123456789";;
*) p="operation"; 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 - vsfs results $msg
green = correct |
red = wrong |
"
out=$(
(echo "$in"; python3 ./vsfs.py -s "$seed" -n "$n" -i "$i" -d "$d" "$r" -c | grep -v '^ARG') |
awk -v "r=$r" 'BEGIN { v=1; icount=0;
} {
# user input: U name value
# vsfs.py input: mkdir("/g/w"); -- or creat, etc.
# or: inode bitmap 11111110
# inodes [d a:0 r:4] [d a:1 r:3] ...
# data bitmap 11110000
# data [(.,0) (..,0) (g,1) (q,2) (u,3) (t,4)] ...
if( $1 != "") { if( $1 == "U") u[$2]=$3;
else if(r=="") {
cmd=""; arg2="";
if( $1 ~ /^mkdir/) { cmd="mkdir"; split($1,t,"\""); arg1=t[2]; }
else if( $1 ~ /^creat/) { cmd="creat"; split($1,t,"\""); arg1=t[2]; }
else if( $1 ~ /^fd=open/) { cmd="open"; split($1,t,"\""); arg1=t[2]; }
else if( $1 ~ /^link/) { cmd="link"; split($0,t,"\""); arg1=t[2]; arg2=t[4]; }
else if( $1 ~ /^unlink/) { cmd="unlink"; split($1,t,"\""); arg1=t[2]; }
if( cmd != "") {
# print "v = "v", cmd = "cmd", arg1 = "arg1", arg2 = "arg2;
print "\n
";
x=u["v"v"op"]; if( x == cmd) color="#90EE90"; else color="#FF6347";
if( x == "") x = " "
print ""v". operation | "x" |
";
x1=u["v"v"arg1"]; if( x1 == arg1 || "/"x1 == arg1) color="#90EE90"; else color="#FF6347";
if( x == "") x = " "
print "arg1 | "x1" |
";
x2=u["v"v"arg2"]; if( arg2 != "" || x2 != "")
{ if( x2 == arg2 || "/"x2 == arg2) color="#90EE90"; else color="#FF6347";
if( x == "") x = " "
print "arg2 | "x2" |
"; }
print "
";
++v;
}
else print;
} else {
if( $1 ~ /^(mkdir|creat|fd=open|link|unlink)/)
{ if(v==1) printf("\n"); print v". "$0"\n"; next; }
if( $1 == "inode") ++icount; if( icount < 2) { print; next; }
if( $1 == "inode") { ib=$3;
x=u["v"v"ib"]; if( x == ib) color="#90EE90"; else color="#FF6347";
print "";
print "inode bitmap | ";
if( x == "") x = " "
print ""x" |
";
} else if( $1 == "inodes") { gsub(/ /,"",$0); i=substr($0,7);
x=u["v"v"i"]; if( x == i) color="#90EE90"; else color="#FF6347";
print "inodes | ";
if( x == "") x = " "
print ""x" |
";
} else if( $1 == "data") if( $2 == "bitmap") { db=$3;
x=u["v"v"db"]; if( x == db) color="#90EE90"; else color="#FF6347";
print "data bitmap | ";
if( x == "") x = " "
print ""x" |
";
} else { gsub(/ /,"",$0); d=substr($0,5);
x=u["v"v"d"]; if( x == d) color="#90EE90"; else color="#FF6347";
print "data | ";
if( x == "") x = " "
print ""x" |
";
++v;
} else 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 ${p}: good $good bad $bad in: $log" >> log
fi
echo "\n$out
"