mirror of https://github.com/dirtbags/moth.git
Start at a portable puzzle format
This commit is contained in:
parent
abe77091e0
commit
afc015dcc8
37
mkpuzzles
37
mkpuzzles
|
@ -5,6 +5,11 @@ set -e
|
||||||
indir=$1; shift
|
indir=$1; shift
|
||||||
outdir=$1; shift
|
outdir=$1; shift
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "$@" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
escape () {
|
escape () {
|
||||||
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
||||||
}
|
}
|
||||||
|
@ -12,6 +17,7 @@ escape () {
|
||||||
template () {
|
template () {
|
||||||
cat="$1"; shift
|
cat="$1"; shift
|
||||||
points="$1"; shift
|
points="$1"; shift
|
||||||
|
author=$(echo $1 | escape); shift
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -47,6 +53,7 @@ EOF
|
||||||
Answer:<input name="a" size="20">
|
Answer:<input name="a" size="20">
|
||||||
<input type="submit" value="submit">
|
<input type="submit" value="submit">
|
||||||
</form>
|
</form>
|
||||||
|
<address>Puzzle by $author</address>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
EOF
|
EOF
|
||||||
|
@ -78,8 +85,8 @@ for dn in $indir/[0-9]*; do
|
||||||
files=
|
files=
|
||||||
for fn in $dn/*; do
|
for fn in $dn/*; do
|
||||||
case $(basename $fn) in
|
case $(basename $fn) in
|
||||||
key|summary|index.mdwn)
|
@*)
|
||||||
# Handle these later
|
# Handle meta-information later
|
||||||
;;
|
;;
|
||||||
*~|"#"*)
|
*~|"#"*)
|
||||||
# Don't copy temporary or backup files
|
# Don't copy temporary or backup files
|
||||||
|
@ -96,23 +103,29 @@ for dn in $indir/[0-9]*; do
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Append keys
|
# Append answers
|
||||||
if [ -f $dn/key ]; then
|
if [ -f $dn/@answer.txt ]; then
|
||||||
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/key >> $uanswers
|
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/@answer.txt >> $uanswers
|
||||||
else
|
else
|
||||||
echo "$dn/key: No such file or directory" 1>&2
|
die "$dn/@answer.txt: No such file or directory"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Append summary
|
# Append summary
|
||||||
if [ -f $dn/summary ]; then
|
if [ -f $dn/@summary.txt ]; then
|
||||||
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/summary >> $usummary
|
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/@summary.txt >> $usummary
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read author
|
||||||
|
if [ -f $dn/@author.txt ]; then
|
||||||
|
author=$(cat $dn/@author.txt)
|
||||||
|
else
|
||||||
|
die "$dn/@author.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/index.mdwn ]; then
|
if [ -f $dn/@index.mdwn ]; then
|
||||||
markdown --html4tags $dn/index.mdwn
|
markdown --html4tags $dn/@index.mdwn
|
||||||
fi | template $cat $points $files > $tgt/index.html
|
fi | template $cat $points "$author" $files > $tgt/index.html
|
||||||
done
|
done
|
||||||
|
|
||||||
sort -n $uanswers > $outdir/answers.txt
|
sort -n $uanswers > $outdir/answers.txt
|
||||||
|
|
|
@ -68,8 +68,6 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char cat[50];
|
char cat[50];
|
||||||
int catlen;
|
int catlen;
|
||||||
char token[200];
|
|
||||||
size_t tokenlen;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
catlen = read(5, cat, sizeof(cat) - 1);
|
catlen = read(5, cat, sizeof(cat) - 1);
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include "token.h"
|
|
||||||
#include "arc4.h"
|
|
||||||
|
|
||||||
#ifndef CTF_BASE
|
|
||||||
#define CTF_BASE "/var/lib/ctf"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ssize_t
|
|
||||||
write_token(FILE *out,
|
|
||||||
const char *name,
|
|
||||||
const uint8_t *key, size_t keylen)
|
|
||||||
{
|
|
||||||
char *base;
|
|
||||||
char path[PATH_MAX];
|
|
||||||
int pathlen;
|
|
||||||
FILE *f;
|
|
||||||
ssize_t ret;
|
|
||||||
|
|
||||||
base = getenv("CTF_BASE");
|
|
||||||
if (! base) base = CTF_BASE;
|
|
||||||
|
|
||||||
pathlen = snprintf(path, sizeof(path) - 1,
|
|
||||||
"%s/tokens/%s", base, name);
|
|
||||||
path[pathlen] = '\0';
|
|
||||||
|
|
||||||
f = fopen(path, "r");
|
|
||||||
if (NULL == f) return -1;
|
|
||||||
ret = arc4_decrypt_stream(out, f, key, keylen);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t
|
|
||||||
print_token(const char *name,
|
|
||||||
const uint8_t *key, size_t keylen)
|
|
||||||
{
|
|
||||||
return write_token(stdout, name, key, keylen);
|
|
||||||
}
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../../src/token.c
|
|
@ -1,15 +0,0 @@
|
||||||
#ifndef __TOKEN_H__
|
|
||||||
#define __TOKEN_H__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
ssize_t write_token(FILE *out,
|
|
||||||
const char *name,
|
|
||||||
const uint8_t *key, size_t keylen);
|
|
||||||
ssize_t print_token(const char *name,
|
|
||||||
const uint8_t *key, size_t keylen);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../../src/token.h
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Neale Pickett <neale@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Danny Quist <dquist@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Danny Quist <dquist@lanl.gov>
|
|
@ -0,0 +1 @@
|
||||||
|
Danny Quist <dquist@lanl.gov>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue