Lotsa bugfixes

This commit is contained in:
Neale Pickett 2010-09-23 23:27:14 -06:00
parent ea1653cf03
commit 6256b7da77
10 changed files with 81 additions and 42 deletions

View File

@ -4,15 +4,34 @@ CTF Packages
Packages are squashfs files. Packages are squashfs files.
A hypothetical package named pkgname.sfs will be mounted under A hypothetical package named pkgname.sfs will be mounted under
/srv/pkgname. The following top-level files and directories are /opt/pkgname. The following top-level files and directories are
significant: significant:
* /www/ - Will appear as http://host/pkgname/, CGI can be run * /setup - Run after package is mounted
* /bin/ - Will be added to $PATH * /bin/ - Added to $PATH for login shells
* /puzzles/ - Will appear as a puzzle category (see "Puzzles" below) * /puzzles/ - Appears as a puzzle category (see "Puzzles" below)
* /answers.txt - Puzzle answers for category pkgname (see "Puzzles" below) * /answers.txt - Puzzle answers for category pkgname (see "Puzzles" below)
setup script
------------
The setup script (if it exists and is executable) will be run from within
the mounted directory. This is mostly so you can copy things out of your
read-only package and into read/write areas.
Don't start your service here, instead, make a new directory in
/var/service and place a "run" script in it. More information can be found
at <http://smarden.org/runit/>.
Some common actions in setup:
cp -r service/* /var/service # Install startup services
# Set up a file with ownership
install -o ctf -m 0644 /var/lib/ctf/whatever.db
Puzzles Puzzles
------- -------

View File

@ -12,12 +12,14 @@ $(PACKAGE): build
cp setup $(PKGDIR) cp setup $(PKGDIR)
find bin -not -name '*~' | cpio -p $(PKGDIR) find bin -not -name '*~' | cpio -p $(PKGDIR)
cp src/in.tokend src/tokencli src/pointscli $(PKGDIR)/bin cp src/in.tokend $(PKGDIR)/bin
cp src/tokencli src/pointscli $(PKGDIR)/bin
cp src/puzzles.cgi $(PKGDIR)/bin
find service -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR) find service -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR)
find www -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR) find www -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR)
cp src/puzzler.cgi src/puzzles.cgi src/claim.cgi $(PKGDIR)/www cp src/puzzler.cgi src/claim.cgi $(PKGDIR)/www
mksquashfs $(PKGDIR) $(PACKAGE) -all-root -noappend mksquashfs $(PKGDIR) $(PACKAGE) -all-root -noappend

View File

@ -5,10 +5,15 @@ if [ $# -ne 1 ]; then
exit 64 exit 64
fi fi
escape () {
sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
}
# Don't overwrite files # Don't overwrite files
set -C set -C
base=${CTF_BASE:-/var/lib/ctf} base=${CTF_BASE:-/var/lib/ctf}
www=${CTF_BASE:-/var/www}
# Assign a color. I spent two days selecting this color pallette for # Assign a color. I spent two days selecting this color pallette for
# people with protanopia. Please don't change these colors. # people with protanopia. Please don't change these colors.
@ -45,3 +50,6 @@ echo "$1" > $base/teams/names/$hash
echo "$color" > $base/teams/colors/$hash echo "$color" > $base/teams/colors/$hash
echo "Registered with hash: $hash" echo "Registered with hash: $hash"
# Write teams.html if it's an actual contest
/opt/mcp/bin/teams.sh > $www/teams.html.new && mv $www/teams.html.new $www/teams.html

View File

@ -10,17 +10,6 @@ STATE=${CTF_BASE:-/var/lib/ctf}
NEWPOINTS=$STATE/points.new NEWPOINTS=$STATE/points.new
POINTS=$STATE/points.log POINTS=$STATE/points.log
SCOREBOARD=$WWW/scoreboard.html SCOREBOARD=$WWW/scoreboard.html
PUZZLES=$WWW/puzzles.html
TEAMS=$WWW/teams.html
install -u ctf -m 0644 /dev/null $STATE/tokens.db
install -u ctf -m 0644 /dev/null $STATE/claim.db
install -u root -m 0644 /dev/null $POINTS
install -u ctf -d $NEWPOINTS
install -u root -d $STATE/teams/names
install -u root -d $STATE/teams/colors
install -u root -d $STATE/token.keys
if ! [ -f $SCOREBOARD ]; then if ! [ -f $SCOREBOARD ]; then
$BIN/scoreboard < $POINTS > $SCOREBOARD $BIN/scoreboard < $POINTS > $SCOREBOARD
@ -42,16 +31,6 @@ while true; do
$BIN/scoreboard < $POINTS > $SCOREBOARD.new && mv $SCOREBOARD.new $SCOREBOARD $BIN/scoreboard < $POINTS > $SCOREBOARD.new && mv $SCOREBOARD.new $SCOREBOARD
fi fi
# Render puzzles list
if [ $STATE/puzzler.db -nt $PUZZLES ]; then
$WWW/puzzles.cgi > $PUZZLES.new && mv $PUZZLES.new $PUZZLES
fi
# Render team names
if [ $STATE/teams/names -nt $TEAMS ]; then
$BIN/teams.sh > $TEAMS.new && mv $TEAMS.new $TEAMS
fi
now=$(date +%s) now=$(date +%s)
if [ $now -lt $next ]; then if [ $now -lt $next ]; then
sleep $(expr $next - $now) sleep $(expr $next - $now)

View File

@ -66,7 +66,7 @@ function output( t, c) {
BEGIN { BEGIN {
base = ENVIRON["CTF_BASE"] base = ENVIRON["CTF_BASE"]
if (! base) { if (! base) {
base = "/srv/ctf" base = "/var/lib/ctf"
} }
# Only display two decimal places # Only display two decimal places
@ -101,13 +101,19 @@ BEGIN {
# Get team colors and names # Get team colors and names
for (team in teams) { for (team in teams) {
fn = base "/teams/colors/" team # Busybox awk segfaults if you try to close a file that didn't
getline colors_by_team[team] < fn # exist. We work around it by calling cat.
close(fn) cmd = sprintf("cat %s/teams/colors/%s", base, team)
cmd | getline color
if (! color) color = "cccccc";
colors_by_team[team] = color
close(cmd)
fn = base "/teams/names/" team cmd = sprintf("cat %s/teams/names/%s", base, team)
getline names_by_team[team] < fn cmd | getline name
close(fn) if (! name) name = team
names_by_team[team] = name
close(cmd)
} }
# Sort categories # Sort categories

View File

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
cd /var/lib/ctf/teams/names cd ${CTF_BASE:-/var/lib/ctf}/teams/names
escape () { escape () {
sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
@ -21,7 +21,7 @@ EOF
echo "<table>" echo "<table>"
echo "<tr><th>Team Name</th><th>Token</th></tr>" echo "<tr><th>Team Name</th><th>Token</th></tr>"
for i in ??????; do for i in *; do
echo "<tr><td>" echo "<tr><td>"
escape < $i escape < $i
echo "</td><td><samp>$i</samp></td></tr>" echo "</td><td><samp>$i</samp></td></tr>"
@ -32,4 +32,4 @@ cat <<EOF
<p>Use your team's token to claim points.</p> <p>Use your team's token to claim points.</p>
</body> </body>
</html> </html>
EOF EOF

View File

@ -1,8 +1,20 @@
#! /bin/sh #! /bin/sh
## Set up this package ## Set up the MCP (Master Control Program) server
hostname mcp hostname mcp
cp -r service/* /var/service cp -r service/* /var/service/
cp -r www /var cp -r www /var/
install -o ctf -m 0644 /dev/null /var/lib/ctf/tokens.db
install -o ctf -m 0644 /dev/null /var/lib/ctf/claim.db
install -o ctf -m 0644 /dev/null /var/lib/ctf/puzzles.db
install -o root -m 0644 /dev/null /var/lib/ctf/points.log
install -o ctf -d /var/lib/ctf/points.new
install -o ctf -d /var/lib/ctf/points.tmp
install -o root -d /var/lib/ctf/teams/names
install -o root -d /var/lib/ctf/teams/colors
install -o root -d /var/lib/ctf/token.keys

View File

@ -442,7 +442,7 @@ award_points(char const *teamhash,
token log. token log.
*/ */
filename = state_path("points.new/%d.%d.%s.%s.%ld", filename = state_path("points.tmp/%d.%d.%s.%s.%ld",
now, getpid(), now, getpid(),
teamhash, category, points); teamhash, category, points);
@ -457,6 +457,18 @@ award_points(char const *teamhash,
} }
close(fd); close(fd);
/* Rename into points.new */
{
char ofn[PATH_MAX];
strncpy(ofn, filename, sizeof(ofn));
filename = state_path("points.new/%d.%d.%s.%s.%ld",
now, getpid(),
teamhash, category, points);
rename(ofn, filename);
}
return 0; return 0;
} }

View File

@ -11,6 +11,7 @@ mkdir $CTF_BASE
# Some skeletal structure # Some skeletal structure
mkdir -p $CTF_BASE/points.new mkdir -p $CTF_BASE/points.new
mkdir -p $CTF_BASE/points.tmp
# Set up some packages # Set up some packages
for cat in cat1 cat2 cat3; do for cat in cat1 cat2 cat3; do

View File

@ -13,7 +13,7 @@
<a href="scoreboard.html">Scoreboard</a> <a href="scoreboard.html">Scoreboard</a>
</li> </li>
<li> <li>
<a href="puzzles.cgi">Puzzles</a> <a href="puzzles.html">Puzzles</a>
</li> </li>
<li> <li>
<a href="teams.html">Teams</a> <a href="teams.html">Teams</a>