You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
871 B

  1. #!/usr/bin/env lua
  2. local fcgi = require"fcgi"
  3. local etlua = require"etlua"
  4. apps = {
  5. yqtemplate = require"yqtemplate"
  6. }
  7. local template = etlua.compile[[
  8. <!DOCTYPE html>
  9. <html>
  10. <head>
  11. <title>Annwan's CGI scripts</title>
  12. </head>
  13. <body>
  14. <% if app and app ~= "" then %>
  15. <p>No such application: <b><%= app -%></b></p>
  16. <% end %>
  17. <h1>Available Applications</h1>
  18. <ul>
  19. <% for name, appdata in pairs(apps) do %>
  20. <li><a href=/cgi/<%= name -%>><%=name -%></a>: <%= appdata.desc -%></li>
  21. <% end %>
  22. </ul>
  23. </body>
  24. </html>
  25. ]]
  26. while fcgi.accept() do
  27. app = fcgi.getenv("DOCUMENT_URI"):sub(6)
  28. appfn = apps[app]
  29. if appfn then
  30. appfn.run(fcgi)
  31. else
  32. fcgi.print"Content-Type: text/html; charset=utf-8\r\n\r\n"
  33. fcgi.print(template{
  34. app = app,
  35. apps = apps
  36. })
  37. end
  38. end