diff --git a/README.md b/README.md index 37c294e..766f78c 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,21 @@ Please check out [the overview](doc/overview.md) for details. +Getting Started Developing +------------------------------- + + $ git clone $your_puzzles_repo puzzles + $ python3 tools/devel-server.py + +Then point a web browser at http://localhost:8080/ +and start hacking on things in your `puzzles` directory. + + +Running A Production Server +==================== + +XXX: Update this + How to set it up -------------------- diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 4228e72..0000000 --- a/TODO.md +++ /dev/null @@ -1,9 +0,0 @@ -* Scoreboard refresh - -Test: - -* awarding points -* points already awarded -* bad team hash -* category doesn't exist -* puzzle doesn't exist diff --git a/CREDITS.md b/doc/CREDITS.md similarity index 100% rename from CREDITS.md rename to doc/CREDITS.md diff --git a/LICENSE.md b/doc/LICENSE.md similarity index 100% rename from LICENSE.md rename to doc/LICENSE.md diff --git a/kothd b/kothd deleted file mode 100755 index ffad247..0000000 --- a/kothd +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/sh - -cd ${1:-$(dirname $0)} -KOTH_BASE=$(pwd) - -echo "Running koth instances in $KOTH_BASE" - -while true; do - for i in $KOTH_BASE/*/assigned.txt; do - dir=${i%/*} - $dir/bin/once - done - sleep 5 -done diff --git a/package-puzzles b/package-puzzles new file mode 100755 index 0000000..bf0eb71 --- /dev/null +++ b/package-puzzles @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 + +import argparse +import binascii +import glob +import hashlib +import io +import json +import os +import shutil +import sys +import zipfile + +import puzzles + +TMPFILE = "%s.tmp" + +def write_kv_pairs(ziphandle, filename, kv): + """ Write out a sorted map to file + :param ziphandle: a zipfile object + :param filename: The filename to write within the zipfile object + :param kv: the map to write out + :return: + """ + filehandle = io.StringIO() + for key in sorted(kv.keys()): + if type(kv[key]) == type([]): + for val in kv[key]: + filehandle.write("%s: %s%s" % (key, val, os.linesep)) + else: + filehandle.write("%s: %s%s" % (key, kv[key], os.linesep)) + filehandle.seek(0) + ziphandle.writestr(filename, filehandle.read()) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Build a category package') + parser.add_argument('categorydirs', nargs='+', help='Directory of category source') + parser.add_argument('outdir', help='Output directory') + args = parser.parse_args() + + for categorydir in args.categorydirs: + puzzles_dict = {} + secrets = {} + + categoryname = os.path.basename(categorydir.strip(os.sep)) + + # create zipfile + zipfilename = os.path.join(args.outdir, "%s.zip" % categoryname) + if os.path.exists(zipfilename): + # open and gather some state + zf = zipfile.ZipFile(zipfilename, 'r') + try: + category_seed = zf.open(os.path.join(categoryname, "category_seed.txt")).read().strip() + except: + pass + zf.close() + + zf = zipfile.ZipFile(TMPFILE % zipfilename, 'w') + if 'category_seed' not in locals(): + category_seed = binascii.b2a_hex(os.urandom(20)) + + # read in category details (will be pflarr in future) + for categorypath in glob.glob(os.path.join(categorydir, "*", "puzzle.moth")): + points = categorypath.split(os.sep)[-2] # directory before '/puzzle.moth' + categorypath = os.path.dirname(categorypath) + print(categorypath) + try: + points = int(points) + except: + print("Failed to identify points on: %s" % categorypath, file=sys.stderr) + continue + puzzle = puzzles.Puzzle(category_seed, categorypath) + puzzles_dict[points] = puzzle + + # build mapping, answers, and summary + mapping = {} + answers = {} + summary = {} + for points in sorted(puzzles_dict): + puzzle = puzzles_dict[points] + hashmap = hashlib.sha1(category_seed) + hashmap.update(str(points).encode('utf-8')) + mapping[points] = hashmap.hexdigest() + answers[points] = puzzle['answer'] + if len(puzzle['summary']) > 0: + summary[points] = puzzle['summary'] + + # write mapping, answers, summary, category_seed + write_kv_pairs(zf, os.path.join(categoryname, 'map.txt'), mapping) + write_kv_pairs(zf, os.path.join(categoryname, 'answers.txt'), answers) + write_kv_pairs(zf, os.path.join(categoryname, 'summary.txt'), summary) + zf.writestr(os.path.join(categoryname, "category_seed.txt"), category_seed) + + # write out puzzles + for points in sorted(puzzles_dict): + puzzle = puzzles_dict[points] + puzzledir = os.path.join(categoryname, 'content', mapping[points]) + puzzlejson = puzzle.publish() + + # write associated files + assoc_files = [] + for fobj in puzzle['files']: + if fobj.visible == True: + assoc_files.append(fobj.name) + zf.writestr(os.path.join(puzzledir, fobj.name), \ + fobj.handle.read()) + + if len(assoc_files) > 0: + puzzlejson["associated_files"] = assoc_files + + # non-optimal writing of file-like objects, but it works + zf.writestr(os.path.join(puzzledir, 'puzzle.json'), \ + json.dumps(puzzlejson)) + + # clean up + zf.close() + shutil.move(TMPFILE % zipfilename, zipfilename) +#vim:py diff --git a/bin/award b/src/bin/award similarity index 100% rename from bin/award rename to src/bin/award diff --git a/bin/install-category b/src/bin/install-category similarity index 100% rename from bin/install-category rename to src/bin/install-category diff --git a/bin/mktokens b/src/bin/mktokens similarity index 100% rename from bin/mktokens rename to src/bin/mktokens diff --git a/bin/new b/src/bin/new similarity index 100% rename from bin/new rename to src/bin/new diff --git a/bin/once b/src/bin/once similarity index 100% rename from bin/once rename to src/bin/once diff --git a/bin/points b/src/bin/points similarity index 100% rename from bin/points rename to src/bin/points diff --git a/bin/puzzles b/src/bin/puzzles similarity index 100% rename from bin/puzzles rename to src/bin/puzzles diff --git a/mothd b/src/mothd similarity index 100% rename from mothd rename to src/mothd diff --git a/www/cgi-bin/cgi.lua b/src/www/cgi-bin/cgi.lua similarity index 100% rename from www/cgi-bin/cgi.lua rename to src/www/cgi-bin/cgi.lua diff --git a/www/cgi-bin/koth.lua b/src/www/cgi-bin/koth.lua similarity index 100% rename from www/cgi-bin/koth.lua rename to src/www/cgi-bin/koth.lua diff --git a/www/cgi-bin/puzzler.cgi b/src/www/cgi-bin/puzzler.cgi similarity index 100% rename from www/cgi-bin/puzzler.cgi rename to src/www/cgi-bin/puzzler.cgi diff --git a/www/cgi-bin/register.cgi b/src/www/cgi-bin/register.cgi similarity index 100% rename from www/cgi-bin/register.cgi rename to src/www/cgi-bin/register.cgi diff --git a/www/cgi-bin/token.cgi b/src/www/cgi-bin/token.cgi similarity index 100% rename from www/cgi-bin/token.cgi rename to src/www/cgi-bin/token.cgi diff --git a/www/credits.html b/src/www/credits.html similarity index 100% rename from www/credits.html rename to src/www/credits.html diff --git a/www/fonts/MicroFLF-Bold.ttf b/src/www/fonts/MicroFLF-Bold.ttf similarity index 100% rename from www/fonts/MicroFLF-Bold.ttf rename to src/www/fonts/MicroFLF-Bold.ttf diff --git a/www/fonts/MicroFLF-BoldItalic.ttf b/src/www/fonts/MicroFLF-BoldItalic.ttf similarity index 100% rename from www/fonts/MicroFLF-BoldItalic.ttf rename to src/www/fonts/MicroFLF-BoldItalic.ttf diff --git a/www/fonts/MicroFLF-Italic.ttf b/src/www/fonts/MicroFLF-Italic.ttf similarity index 100% rename from www/fonts/MicroFLF-Italic.ttf rename to src/www/fonts/MicroFLF-Italic.ttf diff --git a/www/fonts/MicroFLF.css b/src/www/fonts/MicroFLF.css similarity index 100% rename from www/fonts/MicroFLF.css rename to src/www/fonts/MicroFLF.css diff --git a/www/fonts/MicroFLF.ttf b/src/www/fonts/MicroFLF.ttf similarity index 100% rename from www/fonts/MicroFLF.ttf rename to src/www/fonts/MicroFLF.ttf diff --git a/www/fonts/maven_pro.css b/src/www/fonts/maven_pro.css similarity index 100% rename from www/fonts/maven_pro.css rename to src/www/fonts/maven_pro.css diff --git a/www/fonts/maven_pro_black-webfont.eot b/src/www/fonts/maven_pro_black-webfont.eot similarity index 100% rename from www/fonts/maven_pro_black-webfont.eot rename to src/www/fonts/maven_pro_black-webfont.eot diff --git a/www/fonts/maven_pro_black-webfont.svg b/src/www/fonts/maven_pro_black-webfont.svg similarity index 100% rename from www/fonts/maven_pro_black-webfont.svg rename to src/www/fonts/maven_pro_black-webfont.svg diff --git a/www/fonts/maven_pro_black-webfont.ttf b/src/www/fonts/maven_pro_black-webfont.ttf similarity index 100% rename from www/fonts/maven_pro_black-webfont.ttf rename to src/www/fonts/maven_pro_black-webfont.ttf diff --git a/www/fonts/maven_pro_black-webfont.woff b/src/www/fonts/maven_pro_black-webfont.woff similarity index 100% rename from www/fonts/maven_pro_black-webfont.woff rename to src/www/fonts/maven_pro_black-webfont.woff diff --git a/www/fonts/maven_pro_bold-webfont.eot b/src/www/fonts/maven_pro_bold-webfont.eot similarity index 100% rename from www/fonts/maven_pro_bold-webfont.eot rename to src/www/fonts/maven_pro_bold-webfont.eot diff --git a/www/fonts/maven_pro_bold-webfont.svg b/src/www/fonts/maven_pro_bold-webfont.svg similarity index 100% rename from www/fonts/maven_pro_bold-webfont.svg rename to src/www/fonts/maven_pro_bold-webfont.svg diff --git a/www/fonts/maven_pro_bold-webfont.ttf b/src/www/fonts/maven_pro_bold-webfont.ttf similarity index 100% rename from www/fonts/maven_pro_bold-webfont.ttf rename to src/www/fonts/maven_pro_bold-webfont.ttf diff --git a/www/fonts/maven_pro_bold-webfont.woff b/src/www/fonts/maven_pro_bold-webfont.woff similarity index 100% rename from www/fonts/maven_pro_bold-webfont.woff rename to src/www/fonts/maven_pro_bold-webfont.woff diff --git a/www/fonts/maven_pro_medium-webfont.eot b/src/www/fonts/maven_pro_medium-webfont.eot similarity index 100% rename from www/fonts/maven_pro_medium-webfont.eot rename to src/www/fonts/maven_pro_medium-webfont.eot diff --git a/www/fonts/maven_pro_medium-webfont.svg b/src/www/fonts/maven_pro_medium-webfont.svg similarity index 100% rename from www/fonts/maven_pro_medium-webfont.svg rename to src/www/fonts/maven_pro_medium-webfont.svg diff --git a/www/fonts/maven_pro_medium-webfont.ttf b/src/www/fonts/maven_pro_medium-webfont.ttf similarity index 100% rename from www/fonts/maven_pro_medium-webfont.ttf rename to src/www/fonts/maven_pro_medium-webfont.ttf diff --git a/www/fonts/maven_pro_medium-webfont.woff b/src/www/fonts/maven_pro_medium-webfont.woff similarity index 100% rename from www/fonts/maven_pro_medium-webfont.woff rename to src/www/fonts/maven_pro_medium-webfont.woff diff --git a/www/fonts/maven_pro_regular-webfont.eot b/src/www/fonts/maven_pro_regular-webfont.eot similarity index 100% rename from www/fonts/maven_pro_regular-webfont.eot rename to src/www/fonts/maven_pro_regular-webfont.eot diff --git a/www/fonts/maven_pro_regular-webfont.svg b/src/www/fonts/maven_pro_regular-webfont.svg similarity index 100% rename from www/fonts/maven_pro_regular-webfont.svg rename to src/www/fonts/maven_pro_regular-webfont.svg diff --git a/www/fonts/maven_pro_regular-webfont.ttf b/src/www/fonts/maven_pro_regular-webfont.ttf similarity index 100% rename from www/fonts/maven_pro_regular-webfont.ttf rename to src/www/fonts/maven_pro_regular-webfont.ttf diff --git a/www/fonts/maven_pro_regular-webfont.woff b/src/www/fonts/maven_pro_regular-webfont.woff similarity index 100% rename from www/fonts/maven_pro_regular-webfont.woff rename to src/www/fonts/maven_pro_regular-webfont.woff diff --git a/www/images/brown-circles.jpg b/src/www/images/brown-circles.jpg similarity index 100% rename from www/images/brown-circles.jpg rename to src/www/images/brown-circles.jpg diff --git a/www/images/doe.png b/src/www/images/doe.png similarity index 100% rename from www/images/doe.png rename to src/www/images/doe.png diff --git a/www/images/lanl.png b/src/www/images/lanl.png similarity index 100% rename from www/images/lanl.png rename to src/www/images/lanl.png diff --git a/www/images/sandia.png b/src/www/images/sandia.png similarity index 100% rename from www/images/sandia.png rename to src/www/images/sandia.png diff --git a/www/images/tf6.png b/src/www/images/tf6.png similarity index 100% rename from www/images/tf6.png rename to src/www/images/tf6.png diff --git a/www/images/tf6bg.png b/src/www/images/tf6bg.png similarity index 100% rename from www/images/tf6bg.png rename to src/www/images/tf6bg.png diff --git a/www/index.html b/src/www/index.html similarity index 100% rename from www/index.html rename to src/www/index.html diff --git a/www/projections.json b/src/www/projections.json similarity index 100% rename from www/projections.json rename to src/www/projections.json diff --git a/www/projector.html b/src/www/projector.html similarity index 100% rename from www/projector.html rename to src/www/projector.html diff --git a/www/puzzles.html b/src/www/puzzles.html similarity index 100% rename from www/puzzles.html rename to src/www/puzzles.html diff --git a/www/register.html b/src/www/register.html similarity index 100% rename from www/register.html rename to src/www/register.html diff --git a/www/res/Dosis-Bold.ttf b/src/www/res/Dosis-Bold.ttf similarity index 100% rename from www/res/Dosis-Bold.ttf rename to src/www/res/Dosis-Bold.ttf diff --git a/www/res/Dosis-ExtraBold.ttf b/src/www/res/Dosis-ExtraBold.ttf similarity index 100% rename from www/res/Dosis-ExtraBold.ttf rename to src/www/res/Dosis-ExtraBold.ttf diff --git a/www/res/Dosis-ExtraLight.ttf b/src/www/res/Dosis-ExtraLight.ttf similarity index 100% rename from www/res/Dosis-ExtraLight.ttf rename to src/www/res/Dosis-ExtraLight.ttf diff --git a/www/res/Dosis-Light.ttf b/src/www/res/Dosis-Light.ttf similarity index 100% rename from www/res/Dosis-Light.ttf rename to src/www/res/Dosis-Light.ttf diff --git a/www/res/Dosis-Medium.ttf b/src/www/res/Dosis-Medium.ttf similarity index 100% rename from www/res/Dosis-Medium.ttf rename to src/www/res/Dosis-Medium.ttf diff --git a/www/res/Dosis-Regular.ttf b/src/www/res/Dosis-Regular.ttf similarity index 100% rename from www/res/Dosis-Regular.ttf rename to src/www/res/Dosis-Regular.ttf diff --git a/www/res/Dosis-SemiBold.ttf b/src/www/res/Dosis-SemiBold.ttf similarity index 100% rename from www/res/Dosis-SemiBold.ttf rename to src/www/res/Dosis-SemiBold.ttf diff --git a/www/res/Dosis.css b/src/www/res/Dosis.css similarity index 100% rename from www/res/Dosis.css rename to src/www/res/Dosis.css diff --git a/www/res/Lato-Black.ttf b/src/www/res/Lato-Black.ttf similarity index 100% rename from www/res/Lato-Black.ttf rename to src/www/res/Lato-Black.ttf diff --git a/www/res/Lato-BlackItalic.ttf b/src/www/res/Lato-BlackItalic.ttf similarity index 100% rename from www/res/Lato-BlackItalic.ttf rename to src/www/res/Lato-BlackItalic.ttf diff --git a/www/res/Lato-Bold.ttf b/src/www/res/Lato-Bold.ttf similarity index 100% rename from www/res/Lato-Bold.ttf rename to src/www/res/Lato-Bold.ttf diff --git a/www/res/Lato-BoldItalic.ttf b/src/www/res/Lato-BoldItalic.ttf similarity index 100% rename from www/res/Lato-BoldItalic.ttf rename to src/www/res/Lato-BoldItalic.ttf diff --git a/www/res/Lato-Hairline.ttf b/src/www/res/Lato-Hairline.ttf similarity index 100% rename from www/res/Lato-Hairline.ttf rename to src/www/res/Lato-Hairline.ttf diff --git a/www/res/Lato-HairlineItalic.ttf b/src/www/res/Lato-HairlineItalic.ttf similarity index 100% rename from www/res/Lato-HairlineItalic.ttf rename to src/www/res/Lato-HairlineItalic.ttf diff --git a/www/res/Lato-Italic.ttf b/src/www/res/Lato-Italic.ttf similarity index 100% rename from www/res/Lato-Italic.ttf rename to src/www/res/Lato-Italic.ttf diff --git a/www/res/Lato-Light.ttf b/src/www/res/Lato-Light.ttf similarity index 100% rename from www/res/Lato-Light.ttf rename to src/www/res/Lato-Light.ttf diff --git a/www/res/Lato-LightItalic.ttf b/src/www/res/Lato-LightItalic.ttf similarity index 100% rename from www/res/Lato-LightItalic.ttf rename to src/www/res/Lato-LightItalic.ttf diff --git a/www/res/Lato-Regular.ttf b/src/www/res/Lato-Regular.ttf similarity index 100% rename from www/res/Lato-Regular.ttf rename to src/www/res/Lato-Regular.ttf diff --git a/www/res/Lato.css b/src/www/res/Lato.css similarity index 100% rename from www/res/Lato.css rename to src/www/res/Lato.css diff --git a/www/res/brown-lines.jpg b/src/www/res/brown-lines.jpg similarity index 100% rename from www/res/brown-lines.jpg rename to src/www/res/brown-lines.jpg diff --git a/www/res/common.js b/src/www/res/common.js similarity index 100% rename from www/res/common.js rename to src/www/res/common.js diff --git a/www/res/luna-moth.png b/src/www/res/luna-moth.png similarity index 100% rename from www/res/luna-moth.png rename to src/www/res/luna-moth.png diff --git a/www/res/luna-moth.svg b/src/www/res/luna-moth.svg similarity index 100% rename from www/res/luna-moth.svg rename to src/www/res/luna-moth.svg diff --git a/www/res/main.js b/src/www/res/main.js similarity index 100% rename from www/res/main.js rename to src/www/res/main.js diff --git a/www/res/md5.min.js b/src/www/res/md5.min.js similarity index 100% rename from www/res/md5.min.js rename to src/www/res/md5.min.js diff --git a/www/res/messages.js b/src/www/res/messages.js similarity index 100% rename from www/res/messages.js rename to src/www/res/messages.js diff --git a/www/res/overview.js b/src/www/res/overview.js similarity index 100% rename from www/res/overview.js rename to src/www/res/overview.js diff --git a/www/res/preview.png b/src/www/res/preview.png similarity index 100% rename from www/res/preview.png rename to src/www/res/preview.png diff --git a/www/res/puzzles.js b/src/www/res/puzzles.js similarity index 100% rename from www/res/puzzles.js rename to src/www/res/puzzles.js diff --git a/www/res/scoreboard.js b/src/www/res/scoreboard.js similarity index 100% rename from www/res/scoreboard.js rename to src/www/res/scoreboard.js diff --git a/www/res/style.css b/src/www/res/style.css similarity index 100% rename from www/res/style.css rename to src/www/res/style.css diff --git a/www/res/terminal.js b/src/www/res/terminal.js similarity index 100% rename from www/res/terminal.js rename to src/www/res/terminal.js diff --git a/www/restore.html b/src/www/restore.html similarity index 100% rename from www/restore.html rename to src/www/restore.html diff --git a/www/scoreboard.html b/src/www/scoreboard.html similarity index 100% rename from www/scoreboard.html rename to src/www/scoreboard.html diff --git a/www/scoreboard.js b/src/www/scoreboard.js similarity index 100% rename from www/scoreboard.js rename to src/www/scoreboard.js diff --git a/www/scoring.html b/src/www/scoring.html similarity index 100% rename from www/scoring.html rename to src/www/scoring.html diff --git a/www/style.css b/src/www/style.css similarity index 100% rename from www/style.css rename to src/www/style.css diff --git a/www/terminal.js b/src/www/terminal.js similarity index 100% rename from www/terminal.js rename to src/www/terminal.js diff --git a/answer_words.txt b/tools/answer_words.txt similarity index 100% rename from answer_words.txt rename to tools/answer_words.txt diff --git a/build-puzzles b/tools/build-puzzles.py similarity index 100% rename from build-puzzles rename to tools/build-puzzles.py diff --git a/devel-server.py b/tools/devel-server.py similarity index 98% rename from devel-server.py rename to tools/devel-server.py index 10133e5..8befebc 100755 --- a/devel-server.py +++ b/tools/devel-server.py @@ -4,9 +4,9 @@ import cgi import glob import http.server import mistune +import moth import os import pathlib -import puzzles import socketserver import sys import traceback @@ -27,7 +27,7 @@ def page(title, body):