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. Puzzle categories are distributed in a different way than the server.
After setting up (see above), just run 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 Permissions

View File

@ -1,12 +1,12 @@
#! /bin/sh #! /bin/sh
cd ${1:-$(dirname $0)} 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 while true; do
for i in $KOTH_BASE/*/assigned.txt; do for i in $MOTH_BASE/*/assigned.txt; do
dir=${i%/*} dir=${i%/*}
$dir/bin/once $dir/bin/once
done done

View File

@ -1,12 +1,12 @@
#! /bin/sh #! /bin/sh
cd ${1:-$(dirname $0)} 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 while true; do
for i in $KOTH_BASE/*/assigned.txt; do for i in $MOTH_BASE/*/assigned.txt; do
dir=${i%/*} dir=${i%/*}
$dir/bin/once $dir/bin/once
done done

View File

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

View File

@ -3,7 +3,7 @@
package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua" package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
local cgi = require "cgi" local cgi = require "cgi"
local koth = require "koth" local moth = require "moth"
local team = cgi.fields['t'] or "" local team = cgi.fields['t'] or ""
local category = cgi.fields['c'] or "" local category = cgi.fields['c'] or ""
@ -15,20 +15,20 @@ category = category:gsub("[^A-Za-z0-9_]", "-")
-- Check answer -- Check answer
local needle = points .. " " .. answer local needle = points .. " " .. answer
local haystack = koth.path("packages/" .. category .. "/answers.txt") local haystack = moth.path("packages/" .. category .. "/answers.txt")
local found, err = koth.anchored_search(haystack, needle) local found, err = moth.anchored_search(haystack, needle)
if (not found) then if (not found) then
koth.page("Wrong answer", err) moth.page("Wrong answer", err)
end end
local ok, err = koth.award_points(team, category, points) local ok, err = moth.award_points(team, category, points)
if (not ok) then 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>You got the right answer, but there was a problem trying to give you points:</p>" ..
"<p>" .. err .. "</p>") "<p>" .. err .. "</p>")
end end
koth.page("Points awarded", moth.page("Points awarded",
"<p>" .. points .. " points for " .. team .. "!</p>" .. "<p>" .. points .. " points for " .. team .. "!</p>" ..
"<p><a href=\"../puzzles.html\">Back to puzzles</a></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 cgi = require "cgi"
local koth = require "koth" local moth = require "moth"
local team = cgi.fields["n"] or "" local team = cgi.fields["n"] or ""
local hash = cgi.fields["h"] or "" local hash = cgi.fields["h"] or ""
@ -12,22 +12,22 @@ local hash = cgi.fields["h"] or ""
hash = hash:match("[0-9a-f]*") 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?") moth.page("Invalid Entry", "Oops! Are you sure you got that right?")
elseif (not koth.anchored_search(koth.path("state/assigned.txt"), hash)) then elseif (not moth.anchored_search(moth.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 Hash", "Oops! I don't have a record of that hash. Did you maybe use capital letters accidentally?")
end end
local f = io.open(koth.path("state/teams/" .. hash)) local f = io.open(moth.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.") moth.page("Already Exists", "Your team has already been named! Maybe somebody on your team beat you to it.")
end 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 if (not f) then
koth.page("Kersplode", err) moth.page("Kersplode", err)
end end
f:write(team) f:write(team)
f:close() 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" package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
local cgi = require "cgi" local cgi = require "cgi"
local koth = require "koth" local moth = require "moth"
local team = cgi.fields['t'] or "" local team = cgi.fields['t'] or ""
local token = cgi.fields['k'] or "" local token = cgi.fields['k'] or ""
-- Check answer -- Check answer
local needle = token local needle = token
local haystack = koth.path("state/tokens.txt") local haystack = moth.path("state/tokens.txt")
local found, err = koth.anchored_search(haystack, needle) local found, err = moth.anchored_search(haystack, needle)
if (not found) then if (not found) then
koth.page("Unrecognized token", err) moth.page("Unrecognized token", err)
end end
local category, points = token:match("^(.*):(.*):") local category, points = token:match("^(.*):(.*):")
if ((category == nil) or (points == nil)) then 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 end
points = tonumber(points) points = tonumber(points)
-- Defang category name; prevent directory traversal -- Defang category name; prevent directory traversal
category = category:gsub("[^A-Za-z0-9]", "-") 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 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>You entered a valid token, but there was a problem trying to give you points:</p>" ..
"<p>" .. err .. "</p>") "<p>" .. err .. "</p>")
end end
koth.page("Points awarded", moth.page("Points awarded",
"<p>" .. points .. " points for " .. team .. "!</p>" .. "<p>" .. points .. " points for " .. team .. "!</p>" ..
"<p><a href=\"../puzzles.html\">Back to puzzles</a></p>") "<p><a href=\"../puzzles.html\">Back to puzzles</a></p>")