aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-02-07 14:43:23 -0600
committerthe lemons <citrons@mondecitronne.com>2022-02-07 14:43:23 -0600
commit870ccb5124109afadb42691efea8cb727cbde326 (patch)
tree487ccc458252884f22f4ecc259dc13dd019ceafb
parent08fdf170d51768125fc104ff964bb3bad29f3891 (diff)
bugfixes and miscellaneous improvements
-rwxr-xr-xzzcxz.cgi30
1 files changed, 19 insertions, 11 deletions
diff --git a/zzcxz.cgi b/zzcxz.cgi
index 74dbfc5..7fa53ee 100755
--- a/zzcxz.cgi
+++ b/zzcxz.cgi
@@ -92,11 +92,12 @@ local function parse_qs(str,sep)
return values
end
-local cookies = parse_qs(env "HTTP_COOKIE","; ")
+local cookies = env "HTTP_COOKIE" and parse_qs(env "HTTP_COOKIE","; ") or {}
local flags = {}
for k,v in pairs(cookies) do
- if k:sub(1,5) == "flag_" then
- flags[k:sub(6)] = v
+ local flag = k:match "flag_(.+)"
+ if flag then
+ flags[flag] = v
end
end
@@ -168,10 +169,13 @@ local function parse_directive(line, directives)
local text = ""
if not flagname then
flagname, text = args:match "^%s*(%w+)%s*(%w+)%s*$"
- if not flagname or not text or utf8.len(text) > 1000 then return end
+ if not flagname or not text or utf8.len(text) > 1000 then
+ return
+ end
end
if utf8.len(flagname) > 150 then return end
- directives.flags["flag_"..flagname] = url_encode(text)
+ directives.flags_updated[flagname] = text
+ flags[flagname] = text
else
return
end
@@ -181,7 +185,7 @@ end
local load_page
local function convert_markup(m)
local result = {}
- local directives = {flags={}}
+ local directives = {flags_updated = {}}
local code_block = false
for line in (m..'\n'):gmatch "(.-)\n" do
if not code_block then
@@ -276,7 +280,8 @@ local function new_action(page, action, result)
::generate_name::
local new_name = {}
for i=1,5 do
- table.insert(new_name, string.char(string.byte 'a' + math.random(0,25)))
+ table.insert(new_name, string.char(
+ string.byte 'a' + math.random(0,25)))
end
new_name = table.concat(new_name)
@@ -320,10 +325,6 @@ map["^/g/(%w%w%w%w%w)$"] = function(p)
local page = load_page(p)
if not page then return not_found() end
local _, directives = convert_markup(page.content)
- local cookies = {}
- for k,v in pairs(directives.flags) do
- table.insert(cookies,k.."="..v.."; Secure; Max-Age=1000000000")
- end
if env "REQUEST_METHOD" ~= "POST" then
local actions = {}
for _,a in ipairs(page.actions) do
@@ -340,6 +341,13 @@ map["^/g/(%w%w%w%w%w)$"] = function(p)
)
end
+ local cookies = {}
+ for flagname, text in pairs(directives.flags_updated) do
+ table.insert(cookies,
+ ('flag_%s=%s; Secure; Max-Age=999999999')
+ :format(flagname, url_encode(text)))
+ end
+
return base {
title = html_encode(page.title),
content = page_template {