]> Untitled Git - public.git/blob - lua/publish.lua
Updated publish with FQDN override
[public.git] / lua / publish.lua
1 require "apache2"
2
3 function publish(dir, pattern)
4     local cmd = ("%s/publish.sh %s"):format(dir, pattern)
5     local handle = io.popen(cmd)
6     local output = handle:read('*a')
7     handle:close()
8
9     return output
10 end
11
12 function get_form(dir)
13     local handle = io.open(dir .. '/submit.html')
14     local output = handle:read('*a')
15     handle:close()
16
17     return output;
18 end
19
20 function handle(r)
21     r.content_type = "text/html"
22
23     local args = r:parseargs()
24     local pattern = args.pattern 
25
26     if pattern then
27         local nonce = publish(r.context_document_root, pattern)
28
29         -- if FQDN override is set,
30         -- use override instead of my own server name and port number
31         local fqdn = os.getenv('PUBLIC_FQDN_OVERRIDE')
32         fqdn = fqdn or (r.is_https and "https" or "http") .. "://" .. r.server_name .. ":" ..r.port
33
34         local uri = ("%s/%s"):format(fqdn, nonce)
35         r:puts( ([[<a href="%s">%s</a>]]):format(uri, uri) )
36     else
37         local template = get_form(r.context_document_root)
38         r:puts( template )
39     end
40
41     return apache2.OK
42 end