This commit is contained in:
metamuffin 2024-10-30 02:11:09 +01:00
parent 6e0afc292b
commit 585dd5ac36
No known key found for this signature in database
GPG key ID: 718F9749DCDBD654

View file

@ -2,6 +2,7 @@
local path = os.getenv("PATH_INFO")
local method = os.getenv("REQUEST_METHOD")
local query = os.getenv("QUERY_STRING")
local function escape(s)
return s:gsub("<", "&lt;"):gsub("<", "&lt;")
@ -53,10 +54,34 @@ local function read_log()
end
end
local function balances()
local users = {}
for _, username, amount, _ in read_log() do
users[username] = (users[username] or 0) + amount
end
return users
end
if path == "/" then
print("Status: 200 OK")
print("Content-Type: text/plain")
print("")
if query == "?log" then
return respond(200, "Log", function()
print("<table>")
print("<tr><th>Time</th><th>Username</th><th>Amount</th><th>Comment</th></tr>")
for time, username, amount, comment in read_log() do
print(string.format("<tr><td>%d</td><td>%s</td><td>%.02f€</td><td>%s</td></tr>", time, escape(username),
amount / 100, escape(comment)))
end
print("</table>")
end)
end
return respond(200, "Users", function()
print("<ul>")
for username, balance in balances() do
print(string.format("<li><a href=\"/%s\">%s</a>: %.02f€</li>", escape(username), escape(username),
balance / 100))
end
print("</ul>")
end)
elseif path ~= nil then
local username = path:sub(2)
if username:match("^[%w_-]+$") == nil then