More last-minute tweaks

This commit is contained in:
Neale Pickett 2015-04-21 07:57:11 -06:00
parent 9bfc0cd23b
commit f0cffd770a
10 changed files with 54 additions and 22 deletions

View File

@ -53,7 +53,7 @@ EOF
cat <<EOF
<section id="form">
<form id="puzzler" action="/puzzler.cgi" method="post" accept-charset="utf-8" autocomplete="off">
<form id="puzzler" action="../../cgi/puzzler.cgi" method="get" accept-charset="utf-8" autocomplete="off">
<input type="hidden" name="c" value="$cat">
<input type="hidden" name="p" value="$points">
<div>Team hash:<input name="t" size="8"></div>

View File

@ -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

View File

@ -33,7 +33,7 @@ function koth.page(title, body)
print()
end
print("<!DOCTYPE html>")
print("<html><head><title>" .. title .. "</title><link rel=\"stylesheet\" href=\"style.css\"><meta name=\"viewport\" content=\"width=device-width\"></head>")
print("<html><head><title>" .. title .. "</title><link rel=\"stylesheet\" href=\"../style.css\"><meta name=\"viewport\" content=\"width=device-width\"></head>")
print("<body><h1>" .. title .. "</h1>")
if (body) then
print("<section>")
@ -41,9 +41,9 @@ function koth.page(title, body)
print("</section>")
end
print([[<section id="sponsors">
<img src="images/lanl.png" alt="Los Alamos National Laboratory">
<img src="images/doe.png" alt="US Department Of Energy">
<img src="images/sandia.png" alt="Sandia National Laboratories">
<img src="../images/lanl.png" alt="Los Alamos National Laboratory">
<img src="../images/doe.png" alt="US Department Of Energy">
<img src="../images/sandia.png" alt="Sandia National Laboratories">
</section>]])
print("</body></html>")
@ -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

View File

@ -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

View File

@ -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 .. "<dt>" .. cat .. "</dt>"
body = body .. "<dd>"
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 .. "<a href=\"" .. cat .. "/" .. dirname .. "/index.html\">" .. points .. "</a> "
body = body .. "<a href=\"../" .. cat .. "/" .. dirname .. "/index.html\">" .. points .. "</a> "
if (points > biggest) then
break
end

View File

@ -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()

View File

@ -24,7 +24,7 @@
you don't need to do it again.
</p>
<form method="get" action="register.cgi">
<form method="get" action="cgi/register.cgi">
<label>Team Hash:</label>
<input type="text" name="h">
<br>

View File

@ -7,7 +7,7 @@
<script>
function init() {
var sb = document.getElementById("scoreboard");
scoreboard(sb);
scoreboard(sb, true);
}
window.addEventListener("load", init);

View File

@ -9,7 +9,7 @@ function loadJSON(url, callback) {
xhr.send();
}
function scoreboard(element) {
function scoreboard(element, continuous) {
function update(state) {
var teamnames = state["teams"];
var pointslog = state["points"];
@ -100,5 +100,11 @@ function scoreboard(element) {
}
}
function once() {
loadJSON("points.json", update);
}
if (continuous) {
setInterval(once, 60000);
}
once();
}