mirror of https://github.com/dirtbags/moth.git
More last-minute tweaks
This commit is contained in:
parent
d310ed3f74
commit
4c91d0ad93
|
@ -53,7 +53,7 @@ EOF
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
<section id="form">
|
<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="c" value="$cat">
|
||||||
<input type="hidden" name="p" value="$points">
|
<input type="hidden" name="p" value="$points">
|
||||||
<div>Team hash:<input name="t" size="8"></div>
|
<div>Team hash:<input name="t" size="8"></div>
|
||||||
|
|
2
bin/once
2
bin/once
|
@ -23,7 +23,7 @@ find state/points.new -type f | while read fn; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Generate new puzzles.html
|
# 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
|
mv www/puzzles.new www/puzzles.html
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ function koth.page(title, body)
|
||||||
print()
|
print()
|
||||||
end
|
end
|
||||||
print("<!DOCTYPE html>")
|
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>")
|
print("<body><h1>" .. title .. "</h1>")
|
||||||
if (body) then
|
if (body) then
|
||||||
print("<section>")
|
print("<section>")
|
||||||
|
@ -41,9 +41,9 @@ function koth.page(title, body)
|
||||||
print("</section>")
|
print("</section>")
|
||||||
end
|
end
|
||||||
print([[<section id="sponsors">
|
print([[<section id="sponsors">
|
||||||
<img src="images/lanl.png" alt="Los Alamos National Laboratory">
|
<img src="../images/lanl.png" alt="Los Alamos National Laboratory">
|
||||||
<img src="images/doe.png" alt="US Department Of Energy">
|
<img src="../images/doe.png" alt="US Department Of Energy">
|
||||||
<img src="images/sandia.png" alt="Sandia National Laboratories">
|
<img src="../images/sandia.png" alt="Sandia National Laboratories">
|
||||||
</section>]])
|
</section>]])
|
||||||
|
|
||||||
print("</body></html>")
|
print("</body></html>")
|
||||||
|
@ -63,19 +63,19 @@ function koth.award_points(team, category, points, comment)
|
||||||
entry = entry .. " " .. comment
|
entry = entry .. " " .. comment
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = io.open("../state/teams/" .. team)
|
local f = io.open(koth.path("state/teams/" .. team))
|
||||||
if (f) then
|
if (f) then
|
||||||
f:close()
|
f:close()
|
||||||
else
|
else
|
||||||
return false, "No such team"
|
return false, "No such team"
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok = koth.anchored_search("../state/points.log", entry, " ")
|
local ok = koth.anchored_search(koth.path("state/points.log"), entry, " ")
|
||||||
if (ok) then
|
if (ok) then
|
||||||
return false, "Points already awarded"
|
return false, "Points already awarded"
|
||||||
end
|
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
|
if (not f) then
|
||||||
return false, "Unable to write to points file"
|
return false, "Unable to write to points file"
|
||||||
end
|
end
|
||||||
|
@ -86,5 +86,22 @@ function koth.award_points(team, category, points, comment)
|
||||||
return true
|
return true
|
||||||
end
|
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
|
return koth
|
|
@ -1,5 +1,7 @@
|
||||||
#! /usr/bin/lua
|
#! /usr/bin/lua
|
||||||
|
|
||||||
|
package.path = "?.lua;cgi/?.lua;www/cgi/?.lua"
|
||||||
|
|
||||||
local cgi = require "cgi"
|
local cgi = require "cgi"
|
||||||
local koth = require "koth"
|
local koth = require "koth"
|
||||||
|
|
||||||
|
@ -13,7 +15,7 @@ category = category:gsub("[^A-Za-z0-9]", "-")
|
||||||
|
|
||||||
-- Check answer
|
-- Check answer
|
||||||
local needle = points .. " " .. 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)
|
local found, err = koth.anchored_search(haystack, needle)
|
||||||
|
|
||||||
if (not found) then
|
if (not found) then
|
|
@ -1,18 +1,19 @@
|
||||||
#! /usr/bin/lua
|
#! /usr/bin/lua
|
||||||
|
|
||||||
package.path = "www/?.lua"
|
package.path = "?.lua;cgi/?.lua;www/cgi/?.lua"
|
||||||
|
|
||||||
local koth = require "koth"
|
local koth = require "koth"
|
||||||
|
|
||||||
local max_by_cat = {}
|
local max_by_cat = {}
|
||||||
|
|
||||||
local f = io.popen("ls packages")
|
local f = io.popen("ls " .. koth.path("packages"))
|
||||||
for cat in f:lines() do
|
for cat in f:lines() do
|
||||||
max_by_cat[cat] = 0
|
max_by_cat[cat] = 0
|
||||||
end
|
end
|
||||||
f:close()
|
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+) ?(.*)")
|
local ts, team, cat, points, comment = line:match("^(%d+) (%w+) (%w+) (%d+) ?(.*)")
|
||||||
points = tonumber(points) or 0
|
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 .. "<dt>" .. cat .. "</dt>"
|
||||||
body = body .. "<dd>"
|
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, dirname = line:match("^(%d+) (.*)")
|
||||||
points = tonumber(points)
|
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
|
if (points > biggest) then
|
||||||
break
|
break
|
||||||
end
|
end
|
|
@ -1,5 +1,8 @@
|
||||||
#! /usr/bin/lua
|
#! /usr/bin/lua
|
||||||
|
|
||||||
|
package.path = "?.lua;cgi/?.lua;www/cgi/?.lua"
|
||||||
|
|
||||||
|
|
||||||
local cgi = require "cgi"
|
local cgi = require "cgi"
|
||||||
local koth = require "koth"
|
local koth = require "koth"
|
||||||
|
|
||||||
|
@ -10,17 +13,20 @@ hash = hash:match("[0-9a-f]*")
|
||||||
|
|
||||||
if ((hash == "") or (team == "")) then
|
if ((hash == "") or (team == "")) then
|
||||||
koth.page("Invalid Entry", "Oops! Are you sure you got that right?")
|
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?")
|
koth.page("Invalid Hash", "Oops! I don't have a record of that hash. Did you maybe use capital letters accidentally?")
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = io.open("../state/teams/" .. hash)
|
local f = io.open(koth.path("state/teams/" .. hash))
|
||||||
if (f) then
|
if (f) then
|
||||||
f:close()
|
f:close()
|
||||||
koth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
|
koth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
|
||||||
end
|
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:write(team)
|
||||||
f:close()
|
f:close()
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
you don't need to do it again.
|
you don't need to do it again.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form method="get" action="register.cgi">
|
<form method="get" action="cgi/register.cgi">
|
||||||
<label>Team Hash:</label>
|
<label>Team Hash:</label>
|
||||||
<input type="text" name="h">
|
<input type="text" name="h">
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<script>
|
<script>
|
||||||
function init() {
|
function init() {
|
||||||
var sb = document.getElementById("scoreboard");
|
var sb = document.getElementById("scoreboard");
|
||||||
scoreboard(sb);
|
scoreboard(sb, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", init);
|
window.addEventListener("load", init);
|
||||||
|
|
|
@ -9,7 +9,7 @@ function loadJSON(url, callback) {
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function scoreboard(element) {
|
function scoreboard(element, continuous) {
|
||||||
function update(state) {
|
function update(state) {
|
||||||
var teamnames = state["teams"];
|
var teamnames = state["teams"];
|
||||||
var pointslog = state["points"];
|
var pointslog = state["points"];
|
||||||
|
@ -100,5 +100,11 @@ function scoreboard(element) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadJSON("points.json", update);
|
function once() {
|
||||||
|
loadJSON("points.json", update);
|
||||||
|
}
|
||||||
|
if (continuous) {
|
||||||
|
setInterval(once, 60000);
|
||||||
|
}
|
||||||
|
once();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue