moth/packages/rlyeh/service/rlyeh/rlyeh-ctf

45 lines
834 B
Plaintext
Raw Normal View History

2011-02-07 22:38:13 -07:00
#! /bin/sh
base=${CTF_BASE:-/var/lib/ctf}
2011-02-09 15:31:15 -07:00
echo -n "Team password: "
read -r teamhash
2011-02-07 22:38:13 -07:00
if ! KEY='Too much cheese.' arc4 < $base/teams.txt | grep -q -F -e "$teamhash"; then
echo 'No such team.'
exit
fi
cd $base/rlyeh
if [ -f $teamhash ]; then
now=$(date +%s)
ts=$(stat -c %Y $teamhash)
d=$(expr $now - $ts)
if [ $d -lt 60 ]; then
echo 'You are trying to connect too fast.'
exit
fi
else
2011-02-09 15:31:15 -07:00
echo 1 > $teamhash
2011-02-07 22:38:13 -07:00
fi
read level < $teamhash
(
if ! flock -n 8; then
echo 'Your team is already logged in.'
exit
fi
echo "Your team is on level $level."
echo
2011-02-09 15:31:15 -07:00
if setuidgid nobody rlyeh $level; then
arc4 /opt/rlyeh/tokens/rlyeh/enc.key < $base/tokens/rlyeh
echo
2011-02-07 22:38:13 -07:00
expr $level + 1 > $teamhash
else
touch $teamhash
fi
) 8<$teamhash