2012-04-24 12:22:32 -06:00
|
|
|
#! /bin/sh
|
|
|
|
|
2012-05-25 22:38:46 -06:00
|
|
|
: ${BASE:=/var/lib/ctf/p2}
|
2012-04-24 12:22:32 -06:00
|
|
|
|
|
|
|
mkdir -p $BASE
|
|
|
|
|
2012-05-25 22:38:46 -06:00
|
|
|
if ! [ -f $BASE/salt ]; then
|
|
|
|
dd if=/dev/urandom count=1 | md5sum - > $BASE/salt
|
2012-04-24 12:22:32 -06:00
|
|
|
fi
|
|
|
|
clear
|
2012-05-25 22:38:46 -06:00
|
|
|
read salt < $BASE/salt
|
2012-04-24 12:22:32 -06:00
|
|
|
|
2012-05-24 15:16:19 -06:00
|
|
|
esc () {
|
|
|
|
printf '%s' "$*" | sed 's/[^-0-9A-Za-z ]/_/g; s/ /+/g'
|
|
|
|
}
|
|
|
|
|
2012-04-24 12:22:32 -06:00
|
|
|
newteam () {
|
|
|
|
echo '== Team Creation =='
|
|
|
|
echo
|
|
|
|
echo -n 'What would you like your team to be called (3-12 chars)? '
|
|
|
|
read -r name
|
|
|
|
echo
|
|
|
|
namelen=$(printf "%s" "$name" | wc -c)
|
|
|
|
if [ $namelen -lt 3 ] || [ $namelen -gt 12 ]; then
|
|
|
|
echo 'Invalid name length'
|
|
|
|
return
|
|
|
|
fi
|
2012-05-25 22:38:46 -06:00
|
|
|
hash=$(printf '%s %s' "$salt" "$name" | md5sum | cut -b 1-8)
|
2012-04-24 12:22:32 -06:00
|
|
|
|
|
|
|
if [ -d $BASE/$hash ]; then
|
|
|
|
echo "That name is already in use. Try another one."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir $BASE/$hash
|
|
|
|
|
|
|
|
printf '%s' "$name" > $BASE/$hash/.name
|
|
|
|
|
2012-05-24 15:16:19 -06:00
|
|
|
cat <<EOD
|
|
|
|
Your team hash is $hash. Write that down somewhere and don't lose it.
|
|
|
|
If you forget your hash, you'll have to start over from the beginning
|
|
|
|
with a new team and everybody will laugh at you.
|
|
|
|
EOD
|
|
|
|
}
|
|
|
|
|
2012-05-25 22:38:46 -06:00
|
|
|
fini () {
|
2012-05-24 15:16:19 -06:00
|
|
|
echo
|
|
|
|
echo "Press [Enter] to clear the screen."
|
|
|
|
read
|
|
|
|
exit 0
|
2012-04-24 12:22:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
echo -n 'Team hash ("new" to create a new team): '
|
|
|
|
read -r hash
|
|
|
|
echo
|
|
|
|
if [ -z "$hash" ]; then
|
|
|
|
exit 0
|
|
|
|
elif [ "$hash" = "new" ]; then
|
|
|
|
newteam
|
2012-05-25 22:38:46 -06:00
|
|
|
fini
|
2012-04-24 12:22:32 -06:00
|
|
|
elif ! [ -d $BASE/$hash ]; then
|
|
|
|
echo "No such team, fool."
|
|
|
|
echo "Is this when everybody laughs at you for forgetting your hash?"
|
2012-05-25 22:38:46 -06:00
|
|
|
fini
|
2012-04-24 12:22:32 -06:00
|
|
|
fi
|
|
|
|
|
2012-05-24 15:16:19 -06:00
|
|
|
read -r name < $BASE/$hash/.name
|
2012-05-25 22:38:46 -06:00
|
|
|
printf "%s answer: " "$name"
|
2012-05-24 15:16:19 -06:00
|
|
|
read -r answer
|
2012-05-25 22:38:46 -06:00
|
|
|
echo
|
|
|
|
|
2012-05-24 15:16:19 -06:00
|
|
|
match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt)
|
2012-05-25 22:38:46 -06:00
|
|
|
if [ -z "$match" ]; then
|
|
|
|
echo "That is not a correct answer."
|
|
|
|
fini
|
|
|
|
fi
|
|
|
|
|
2012-05-24 15:16:19 -06:00
|
|
|
cat=${match% *}
|
|
|
|
points=${match#* }
|
|
|
|
fn=$BASE/$hash/$cat.$points
|
|
|
|
if [ -f $fn ]; then
|
|
|
|
echo "You've already received points for this answer."
|
|
|
|
else
|
2012-05-25 22:38:46 -06:00
|
|
|
> $fn
|
2012-05-24 15:16:19 -06:00
|
|
|
echo "You get $points more points in the $cat category."
|
|
|
|
# run puzzles.cgi
|
|
|
|
# update scoreboard
|
|
|
|
fi
|
|
|
|
|
2012-05-25 22:38:46 -06:00
|
|
|
fini
|
2012-04-24 12:22:32 -06:00
|
|
|
|