diff --git a/bin/puzzles b/bin/puzzles
index 5e05d80..883b9ee 100755
--- a/bin/puzzles
+++ b/bin/puzzles
@@ -43,5 +43,6 @@ for cat, biggest in pairs(max_by_cat) do
body = body .. "\n"
end
body = body .. "\n"
+body = body .. "
Reloading this page periodically may yield updated puzzle lists.
"
koth.page("Open Puzzles", body)
\ No newline at end of file
diff --git a/html/register.cgi b/html/register.cgi
deleted file mode 100755
index 65d2781..0000000
--- a/html/register.cgi
+++ /dev/null
@@ -1,69 +0,0 @@
-#! /bin/sh -e
-
-# Change to CTF_BASE
-cd ${CTF_BASE:-.}
-for i in $(seq 5); do
- [ -f assigned.txt ] && break
- cd ..
-done
-if ! [ -f assigned.txt ]; then
- cat <
-
-
-
- Team Registration
-
-
-
-
Okay, your team has been named and you may begin using your hash!
"
-fi
-
-cat <
-
-
-
-EOF
diff --git a/install b/install
index 307c7ca..71db6e8 100755
--- a/install
+++ b/install
@@ -28,15 +28,6 @@ copy () {
fi
}
-web () {
- target=$DESTDIR/www/${1#*/}
- if older $target $1; then
- echo "WEB $1"
- mkdir -p $(dirname $target)
- cp $1 $target
- fi
-}
-
setup() {
[ -d $DESTDIR/state ] && return
echo "SETUP"
@@ -71,8 +62,8 @@ git ls-files | while read fn; do
;;
doc/*)
;;
- html/*)
- web $fn
+ www/*)
+ copy $fn
;;
bin/*)
copy $fn
diff --git a/html/cgi.lua b/www/cgi.lua
similarity index 100%
rename from html/cgi.lua
rename to www/cgi.lua
diff --git a/html/credits.html b/www/credits.html
similarity index 100%
rename from html/credits.html
rename to www/credits.html
diff --git a/html/fonts/maven_pro.css b/www/fonts/maven_pro.css
similarity index 100%
rename from html/fonts/maven_pro.css
rename to www/fonts/maven_pro.css
diff --git a/html/fonts/maven_pro_black-webfont.eot b/www/fonts/maven_pro_black-webfont.eot
similarity index 100%
rename from html/fonts/maven_pro_black-webfont.eot
rename to www/fonts/maven_pro_black-webfont.eot
diff --git a/html/fonts/maven_pro_black-webfont.svg b/www/fonts/maven_pro_black-webfont.svg
similarity index 100%
rename from html/fonts/maven_pro_black-webfont.svg
rename to www/fonts/maven_pro_black-webfont.svg
diff --git a/html/fonts/maven_pro_black-webfont.ttf b/www/fonts/maven_pro_black-webfont.ttf
similarity index 100%
rename from html/fonts/maven_pro_black-webfont.ttf
rename to www/fonts/maven_pro_black-webfont.ttf
diff --git a/html/fonts/maven_pro_black-webfont.woff b/www/fonts/maven_pro_black-webfont.woff
similarity index 100%
rename from html/fonts/maven_pro_black-webfont.woff
rename to www/fonts/maven_pro_black-webfont.woff
diff --git a/html/fonts/maven_pro_bold-webfont.eot b/www/fonts/maven_pro_bold-webfont.eot
similarity index 100%
rename from html/fonts/maven_pro_bold-webfont.eot
rename to www/fonts/maven_pro_bold-webfont.eot
diff --git a/html/fonts/maven_pro_bold-webfont.svg b/www/fonts/maven_pro_bold-webfont.svg
similarity index 100%
rename from html/fonts/maven_pro_bold-webfont.svg
rename to www/fonts/maven_pro_bold-webfont.svg
diff --git a/html/fonts/maven_pro_bold-webfont.ttf b/www/fonts/maven_pro_bold-webfont.ttf
similarity index 100%
rename from html/fonts/maven_pro_bold-webfont.ttf
rename to www/fonts/maven_pro_bold-webfont.ttf
diff --git a/html/fonts/maven_pro_bold-webfont.woff b/www/fonts/maven_pro_bold-webfont.woff
similarity index 100%
rename from html/fonts/maven_pro_bold-webfont.woff
rename to www/fonts/maven_pro_bold-webfont.woff
diff --git a/html/fonts/maven_pro_medium-webfont.eot b/www/fonts/maven_pro_medium-webfont.eot
similarity index 100%
rename from html/fonts/maven_pro_medium-webfont.eot
rename to www/fonts/maven_pro_medium-webfont.eot
diff --git a/html/fonts/maven_pro_medium-webfont.svg b/www/fonts/maven_pro_medium-webfont.svg
similarity index 100%
rename from html/fonts/maven_pro_medium-webfont.svg
rename to www/fonts/maven_pro_medium-webfont.svg
diff --git a/html/fonts/maven_pro_medium-webfont.ttf b/www/fonts/maven_pro_medium-webfont.ttf
similarity index 100%
rename from html/fonts/maven_pro_medium-webfont.ttf
rename to www/fonts/maven_pro_medium-webfont.ttf
diff --git a/html/fonts/maven_pro_medium-webfont.woff b/www/fonts/maven_pro_medium-webfont.woff
similarity index 100%
rename from html/fonts/maven_pro_medium-webfont.woff
rename to www/fonts/maven_pro_medium-webfont.woff
diff --git a/html/fonts/maven_pro_regular-webfont.eot b/www/fonts/maven_pro_regular-webfont.eot
similarity index 100%
rename from html/fonts/maven_pro_regular-webfont.eot
rename to www/fonts/maven_pro_regular-webfont.eot
diff --git a/html/fonts/maven_pro_regular-webfont.svg b/www/fonts/maven_pro_regular-webfont.svg
similarity index 100%
rename from html/fonts/maven_pro_regular-webfont.svg
rename to www/fonts/maven_pro_regular-webfont.svg
diff --git a/html/fonts/maven_pro_regular-webfont.ttf b/www/fonts/maven_pro_regular-webfont.ttf
similarity index 100%
rename from html/fonts/maven_pro_regular-webfont.ttf
rename to www/fonts/maven_pro_regular-webfont.ttf
diff --git a/html/fonts/maven_pro_regular-webfont.woff b/www/fonts/maven_pro_regular-webfont.woff
similarity index 100%
rename from html/fonts/maven_pro_regular-webfont.woff
rename to www/fonts/maven_pro_regular-webfont.woff
diff --git a/html/images/brown-circles.jpg b/www/images/brown-circles.jpg
similarity index 100%
rename from html/images/brown-circles.jpg
rename to www/images/brown-circles.jpg
diff --git a/html/images/doe.png b/www/images/doe.png
similarity index 100%
rename from html/images/doe.png
rename to www/images/doe.png
diff --git a/html/images/lanl.png b/www/images/lanl.png
similarity index 100%
rename from html/images/lanl.png
rename to www/images/lanl.png
diff --git a/html/images/sandia.png b/www/images/sandia.png
similarity index 100%
rename from html/images/sandia.png
rename to www/images/sandia.png
diff --git a/html/index.html b/www/index.html
similarity index 100%
rename from html/index.html
rename to www/index.html
diff --git a/html/koth.lua b/www/koth.lua
similarity index 81%
rename from html/koth.lua
rename to www/koth.lua
index 9360bd6..b7728d9 100644
--- a/html/koth.lua
+++ b/www/koth.lua
@@ -3,8 +3,13 @@
local koth = {}
-- cut -d$ANCHOR -f2- | grep -Fx "$NEEDLE"
-function anchored_search(haystack, needle, anchor)
- for line in io.lines(haystack) do
+function koth.anchored_search(haystack, needle, anchor)
+ local f, err = io.open(haystack)
+ if (not f) then
+ return false, err
+ end
+
+ for line in f:lines() do
if (anchor) then
pos = line:find(anchor)
if (pos) then
@@ -13,19 +18,15 @@ function anchored_search(haystack, needle, anchor)
end
if (line == needle) then
+ f:close()
return true
end
end
+ f:close()
return false
end
-function koth.anchored_search(haystack, needle, anchor)
- local ok, ret = pcall(anchored_search, haystack, needle, anchor)
-
- return ok and ret
-end
-
function koth.page(title, body)
if (os.getenv("REQUEST_METHOD")) then
print("Content-type: text/html")
@@ -53,6 +54,8 @@ end
-- We're going to rely on `bin/once` only processing files with the right number of lines.
--
function koth.award_points(team, category, points, comment)
+ team = team:gsub("[^0-9a-f]", "-")
+
local filename = team .. "." .. category .. "." .. points
local entry = team .. " " .. category .. " " .. points
@@ -60,8 +63,15 @@ function koth.award_points(team, category, points, comment)
entry = entry .. " " .. comment
end
- local ok = anchored_search("../state/points.log", entry, " ")
- if (not ok) then
+ local f = io.open("../state/teams/" .. team)
+ if (f) then
+ f:close()
+ else
+ return false, "No such team"
+ end
+
+ local ok = koth.anchored_search("../state/points.log", entry, " ")
+ if (ok) then
return false, "Points already awarded"
end
diff --git a/html/puzzler.cgi b/www/puzzler.cgi
similarity index 73%
rename from html/puzzler.cgi
rename to www/puzzler.cgi
index ee4d24a..a683116 100755
--- a/html/puzzler.cgi
+++ b/www/puzzler.cgi
@@ -13,17 +13,17 @@ category = category:gsub("[^A-Za-z0-9]", "-")
-- Check answer
local needle = points .. " " .. answer
-local haystack = "../puzzles/" .. category .. "/answers.txt"
-local found = koth.anchored_search(haystack, needle)
+local haystack = "../packages/" .. category .. "/answers.txt"
+local found, err = koth.anchored_search(haystack, needle)
if (not found) then
- koth.page("Wrong answer")
+ koth.page("Wrong answer", err)
end
local ok, err = koth.award_points(team, category, points)
if (not ok) then
koth.page("Error awarding points",
- "
You got the right answer, but something blew up trying to give you points.
" ..
+ "
You got the right answer, but there was a problem trying to give you points:
" ..
"
" .. err .. "
")
end
diff --git a/www/register.cgi b/www/register.cgi
new file mode 100755
index 0000000..0429881
--- /dev/null
+++ b/www/register.cgi
@@ -0,0 +1,27 @@
+#! /usr/bin/lua
+
+local cgi = require "cgi"
+local koth = require "koth"
+
+local team = cgi.fields["n"] or ""
+local hash = cgi.fields["h"] or ""
+
+hash = hash:match("[0-9a-f]*")
+
+if ((hash == "") or (team == "")) then
+ koth.page("Invalid Entry", "Oops! Are you sure you got that right?")
+elseif (not koth.anchored_search("../assigned.txt", hash)) then
+ koth.page("Invalid Hash", "Oops! I don't have a record of that hash. Did you maybe use capital letters accidentally?")
+end
+
+local f = io.open("../state/teams/" .. hash)
+if (f) then
+ f:close()
+ koth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
+end
+
+local f = io.open("../state/teams/" .. hash, "w+")
+f:write(team)
+f:close()
+
+koth.page("Success", "Okay, your team has been named and you may begin using your hash!")
diff --git a/html/register.html b/www/register.html
similarity index 100%
rename from html/register.html
rename to www/register.html
diff --git a/html/scoreboard.html b/www/scoreboard.html
similarity index 100%
rename from html/scoreboard.html
rename to www/scoreboard.html
diff --git a/html/scoreboard.js b/www/scoreboard.js
similarity index 100%
rename from html/scoreboard.js
rename to www/scoreboard.js
diff --git a/html/scoring.html b/www/scoring.html
similarity index 100%
rename from html/scoring.html
rename to www/scoring.html
diff --git a/html/style.css b/www/style.css
similarity index 100%
rename from html/style.css
rename to www/style.css
diff --git a/html/terminal.js b/www/terminal.js
similarity index 100%
rename from html/terminal.js
rename to www/terminal.js