mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2024-12-29 16:14:36 +00:00
things
This commit is contained in:
parent
6e0afc292b
commit
585dd5ac36
1 changed files with 28 additions and 3 deletions
|
@ -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("<", "<"):gsub("<", "<")
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue