mirror of https://github.com/dirtbags/moth.git
Token submission
This commit is contained in:
parent
22d02c3eff
commit
dd4c6b30b6
|
@ -44,6 +44,14 @@ for cat, biggest in pairs(max_by_cat) do
|
|||
body = body .. "</dd>\n"
|
||||
end
|
||||
body = body .. "</dl>\n"
|
||||
body = body .. "<fieldset><legend>Sandia Token:</legend>"
|
||||
body = body .. "<p>Example: <samp>sandia:5:xylep-radar-nanox</samp></p>"
|
||||
body = body .. "<form action='cgi-bin/token.cgi'>"
|
||||
body = body .. "Team Hash: <input name='t'><br>"
|
||||
body = body .. "Token: <input name='k'>"
|
||||
body = body .. "<input type='submit'>"
|
||||
body = body .. "</form>"
|
||||
body = body .. "</fieldset>"
|
||||
body = body .. "<p>Reloading this page periodically may yield updated puzzle lists.</p>"
|
||||
|
||||
koth.page("Open Puzzles", body)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#! /usr/bin/env lua
|
||||
|
||||
package.path = "?.lua;cgi-bin/?.lua;www/cgi-bin/?.lua"
|
||||
|
||||
local cgi = require "cgi"
|
||||
local koth = require "koth"
|
||||
|
||||
local team = cgi.fields['t'] or ""
|
||||
local token = cgi.fields['k'] or ""
|
||||
|
||||
-- Defang category name; prevent directory traversal
|
||||
category = category:gsub("[^A-Za-z0-9]", "-")
|
||||
|
||||
-- Check answer
|
||||
local needle = token
|
||||
local haystack = koth.path("tokens.txt")
|
||||
local found, err = koth.anchored_search(haystack, needle)
|
||||
|
||||
if (not found) then
|
||||
koth.page("Unrecognized token", err)
|
||||
end
|
||||
|
||||
local category, points = token.match("^(.*):(.*):")
|
||||
if ((category == nil) || (points == nil)) then
|
||||
koth.page("Unrecognized token", "Something doesn't look right about that token")
|
||||
end
|
||||
points = tonumber(points)
|
||||
|
||||
local ok, err = koth.award_points(team, category, points, token)
|
||||
if (not ok) then
|
||||
koth.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",
|
||||
"<p>" .. points .. " points for " .. team .. "!</p>" ..
|
||||
"<p><a href=\"../puzzles.html\">Back to puzzles</a></p>")
|
Loading…
Reference in New Issue