aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http_files.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-12-11 23:40:30 +0100
committerKim Alvefur <zash@zash.se>2012-12-11 23:40:30 +0100
commit8c8d3b759f1d99a687f859c2ca96bf008bcd24ec (patch)
tree01480064b551797a731a1c5e9711d20bace32942 /plugins/mod_http_files.lua
parentf0449e8428793c51d3ef5776b883a140cc84237f (diff)
downloadprosody-8c8d3b759f1d99a687f859c2ca96bf008bcd24ec.tar.gz
prosody-8c8d3b759f1d99a687f859c2ca96bf008bcd24ec.zip
mod_http_files: Generate simple directory index.
Diffstat (limited to 'plugins/mod_http_files.lua')
-rw-r--r--plugins/mod_http_files.lua25
1 files changed, 23 insertions, 2 deletions
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua
index f4246fd5..764991b8 100644
--- a/plugins/mod_http_files.lua
+++ b/plugins/mod_http_files.lua
@@ -15,6 +15,7 @@ local stat = lfs.attributes;
local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files"));
local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" });
+local show_file_list = module:get_option_boolean("http_files_show_list");
local mime_map = module:shared("mime").types;
if not mime_map then
@@ -79,8 +80,28 @@ function serve_file(event, path)
end
end
- -- TODO File listing
- return 403;
+ if not show_file_list then
+ return 403;
+ else
+ local html = require"util.stanza".stanza("html")
+ :tag("head"):tag("title"):text(path):up()
+ :tag("meta", { charset="utf-8" }):up()
+ :up()
+ :tag("body"):tag("h1"):text(path):up()
+ :tag("ul");
+ for file in lfs.dir(full_path) do
+ if file:sub(1,1) ~= "." then
+ local attr = stat(full_path..file) or {};
+ html:tag("li", { class = attr.mode })
+ :tag("a", { href = file }):text(file)
+ :up():up();
+ end
+ end
+ data = "<!DOCTYPE html>\n"..tostring(html);
+ cache[path] = { data = html, content_type = mime_map.html; hits = 0 };
+ response.headers.content_type = mime_map.html;
+ end
+
else
local f = open(full_path, "rb");
data = f and f:read("*a");