2024-11-09 01:14:03 +00:00
|
|
|
#!/usr/bin/env lua
|
2024-11-04 17:12:10 +00:00
|
|
|
--[[
|
|
|
|
Abrechenbarkeit - A simple trust-based ledger
|
|
|
|
Copyright 2024 metamuffin
|
|
|
|
Copyright 2024 dasriley
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, version 3 of the License only.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2024-11-04 19:05:04 +00:00
|
|
|
]] --
|
2024-10-30 01:00:27 +00:00
|
|
|
|
2024-11-05 00:13:19 +00:00
|
|
|
-- TODO: allow unicode
|
|
|
|
-- TODO: somehow remove _opt variants
|
2024-11-04 23:29:54 +00:00
|
|
|
local matchers = {
|
|
|
|
time = "(%d+)",
|
2024-11-05 00:13:19 +00:00
|
|
|
user = "([%w_@ -]+)",
|
2024-11-05 00:36:00 +00:00
|
|
|
user_opt = "([%w_@ -]*)",
|
2024-11-04 23:29:54 +00:00
|
|
|
amount = "(-?%d+)",
|
2024-11-05 00:13:19 +00:00
|
|
|
amount_opt = "(-?%d*)",
|
|
|
|
comment = "([%w_ -]+)",
|
|
|
|
comment_opt = "([%w_ -]*)",
|
|
|
|
barcode = "([%w_-]+)",
|
|
|
|
barcode_opt = "([%w_-]*)",
|
|
|
|
name = "([%w_ -]+)",
|
2024-11-04 23:29:54 +00:00
|
|
|
}
|
|
|
|
local matchers_global = (function()
|
|
|
|
local s = {}
|
|
|
|
for k, v in pairs(matchers) do s[k] = ("^%s$"):format(v) end
|
|
|
|
return s
|
|
|
|
end)()
|
|
|
|
|
2024-10-30 01:00:27 +00:00
|
|
|
local function escape(s)
|
|
|
|
return s:gsub("<", "<"):gsub("<", "<")
|
|
|
|
end
|
2024-10-31 01:00:42 +00:00
|
|
|
|
2024-10-30 12:50:36 +00:00
|
|
|
local function urldecode(s)
|
|
|
|
if s == nil then return nil end
|
2024-11-04 23:29:54 +00:00
|
|
|
local t, _ = s:gsub("+", " "):gsub("%%(%x%x)",
|
|
|
|
function(cap) return string.char(tonumber(cap, 16)) end)
|
|
|
|
return t
|
2024-10-30 12:50:36 +00:00
|
|
|
end
|
2024-10-31 01:00:42 +00:00
|
|
|
|
2024-10-30 12:50:36 +00:00
|
|
|
local function urlencode(s)
|
|
|
|
if s == nil then return nil end
|
2024-11-04 23:29:54 +00:00
|
|
|
return s:gsub("[^%w]",
|
2024-11-05 00:36:00 +00:00
|
|
|
function(cap) return string.format("%%%02x", string.byte(cap, 1)) end)
|
2024-10-30 12:50:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function parse_query(q)
|
|
|
|
if q == nil then return {} end
|
|
|
|
local data = {}
|
|
|
|
for pair in string.gmatch(q, "([^&]+)") do
|
|
|
|
local flag = string.match(pair, "^([^=]+)$")
|
|
|
|
if flag ~= nil then
|
|
|
|
data[flag] = "1"
|
|
|
|
else
|
|
|
|
local key, value = string.match(pair, "^([^=]+)=([^=]*)$")
|
|
|
|
if key ~= nil and value ~= nil then
|
|
|
|
data[key] = urldecode(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return data
|
|
|
|
end
|
|
|
|
|
2024-10-30 22:09:58 +00:00
|
|
|
local function load_config()
|
|
|
|
local log = io.open("config", "r")
|
|
|
|
if log == nil then return {} end
|
|
|
|
local config = {}
|
|
|
|
for l in log:lines("l") do
|
|
|
|
if l ~= "" and l[0] ~= "#" then
|
|
|
|
local key, value = string.match(l, "^([^=]+)=([^=]*)")
|
|
|
|
if key ~= nil and value ~= nil then
|
|
|
|
config[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return config
|
|
|
|
end
|
|
|
|
|
2024-11-04 19:05:04 +00:00
|
|
|
local function load_translations(langs)
|
|
|
|
local t = {}
|
|
|
|
for _, lcode in ipairs(langs) do
|
|
|
|
local file = io.open(string.format("locale/%s.ini", lcode), "r")
|
|
|
|
if file ~= nil then
|
|
|
|
for l in file:lines("l") do
|
|
|
|
if l ~= "" then
|
2024-11-05 00:54:30 +00:00
|
|
|
local key, value = string.match(l, "^([^=%s]+)%s?=%s?([^=]*)")
|
2024-11-04 19:05:04 +00:00
|
|
|
if key ~= nil and value ~= nil then
|
2024-11-04 23:29:54 +00:00
|
|
|
t["+" .. key] = value
|
2024-11-04 19:05:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2024-10-30 22:09:58 +00:00
|
|
|
local config = load_config()
|
2024-10-30 12:50:36 +00:00
|
|
|
local path = os.getenv("PATH_INFO")
|
|
|
|
local method = os.getenv("REQUEST_METHOD")
|
|
|
|
local query = parse_query(os.getenv("QUERY_STRING"))
|
2024-11-04 19:05:04 +00:00
|
|
|
local translations = load_translations({ "en", config.language })
|
2024-10-30 12:50:36 +00:00
|
|
|
|
2024-11-03 17:38:21 +00:00
|
|
|
local stylesheet = io.open("style.css"):read("a")
|
|
|
|
local script = io.open("script.js"):read("a")
|
2024-10-30 12:50:36 +00:00
|
|
|
|
2024-11-04 19:05:04 +00:00
|
|
|
local function format(template, params)
|
2024-11-04 21:06:07 +00:00
|
|
|
params = params or {}
|
|
|
|
if template == nil then return "NIL TEMPLATE" end
|
2024-11-04 23:29:54 +00:00
|
|
|
local s, _ = string.gsub(template, "{([%w\\+_\\.!]+)}", function(n)
|
|
|
|
local esc = n:sub(1, 1) == "!"
|
|
|
|
if esc then n = n:sub(2) end
|
|
|
|
local s = params[n] or translations[n] or "NIL PARAM"
|
|
|
|
if not esc then s = format(s, params) end
|
|
|
|
return esc and escape(s) or s
|
2024-11-04 19:05:04 +00:00
|
|
|
end)
|
2024-11-04 23:29:54 +00:00
|
|
|
return s
|
2024-11-04 19:05:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function format_amount(amount, tag, classes)
|
2024-11-06 19:48:09 +00:00
|
|
|
local s = format("{+price.amount}", {
|
2024-11-10 19:58:55 +00:00
|
|
|
sign = amount >= 0 and "+" or "-",
|
|
|
|
amount = string.format("%.2f", math.abs(amount / 100)),
|
|
|
|
unit = config.unit or "€"
|
2024-11-06 19:48:09 +00:00
|
|
|
})
|
2024-11-04 19:05:04 +00:00
|
|
|
if tag == nil then return s end
|
2024-11-04 23:29:54 +00:00
|
|
|
return format(
|
2024-11-05 21:21:19 +00:00
|
|
|
[[<{tag} class="amount-{sign} {classes}">{content}</{tag}>]], {
|
|
|
|
tag = tag,
|
|
|
|
sign = amount >= 0 and "pos" or "neg",
|
|
|
|
classes = classes or "",
|
|
|
|
content = s
|
|
|
|
})
|
2024-11-04 19:05:04 +00:00
|
|
|
end
|
|
|
|
|
2024-11-03 22:33:09 +00:00
|
|
|
local function get_user_theme(username)
|
|
|
|
local c = ""
|
|
|
|
if username == "_jeb" then
|
|
|
|
c = "html { animation: 2s jeb infinite; }"
|
|
|
|
c = c .. "@keyframes jeb {\n"
|
2024-11-04 15:16:28 +00:00
|
|
|
for i = 0, 100 do
|
2024-11-03 22:33:09 +00:00
|
|
|
c = c .. string.format("%.02f%% { --hue: %.02f; } \n", i, i / 100 * 360)
|
|
|
|
end
|
|
|
|
c = c .. "\n}"
|
|
|
|
elseif username == "Dinnerbone" then
|
2024-11-04 10:59:53 +00:00
|
|
|
c = "html { transform: scale(-1); } "
|
2024-11-03 22:33:09 +00:00
|
|
|
end
|
2024-11-04 19:05:04 +00:00
|
|
|
return c
|
2024-11-03 22:33:09 +00:00
|
|
|
end
|
|
|
|
|
2024-11-04 19:05:04 +00:00
|
|
|
local function format_duration(t)
|
2024-11-04 23:29:54 +00:00
|
|
|
local unit = nil
|
|
|
|
local n = nil
|
|
|
|
if t > 86400 then
|
|
|
|
n = math.floor(t / 86400)
|
|
|
|
unit = "day"
|
|
|
|
elseif t > 3600 then
|
|
|
|
n = math.floor(t / 3600)
|
|
|
|
unit = "hour"
|
|
|
|
elseif t > 60 then
|
|
|
|
n = math.floor(t / 60)
|
|
|
|
unit = "minute"
|
|
|
|
else
|
|
|
|
n = t
|
|
|
|
unit = "second"
|
|
|
|
end
|
|
|
|
return format("{+time.delta_past}",
|
|
|
|
{ n = n, unit = translations["+time." .. unit .. (n ~= 1 and "s" or "")] })
|
2024-11-04 19:05:04 +00:00
|
|
|
end
|
2024-11-04 10:59:53 +00:00
|
|
|
|
2024-11-04 19:05:04 +00:00
|
|
|
local function respond(status, title, body)
|
2024-10-30 01:00:27 +00:00
|
|
|
print(string.format("Status: %d", status))
|
|
|
|
print("Content-Type: text/html")
|
|
|
|
print("")
|
2024-11-04 19:05:04 +00:00
|
|
|
print(format([[
|
2024-10-30 21:00:15 +00:00
|
|
|
<!DOCTYPE html>
|
2024-10-30 01:00:27 +00:00
|
|
|
<html><head>
|
2024-11-04 19:05:04 +00:00
|
|
|
<title>{title}</title>
|
2024-10-30 01:00:27 +00:00
|
|
|
<meta charset="utf-8" />
|
2024-11-04 19:05:04 +00:00
|
|
|
<style>{style}</style>
|
|
|
|
<style>{user_style}</style>
|
|
|
|
<script>{script}</script>
|
|
|
|
{head_extra}
|
2024-10-30 12:50:36 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<nav>
|
2024-11-03 17:31:13 +00:00
|
|
|
<a class="logo" href="/">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-receipt-cutoff" viewBox="0 0 16 16">
|
|
|
|
<path d="M3 4.5a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5M11.5 4a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1z"/>
|
|
|
|
<path d="M2.354.646a.5.5 0 0 0-.801.13l-.5 1A.5.5 0 0 0 1 2v13H.5a.5.5 0 0 0 0 1h15a.5.5 0 0 0 0-1H15V2a.5.5 0 0 0-.053-.224l-.5-1a.5.5 0 0 0-.8-.13L13 1.293l-.646-.647a.5.5 0 0 0-.708 0L11 1.293l-.646-.647a.5.5 0 0 0-.708 0L9 1.293 8.354.646a.5.5 0 0 0-.708 0L7 1.293 6.354.646a.5.5 0 0 0-.708 0L5 1.293 4.354.646a.5.5 0 0 0-.708 0L3 1.293zm-.217 1.198.51.51a.5.5 0 0 0 .707 0L4 1.707l.646.647a.5.5 0 0 0 .708 0L6 1.707l.646.647a.5.5 0 0 0 .708 0L8 1.707l.646.647a.5.5 0 0 0 .708 0L10 1.707l.646.647a.5.5 0 0 0 .708 0L12 1.707l.646.647a.5.5 0 0 0 .708 0l.509-.51.137.274V15H2V2.118z"/>
|
|
|
|
</svg>
|
2024-11-04 23:29:54 +00:00
|
|
|
{+appname}
|
2024-11-04 19:05:04 +00:00
|
|
|
</a>
|
2024-11-08 23:35:52 +00:00
|
|
|
<a href="/?users">{+users}</a>
|
|
|
|
<a href="/?spus">{+spus}</a>
|
2024-11-04 23:29:54 +00:00
|
|
|
<a href="/?products">{+products}</a>
|
2024-11-08 23:35:52 +00:00
|
|
|
<a href="/?log">{+log}</a>
|
2024-11-04 23:29:54 +00:00
|
|
|
<a href="/?about">{+about}</a>
|
2024-10-30 12:50:36 +00:00
|
|
|
</nav>
|
2024-11-04 19:05:04 +00:00
|
|
|
]], {
|
|
|
|
title = escape(title),
|
|
|
|
style = stylesheet,
|
|
|
|
user_style = get_user_theme(path and path:sub(2)),
|
|
|
|
script = script,
|
|
|
|
head_extra = config.head_extra or ""
|
|
|
|
}))
|
2024-11-08 23:35:52 +00:00
|
|
|
if config.header ~= nil then
|
|
|
|
print(config.header)
|
|
|
|
end
|
2024-10-30 01:00:27 +00:00
|
|
|
body()
|
2024-11-08 23:35:52 +00:00
|
|
|
if config.footer ~= nil then
|
|
|
|
print(config.footer)
|
|
|
|
end
|
2024-11-04 19:05:04 +00:00
|
|
|
print("</body></html>")
|
2024-10-30 01:00:27 +00:00
|
|
|
end
|
|
|
|
|
2024-11-10 19:58:55 +00:00
|
|
|
local function error_box(message, params)
|
|
|
|
return string.format([[<div class="notif error"><p>Error: %s</p></div>]], escape(format(message, params)))
|
2024-11-04 13:44:56 +00:00
|
|
|
end
|
|
|
|
|
2024-10-30 01:00:27 +00:00
|
|
|
local function respond_error(message)
|
|
|
|
respond(400, "Error", function()
|
2024-11-10 19:58:55 +00:00
|
|
|
print(error_box("{!x}", { x = message }))
|
2024-10-30 01:00:27 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2024-10-30 11:20:03 +00:00
|
|
|
local function redirect(path)
|
|
|
|
print("Status: 307")
|
|
|
|
print(string.format("Location: %s", path))
|
|
|
|
print()
|
|
|
|
end
|
|
|
|
|
2024-10-30 01:00:27 +00:00
|
|
|
local function form_data()
|
2024-10-30 12:50:36 +00:00
|
|
|
return parse_query(io.read())
|
2024-10-30 01:00:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function read_log()
|
|
|
|
local log = io.open("log", "r")
|
|
|
|
if log == nil then
|
|
|
|
return function() return nil end
|
|
|
|
end
|
|
|
|
local lines = log:lines("l")
|
|
|
|
return function()
|
|
|
|
local l = lines()
|
2024-10-30 12:50:36 +00:00
|
|
|
if l == "" or l == nil then
|
|
|
|
return nil
|
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
local time, user_src, user_dst, amount, pcode, pcount, comment = string.match(l,
|
2024-11-05 00:13:19 +00:00
|
|
|
format("^{time},{user},{user},{amount},{barcode_opt},{amount_opt},{comment_opt}$", matchers))
|
2024-11-04 23:29:54 +00:00
|
|
|
return tonumber(time), user_src, user_dst, tonumber(amount), pcode, tonumber(pcount), comment
|
2024-10-30 01:00:27 +00:00
|
|
|
end
|
|
|
|
end
|
2024-10-31 01:00:42 +00:00
|
|
|
|
2024-10-30 12:50:36 +00:00
|
|
|
local function read_products()
|
|
|
|
local log = io.open("products", "r")
|
|
|
|
if log == nil then
|
|
|
|
return function() return nil end
|
|
|
|
end
|
|
|
|
local lines = log:lines("l")
|
|
|
|
return function()
|
|
|
|
local l = lines()
|
|
|
|
if l == "" or l == nil then
|
|
|
|
return nil
|
|
|
|
end
|
2024-11-05 00:36:00 +00:00
|
|
|
local barcode, price, user, name = string.match(l, format("^{barcode},{amount},{user_opt},{name}$", matchers))
|
2024-11-04 23:29:54 +00:00
|
|
|
return barcode, tonumber(price), user, name
|
2024-10-30 12:50:36 +00:00
|
|
|
end
|
|
|
|
end
|
2024-10-30 01:00:27 +00:00
|
|
|
|
2024-10-30 01:11:09 +00:00
|
|
|
local function balances()
|
|
|
|
local users = {}
|
2024-11-04 23:29:54 +00:00
|
|
|
for _, user_src, user_dst, amount, _, _, _ in read_log() do
|
|
|
|
users[user_src] = (users[user_src] or 0) - amount
|
|
|
|
users[user_dst] = (users[user_dst] or 0) + amount
|
2024-10-30 01:11:09 +00:00
|
|
|
end
|
|
|
|
return users
|
|
|
|
end
|
2024-10-31 01:00:42 +00:00
|
|
|
|
2024-11-03 18:38:24 +00:00
|
|
|
local function product_balances()
|
|
|
|
local products = {}
|
2024-11-04 23:29:54 +00:00
|
|
|
for _, _, _, _, pcode, pcount, _ in read_log() do
|
2024-11-03 18:38:24 +00:00
|
|
|
if pcode ~= nil and pcount ~= nil then
|
|
|
|
products[pcode] = (products[pcode] or 0) + pcount
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return products
|
|
|
|
end
|
|
|
|
|
2024-10-30 21:00:15 +00:00
|
|
|
local function last_txns()
|
|
|
|
local users = {}
|
2024-11-04 23:29:54 +00:00
|
|
|
for time, user_src, user_dst, _, _, _, _ in read_log() do
|
|
|
|
users[user_src] = time
|
|
|
|
users[user_dst] = time
|
2024-10-30 01:00:27 +00:00
|
|
|
end
|
2024-10-30 21:00:15 +00:00
|
|
|
return users
|
|
|
|
end
|
|
|
|
|
2024-11-03 21:23:21 +00:00
|
|
|
local function get_active_users()
|
2024-11-03 21:34:04 +00:00
|
|
|
local user_balances = {}
|
2024-11-04 23:29:54 +00:00
|
|
|
for time, user_src, user_dst, amount, _, _, _ in read_log() do
|
|
|
|
user_balances[user_src] = {
|
|
|
|
time = time,
|
2024-11-05 00:13:19 +00:00
|
|
|
name = user_src,
|
2024-11-04 23:29:54 +00:00
|
|
|
balance = (user_balances[user_src] or { balance = 0 }).balance - amount
|
|
|
|
}
|
|
|
|
user_balances[user_dst] = {
|
2024-11-03 21:34:04 +00:00
|
|
|
time = time,
|
2024-11-05 00:13:19 +00:00
|
|
|
name = user_dst,
|
2024-11-04 23:29:54 +00:00
|
|
|
balance = (user_balances[user_dst] or { balance = 0 }).balance + amount
|
2024-11-03 21:23:21 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-11-03 21:34:04 +00:00
|
|
|
local users = {}
|
|
|
|
for _, user in pairs(user_balances) do
|
|
|
|
table.insert(users, user)
|
|
|
|
end
|
|
|
|
|
2024-11-12 23:39:43 +00:00
|
|
|
table.sort(users, function(a, b) return ((a.time == b.time) and a.name > b.name) or (a.time > b.time) end)
|
2024-11-03 21:23:21 +00:00
|
|
|
return users
|
|
|
|
end
|
|
|
|
|
2024-11-05 00:13:19 +00:00
|
|
|
local function r_transaction_post()
|
2024-10-30 21:00:15 +00:00
|
|
|
local data = form_data()
|
2024-11-05 00:13:19 +00:00
|
|
|
local user_src = data.user_src
|
2024-11-04 23:29:54 +00:00
|
|
|
local user_dst = data.user_dst
|
2024-11-03 20:21:35 +00:00
|
|
|
local amount = tonumber(data.amount)
|
2024-11-04 23:29:54 +00:00
|
|
|
local pcode = data.pcode
|
|
|
|
local pcount = tonumber(data.pcount)
|
2024-11-03 20:21:35 +00:00
|
|
|
local comment = data.comment
|
2024-11-05 00:13:19 +00:00
|
|
|
if pcode ~= nil and pcode ~= "" then
|
2024-11-04 23:29:54 +00:00
|
|
|
local exists = false
|
|
|
|
for p_barcode, p_amount, p_user, p_name in read_products() do
|
|
|
|
if p_barcode == pcode then
|
2024-11-03 20:21:35 +00:00
|
|
|
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
|
2024-11-04 23:29:54 +00:00
|
|
|
amount = amount or pcount * p_amount
|
2024-11-05 00:36:00 +00:00
|
|
|
user_src = user_src or p_user
|
2024-11-04 23:29:54 +00:00
|
|
|
comment = comment or
|
|
|
|
string.format("%s %d %s", pcount < 0 and "Buy" or "Restock", math.abs(pcount or 0), p_name)
|
|
|
|
exists = true
|
2024-10-30 12:50:36 +00:00
|
|
|
end
|
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
if not exists then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.unknown_product}")
|
2024-10-30 01:00:27 +00:00
|
|
|
end
|
|
|
|
end
|
2024-11-08 23:35:52 +00:00
|
|
|
user_src = user_src or "@Potential"
|
2024-10-30 21:00:15 +00:00
|
|
|
if amount == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_amount}")
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
2024-11-05 00:13:19 +00:00
|
|
|
if comment == nil or comment:match(matchers_global.comment_opt) == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_comment}")
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
if user_src == nil or user_src:match(matchers_global.user) == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_user_src}")
|
2024-11-04 23:29:54 +00:00
|
|
|
end
|
|
|
|
if user_dst == nil or user_dst:match(matchers_global.user) == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_user_dst}")
|
2024-11-04 23:29:54 +00:00
|
|
|
end
|
2024-10-30 21:00:15 +00:00
|
|
|
local log = io.open("log", "a+")
|
|
|
|
if log == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.open_log}")
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
|
|
|
local time = os.time()
|
2024-11-04 23:29:54 +00:00
|
|
|
log:write(string.format("%d,%s,%s,%d,%s,%s,%s\n",
|
|
|
|
time, user_src, user_dst, amount, pcode or "", pcount or "", comment))
|
2024-10-30 21:00:15 +00:00
|
|
|
log:flush()
|
|
|
|
log:close()
|
2024-11-04 19:05:04 +00:00
|
|
|
return format([[
|
2024-11-04 23:29:54 +00:00
|
|
|
<div class="notif"><p>{+user.form.transaction.success}: {amount} ({!comment})</p></div>
|
2024-11-04 19:05:04 +00:00
|
|
|
<audio src="{sound}" autoplay></audio>
|
|
|
|
]], {
|
|
|
|
sign = amount >= 0 and "pos" or "neg",
|
|
|
|
amount = format_amount(amount, "strong"),
|
2024-11-04 23:29:54 +00:00
|
|
|
comment = comment,
|
2024-11-04 19:05:04 +00:00
|
|
|
sound = config.transaction_sound or ""
|
|
|
|
})
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
2024-10-30 01:00:27 +00:00
|
|
|
|
2024-10-30 21:00:15 +00:00
|
|
|
local function r_user(username)
|
|
|
|
local notif = nil
|
|
|
|
if method == "POST" then
|
2024-11-05 00:13:19 +00:00
|
|
|
notif = r_transaction_post()
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
2024-11-03 17:31:13 +00:00
|
|
|
return respond(200, string.format("Abrechenbarheit: %s", username), function()
|
2024-11-08 23:35:52 +00:00
|
|
|
local is_special = username:sub(1, 1) == "@"
|
|
|
|
local username_display = username:gsub("@", "")
|
2024-11-10 19:58:55 +00:00
|
|
|
print(format(is_special and "<h1><i>{!username}</i></h1>" or "<h1>{!username}</h1>",
|
|
|
|
{ username = username_display }))
|
2024-10-30 12:50:36 +00:00
|
|
|
local balance = balances()[username]
|
2024-10-30 21:00:15 +00:00
|
|
|
local last_txn = last_txns()[username]
|
2024-10-30 12:50:36 +00:00
|
|
|
local new_user = balance == nil
|
|
|
|
balance = balance or 0
|
2024-10-30 22:09:58 +00:00
|
|
|
if notif then print(notif) end
|
2024-11-08 23:35:52 +00:00
|
|
|
if is_special then
|
|
|
|
print(format([[<div class="notif"><p><i>{+user.special}</i></p></div>]]))
|
|
|
|
end
|
2024-10-30 12:50:36 +00:00
|
|
|
if new_user then
|
2024-11-04 23:29:54 +00:00
|
|
|
print(format([[<div class="notif"><p><i>{+user.lazy_creation}</i></p></div>]]))
|
2024-10-30 22:09:58 +00:00
|
|
|
else
|
2024-11-04 15:16:28 +00:00
|
|
|
print([[<div class="backgroundbox userinfo">]])
|
2024-11-04 23:29:54 +00:00
|
|
|
print(format([[{+user.balance}: <br>{amount}<br>]],
|
|
|
|
{ amount = format_amount(balance, "span", "balance-value") }))
|
|
|
|
print(format([[{+user.last_txn} <a href="/{username}?log">{+user.view_log}</a>]],
|
2024-11-04 19:05:04 +00:00
|
|
|
{ time = format_duration(os.time() - last_txn), username = urlencode(username) }))
|
2024-11-04 15:16:28 +00:00
|
|
|
print([[</div>]])
|
2024-10-30 12:50:36 +00:00
|
|
|
end
|
2024-11-03 18:38:22 +00:00
|
|
|
print([[<div class="transactions container firstchildlarge">]])
|
2024-11-03 20:21:35 +00:00
|
|
|
print([[<div class="amount-presets backgroundbox">]])
|
2024-11-03 17:31:13 +00:00
|
|
|
for _, type in ipairs({ 1, -1 }) do
|
|
|
|
for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
|
2024-11-04 23:29:54 +00:00
|
|
|
local a = amount * type
|
2024-11-08 23:35:52 +00:00
|
|
|
print(format([[<form action="" method="POST" class="{disable_class}">
|
2024-11-05 00:13:19 +00:00
|
|
|
<input type="text" name="user_dst" value="{!username}" hidden />
|
|
|
|
<input type="number" name="amount" value="{a_raw}" hidden />
|
|
|
|
<input type="text" name="comment" value="" hidden />
|
2024-11-04 23:29:54 +00:00
|
|
|
<input type="submit" value="{amount}" class="amount-{sign} button" />
|
|
|
|
</form>]], {
|
2024-11-05 00:13:19 +00:00
|
|
|
username = username,
|
2024-11-04 23:29:54 +00:00
|
|
|
a_raw = a,
|
|
|
|
amount = format_amount(a),
|
2024-11-08 23:35:52 +00:00
|
|
|
sign = a < 0 and "neg" or "pos",
|
|
|
|
disable_class = is_special and "disabled" or ""
|
2024-11-04 23:29:54 +00:00
|
|
|
}))
|
2024-11-03 17:31:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
print("</div>")
|
2024-11-04 19:05:04 +00:00
|
|
|
print(format([[
|
2024-11-08 23:35:52 +00:00
|
|
|
<form class="transaction box backgroundbox {disable_class}" action="" method="POST">
|
2024-11-04 23:29:54 +00:00
|
|
|
<h3>{+user.form.transaction}</h3>
|
2024-11-05 00:13:19 +00:00
|
|
|
<input type="text" name="user_dst" value="{!username}" hidden />
|
2024-11-03 19:58:57 +00:00
|
|
|
<label for="amount">Amount (ct): </label>
|
2024-11-03 17:31:13 +00:00
|
|
|
<input type="number" name="amount" id="amount" />
|
2024-10-30 01:00:27 +00:00
|
|
|
<label for="comment">Comment: </label>
|
2024-11-03 17:31:13 +00:00
|
|
|
<input type="text" name="comment" id="comment" />
|
2024-11-04 23:29:54 +00:00
|
|
|
<input type="submit" value="{+user.form.transaction.submit}" class="amount-ntr button" />
|
2024-10-30 01:00:27 +00:00
|
|
|
</form>
|
2024-11-08 23:35:52 +00:00
|
|
|
<form class="transaction box backgroundbox {disable_class}" action="" method="POST" id="buy_product">
|
2024-11-04 23:29:54 +00:00
|
|
|
<h3>{+user.form.buy}</h3>
|
2024-11-05 00:13:19 +00:00
|
|
|
<input type="text" name="user_dst" value="{!username}" hidden />
|
2024-11-03 20:21:35 +00:00
|
|
|
<input type="text" name="negate_pcount" value="1" hidden />
|
|
|
|
<label for="pcount">Count: </label>
|
|
|
|
<input type="number" name="pcount" id="pcount" value="1" />
|
2024-11-04 23:29:54 +00:00
|
|
|
<label for="pcode">{+field.barcode}: </label>
|
2024-11-03 20:21:35 +00:00
|
|
|
<input type="text" name="pcode" id="pcode" />
|
2024-11-04 23:29:54 +00:00
|
|
|
<input class="amount-neg button" type="submit" value="{+user.form.buy.submit}" />
|
2024-10-30 21:00:15 +00:00
|
|
|
</form>
|
2024-11-08 23:35:52 +00:00
|
|
|
<form class="transaction box backgroundbox {disable_class}" action="" method="POST" id="buy_product">
|
2024-11-04 23:29:54 +00:00
|
|
|
<h3>{+user.form.restock}</h3>
|
2024-11-05 00:13:19 +00:00
|
|
|
<input type="text" name="user_dst" value="{!username}" hidden />
|
2024-11-04 23:29:54 +00:00
|
|
|
<label for="pcount">{+field.count}: </label>
|
2024-11-03 20:21:35 +00:00
|
|
|
<input type="number" name="pcount" id="pcount" value="1" />
|
2024-11-04 23:29:54 +00:00
|
|
|
<label for="amount">{+field.upstream_price}: </label>
|
2024-11-03 20:21:35 +00:00
|
|
|
<input type="number" name="amount" id="amount" />
|
2024-11-04 23:29:54 +00:00
|
|
|
<label for="pcode">{+field.barcode}: </label>
|
2024-11-03 20:21:35 +00:00
|
|
|
<input type="text" name="pcode" id="pcode" />
|
2024-11-04 23:29:54 +00:00
|
|
|
<input type="submit" value="{+user.form.restock.submit}" class="button amount-pos" />
|
2024-11-03 20:21:35 +00:00
|
|
|
</form>
|
2024-11-08 23:35:52 +00:00
|
|
|
]], { username = username, disable_class = is_special and "disabled" or "" }))
|
2024-10-30 12:50:36 +00:00
|
|
|
print("</div>")
|
2024-10-30 01:00:27 +00:00
|
|
|
end)
|
|
|
|
end
|
2024-10-30 11:20:03 +00:00
|
|
|
|
2024-10-30 21:00:15 +00:00
|
|
|
local function r_log(filter)
|
2024-11-05 00:13:19 +00:00
|
|
|
local notif = nil
|
|
|
|
if method == "POST" then
|
|
|
|
notif = r_transaction_post()
|
|
|
|
end
|
2024-11-03 17:31:13 +00:00
|
|
|
return respond(200, "Abrechnungen", function()
|
2024-11-05 00:13:19 +00:00
|
|
|
if notif then print(notif) end
|
2024-11-04 23:29:54 +00:00
|
|
|
print([[<table class="log"]])
|
|
|
|
print(format([[<thead><tr>
|
|
|
|
<th>{+field.time}</th>
|
|
|
|
<th>{+field.username}</th>
|
|
|
|
<th>{+field.amount}</th>
|
|
|
|
<th>{+field.barcode}</th>
|
|
|
|
<th>{+field.count}</th>
|
|
|
|
<th>{+field.comment}</th>
|
|
|
|
<th>{+log.actions}</th>
|
|
|
|
</tr></thead>]]))
|
2024-11-04 12:47:45 +00:00
|
|
|
print("<tbody>")
|
2024-11-04 23:29:54 +00:00
|
|
|
for time, user_src, user_dst, amount, pcode, pcount, comment in read_log() do
|
|
|
|
if filter == nil or filter == user_src or filter == user_dst then
|
|
|
|
print(format([[
|
2024-10-30 23:19:10 +00:00
|
|
|
<tr>
|
2024-11-04 23:29:54 +00:00
|
|
|
<td>{time} ({time_delta})</td>
|
2024-11-05 00:36:00 +00:00
|
|
|
<td><a href="/{user_src_url}">{user_src}</a> → <a href="/{user_dst_url}">{user_dst}</a></td>
|
2024-11-04 23:29:54 +00:00
|
|
|
{amount}
|
|
|
|
<td>{pcode}</td>
|
|
|
|
<td>{pcount}</td>
|
|
|
|
<td>{comment}</td>
|
2024-10-30 23:19:10 +00:00
|
|
|
<td>
|
2024-11-05 00:13:19 +00:00
|
|
|
<form action="/?log" method="POST">
|
|
|
|
<input type="text" name="user_src" value="{user_src}" hidden />
|
|
|
|
<input type="text" name="user_dst" value="{user_dst}" hidden />
|
2024-11-04 23:29:54 +00:00
|
|
|
<input type="number" name="amount" value="{revert_amount}" hidden />
|
2024-11-05 00:13:19 +00:00
|
|
|
<input type="text" name="pcode" value="{pcode}" hidden />
|
2024-11-04 23:29:54 +00:00
|
|
|
<input type="number" name="pcount" value="{revert_pcount}" hidden />
|
|
|
|
<input type="text" name="comment" value="Revert {comment}" hidden />
|
2024-11-05 21:21:19 +00:00
|
|
|
<input type="submit" class="amount-ntr button" value="{+log.actions.revert}" />
|
2024-10-30 23:19:10 +00:00
|
|
|
</form>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2024-11-04 23:29:54 +00:00
|
|
|
]], {
|
|
|
|
time = os.date("!%Y-%m-%dT%H:%M:%SZ", time),
|
|
|
|
time_delta = format_duration(os.time() - time),
|
|
|
|
user_src = escape(user_src),
|
|
|
|
user_dst = escape(user_dst),
|
2024-11-05 00:36:00 +00:00
|
|
|
user_src_url = urlencode(user_src),
|
|
|
|
user_dst_url = urlencode(user_dst),
|
2024-11-04 23:29:54 +00:00
|
|
|
amount = format_amount(amount, "td"),
|
|
|
|
pcode = escape(pcode),
|
2024-11-08 23:50:54 +00:00
|
|
|
pcount = pcount and tostring(math.abs(pcount)) or "",
|
2024-11-04 23:29:54 +00:00
|
|
|
comment = escape(comment),
|
|
|
|
revert_amount = -amount,
|
2024-11-05 00:13:19 +00:00
|
|
|
revert_pcount = -(pcount or 0),
|
2024-11-04 23:29:54 +00:00
|
|
|
}))
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
2024-10-30 11:20:03 +00:00
|
|
|
end
|
2024-11-04 12:47:45 +00:00
|
|
|
print("</tbody>")
|
2024-10-30 11:20:03 +00:00
|
|
|
print("</table>")
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2024-11-08 23:35:52 +00:00
|
|
|
local function r_users(show_special)
|
2024-11-03 17:31:13 +00:00
|
|
|
return respond(200, "Abrechenbarkeit", function()
|
2024-11-13 18:43:44 +00:00
|
|
|
if not show_special then
|
|
|
|
print(format([[
|
|
|
|
<form action="/" method="GET" id="user_creation">
|
|
|
|
<h3>{+index.form.create_user}</h3>
|
|
|
|
<label for="username">{+field.username}: </label>
|
|
|
|
<input type="text" name="create_user" id="username" />
|
|
|
|
<input type="submit" value="{+index.form.create_user.submit}" class="button amount-ntr" />
|
|
|
|
</form>
|
|
|
|
]]))
|
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
print([[<div class="userlist"></div>]]) -- for printing
|
2024-11-03 21:55:29 +00:00
|
|
|
print([[<ul class="userlist">]])
|
2024-11-03 21:23:21 +00:00
|
|
|
for _, user in ipairs(get_active_users()) do
|
2024-11-08 23:35:52 +00:00
|
|
|
local is_spu = user.name:sub(1, 1) == "@"
|
|
|
|
if is_spu == show_special then
|
2024-11-05 00:13:19 +00:00
|
|
|
print(format([[<li>
|
|
|
|
<a href="/{username_url}">
|
|
|
|
<span class="name">{!username}</span>
|
|
|
|
{balance}
|
|
|
|
</a>
|
|
|
|
</li>]], {
|
|
|
|
username_url = urlencode(user.name),
|
2024-11-08 23:35:52 +00:00
|
|
|
username = user.name:gsub("@", ""),
|
2024-11-05 00:13:19 +00:00
|
|
|
balance = format_amount(user.balance, "span")
|
|
|
|
}))
|
|
|
|
end
|
2024-10-30 11:20:03 +00:00
|
|
|
end
|
|
|
|
print("</ul>")
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function r_create_user()
|
2024-10-30 12:50:36 +00:00
|
|
|
local username = query.create_user
|
2024-11-04 23:29:54 +00:00
|
|
|
if username:match(matchers_global.user) == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return respond_error(format("{+error.invalid_user}"))
|
2024-10-30 11:20:03 +00:00
|
|
|
end
|
2024-10-30 12:50:36 +00:00
|
|
|
return redirect(string.format("/%s", urlencode(username)))
|
2024-10-30 11:20:03 +00:00
|
|
|
end
|
|
|
|
|
2024-11-03 01:20:52 +00:00
|
|
|
local function r_products_post()
|
|
|
|
local data = form_data()
|
|
|
|
local barcode = data.barcode
|
2024-11-04 23:29:54 +00:00
|
|
|
if barcode == nil or barcode:match("^[%w_-]*$") == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_barcode}")
|
2024-11-03 01:20:52 +00:00
|
|
|
end
|
|
|
|
if data.delete then
|
|
|
|
local new_products = io.open("products.new", "w+")
|
|
|
|
if new_products == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.open_new_products}")
|
2024-11-03 01:20:52 +00:00
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
for a_barcode, price, user, name in read_products() do
|
2024-11-03 01:20:52 +00:00
|
|
|
if barcode ~= a_barcode then
|
2024-11-04 23:29:54 +00:00
|
|
|
new_products:write(string.format("%s,%d,%s,%s\n", a_barcode, price, user, name))
|
2024-11-03 01:20:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
new_products:flush()
|
|
|
|
new_products:close()
|
|
|
|
os.rename("products.new", "products")
|
|
|
|
else
|
|
|
|
local price = tonumber(data.price)
|
|
|
|
local name = data.name
|
2024-11-04 23:29:54 +00:00
|
|
|
local user = data.user
|
2024-11-03 01:20:52 +00:00
|
|
|
if price == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_price}")
|
2024-11-03 01:20:52 +00:00
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
if name == nil or name:match(matchers_global.name) == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_price}")
|
2024-11-03 01:20:52 +00:00
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
if user == nil or user:match(matchers_global.user) == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.invalid_user}")
|
2024-11-04 23:29:54 +00:00
|
|
|
end
|
2024-11-03 01:20:52 +00:00
|
|
|
local products = io.open("products", "a+")
|
|
|
|
if products == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return error_box("{+error.open_products}")
|
2024-11-03 01:20:52 +00:00
|
|
|
end
|
2024-11-04 23:29:54 +00:00
|
|
|
products:write(string.format("%s,%d,%s,%s\n", barcode, price, user, name))
|
2024-11-03 01:20:52 +00:00
|
|
|
products:flush()
|
|
|
|
products:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-31 01:00:42 +00:00
|
|
|
local function r_products()
|
2024-11-03 01:20:52 +00:00
|
|
|
local notif = nil
|
|
|
|
if method == "POST" then
|
|
|
|
notif = r_products_post()
|
|
|
|
end
|
|
|
|
respond(200, "Abrechenbare Product List", function()
|
2024-11-05 21:21:19 +00:00
|
|
|
print(format("<h1>{+products.title}</h1>"))
|
2024-11-03 01:20:52 +00:00
|
|
|
if notif then print(notif) end
|
2024-11-05 21:21:19 +00:00
|
|
|
print(format([[
|
2024-11-03 18:38:22 +00:00
|
|
|
<div class="container">
|
|
|
|
<form action="/?products" method="POST" class="box backgroundbox">
|
2024-11-05 21:21:19 +00:00
|
|
|
<h3>{+products.form.add}</h3>
|
2024-11-06 17:31:21 +00:00
|
|
|
<label for="name">{+field.name}: </label>
|
2024-11-03 18:38:22 +00:00
|
|
|
<input type="text" name="name" id="name" />
|
2024-11-06 17:31:21 +00:00
|
|
|
<label for="price">{+field.price}: </label>
|
2024-11-03 20:05:03 +00:00
|
|
|
<input type="number" name="price" id="price" />
|
2024-11-06 17:31:21 +00:00
|
|
|
<label for="user">{+field.user}: </label>
|
2024-11-04 23:29:54 +00:00
|
|
|
<input type="text" name="user" id="user" />
|
2024-11-06 17:31:21 +00:00
|
|
|
<label for="barcode">{+field.barcode}: </label>
|
2024-11-03 20:21:35 +00:00
|
|
|
<input type="text" name="barcode" id="barcode" />
|
2024-11-09 01:13:49 +00:00
|
|
|
<input type="submit" value="{+products.form.add.submit}" class="amount-ntr button" />
|
2024-11-03 01:20:52 +00:00
|
|
|
</form>
|
2024-11-03 18:38:22 +00:00
|
|
|
<form action="/?products" method="POST" class="box backgroundbox">
|
2024-11-05 21:21:19 +00:00
|
|
|
<h3>{+products.form.remove}</h3>
|
2024-11-03 01:20:52 +00:00
|
|
|
<input type="text" name="delete" value="1" hidden />
|
2024-11-06 17:31:21 +00:00
|
|
|
<label for="barcode">{+field.barcode}: </label>
|
2024-11-03 18:38:22 +00:00
|
|
|
<input type="text" name="barcode" id="barcode" />
|
2024-11-09 01:13:49 +00:00
|
|
|
<input type="submit" value="{+products.form.remove.submit}" class="amount-ntr button" />
|
2024-11-03 01:20:52 +00:00
|
|
|
</form>
|
2024-11-03 18:38:22 +00:00
|
|
|
</div>
|
2024-11-05 21:21:19 +00:00
|
|
|
]], {
|
|
|
|
currency = config.unit or "€",
|
|
|
|
}))
|
|
|
|
print(format([[<table class="productlist"><tr>
|
2024-11-06 17:31:21 +00:00
|
|
|
<th>{+field.name}</th>
|
|
|
|
<th>{+field.price}</th>
|
|
|
|
<th>{+field.barcode}</th>
|
|
|
|
<th>{+field.count}</th>
|
|
|
|
<th>{+field.user}</th>
|
2024-11-05 21:21:19 +00:00
|
|
|
</tr>]]))
|
2024-11-03 18:38:24 +00:00
|
|
|
local pbals = product_balances()
|
2024-11-04 23:29:54 +00:00
|
|
|
for barcode, price, user, name in read_products() do
|
2024-11-05 00:13:19 +00:00
|
|
|
print(format([[<tr>
|
2024-11-04 23:29:54 +00:00
|
|
|
<td>{!name}</td>
|
|
|
|
{price}
|
|
|
|
<td>{!barcode}</td>
|
|
|
|
<td>{!count}</td>
|
|
|
|
<td>{!user}</td>
|
|
|
|
</tr>]], {
|
|
|
|
name = name,
|
2024-11-05 00:13:19 +00:00
|
|
|
price = format_amount(-price, "td"),
|
2024-11-04 23:29:54 +00:00
|
|
|
barcode = barcode,
|
2024-11-05 00:36:00 +00:00
|
|
|
count = tostring(pbals[barcode] or 0),
|
2024-11-04 23:29:54 +00:00
|
|
|
user = user,
|
|
|
|
}))
|
2024-10-31 01:00:42 +00:00
|
|
|
end
|
|
|
|
print("</table>")
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2024-11-04 17:12:10 +00:00
|
|
|
local function r_about()
|
|
|
|
respond(200, "About Abrechenbarkeit", function()
|
2024-11-04 23:29:54 +00:00
|
|
|
print(format([[
|
|
|
|
<h1>{+about.title}</h1>
|
|
|
|
<p>{+about.desc}</p>
|
|
|
|
<p>{+about.license}<p>
|
|
|
|
<p>{+about.source}</p>
|
|
|
|
<p>{+about.thanks}</p>
|
|
|
|
]], {
|
|
|
|
issues = [[<a href="https://codeberg.org/metamuffin/strichliste/issues">]],
|
|
|
|
codeberg = [[<a href="https://codeberg.org/metamuffin/strichliste">]],
|
|
|
|
ae = [[</a>]],
|
|
|
|
}))
|
2024-11-04 17:12:10 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2024-10-30 21:00:15 +00:00
|
|
|
local function extract_username()
|
|
|
|
if path == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return respond_error(format("{+error.no_path}"))
|
2024-10-30 21:00:15 +00:00
|
|
|
end
|
|
|
|
local username = urldecode(path:sub(2))
|
2024-11-04 23:29:54 +00:00
|
|
|
if username == nil or username:match(matchers_global.user) == nil then
|
2024-10-30 21:00:15 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return username
|
|
|
|
end
|
|
|
|
|
2024-10-30 11:20:03 +00:00
|
|
|
if path == "/" then
|
2024-11-04 17:12:10 +00:00
|
|
|
if query.about then
|
|
|
|
return r_about()
|
|
|
|
elseif query.products then
|
2024-10-31 01:00:42 +00:00
|
|
|
return r_products()
|
|
|
|
elseif query.log then
|
2024-10-30 11:20:03 +00:00
|
|
|
return r_log()
|
2024-10-30 12:50:36 +00:00
|
|
|
elseif query.create_user then
|
2024-10-30 11:20:03 +00:00
|
|
|
return r_create_user()
|
2024-11-08 23:35:52 +00:00
|
|
|
elseif query.spus then
|
|
|
|
return r_users(true)
|
|
|
|
elseif query.users then
|
|
|
|
return r_users(false)
|
2024-10-30 11:20:03 +00:00
|
|
|
else
|
2024-11-08 23:35:52 +00:00
|
|
|
return r_users(false)
|
2024-10-30 11:20:03 +00:00
|
|
|
end
|
|
|
|
else
|
2024-10-30 21:00:15 +00:00
|
|
|
local username = extract_username()
|
2024-11-04 23:29:54 +00:00
|
|
|
if username == nil then
|
2024-11-10 19:58:55 +00:00
|
|
|
return respond_error(format("{+error.invalid_user}"))
|
2024-10-30 21:00:15 +00:00
|
|
|
elseif query.log then
|
|
|
|
return r_log(username)
|
|
|
|
else
|
|
|
|
return r_user(username)
|
|
|
|
end
|
2024-10-30 11:20:03 +00:00
|
|
|
end
|