And with that, I think it is working again

This commit is contained in:
Neale Pickett 2015-04-12 11:11:15 -06:00
parent a701683c73
commit 5139c548b1
7 changed files with 126 additions and 4787 deletions

View File

@ -8,20 +8,20 @@ if ! [ -d $indir ]; then
fi
die () {
echo "$@" 1>&2
exit 1
echo "$@" 1>&2
exit 1
}
escape () {
sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
}
template () {
cat="$1"; shift
points="$1"; shift
author=$(echo $1 | escape); shift
cat="$1"; shift
points="$1"; shift
author=$(echo $1 | escape); shift
cat <<EOF
cat <<EOF
<!DOCTYPE html>
<html>
<head>
@ -33,24 +33,24 @@ template () {
<h1>$cat for $points points</h1>
EOF
echo "<section id=\"readme\">"
cat
echo "</section>"
echo "<section id=\"readme\">"
cat
echo "</section>"
if [ $# -gt 0 ]; then
echo "<section id=\"files\">"
echo "<h2>Associated files:</h2>"
echo "<ul>"
while [ $# -gt 0 ]; do
fn="$1"; shift
efn="$(echo $fn | escape)"
echo "<li><a href=\"$fn\">$efn</a></li>"
done
echo "</ul>"
echo "</section>"
fi
if [ $# -gt 0 ]; then
echo "<section id=\"files\">"
echo "<h2>Associated files:</h2>"
echo "<ul>"
while [ $# -gt 0 ]; do
fn="$1"; shift
efn="$(echo $fn | escape)"
echo "<li><a href=\"$fn\">$efn</a></li>"
done
echo "</ul>"
echo "</section>"
fi
cat <<EOF
cat <<EOF
<section id="form">
<form id="puzzler" action="/puzzler.cgi" method="post" accept-charset="utf-8">
<input type="hidden" name="c" value="$cat">
@ -67,13 +67,14 @@ EOF
}
cat=$(basename $indir)
outdir=$(dirname $0)/puzzles/$cat
outdir=$(dirname $0)/../packages/$cat
uanswers=$outdir/answers.unsorted
usummary=$outdir/summary.unsorted
umap=$outdir/map.unsorted
mkdir -p $outdir
if ! [ -r $outdir/mkpuzzles.salt ]; then
dd if=/dev/urandom bs=1 count=16 2>/dev/null | md5sum | cut -d\ -f1 > $outdir/salt
dd if=/dev/urandom bs=1 count=16 2>/dev/null | md5sum | cut -c1-16 > $outdir/salt
fi
read salt < $outdir/salt
@ -81,87 +82,97 @@ read salt < $outdir/salt
rm -f $usummary
for dn in $indir/[0-9]*; do
[ -d $dn ] || continue
points=$(basename $dn)
[ -d $dn ] || continue
points=$(basename $dn)
echo $dn
echo $dn
odn=$(printf "%s/%s/%s" "$salt" "$cat" "$points" | md5sum | sed 's/\(....\)/\1./g' | cut -b 1-19)
tgt=$outdir/puzzles/$odn
mkdir -p $tgt
#touch $tgt/index.html
odn=$(printf "%s/%s/%s" "$salt" "$cat" "$points" | md5sum | sed 's/\(....\)/\1./g' | cut -b 1-19)
tgt=$outdir/puzzles/$odn
mkdir -p $tgt
#touch $tgt/index.html
if [ -f $dn/Makefile ]; then
# If there's a Makefile, run make
make DESTDIR=$(pwd)/$tgt -C $dn || exit 1
files=$(ls -1 $tgt | grep -v index.html || true)
elif [ -f $dn/00manifest.txt ]; then
# If there's a manifest, use that
files=
while read fn; do
ln -f $dn/$fn $tgt/
case $fn in
,*)
;;
*)
files="$files $fn"
;;
esac
done < $dn/00manifest.txt
else
# Otherwise, look for special files and copy the rest
files=
for fn in $dn/*; do
case $(basename $fn) in
00*)
# Handle meta-information later
;;
*~|"#"*)
# Don't copy temporary or backup files
;;
,*)
# Copy but don't list
ln -f $fn $tgt/
;;
*)
#ext=$(echo $fn | sed -ne 's/.*\././p')
cfn=$(md5sum $fn | cut -b -8)$ext
ln -f $fn $tgt/$cfn
files="$files $cfn"
;;
esac
done
fi
if [ -f $dn/Makefile ]; then
# If there's a Makefile, run make
make DESTDIR=$(pwd)/$tgt -C $dn || exit 1
files=$(ls -1 $tgt | grep -v index.html || true)
elif [ -f $dn/00manifest.txt ]; then
# If there's a manifest, use that
files=
while read fn; do
ln -f $dn/$fn $tgt/
case $fn in
,*)
;;
*)
files="$files $fn"
;;
esac
done < $dn/00manifest.txt
else
# Otherwise, look for special files and copy the rest
files=
for fn in $dn/*; do
case $(basename $fn) in
00*)
# Handle meta-information later
;;
*~|"#"*)
# Don't copy temporary or backup files
;;
,*)
# Copy but don't list
ln -f $fn $tgt/
;;
*)
#ext=$(echo $fn | sed -ne 's/.*\././p')
cfn=$(md5sum $fn | cut -b -8)$ext
ln -f $fn $tgt/$cfn
files="$files $cfn"
;;
esac
done
fi
# Append answers
if [ -f $dn/00answer.txt ]; then
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00answer.txt >> $uanswers
else
die "$dn/00answer.txt: No such file or directory"
fi
# Append answers
if [ -f $dn/00answer.txt ]; then
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00answer.txt >> $uanswers
else
die "$dn/00answer.txt: No such file or directory"
fi
# Append summary
if [ -f $dn/00summary.txt ]; then
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00summary.txt >> $usummary
fi
# Append summary
if [ -f $dn/00summary.txt ]; then
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00summary.txt >> $usummary
fi
# Read author
if [ -f $dn/00author.txt ]; then
author=$(cat $dn/00author.txt)
else
die "$dn/00author.txt does not exist."
fi
# Read author
if [ -f $dn/00author.txt ]; then
author=$(cat $dn/00author.txt)
else
die "$dn/00author.txt does not exist."
fi
# Generate index now that we have a list of files
if [ -f $dn/00index.mdwn ]; then
markdown --html4tags $dn/00index.mdwn
fi | template $cat $points "$author" $files > $tgt/index.html
# Generate index now that we have a list of files
if [ -f $dn/00index.mdwn ]; then
markdown --html4tags $dn/00index.mdwn
fi | template $cat $points "$author" $files > $tgt/index.html
# Write to map
printf "%d %s\n" $points $odn >> $umap
# Write to map
printf "%d %s\n" $points $odn >> $umap
done
echo "Generating URL map"
sort -n $umap > $outdir/map.txt
echo "Generating answers list"
sort -n $uanswers > $outdir/answers.txt
echo "Generating summary"
[ -f $usummary ] && sort -ns $usummary > $outdir/summary.txt
echo "Linking into web space"
ln -s ../packages/$cat/puzzles www/$cat
echo "Cleaning up"
rm -f $uanswers $usummary $umap

View File

@ -1,6 +1,6 @@
#! /bin/sh
cd $(dirname $0)
cd $(dirname $0)/..
# Do nothing if `disabled` is present
if [ -f disabled ]; then
@ -10,7 +10,7 @@ fi
# Reset to initial state if `reset` is present
if [ -f reset ]; then
rm -f state/teams/* state/points.new/* state/points.tmp/*
> state/points.log
: > state/points.log
fi
# Collect new points
@ -20,11 +20,11 @@ find state/points.new -type f | while read fn; do
done
# Generate new puzzles.html
if $KOTH_BASE/puzzles.cgi > www/puzzles.new; then
if www/puzzles.cgi > www/puzzles.new; then
mv www/puzzles.new www/puzzles.html
fi
# Generate new points.json
if $KOTH_BASE/points > www/points.new; then
if bin/points state/points.log > www/points.new; then
mv www/points.new www/points.json
fi

View File

@ -108,7 +108,7 @@ hr {
/**** Section ****/
section, nav {
section, nav, address {
color: #35170c;
max-width: 35em;
border-radius: 0.6em;
@ -116,7 +116,7 @@ section, nav {
padding: 0.5em;
}
section {
section, address {
background: #e1caa5;
}

View File

@ -54,6 +54,10 @@ function scoreboard(element) {
for (var i in teams) {
winners.push(teams[i]);
}
if (winners.length == 0) {
// No teams!
return;
}
winners.sort(teamCompare);
winners.reverse();

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,7 @@ web () {
cgi () {
target=$DESTDIR/www/$(basename $1 .c)
if older $target $@; then
if older $target src/common.c $@; then
mkdir -p $(dirname $target)
src=$1; shift
echo "CGI $src"
@ -64,6 +64,7 @@ setup() {
mkdir -p $dir
setfacl -m ${www}:rwx $dir
done
mkdir -p $DESTDIR/packages
>> $DESTDIR/state/points.log
if ! [ -f $DESTDIR/assigned.txt ]; then
hd </dev/urandom | awk '{print $3 $4 $5 $6;}' | head -n 100 > $DESTDIR/assigned.txt
@ -97,6 +98,8 @@ git ls-files | while read fn; do
;;
src/common.c)
;;
src/*.h)
;;
src/pointscli.c)
cc $fn src/common.c
;;
@ -106,8 +109,6 @@ git ls-files | while read fn; do
src/*.c)
cc $fn
;;
src/*.h)
;;
*)
echo "??? $fn"
;;

View File

@ -203,9 +203,9 @@ cgi_foot()
{
printf("\n</section>\n");
printf("<nav><ul>\n");
printf("<li><a href="register.html">Register</a></li>\n");
printf("<li><a href="puzzles.html">Puzzles</a></li>\n");
printf("<li><a href="scoreboard.html">Scoreboard</a></li>\n");
printf("<li><a href=\"register.html\">Register</a></li>\n");
printf("<li><a href=\"puzzles.html\">Puzzles</a></li>\n");
printf("<li><a href=\"scoreboard.html\">Scoreboard</a></li>\n");
printf("</ul></nav>\n");
printf("</body></html>\n");
@ -393,12 +393,12 @@ ctf_chdir()
}
/*
* Keep going up one directory until there's a packages directory
* Keep going up one directory until there's an assigned.txt file
*/
for (i = 0; i < 5; i += 1) {
struct stat st;
if ((0 == stat("packages", &st)) && S_ISDIR(st.st_mode)) {
if ((0 == stat("assigned.txt", &st)) && S_ISREG(st.st_mode)) {
return;
}
chdir("..");
@ -473,7 +473,7 @@ team_exists(char const *teamhash)
/*
* stat seems to be the preferred way to check for existence.
*/
ret = stat(state_path("teams/names/%s", teamhash), &buf);
ret = stat(state_path("teams/%s", teamhash), &buf);
if (-1 == ret) {
return 0;
}