From 1d45ca612dc5e99b31f155000c550743ab26b94f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Apr 2015 07:57:11 -0600 Subject: [PATCH] More last-minute tweaks --- bin/install-category | 2 +- bin/once | 2 +- www/{ => cgi}/cgi.lua | 0 www/{ => cgi}/koth.lua | 31 +++++++++++++++++++++++------- www/{ => cgi}/puzzler.cgi | 4 +++- bin/puzzles => www/cgi/puzzles.cgi | 11 ++++++----- www/{ => cgi}/register.cgi | 12 +++++++++--- www/register.html | 2 +- www/scoreboard.html | 2 +- www/scoreboard.js | 10 ++++++++-- 10 files changed, 54 insertions(+), 22 deletions(-) rename www/{ => cgi}/cgi.lua (100%) rename www/{ => cgi}/koth.lua (65%) rename www/{ => cgi}/puzzler.cgi (87%) rename bin/puzzles => www/cgi/puzzles.cgi (71%) rename www/{ => cgi}/register.cgi (69%) diff --git a/bin/install-category b/bin/install-category index ceb0be3..7d6ae94 100755 --- a/bin/install-category +++ b/bin/install-category @@ -53,7 +53,7 @@ EOF cat < -
+
Team hash:
diff --git a/bin/once b/bin/once index 23b06c9..f38c6f1 100755 --- a/bin/once +++ b/bin/once @@ -23,7 +23,7 @@ find state/points.new -type f | while read fn; do done # Generate new puzzles.html -if bin/puzzles > www/puzzles.new; then +if www/cgi/puzzles.cgi > www/puzzles.new; then mv www/puzzles.new www/puzzles.html fi diff --git a/www/cgi.lua b/www/cgi/cgi.lua similarity index 100% rename from www/cgi.lua rename to www/cgi/cgi.lua diff --git a/www/koth.lua b/www/cgi/koth.lua similarity index 65% rename from www/koth.lua rename to www/cgi/koth.lua index 32085ca..f002bbd 100644 --- a/www/koth.lua +++ b/www/cgi/koth.lua @@ -33,7 +33,7 @@ function koth.page(title, body) print() end print("") - print("" .. title .. "") + print("" .. title .. "") print("

" .. title .. "

") if (body) then print("
") @@ -41,9 +41,9 @@ function koth.page(title, body) print("
") end print([[
- Los Alamos National Laboratory - US Department Of Energy - Sandia National Laboratories + Los Alamos National Laboratory + US Department Of Energy + Sandia National Laboratories
]]) print("") @@ -63,19 +63,19 @@ function koth.award_points(team, category, points, comment) entry = entry .. " " .. comment end - local f = io.open("../state/teams/" .. team) + local f = io.open(koth.path("state/teams/" .. team)) if (f) then f:close() else return false, "No such team" end - local ok = koth.anchored_search("../state/points.log", entry, " ") + local ok = koth.anchored_search(koth.path("state/points.log"), entry, " ") if (ok) then return false, "Points already awarded" end - local f = io.open("../state/points.new/" .. filename, "a") + local f = io.open(koth.path("state/points.new/" .. filename), "a") if (not f) then return false, "Unable to write to points file" end @@ -86,5 +86,22 @@ function koth.award_points(team, category, points, comment) return true end +-- Most web servers cd to the directory containing the CGI. +-- Not uhttpd. + +koth.base = "" +function koth.path(p) + return koth.base .. p +end + +-- Traverse up to find assigned.txt +for i = 0, 5 do + local f = io.open(koth.path("assigned.txt")) + if (f) then + f:close() + break + end + koth.base = koth.base .. "../" +end return koth diff --git a/www/puzzler.cgi b/www/cgi/puzzler.cgi similarity index 87% rename from www/puzzler.cgi rename to www/cgi/puzzler.cgi index a683116..1cb2c91 100755 --- a/www/puzzler.cgi +++ b/www/cgi/puzzler.cgi @@ -1,5 +1,7 @@ #! /usr/bin/lua +package.path = "?.lua;cgi/?.lua;www/cgi/?.lua" + local cgi = require "cgi" local koth = require "koth" @@ -13,7 +15,7 @@ category = category:gsub("[^A-Za-z0-9]", "-") -- Check answer local needle = points .. " " .. answer -local haystack = "../packages/" .. category .. "/answers.txt" +local haystack = koth.path("packages/" .. category .. "/answers.txt") local found, err = koth.anchored_search(haystack, needle) if (not found) then diff --git a/bin/puzzles b/www/cgi/puzzles.cgi similarity index 71% rename from bin/puzzles rename to www/cgi/puzzles.cgi index 883b9ee..aa6475e 100755 --- a/bin/puzzles +++ b/www/cgi/puzzles.cgi @@ -1,18 +1,19 @@ #! /usr/bin/lua -package.path = "www/?.lua" +package.path = "?.lua;cgi/?.lua;www/cgi/?.lua" + local koth = require "koth" local max_by_cat = {} -local f = io.popen("ls packages") +local f = io.popen("ls " .. koth.path("packages")) for cat in f:lines() do max_by_cat[cat] = 0 end f:close() -for line in io.lines("state/points.log") do +for line in io.lines(koth.path("state/points.log")) do local ts, team, cat, points, comment = line:match("^(%d+) (%w+) (%w+) (%d+) ?(.*)") points = tonumber(points) or 0 @@ -28,11 +29,11 @@ for cat, biggest in pairs(max_by_cat) do body = body .. "
" .. cat .. "
" body = body .. "
" - for line in io.lines("packages/" .. cat .. "/map.txt") do + for line in io.lines(koth.path("packages/" .. cat .. "/map.txt")) do points, dirname = line:match("^(%d+) (.*)") points = tonumber(points) - body = body .. "" .. points .. " " + body = body .. "" .. points .. " " if (points > biggest) then break end diff --git a/www/register.cgi b/www/cgi/register.cgi similarity index 69% rename from www/register.cgi rename to www/cgi/register.cgi index 0429881..46a2b84 100755 --- a/www/register.cgi +++ b/www/cgi/register.cgi @@ -1,5 +1,8 @@ #! /usr/bin/lua +package.path = "?.lua;cgi/?.lua;www/cgi/?.lua" + + local cgi = require "cgi" local koth = require "koth" @@ -10,17 +13,20 @@ 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 +elseif (not koth.anchored_search(koth.path("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) +local f = io.open(koth.path("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+") +local f, err = io.open(koth.path("state/teams/" .. hash), "w+") +if (not f) then + koth.page("Kersplode", err) +end f:write(team) f:close() diff --git a/www/register.html b/www/register.html index 991e8f3..6af3602 100644 --- a/www/register.html +++ b/www/register.html @@ -24,7 +24,7 @@ you don't need to do it again.

- +
diff --git a/www/scoreboard.html b/www/scoreboard.html index a37fa7b..801da0a 100644 --- a/www/scoreboard.html +++ b/www/scoreboard.html @@ -7,7 +7,7 @@