|
@ -1,10 +1,31 @@ |
|
|
#!/usr/bin/env lua |
|
|
#!/usr/bin/env lua |
|
|
|
|
|
|
|
|
local fcgi = require"fcgi" |
|
|
local fcgi = require"fcgi" |
|
|
|
|
|
local etlua = require"etlua" |
|
|
apps = { |
|
|
apps = { |
|
|
yqtemplate = require"yqtemplate" |
|
|
yqtemplate = require"yqtemplate" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
local template = etlua.compile[[ |
|
|
|
|
|
<!DOCTYPE html> |
|
|
|
|
|
<html> |
|
|
|
|
|
<head> |
|
|
|
|
|
<title>Annwan's CGI scripts</title> |
|
|
|
|
|
</head> |
|
|
|
|
|
<body> |
|
|
|
|
|
<% if app and app ~= nil then %> |
|
|
|
|
|
<p>No such application: <b><%= app -%></p> |
|
|
|
|
|
<% end %> |
|
|
|
|
|
<h1>Available Applications</h1> |
|
|
|
|
|
<ul> |
|
|
|
|
|
<% for name, appdata in pairs(apps) do %> |
|
|
|
|
|
<li><a href=/cgi/<%= name -%>><%=name -%></a>: <%= appdata.desc -%></li> |
|
|
|
|
|
<% end %> |
|
|
|
|
|
</ul> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html> |
|
|
|
|
|
]] |
|
|
|
|
|
|
|
|
while fcgi.accept() do |
|
|
while fcgi.accept() do |
|
|
app = fcgi.getenv("DOCUMENT_URI"):sub(6) |
|
|
app = fcgi.getenv("DOCUMENT_URI"):sub(6) |
|
|
appfn = apps[app] |
|
|
appfn = apps[app] |
|
@ -12,20 +33,9 @@ while fcgi.accept() do |
|
|
appfn.run(fcgi) |
|
|
appfn.run(fcgi) |
|
|
else |
|
|
else |
|
|
fcgi.print"Content-Type: text/html; charset=utf-8\r\n\r\n" |
|
|
fcgi.print"Content-Type: text/html; charset=utf-8\r\n\r\n" |
|
|
fcgi.print[[<!DOCTYPE html> |
|
|
|
|
|
<html> |
|
|
|
|
|
<head><title>Annwan's CGI scripts</title></head> |
|
|
|
|
|
<body>]] |
|
|
|
|
|
if app and app ~= "" then |
|
|
|
|
|
fcgi.print("<p>No such application: <b>" .. app .. "</b></p̬>\n") |
|
|
|
|
|
end |
|
|
|
|
|
fcgi.print("<p>Available applications:</p><ul>") |
|
|
|
|
|
for n, x in pairs(apps) do |
|
|
|
|
|
fcgi.print("<li><b><a href=/cgi/" .. n .. ">" .. n .. "</a></b> " .. x.desc .. "</li>") |
|
|
|
|
|
end |
|
|
|
|
|
fcgi.print[[ |
|
|
|
|
|
</ul> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html>]] |
|
|
|
|
|
|
|
|
fcgi.print(template{ |
|
|
|
|
|
app = app, |
|
|
|
|
|
apps = apps |
|
|
|
|
|
}) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |