#!/usr/bin/env cgilua.cgi CGILua Test <% require"cgilua.cookies" if cgilua.POST.user then cgilua.cookies.sethtml("cookie_kepler", cgilua.POST.user) end %>
CGILua simple tests

Form Handling

Entering values on this form should display them as values in the first submission, and as a cookie in the next submission

The values should show the previous POST

Values: Username = <%= cgilua.POST.user or "(not set)"%>, Password = <%= cgilua.POST.pass or "(not set)"%>

Cookies test

Here you should see the values posted before the ones shown above

cookie_kepler = <%= cgilua.cookies.get("cookie_kepler") or "(not set)" %>

File Upload

Choose a file to upload, press "Upload" and a link to the file should appear below with the corresponding "Remove" button.

<% local f = cgilua.POST.file if f and next(f) then local _, name = cgilua.splitonlast(f.filename) local file = f.file local dest = io.open(name, "wb") if dest then local bytes = file:read("*a") dest:write(bytes) dest:close() cgilua.print(""..name.."\n") cgilua.print([[
]]) cgilua.print([[]]) cgilua.print([[]]) cgilua.print([[
]]) end end %> <% if cgilua.POST.remove then os.remove(cgilua.POST.filename) end %> <% local function showtable(t) cgilua.put "{" for i,v in pairs (t) do cgilua.put("\n") if type(v) == "table" then local vv = "{\n" for a,b in pairs(v) do vv = string.format ("%s %s = [[%s]],\n", vv, a, tostring(b)) end v = vv.." }," cgilua.put (string.format (" %s = %s", i, tostring(v))) else cgilua.put (string.format (" %s = [[%s]],", i, tostring(v))) end end if next(t) then cgilua.put "\n" end cgilua.put "}\n" end %>

cgilua.QUERY

<% showtable (cgilua.QUERY) %>

cgilua.POST

<% showtable (cgilua.POST) %>

CGILua Variables

<% local vars = { "script_file", "script_path", "script_pdir", "script_vdir", "script_vpath", "urlpath", } for _, v in ipairs(vars) do %> <% end %>
cgilua.<%= v %><%= tostring(cgilua[v]) %>

Server Variables

<% local vars = { "SERVER_SOFTWARE", "SERVER_NAME", "SERVER_PROTOCOL", "SERVER_PORT", "GATEWAY_INTERFACE", "REQUEST_METHOD", "SCRIPT_NAME", "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING", "CONTENT_TYPE", "CONTENT_LENGTH", "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_USER", "REMOTE_IDENT", "AUTH_TYPE", } for _, v in ipairs(vars) do %> <% end %>
<%= v %><%= tostring(cgilua.servervariable(v)) %>

Multiple Output

The next test should show numbers, from 1 to 3, and the string "OK" together. The first line should show the results without spaces and the second should separate them with tabs.

cgilua.put(1, 2, 3, "OK")   --> <% cgilua.put(1, 2, 3, "OK") %>

The next test should show numbers, from 1 to 3, and the string "OK" separated by tabs.

cgilua.print(1, 2, 3, "OK") --> <% cgilua.print(1, 2, 3, "OK") %>

Date

Today is: <%= os.date() %>

Image test

Here should be a small image: a small photograph

FileSystem test

<% local d = lfs.currentdir () or "" cgilua.put("Iterating over "..d.."
") for file in lfs.dir(d) do cgilua.put("   "..file.."
") end %>

Containment test

<% if (x == nil) then x = 1 else x = x + 1 end %> Expected value: 1, actual value: <%= x %>.

Valid XHTML 1.0

$Id: test.lp,v 1.3 2008/07/03 20:34:36 carregal Exp $