aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xzzcxz.cgi65
1 files changed, 57 insertions, 8 deletions
diff --git a/zzcxz.cgi b/zzcxz.cgi
index 52314ba..a650e98 100755
--- a/zzcxz.cgi
+++ b/zzcxz.cgi
@@ -92,11 +92,20 @@ local function parse_qs(str,sep)
return values
end
+<<<<<<< HEAD
+local cookies = env "HTTP_COOKIE" and parse_qs(env "HTTP_COOKIE","; ") or {}
+local flags = {}
+for k,v in pairs(cookies) do
+ local flag = k:match "flag_(.+)"
+ if flag then
+ flags[flag] = v
+=======
local cookies = parse_qs(env "HTTP_COOKIE", "; ")
local flags = {}
for k, v in pairs(cookies) do
if k:sub(1,5) == "flag_" then
flags[k:sub(6)] = v
+>>>>>>> master
end
end
@@ -165,14 +174,19 @@ local function parse_directive(line, directives)
directives.redirect = redirect
elseif directive == "set" then
if args:match "^%s*$" then return end
- local flagname = args:match "^%s*(%w+)%s*$"
- 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
+ local flagname, text = args:match "^%s*(%w+)%s*(.-)%s*$"
+ if not flagname then return end
+ text = text or ""
+ if utf8.len(flagname) > 150 or utf8.len(text) > 1000 then
+ return
end
- if utf8.len(flagname) > 150 then return end
- directives.flags[flagname] = text
+ directives.flags_updated[flagname] = text
+ flags[flagname] = text
+ elseif directive == "unset" then
+ local flagname = args:match "^%s*(%w+)%s*$"
+ if not flagname then return end
+ directives.flags_updated[flagname] = false
+ flags[flagname] = nil
else
return
end
@@ -182,8 +196,12 @@ end
local load_page
local function convert_markup(m)
local result = {}
+<<<<<<< HEAD
+ local directives = {flags_updated = {}}
+=======
local directives = {}
directives.flags = {}
+>>>>>>> master
local code_block = false
for line in (m..'\n'):gmatch "(.-)\n" do
if not code_block then
@@ -278,7 +296,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)
@@ -322,10 +341,13 @@ 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)
+<<<<<<< HEAD
+=======
local cookies = {}
for k,v in pairs(directives.flags) do
table.insert(cookies,"flag_"..k.."="..url_encode(v).."; Secure")
end
+>>>>>>> master
if env "REQUEST_METHOD" ~= "POST" then
local actions = {}
for _,a in ipairs(page.actions) do
@@ -342,14 +364,33 @@ map["^/g/(%w%w%w%w%w)$"] = function(p)
)
end
+ local cookies = {}
+ for flagname, text in pairs(directives.flags_updated) do
+ if text then
+ table.insert(cookies,
+ ('flag_%s=%s; secure; max-age=999999999999')
+ :format(flagname, url_encode(text)))
+ else
+ -- clear the cookie by expiring it in the past
+ table.insert(cookies,
+ ('flag_%s=; expires=Thu, 01 Jan 1970 00:00:00 GMT;')
+ :format(flagname))
+ end
+ end
+
return base {
title = html_encode(page.title),
content = page_template {
title = html_encode(page.title),
content = convert_markup(page.content),
actions = table.concat(actions),
+<<<<<<< HEAD
+ }
+ }, {headers = {["set-cookie"] = cookies, bee = "apio form"}}
+=======
},
}, {headers = {["set-cookie"] = cookies, bees = "3.14"}}
+>>>>>>> master
else
if directives.deadend then
return base {
@@ -495,12 +536,20 @@ resp.content_type = resp.content_type or 'text/html'
resp.status = resp.status or '200 OK'
resp.headers = resp.headers or {}
resp.headers['content-type'] = resp.content_type
+<<<<<<< HEAD
+resp.headers.apioform = 3.5
+print("status: "..resp.status)
+for k,v in pairs(resp.headers) do
+ if type(v) == "table" then
+ for _,v2 in ipairs(v) do
+=======
resp.headers['apioforms'] = math.random(0,104942)/2
print("status: "..resp.status)
for k,v in pairs(resp.headers) do
if type(v) == "table" then
for _, v2 in ipairs(v) do
+>>>>>>> master
print(("%s: %s"):format(k, v2))
end
else