mirror of https://github.com/dirtbags/moth.git
Lotsa bugfixes
This commit is contained in:
parent
ea1653cf03
commit
6256b7da77
|
@ -4,15 +4,34 @@ CTF Packages
|
|||
Packages are squashfs files.
|
||||
|
||||
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:
|
||||
|
||||
* /www/ - Will appear as http://host/pkgname/, CGI can be run
|
||||
* /bin/ - Will be added to $PATH
|
||||
* /puzzles/ - Will appear as a puzzle category (see "Puzzles" below)
|
||||
* /setup - Run after package is mounted
|
||||
* /bin/ - Added to $PATH for login shells
|
||||
* /puzzles/ - Appears as a puzzle category (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
|
||||
-------
|
||||
|
||||
|
|
|
@ -12,12 +12,14 @@ $(PACKAGE): build
|
|||
cp setup $(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 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
|
||||
|
||||
|
|
|
@ -5,10 +5,15 @@ if [ $# -ne 1 ]; then
|
|||
exit 64
|
||||
fi
|
||||
|
||||
escape () {
|
||||
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
||||
}
|
||||
|
||||
# Don't overwrite files
|
||||
set -C
|
||||
|
||||
base=${CTF_BASE:-/var/lib/ctf}
|
||||
www=${CTF_BASE:-/var/www}
|
||||
|
||||
# Assign a color. I spent two days selecting this color pallette for
|
||||
# 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 "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
|
||||
|
|
|
@ -10,17 +10,6 @@ STATE=${CTF_BASE:-/var/lib/ctf}
|
|||
NEWPOINTS=$STATE/points.new
|
||||
POINTS=$STATE/points.log
|
||||
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
|
||||
$BIN/scoreboard < $POINTS > $SCOREBOARD
|
||||
|
@ -42,16 +31,6 @@ while true; do
|
|||
$BIN/scoreboard < $POINTS > $SCOREBOARD.new && mv $SCOREBOARD.new $SCOREBOARD
|
||||
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)
|
||||
if [ $now -lt $next ]; then
|
||||
sleep $(expr $next - $now)
|
||||
|
|
|
@ -66,7 +66,7 @@ function output( t, c) {
|
|||
BEGIN {
|
||||
base = ENVIRON["CTF_BASE"]
|
||||
if (! base) {
|
||||
base = "/srv/ctf"
|
||||
base = "/var/lib/ctf"
|
||||
}
|
||||
|
||||
# Only display two decimal places
|
||||
|
@ -101,13 +101,19 @@ BEGIN {
|
|||
|
||||
# Get team colors and names
|
||||
for (team in teams) {
|
||||
fn = base "/teams/colors/" team
|
||||
getline colors_by_team[team] < fn
|
||||
close(fn)
|
||||
# Busybox awk segfaults if you try to close a file that didn't
|
||||
# exist. We work around it by calling cat.
|
||||
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
|
||||
getline names_by_team[team] < fn
|
||||
close(fn)
|
||||
cmd = sprintf("cat %s/teams/names/%s", base, team)
|
||||
cmd | getline name
|
||||
if (! name) name = team
|
||||
names_by_team[team] = name
|
||||
close(cmd)
|
||||
}
|
||||
|
||||
# Sort categories
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /bin/sh
|
||||
|
||||
cd /var/lib/ctf/teams/names
|
||||
cd ${CTF_BASE:-/var/lib/ctf}/teams/names
|
||||
|
||||
escape () {
|
||||
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
||||
|
@ -21,7 +21,7 @@ EOF
|
|||
|
||||
echo "<table>"
|
||||
echo "<tr><th>Team Name</th><th>Token</th></tr>"
|
||||
for i in ??????; do
|
||||
for i in *; do
|
||||
echo "<tr><td>"
|
||||
escape < $i
|
||||
echo "</td><td><samp>$i</samp></td></tr>"
|
||||
|
|
18
mcp/setup
18
mcp/setup
|
@ -1,8 +1,20 @@
|
|||
#! /bin/sh
|
||||
|
||||
## Set up this package
|
||||
## Set up the MCP (Master Control Program) server
|
||||
|
||||
hostname mcp
|
||||
|
||||
cp -r service/* /var/service
|
||||
cp -r www /var
|
||||
cp -r service/* /var/service/
|
||||
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
|
||||
|
||||
|
|
|
@ -442,7 +442,7 @@ award_points(char const *teamhash,
|
|||
token log.
|
||||
*/
|
||||
|
||||
filename = state_path("points.new/%d.%d.%s.%s.%ld",
|
||||
filename = state_path("points.tmp/%d.%d.%s.%s.%ld",
|
||||
now, getpid(),
|
||||
teamhash, category, points);
|
||||
|
||||
|
@ -457,6 +457,18 @@ award_points(char const *teamhash,
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ mkdir $CTF_BASE
|
|||
|
||||
# Some skeletal structure
|
||||
mkdir -p $CTF_BASE/points.new
|
||||
mkdir -p $CTF_BASE/points.tmp
|
||||
|
||||
# Set up some packages
|
||||
for cat in cat1 cat2 cat3; do
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<a href="scoreboard.html">Scoreboard</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="puzzles.cgi">Puzzles</a>
|
||||
<a href="puzzles.html">Puzzles</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="teams.html">Teams</a>
|
||||
|
|
Loading…
Reference in New Issue