file_list.lua 786 B

1234567891011121314151617181920
  1. return function (connection, args)
  2. connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\Cache-Control: private, no-store\r\n\r\n")
  3. connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Server File Listing</title></head>')
  4. connection:send('<body>')
  5. connection:send('<h1>Server File Listing</h1>')
  6. connection:send("<ul>\n")
  7. local l = file.list()
  8. for name, size in pairs(l) do
  9. local isHttpFile = string.match(name, "(http/)") ~= nil
  10. local url = string.match(name, ".*/(.*)")
  11. if isHttpFile then
  12. connection:send(' <li><a href="' .. url .. '">' .. url .. "</a> (" .. size .. " bytes)</li>\n")
  13. end
  14. end
  15. connection:send("</ul>\n")
  16. connection:send('</body></html>')
  17. end