mirror of https://github.com/dirtbags/moth.git
And with that, I think it is working again
This commit is contained in:
parent
481b53cffe
commit
dda7bd82a8
|
@ -8,20 +8,20 @@ if ! [ -d $indir ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo "$@" 1>&2
|
echo "$@" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
escape () {
|
escape () {
|
||||||
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
template () {
|
template () {
|
||||||
cat="$1"; shift
|
cat="$1"; shift
|
||||||
points="$1"; shift
|
points="$1"; shift
|
||||||
author=$(echo $1 | escape); shift
|
author=$(echo $1 | escape); shift
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -33,24 +33,24 @@ template () {
|
||||||
<h1>$cat for $points points</h1>
|
<h1>$cat for $points points</h1>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "<section id=\"readme\">"
|
echo "<section id=\"readme\">"
|
||||||
cat
|
cat
|
||||||
echo "</section>"
|
echo "</section>"
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
echo "<section id=\"files\">"
|
echo "<section id=\"files\">"
|
||||||
echo "<h2>Associated files:</h2>"
|
echo "<h2>Associated files:</h2>"
|
||||||
echo "<ul>"
|
echo "<ul>"
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
fn="$1"; shift
|
fn="$1"; shift
|
||||||
efn="$(echo $fn | escape)"
|
efn="$(echo $fn | escape)"
|
||||||
echo "<li><a href=\"$fn\">$efn</a></li>"
|
echo "<li><a href=\"$fn\">$efn</a></li>"
|
||||||
done
|
done
|
||||||
echo "</ul>"
|
echo "</ul>"
|
||||||
echo "</section>"
|
echo "</section>"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
<section id="form">
|
<section id="form">
|
||||||
<form id="puzzler" action="/puzzler.cgi" method="post" accept-charset="utf-8">
|
<form id="puzzler" action="/puzzler.cgi" method="post" accept-charset="utf-8">
|
||||||
<input type="hidden" name="c" value="$cat">
|
<input type="hidden" name="c" value="$cat">
|
||||||
|
@ -67,13 +67,14 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
cat=$(basename $indir)
|
cat=$(basename $indir)
|
||||||
outdir=$(dirname $0)/puzzles/$cat
|
outdir=$(dirname $0)/../packages/$cat
|
||||||
uanswers=$outdir/answers.unsorted
|
uanswers=$outdir/answers.unsorted
|
||||||
usummary=$outdir/summary.unsorted
|
usummary=$outdir/summary.unsorted
|
||||||
umap=$outdir/map.unsorted
|
umap=$outdir/map.unsorted
|
||||||
|
|
||||||
|
mkdir -p $outdir
|
||||||
if ! [ -r $outdir/mkpuzzles.salt ]; then
|
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
|
fi
|
||||||
read salt < $outdir/salt
|
read salt < $outdir/salt
|
||||||
|
|
||||||
|
@ -81,87 +82,97 @@ read salt < $outdir/salt
|
||||||
rm -f $usummary
|
rm -f $usummary
|
||||||
|
|
||||||
for dn in $indir/[0-9]*; do
|
for dn in $indir/[0-9]*; do
|
||||||
[ -d $dn ] || continue
|
[ -d $dn ] || continue
|
||||||
points=$(basename $dn)
|
points=$(basename $dn)
|
||||||
|
|
||||||
echo $dn
|
echo $dn
|
||||||
|
|
||||||
odn=$(printf "%s/%s/%s" "$salt" "$cat" "$points" | md5sum | sed 's/\(....\)/\1./g' | cut -b 1-19)
|
odn=$(printf "%s/%s/%s" "$salt" "$cat" "$points" | md5sum | sed 's/\(....\)/\1./g' | cut -b 1-19)
|
||||||
tgt=$outdir/puzzles/$odn
|
tgt=$outdir/puzzles/$odn
|
||||||
mkdir -p $tgt
|
mkdir -p $tgt
|
||||||
#touch $tgt/index.html
|
#touch $tgt/index.html
|
||||||
|
|
||||||
if [ -f $dn/Makefile ]; then
|
if [ -f $dn/Makefile ]; then
|
||||||
# If there's a Makefile, run make
|
# If there's a Makefile, run make
|
||||||
make DESTDIR=$(pwd)/$tgt -C $dn || exit 1
|
make DESTDIR=$(pwd)/$tgt -C $dn || exit 1
|
||||||
files=$(ls -1 $tgt | grep -v index.html || true)
|
files=$(ls -1 $tgt | grep -v index.html || true)
|
||||||
elif [ -f $dn/00manifest.txt ]; then
|
elif [ -f $dn/00manifest.txt ]; then
|
||||||
# If there's a manifest, use that
|
# If there's a manifest, use that
|
||||||
files=
|
files=
|
||||||
while read fn; do
|
while read fn; do
|
||||||
ln -f $dn/$fn $tgt/
|
ln -f $dn/$fn $tgt/
|
||||||
case $fn in
|
case $fn in
|
||||||
,*)
|
,*)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
files="$files $fn"
|
files="$files $fn"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done < $dn/00manifest.txt
|
done < $dn/00manifest.txt
|
||||||
else
|
else
|
||||||
# Otherwise, look for special files and copy the rest
|
# Otherwise, look for special files and copy the rest
|
||||||
files=
|
files=
|
||||||
for fn in $dn/*; do
|
for fn in $dn/*; do
|
||||||
case $(basename $fn) in
|
case $(basename $fn) in
|
||||||
00*)
|
00*)
|
||||||
# Handle meta-information later
|
# Handle meta-information later
|
||||||
;;
|
;;
|
||||||
*~|"#"*)
|
*~|"#"*)
|
||||||
# Don't copy temporary or backup files
|
# Don't copy temporary or backup files
|
||||||
;;
|
;;
|
||||||
,*)
|
,*)
|
||||||
# Copy but don't list
|
# Copy but don't list
|
||||||
ln -f $fn $tgt/
|
ln -f $fn $tgt/
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
#ext=$(echo $fn | sed -ne 's/.*\././p')
|
#ext=$(echo $fn | sed -ne 's/.*\././p')
|
||||||
cfn=$(md5sum $fn | cut -b -8)$ext
|
cfn=$(md5sum $fn | cut -b -8)$ext
|
||||||
ln -f $fn $tgt/$cfn
|
ln -f $fn $tgt/$cfn
|
||||||
files="$files $cfn"
|
files="$files $cfn"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Append answers
|
# Append answers
|
||||||
if [ -f $dn/00answer.txt ]; then
|
if [ -f $dn/00answer.txt ]; then
|
||||||
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00answer.txt >> $uanswers
|
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00answer.txt >> $uanswers
|
||||||
else
|
else
|
||||||
die "$dn/00answer.txt: No such file or directory"
|
die "$dn/00answer.txt: No such file or directory"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Append summary
|
# Append summary
|
||||||
if [ -f $dn/00summary.txt ]; then
|
if [ -f $dn/00summary.txt ]; then
|
||||||
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00summary.txt >> $usummary
|
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/00summary.txt >> $usummary
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read author
|
# Read author
|
||||||
if [ -f $dn/00author.txt ]; then
|
if [ -f $dn/00author.txt ]; then
|
||||||
author=$(cat $dn/00author.txt)
|
author=$(cat $dn/00author.txt)
|
||||||
else
|
else
|
||||||
die "$dn/00author.txt does not exist."
|
die "$dn/00author.txt does not exist."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate index now that we have a list of files
|
# Generate index now that we have a list of files
|
||||||
if [ -f $dn/00index.mdwn ]; then
|
if [ -f $dn/00index.mdwn ]; then
|
||||||
markdown --html4tags $dn/00index.mdwn
|
markdown --html4tags $dn/00index.mdwn
|
||||||
fi | template $cat $points "$author" $files > $tgt/index.html
|
fi | template $cat $points "$author" $files > $tgt/index.html
|
||||||
|
|
||||||
# Write to map
|
# Write to map
|
||||||
printf "%d %s\n" $points $odn >> $umap
|
printf "%d %s\n" $points $odn >> $umap
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "Generating URL map"
|
||||||
sort -n $umap > $outdir/map.txt
|
sort -n $umap > $outdir/map.txt
|
||||||
|
|
||||||
|
echo "Generating answers list"
|
||||||
sort -n $uanswers > $outdir/answers.txt
|
sort -n $uanswers > $outdir/answers.txt
|
||||||
|
|
||||||
|
echo "Generating summary"
|
||||||
[ -f $usummary ] && sort -ns $usummary > $outdir/summary.txt
|
[ -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
|
rm -f $uanswers $usummary $umap
|
||||||
|
|
8
bin/once
8
bin/once
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
cd $(dirname $0)
|
cd $(dirname $0)/..
|
||||||
|
|
||||||
# Do nothing if `disabled` is present
|
# Do nothing if `disabled` is present
|
||||||
if [ -f disabled ]; then
|
if [ -f disabled ]; then
|
||||||
|
@ -10,7 +10,7 @@ fi
|
||||||
# Reset to initial state if `reset` is present
|
# Reset to initial state if `reset` is present
|
||||||
if [ -f reset ]; then
|
if [ -f reset ]; then
|
||||||
rm -f state/teams/* state/points.new/* state/points.tmp/*
|
rm -f state/teams/* state/points.new/* state/points.tmp/*
|
||||||
> state/points.log
|
: > state/points.log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect new points
|
# Collect new points
|
||||||
|
@ -20,11 +20,11 @@ find state/points.new -type f | while read fn; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Generate new puzzles.html
|
# 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
|
mv www/puzzles.new www/puzzles.html
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate new points.json
|
# 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
|
mv www/points.new www/points.json
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -108,7 +108,7 @@ hr {
|
||||||
|
|
||||||
/**** Section ****/
|
/**** Section ****/
|
||||||
|
|
||||||
section, nav {
|
section, nav, address {
|
||||||
color: #35170c;
|
color: #35170c;
|
||||||
max-width: 35em;
|
max-width: 35em;
|
||||||
border-radius: 0.6em;
|
border-radius: 0.6em;
|
||||||
|
@ -116,7 +116,7 @@ section, nav {
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
section {
|
section, address {
|
||||||
background: #e1caa5;
|
background: #e1caa5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,10 @@ function scoreboard(element) {
|
||||||
for (var i in teams) {
|
for (var i in teams) {
|
||||||
winners.push(teams[i]);
|
winners.push(teams[i]);
|
||||||
}
|
}
|
||||||
|
if (winners.length == 0) {
|
||||||
|
// No teams!
|
||||||
|
return;
|
||||||
|
}
|
||||||
winners.sort(teamCompare);
|
winners.sort(teamCompare);
|
||||||
winners.reverse();
|
winners.reverse();
|
||||||
|
|
||||||
|
|
4677
html/points.json
4677
html/points.json
File diff suppressed because it is too large
Load Diff
7
install
7
install
|
@ -48,7 +48,7 @@ web () {
|
||||||
|
|
||||||
cgi () {
|
cgi () {
|
||||||
target=$DESTDIR/www/$(basename $1 .c)
|
target=$DESTDIR/www/$(basename $1 .c)
|
||||||
if older $target $@; then
|
if older $target src/common.c $@; then
|
||||||
mkdir -p $(dirname $target)
|
mkdir -p $(dirname $target)
|
||||||
src=$1; shift
|
src=$1; shift
|
||||||
echo "CGI $src"
|
echo "CGI $src"
|
||||||
|
@ -64,6 +64,7 @@ setup() {
|
||||||
mkdir -p $dir
|
mkdir -p $dir
|
||||||
setfacl -m ${www}:rwx $dir
|
setfacl -m ${www}:rwx $dir
|
||||||
done
|
done
|
||||||
|
mkdir -p $DESTDIR/packages
|
||||||
>> $DESTDIR/state/points.log
|
>> $DESTDIR/state/points.log
|
||||||
if ! [ -f $DESTDIR/assigned.txt ]; then
|
if ! [ -f $DESTDIR/assigned.txt ]; then
|
||||||
hd </dev/urandom | awk '{print $3 $4 $5 $6;}' | head -n 100 > $DESTDIR/assigned.txt
|
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/common.c)
|
||||||
;;
|
;;
|
||||||
|
src/*.h)
|
||||||
|
;;
|
||||||
src/pointscli.c)
|
src/pointscli.c)
|
||||||
cc $fn src/common.c
|
cc $fn src/common.c
|
||||||
;;
|
;;
|
||||||
|
@ -106,8 +109,6 @@ git ls-files | while read fn; do
|
||||||
src/*.c)
|
src/*.c)
|
||||||
cc $fn
|
cc $fn
|
||||||
;;
|
;;
|
||||||
src/*.h)
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
echo "??? $fn"
|
echo "??? $fn"
|
||||||
;;
|
;;
|
||||||
|
|
12
src/common.c
12
src/common.c
|
@ -203,9 +203,9 @@ cgi_foot()
|
||||||
{
|
{
|
||||||
printf("\n</section>\n");
|
printf("\n</section>\n");
|
||||||
printf("<nav><ul>\n");
|
printf("<nav><ul>\n");
|
||||||
printf("<li><a href="register.html">Register</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=\"puzzles.html\">Puzzles</a></li>\n");
|
||||||
printf("<li><a href="scoreboard.html">Scoreboard</a></li>\n");
|
printf("<li><a href=\"scoreboard.html\">Scoreboard</a></li>\n");
|
||||||
printf("</ul></nav>\n");
|
printf("</ul></nav>\n");
|
||||||
printf("</body></html>\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) {
|
for (i = 0; i < 5; i += 1) {
|
||||||
struct stat st;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
chdir("..");
|
chdir("..");
|
||||||
|
@ -473,7 +473,7 @@ team_exists(char const *teamhash)
|
||||||
/*
|
/*
|
||||||
* stat seems to be the preferred way to check for existence.
|
* 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) {
|
if (-1 == ret) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue