2012-04-24 12:22:32 -06:00
|
|
|
|
#! /bin/sh
|
|
|
|
|
|
2012-06-12 18:25:32 -06:00
|
|
|
|
: ${CTF_BASE:=/var/lib/ctf}
|
|
|
|
|
BASE=$CTF_BASE/teams
|
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
|
|
|
|
|
2012-06-12 18:25:32 -06:00
|
|
|
|
if [ -f $BASE/names/$hash ]; then
|
2012-04-24 12:22:32 -06:00
|
|
|
|
echo "That name is already in use. Try another one."
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
2012-06-12 18:25:32 -06:00
|
|
|
|
printf '%s' "$name" > $BASE/names/$hash
|
2012-04-24 12:22:32 -06:00
|
|
|
|
|
2012-05-24 15:16:19 -06:00
|
|
|
|
cat <<EOD
|
2012-06-11 14:37:39 -06:00
|
|
|
|
Your team hash is [1m$hash[0m. Write that down somewhere and don't lose it.
|
2012-05-24 15:16:19 -06:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 18:25:32 -06:00
|
|
|
|
log () {
|
|
|
|
|
awk -v H=$1 '($2 == H) { print($3, $4); }' $CTF_BASE/points.log
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
read salt < $BASE/salt
|
|
|
|
|
|
|
|
|
|
printf '\017Team hash ("new" to create a new team): '
|
2012-04-24 12:22:32 -06:00
|
|
|
|
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-06-12 18:25:32 -06:00
|
|
|
|
elif [ "$hash" = 58 ]; then
|
|
|
|
|
name='Thumper Bumper'
|
|
|
|
|
elif ! [ -f $BASE/names/$hash ]; then
|
2012-04-24 12:22:32 -06:00
|
|
|
|
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-06-12 18:25:32 -06:00
|
|
|
|
else
|
|
|
|
|
read -r name < $BASE/names/$hash
|
2012-04-24 12:22:32 -06:00
|
|
|
|
fi
|
|
|
|
|
|
2012-05-29 22:45:20 -06:00
|
|
|
|
clear
|
|
|
|
|
|
2012-05-25 22:38:46 -06:00
|
|
|
|
|
2012-06-11 14:37:39 -06:00
|
|
|
|
printf 'Welcome back, [1m%s[0m.\n' "$name"
|
2012-05-29 22:45:20 -06:00
|
|
|
|
|
|
|
|
|
while true; do
|
2012-06-11 14:37:39 -06:00
|
|
|
|
printf "[7mp2>[0m "
|
2012-05-29 22:45:20 -06:00
|
|
|
|
read -r answer
|
2012-05-24 15:16:19 -06:00
|
|
|
|
|
2012-05-29 22:45:20 -06:00
|
|
|
|
case "$answer" in
|
|
|
|
|
\?|help)
|
|
|
|
|
cat <<EOD
|
2012-06-11 14:37:39 -06:00
|
|
|
|
[1m Help
|
2012-05-29 22:45:20 -06:00
|
|
|
|
----------------------------------------------------------[0m
|
|
|
|
|
|
2012-06-12 18:25:32 -06:00
|
|
|
|
Type [1mquit[0m to leave the p2 shell.
|
|
|
|
|
Type [1mlog[0m to show answered puzzles.
|
2012-05-29 22:45:20 -06:00
|
|
|
|
|
|
|
|
|
Any other string is checked as an answer. If the answer
|
|
|
|
|
is correct, you are awarded points and the scoreboard will
|
|
|
|
|
update within 10 seconds. Check the puzzles overview to
|
|
|
|
|
see if your answer unlocked a new puzzle.
|
|
|
|
|
EOD
|
|
|
|
|
continue
|
|
|
|
|
;;
|
2012-06-12 18:25:32 -06:00
|
|
|
|
log)
|
|
|
|
|
cat <<EOD
|
|
|
|
|
[1mPuzzles Answered By $name
|
|
|
|
|
---------------------------------------[0m
|
|
|
|
|
EOD
|
|
|
|
|
log $hash
|
|
|
|
|
continue
|
|
|
|
|
;;
|
2012-05-29 22:45:20 -06:00
|
|
|
|
quit)
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt)
|
|
|
|
|
if [ -z "$match" ]; then
|
2012-06-11 14:37:39 -06:00
|
|
|
|
echo 'That is not a correct answer. Type "[1mhelp[0m" for help.'
|
2012-05-29 22:45:20 -06:00
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat=${match% *}
|
|
|
|
|
points=${match#* }
|
|
|
|
|
fn=$BASE/$hash/$cat.$points
|
2012-06-12 18:25:32 -06:00
|
|
|
|
if log $hash | grep -Fxq "$cat $points"; then
|
2012-05-29 22:45:20 -06:00
|
|
|
|
echo "You've already received points for this answer."
|
2012-06-12 18:25:32 -06:00
|
|
|
|
elif pointscli $hash $cat $points p2console; then
|
2012-06-11 14:37:39 -06:00
|
|
|
|
echo "You get [1m$points[0m more points in the [1m$cat[0m category."
|
2012-06-12 18:25:32 -06:00
|
|
|
|
else
|
|
|
|
|
echo "[1mError recording points. Tell the officials![0m"
|
2012-05-29 22:45:20 -06:00
|
|
|
|
fi
|
|
|
|
|
done
|
2012-04-24 12:22:32 -06:00
|
|
|
|
|