aboutsummaryrefslogtreecommitdiff
path: root/www/cgi-bin/test.lua
blob: c86b3f5bc05ec246e2599d073567b7be91e0962b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env luajit

local cgi = require("cgi")
local req_params = require("req-params")
local str=""

if req_params.param("password") and req_params.param("password") == "401" then
    cgi.render("401 Unauthorized",{["Content-Type"]="text/html"},401)
    return
end

-- Access GET parameters
if next(req_params.get_params) then
    str=str..m("h2","GET parameters:")
    for k,v in pairs(req_params.get_params) do
        str=str..k.." = "..v.."<br>"
    end
end

-- Access POST parameters
if next(req_params.post_params) then
    str=str..m("h2","POST parameters:")
    for k,v in pairs(req_params.post_params) do
        str=str..k.." = "..v.."<br>"
    end
end

-- Combined helper
local name = req_params.param("name") or "anonymous"
str=str..m("p","Hello, "..name.."!")

cgi.render(m("html",
    m("head",
        m("title","ssg test")
    )..
    m("body",
        m("h1","Hello from Lua CGI")..
        m("p", "ssg test")..
        m("p",_VERSION)..
        str
    )
),
{["Content-Type"]="text/html"},200)