file_list.lua 1.1 KB

123456789101112131415161718192021222324252627
  1. return function (connection, req, args)
  2. connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nCache-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. local remaining, used, total=file.fsinfo()
  7. connection:send("<b>Total size: </b> " .. total .. " bytes<br/>\n")
  8. connection:send("<b>In Use: </b> " .. used .. " bytes<br/>\n")
  9. connection:send("<b>Free: </b> " .. remaining .. " bytes<br/>\n")
  10. connection:send("<p>\n")
  11. connection:send("<b>Files:</b><br/>\n")
  12. connection:send("<ul>\n")
  13. for name, size in pairs(file.list()) do
  14. local isHttpFile = string.match(name, "(http/)") ~= nil
  15. if isHttpFile then
  16. local url = string.match(name, ".*/(.*)")
  17. connection:send(' <li><a href="' .. url .. '">' .. url .. "</a> (" .. size .. " bytes)</li>\n")
  18. end
  19. end
  20. connection:send("</ul>\n")
  21. connection:send("</p>\n")
  22. connection:send('</body></html>')
  23. end