]> Untitled Git - public.git/blob - lua/dump_files.lua
Hotfix for nonce URL
[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         -- get all local symlinks
31         local links = {}
32         dump_files(links, r, r.document_root)
33
34         -- if FQDN override is set,
35         -- use override instead of my own server name and port number
36         local fqdn = os.getenv('PUBLIC_FQDN_OVERRIDE')
37         fqdn = fqdn or r.server_name .. ":" ..r.port
38
39         -- print each link
40         for filepath, info in pairs(links) do
41             r:puts( ("%s\n"):format(
42                 filepath:gsub(r.document_root, fqdn)
43             ))
44         end
45     else
46         return 501
47     end
48     return apache2.OK
49 end