s/koth/moth/g

This commit is contained in:
John Donaldson 2018-09-09 11:11:51 -05:00
parent 811307b8ce
commit 9b3e44563b
7 changed files with 44 additions and 44 deletions

View File

@ -99,7 +99,7 @@ Installing Puzzle Categories
Puzzle categories are distributed in a different way than the server.
After setting up (see above), just run
$ /srv/koth/mycontest/bin/install-category /path/to/my/category
$ /srv/moth/mycontest/bin/install-category /path/to/my/category
Permissions

View File

@ -1,12 +1,12 @@
#! /bin/sh
cd ${1:-$(dirname $0)}
KOTH_BASE=$(pwd)
MOTH_BASE=$(pwd)
echo "Running koth instances in $KOTH_BASE"
echo "Running moth instances in $MOTH_BASE"
while true; do
for i in $KOTH_BASE/*/assigned.txt; do
for i in $MOTH_BASE/*/assigned.txt; do
dir=${i%/*}
$dir/bin/once
done

View File

@ -1,12 +1,12 @@
#! /bin/sh
cd ${1:-$(dirname $0)}
KOTH_BASE=$(pwd)
MOTH_BASE=$(pwd)
echo "Running koth instances in $KOTH_BASE"
echo "Running moth instances in $MOTH_BASE"
while true; do
for i in $KOTH_BASE/*/assigned.txt; do
for i in $MOTH_BASE/*/assigned.txt; do
dir=${i%/*}
$dir/bin/once
done

View File

@ -1,9 +1,9 @@
#! /usr/bin/env lua
local koth = {}
local moth = {}
-- cut -d$ANCHOR -f2- | grep -Fx "$NEEDLE"
function koth.anchored_search(haystack, needle, anchor)
function moth.anchored_search(haystack, needle, anchor)
local f, err = io.open(haystack)
if (not f) then
return false, err
@ -27,7 +27,7 @@ function koth.anchored_search(haystack, needle, anchor)
return false
end
function koth.page(title, body)
function moth.page(title, body)
if (os.getenv("REQUEST_METHOD")) then
print("Content-type: text/html")
print()
@ -62,7 +62,7 @@ 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)
function moth.award_points(team, category, points, comment)
team = team:gsub("[^0-9a-f]", "-")
if (team == "") then
team = "-"
@ -75,19 +75,19 @@ function koth.award_points(team, category, points, comment)
entry = entry .. " " .. comment
end
local f = io.open(koth.path("state/teams/" .. team))
local f = io.open(moth.path("state/teams/" .. team))
if (f) then
f:close()
else
return false, "No such team"
end
local ok = koth.anchored_search(koth.path("state/points.log"), entry, " ")
local ok = moth.anchored_search(moth.path("state/points.log"), entry, " ")
if (ok) then
return false, "Points already awarded"
end
local f = io.open(koth.path("state/points.new/" .. filename), "a")
local f = io.open(moth.path("state/points.new/" .. filename), "a")
if (not f) then
return false, "Unable to write to points file"
end
@ -101,19 +101,19 @@ end
-- Most web servers cd to the directory containing the CGI.
-- Not uhttpd.
koth.base = ""
function koth.path(p)
return koth.base .. p
moth.base = ""
function moth.path(p)
return moth.base .. p
end
-- Traverse up to find assigned.txt
for i = 0, 5 do
local f = io.open(koth.path("state/assigned.txt"))
local f = io.open(moth.path("state/assigned.txt"))
if (f) then
f:close()
break
end
koth.base = koth.base .. "../"
moth.base = moth.base .. "../"
end
return koth
return moth

View File

@ -3,7 +3,7 @@
package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
local cgi = require "cgi"
local koth = require "koth"
local moth = require "moth"
local team = cgi.fields['t'] or ""
local category = cgi.fields['c'] or ""
@ -15,20 +15,20 @@ category = category:gsub("[^A-Za-z0-9_]", "-")
-- Check answer
local needle = points .. " " .. answer
local haystack = koth.path("packages/" .. category .. "/answers.txt")
local found, err = koth.anchored_search(haystack, needle)
local haystack = moth.path("packages/" .. category .. "/answers.txt")
local found, err = moth.anchored_search(haystack, needle)
if (not found) then
koth.page("Wrong answer", err)
moth.page("Wrong answer", err)
end
local ok, err = koth.award_points(team, category, points)
local ok, err = moth.award_points(team, category, points)
if (not ok) then
koth.page("Error awarding points",
moth.page("Error awarding points",
"<p>You got the right answer, but there was a problem trying to give you points:</p>" ..
"<p>" .. err .. "</p>")
end
koth.page("Points awarded",
moth.page("Points awarded",
"<p>" .. points .. " points for " .. team .. "!</p>" ..
"<p><a href=\"../puzzles.html\">Back to puzzles</a></p>")

View File

@ -4,7 +4,7 @@ package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
local cgi = require "cgi"
local koth = require "koth"
local moth = require "moth"
local team = cgi.fields["n"] or ""
local hash = cgi.fields["h"] or ""
@ -12,22 +12,22 @@ 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(koth.path("state/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?")
moth.page("Invalid Entry", "Oops! Are you sure you got that right?")
elseif (not moth.anchored_search(moth.path("state/assigned.txt"), hash)) then
moth.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(koth.path("state/teams/" .. hash))
local f = io.open(moth.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.")
moth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
end
local f, err = io.open(koth.path("state/teams/" .. hash), "w+")
local f, err = io.open(moth.path("state/teams/" .. hash), "w+")
if (not f) then
koth.page("Kersplode", err)
moth.page("Kersplode", err)
end
f:write(team)
f:close()
koth.page("Success", "Okay, your team has been named and you may begin using your hash!")
moth.page("Success", "Okay, your team has been named and you may begin using your hash!")

View File

@ -3,36 +3,36 @@
package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
local cgi = require "cgi"
local koth = require "koth"
local moth = require "moth"
local team = cgi.fields['t'] or ""
local token = cgi.fields['k'] or ""
-- Check answer
local needle = token
local haystack = koth.path("state/tokens.txt")
local found, err = koth.anchored_search(haystack, needle)
local haystack = moth.path("state/tokens.txt")
local found, err = moth.anchored_search(haystack, needle)
if (not found) then
koth.page("Unrecognized token", err)
moth.page("Unrecognized token", err)
end
local category, points = token:match("^(.*):(.*):")
if ((category == nil) or (points == nil)) then
koth.page("Unrecognized token", "Something doesn't look right about that token")
moth.page("Unrecognized token", "Something doesn't look right about that token")
end
points = tonumber(points)
-- Defang category name; prevent directory traversal
category = category:gsub("[^A-Za-z0-9]", "-")
local ok, err = koth.award_points(team, category, points, token)
local ok, err = moth.award_points(team, category, points, token)
if (not ok) then
koth.page("Error awarding points",
moth.page("Error awarding points",
"<p>You entered a valid token, but there was a problem trying to give you points:</p>" ..
"<p>" .. err .. "</p>")
end
koth.page("Points awarded",
moth.page("Points awarded",
"<p>" .. points .. " points for " .. team .. "!</p>" ..
"<p><a href=\"../puzzles.html\">Back to puzzles</a></p>")