]> Untitled Git - public.git/blob - lua/dump_files.lua
4f98bcb5b953ddc1bda98f8c5f35f87f94c45f33
[public.git] / lua / dump_files.lua
1 require "apache2"
2
3 --[[
4     Dumps all the published links
5 --]]
6 function dump_files(t, r, dir)
7         for _, f in ipairs(r:get_direntries(dir)) do
8         if f ~= "." and f ~= ".." then
9             local filepath = dir .. "/" .. f
10             local info = r:stat(filepath)
11             if info then
12                 -- if this is a file, then add it to the table!
13                 if info.filetype == 1 then
14                     t[filepath] = info
15                 end
16
17                 -- if this is a dir, then descend into it
18                 if info.filetype == 2 then
19                     dump_files(t, r, filepath)
20                 end
21             end
22         end
23         end
24 end
25
26 function handle(r)
27     r.content_type = "text/plain"
28
29     if r.method == 'GET' then
30         local links = {}
31         dump_files(links, r, r.document_root)
32
33         for filepath, info in pairs(links) do
34             r:puts( ("%s\n"):format(
35                 filepath:gsub(r.document_root, r.server_name .. ":" ..r.port)
36             ))
37         end
38     else
39         return 501
40     end
41     return apache2.OK
42 end