Merge branch 'master' of fozzie:projects/ctf

This commit is contained in:
Neale Pickett 2010-10-26 22:35:45 -06:00
commit 94dba25367
22 changed files with 444 additions and 64 deletions

View File

@ -1,2 +1,2 @@
* claim.cgi not exiting (maybe fixed?)
* get LAUR for contest

View File

@ -1,5 +1,5 @@
Things That Need Fixin'
=======================
* puzzles.cgi really needs to cross out points your team has claimed.
* Make an OpenWRT router image for a FitPC
* Do something about all the symbolic links in the build tree
* Make arc4 global somehow

View File

@ -49,3 +49,7 @@ echo "$1" > $base/teams/names/$hash
echo "$color" > $base/teams/colors/$hash
echo "Registered with hash: $hash"
# Create encrypted listing of teams
ls $base/teams/names | KEY="Too much cheese." /opt/mcp/bin/arc4 > $www/teams.txt.$$
mv $www/teams.txt.$$ $www/teams.txt

View File

@ -30,18 +30,18 @@ function escape(s) {
return s
}
function print_bar(cat, team, n, d) {
function print_bar(cat, teamid, teamname, n, d) {
printf("<div class=\"t%s score\"" \
" style=\"height: %.2f%%;\"" \
" onmouseover=\"highlight('%s')\"" \
" onmouseout=\"restore('%s')\">\n" \
"<!-- %s --> %s: %s\n" \
"</div>",
team,
teamid,
100 * n / d,
team,
team,
cat, escape(names_by_team[team]), n)
teamid,
teamid,
cat, escape(name), n)
}
function output( t, c) {
@ -203,7 +203,7 @@ BEGIN {
for (team in teams) {
if (scores[i] == scores_by_team_time[team, lasttime]) {
name = names_by_team[team]
print_bar("total", teams[team], scores[i], ncats)
print_bar("total", teams[team], name, scores[i], ncats)
}
}
}
@ -232,7 +232,7 @@ BEGIN {
points = points_by_cat_team[cat, team]
if (l[j] == points) {
name = names_by_team[team]
print_bar(cat, teams[team], points, points_by_cat[cat])
print_bar(cat, teams[team], name, points, points_by_cat[cat])
}
}
}
@ -242,7 +242,7 @@ BEGIN {
print " </tr>"
print " </table>"
print " <canvas id=\"chart\" width=\"800\" height=\"400\"></canvas>"
print " <canvas id=\"chart\" width=\"800\" height=\"300\"></canvas>"
print " <p><a href=\"scoring.html\">About scoring</a></p>"
print " </body>"
print "</html>"

View File

@ -8,6 +8,7 @@ mcp-install: mcp-build
cp packages/mcp/src/pointscli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/tokencli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/puzzles.cgi $(MCP_PKGDIR)/bin/
cp packages/mcp/src/arc4 $(MCP_PKGDIR)/bin/
$(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service)

View File

@ -4,7 +4,7 @@ exec 2>&1
DB=/var/lib/ctf/tokens.db
if [ ! -f $DB ]; do
if [ ! -f $DB ]; then
# Append any package-provided tokens
cat /opt/*/tokens >$DB 2>/dev/null
chown ctf $DB

View File

@ -1,7 +1,7 @@
CFLAGS = -Wall -Werror
TARGETS = in.tokend tokencli claim.cgi
TARGETS += puzzler.cgi puzzles.cgi
TARGETS += pointscli mktoken
TARGETS += pointscli mktoken arc4
all: build
@ -11,6 +11,7 @@ in.tokend: in.tokend.o arc4.o common.o
tokencli: tokencli.o arc4.o
pointscli: pointscli.o common.o
mktoken: mktoken.o common.o
arc4: arc4-main.o arc4.o
puzzles.cgi: puzzles.cgi.o common.o
claim.cgi: claim.cgi.o common.o

View File

@ -0,0 +1 @@
../../tokens/src/arc4-main.c

View File

@ -0,0 +1 @@
U'0絤騺q<1B>p

View File

@ -37,12 +37,11 @@ a img {
a {
text-decoration: underline;
color: #84b;
font-weight: bold;
}
a:hover {
color: #2a4;
background: #333;
font-weight: bold;
}
@ -69,7 +68,11 @@ th {
}
td {
vertical-align: top;
text-align: right;
text-align: left;
}
dt {
font-weight: bold;
}
p {
@ -83,42 +86,28 @@ hr {
/*** left side bar ***/
/*** navigation bar ***/
#navigation {
position: absolute;
background: HBG;
opacity: 0.9;
top: 80px;
left: 0px;
padding: 0;
nav h2 {
display: none;
}
#navigation h3 {
font-size: 100%;
border-bottom: 2px solid #333;
}
#navigation ul {
nav ul {
list-style: none;
padding: 0;
margin: 0;
text-align: center;
}
#navigation li a {
display: block;
height: 25px;
width: 90px;
padding: 5px;
margin: 5px;
border-right: 4px solid #ddc;
nav li {
display: inline;
}
nav li a {
text-transform: lowercase;
font-size: 0.9em;
}
#navigation li a:hover {
background: #333;
border-right-color: #b71;
nav li + li:before {
content: " | ";
}
/**** special cases ****/
@ -134,12 +123,12 @@ hr {
text-align: center;
}
.scoreboard {
#scoreboard {
background: #112;
}
.scoreboard td {
height: 400px;
#scoreboard td {
height: 300px;
}
#battlefield {
@ -149,19 +138,3 @@ hr {
.solved {
text-decoration: line-through;
}
table.pollster {
margin-left: 5em;
}
table.pollster td {
padding: 2px 1em 2px 5px;
}
table.pollster thead {
font-weight: bold;
}
table.scoreboard {
height: 400px;
}

19
packages/mktokendkey Executable file
View File

@ -0,0 +1,19 @@
#! /bin/sh
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 CATEGORY"
echo
echo "Creates tokend key for CATEGORY."
exit 1
fi
puz=$1; shift
cat=${1:-$puz}
d=$(dirname $0)
td=$d/mcp/tokend.keys/$cat
echo "Writing new server key to $td"
dd bs=1 count=16 if=/dev/urandom of=$td
hd $td

View File

@ -0,0 +1,4 @@
#! /bin/sh
BASE_PATH=/var/lib/ctf/tanks/players/; export BASE_PATH
exec /opt/tanks/bin/designer.cgi

View File

@ -0,0 +1,178 @@
<!DOCTYPE html>
<html>
<head>
<title>Tank Designer</title>
<link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">
#preview {
float: right;
}
#sensors input {
width: 5em;
}
#program textarea {
width: 100%;
min-height: 20em;
}
td {
text-align: left;
}
</style>
<script type="application/javascript" src="tanks.js"></script>
<script type="application/javascript" src="designer.js"></script>
<script type="application/javascript">
window.onload = design;
</script>
</head>
<body>
<h1>Tank Designer</h1>
<div id="preview"><canvas id="design"></canvas><p id="debug"></p></div>
<form action="designer.cgi" method="post">
<fieldset id="metadata">
<legend>Information</legend>
<table>
<tr>
<td>Team hash:</td>
<td><input name="token"></td>
</tr>
<tr>
<td>Tank name:</td>
<td><input name="name"></td>
</tr>
<tr>
<td>Author:</td>
<td>
<input name="author">
(eg. Joe Cool &lt;joe@cool.cc&gt;)
</td>
</tr>
<tr>
<td>Color:</td>
<td>
<input name="color" type="color" value="#c0c0c0" onchange="update();">
(eg. #c7e148)
</td>
</tr>
</table>
</fieldset>
<fieldset id="sensors">
<legend>Sensors</legend>
<table>
<thead>
<tr>
<td>#</td>
<td>Range</td>
<td>Angle</td>
<td>Width</td>
<td>Turret?</td>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td><input name="s0r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s0a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s0w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s0t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>1</td>
<td><input name="s1r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s1a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s1w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s1t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>2</td>
<td><input name="s2r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s2a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s2w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s2t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>3</td>
<td><input name="s3r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s3a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s3w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s3t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>4</td>
<td><input name="s4r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s4a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s4w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s4t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>5</td>
<td><input name="s5r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s5a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s5w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s5t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>6</td>
<td><input name="s6r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s6a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s6w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s6t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>7</td>
<td><input name="s7r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s7a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s7w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s7t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>8</td>
<td><input name="s8r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s8a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s8w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s8t" type="checkbox" onchange="update();"></td>
</tr>
<tr>
<td>9</td>
<td><input name="s9r" type="number" min="0" max="100" onchange="update();"></td>
<td><input name="s9a" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s9w" type="number" min="-360" max="360" onchange="update();"></td>
<td><input name="s9t" type="checkbox" onchange="update();"></td>
</tr>
</tbody>
</table>
</fieldset>
<fieldset id="program">
<legend>Program</legend>
<textarea name="program"></textarea>
</fieldset>
<input type="submit" value="Submit">
</form>
<nav>
<h2>Resources</h2>
<ul>
<li><a href="summary.html">Summary</a></li>
<li><a href="intro.html">Introduction</a></li>
<li><a href="forf.html">Forf manual</a></li>
<li><a href="procs.html">Tanks procedures</a></li>
<li><a href="designer.html">Tanks designer</a></li>
</ul>
</nav>
</body>
</html>

View File

@ -0,0 +1 @@
summary.html

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Tanks</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<h1>Tanks</h1>
<p>
Nothing here yet. You could <a href="intro.html">read the
intro</a> while you're waiting,
or <a href="designer.html">submit a tank</a> to get things
started.
</p>
<p>
Hopefully it goes without saying that you'll need to reload
this page to see if anything's happened.
</p>
</body>
</html>

View File

@ -0,0 +1 @@
U'0絤騺q<1B>p

View File

@ -0,0 +1,3 @@
#! /bin/sh
exec logger -t tanks

View File

@ -0,0 +1,10 @@
#! /bin/sh
exec 2>&1
mkdir -p /var/www/tanks
ln -s /opt/tanks/html/* /var/www/tanks/
ln -sf summary.html /var/www/tanks/index.html
install -o ctf -d /var/lib/ctf/tanks/players
exec ./tanksd

View File

@ -0,0 +1,125 @@
#! /bin/sh
d=/var/lib/ctf/tanks
p=$d/players
w=/var/www/tanks
summary () {
cat <<EOF
<!DOCTYPE html>
<html>
<head>
<title>Tanks</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<h1>Tanks</h1>
<p>New here? Start with the <a href="intro.html">introduction</a>.</p>
<p>New round every minute.</p>
<h2>Round results</h2>
<ul>
EOF
printed=0
find $w -name "round-*.html" | sort -r | while read fn; do
b=$(basename $fn)
if [ $printed -lt 20 ]; then
echo "<li><a href=\"$b\">$b</a></li>"
else
rm -f $fn
fi
printed=$(expr $printed + 1)
done
cat <<EOF
</ul>
EOF
cat /opt/tanks/html/nav.html.inc
cat <<EOF
</body>
</html>
EOF
}
while true; do
# Make sure all teams exist
# XXX: pull this out into another daemon
wget -q -O - http://10.0.0.2/teams.txt | \
KEY="Too much cheese." /opt/tokens/bin/arc4 | \
while read hash; do
install -o ctf -d $p/$hash
done
# Has anyone submitted a program yet?
if [ $(find $p -name program | wc -l) = 0 ]; then
sleep 15
continue
fi
# Round number?
if [ -f $d/next-round ]; then
next=$(cat $d/next-round)
else
next=0
fi
expr $next + 1 > $d/next-round
fn=$(printf "%s/round-%04d.html" $w $next)
rfn=$(printf "/tmp/tanks-results-%04d.txt" $next)
tfn=$(printf "/tmp/tanks-token-%04d.txt" $next)
# Run a game
echo "Running round $next"
cat <<EOF >$fn
<!DOCTYPE html>
<html>
<head>
<title>Tanks Round $next</title>
<script type="application/javascript" src="tanks.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
<script type="application/javascript">
function go() {
start("battlefield",
// Start JSON data
EOF
/opt/tanks/bin/forftanks $p/* >>$fn 3>$rfn
cat <<EOF >>$fn
// end JSON data
);
}
window.onload = go;
</script>
</head>
<body>
<h1>Tanks Round $next</h1>
<div id="game_box"><canvas id="battlefield"></canvas></div>
<p><span id="fps">0</span> fps</p>
EOF
/opt/tanks/bin/rank.awk $rfn >>$fn
cat /opt/tanks/html/nav.html.inc >>$fn
cat <<EOF >>$fn
</body>
</html>
EOF
# Get a token and add it to the redemption log
nc 10.0.0.2 1 -e /opt/tokens/bin/tokencli tanks ./category.key 3> $tfn
k=$(cat $tfn)
/opt/tanks/bin/winners.awk $rfn | while read winner; do
hash=$(basename $winner)
echo "Round $next winner: $hash"
# Squirrel it away just in case
cat $tfn >> $winner/tokens
# XXX: pull this out into another daemon
# XXX: this puts the token in /proc/self/cmdline
wget -q -s "http://10.0.0.2/claim.cgi?t=$hash&k=$k"
done
summary > $w/summary.html.$$
mv -f $w/summary.html.$$ $w/summary.html
rm -f $tfn $rfn
sleep 60
done

View File

@ -15,7 +15,30 @@ $(TANKS_BUILDDIR)/ctanks: $(TANKS_TAR)
tanks-build: tanks-source
$(MAKE) -C $(TANKS_BUILDDIR)/ctanks
# "html" instead of "www" to prevent automatic links
tanks-install: tanks-build
mkdir -p $(TANKS_PKGDIR)/bin
cp $(TANKS_BUILDDIR)/ctanks/forftanks $(TANKS_PKGDIR)/bin
cp $(TANKS_BUILDDIR)/ctanks/designer.cgi $(TANKS_PKGDIR)/bin
cp $(TANKS_BUILDDIR)/ctanks/rank.awk $(TANKS_PKGDIR)/bin
cp $(TANKS_BUILDDIR)/ctanks/winners.awk $(TANKS_PKGDIR)/bin
$(call COPYTREE, packages/tanks/html, $(TANKS_PKGDIR)/html)
cp packages/mcp/www/ctf.css $(TANKS_PKGDIR)/html/style.css
cp packages/mcp/www/grunge.png $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/nav.html.inc $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/tanks.js $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/forf.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/intro.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/figures.js $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/procs.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/designer.js $(TANKS_PKGDIR)/html
$(call COPYTREE, packages/tanks/service, $(TANKS_PKGDIR)/service)
$(call COPYTREE, $(TANKS_BUILDDIR)/ctanks/examples, $(TANKS_PKGDIR)/examples)
tanks-clean:
rm -f $(TANKS_BUILDDIR)
rm -rf $(TANKS_BUILDDIR)
PACKAGES += tanks

View File

@ -1,4 +1,6 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sysexits.h>
#include "arc4.h"
@ -12,6 +14,7 @@ main(int argc, char *argv[])
{
uint8_t key[256];
size_t keylen = 0;
char *ekey = getenv("KEY");
FILE *f;
if (argc == 2) {
@ -25,13 +28,19 @@ main(int argc, char *argv[])
if (f) {
keylen = fread(key, 1, sizeof(key), f);
fclose(f);
} else if (ekey) {
keylen = strlen(ekey);
if (keylen > sizeof(key)) {
keylen = sizeof(key);
}
memcpy(key, ekey, keylen);
}
if (0 == keylen) {
fprintf(stderr, "Usage: %s [KEYFILE] <PLAINTEXT\n", argv[0]);
fprintf(stderr, "\n");
fprintf(stderr, "You can also pass in the key on fd 3; omit\n");
fprintf(stderr, "KEYFILE in this case.\n");
fprintf(stderr, "You can also pass in the key on fd 3 or in\n");
fprintf(stderr, "$KEY; omit KEYFILE in this case.\n");
return EX_IOERR;
}
arc4_init(&ctx, key, (size_t)keylen);

View File

@ -44,8 +44,12 @@ main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "Usage: %s SERVICE SERVICEKEY 3>TOKENFILE\n", argv[0]);
fprintf(stderr, "\n");
fprintf(stderr, "SERVICEKEY is a filenames.\n");
fprintf(stderr, "SERVICEKEY is a filename.\n");
fprintf(stderr, "Server chatter happens over stdin and stdout.\n");
fprintf(stderr, "Tokens are written to file descriptor 3.\n");
fprintf(stderr, "\n");
fprintf(stderr, "To run with netcat:\n");
fprintf(stderr, " nc server 1 -e tokencli cat cat.key 3> tokenfile\n");
return EX_USAGE;
}