Commit 7f6b37b1 authored by Antoine Cellerier's avatar Antoine Cellerier

Misc changes to Lua HTTP interface: spelling, Load/Reload debug message now...

Misc changes to Lua HTTP interface: spelling, Load/Reload debug message now reflects real behavior, enforce .hosts files for directory listings, accept Lua code in CSS files too, remove useless "/old" exclusion.
parent f809a7d0
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
--[==========================================================================[ --[==========================================================================[
Configuration options: Configuration options:
* host: A host to listen on. * host: A host to listen on.
* dir: Directory to use a the http interface's root. * dir: Directory to use as the http interface's root.
* no_error_detail: If set, do not print the Lua error message when generating * no_error_detail: If set, do not print the Lua error message when generating
a page fails. a page fails.
* no_index: If set, don't build directory indexes * no_index: If set, don't build directory indexes
...@@ -69,14 +69,17 @@ function process_raw(filename) ...@@ -69,14 +69,17 @@ function process_raw(filename)
return assert(loadstring(code,filename)) return assert(loadstring(code,filename))
end end
function process(filename) function process(filename)
vlc.msg.dbg("Loading `"..filename.."'") local mtime = 0 -- vlc.fd.stat(filename).modification_time
local mtime = 0 -- vlc.fd.stat(filename).modification_time
local func = false -- process_raw(filename) local func = false -- process_raw(filename)
return function(...) return function(...)
local new_mtime = vlc.fd.stat(filename).modification_time local new_mtime = vlc.fd.stat(filename).modification_time
if new_mtime ~= mtime then if new_mtime ~= mtime then
-- Re-read the file if it changed -- Re-read the file if it changed
vlc.msg.dbg("Reloading `"..filename.."'") if mtime == 0 then
vlc.msg.dbg("Loading `"..filename.."'")
else
vlc.msg.dbg("Reloading `"..filename.."'")
end
func = process_raw(filename) func = process_raw(filename)
mtime = new_mtime mtime = new_mtime
end end
...@@ -101,7 +104,7 @@ function callback_error(path,url,msg) ...@@ -101,7 +104,7 @@ function callback_error(path,url,msg)
</html>]] </html>]]
end end
function dirlisting(url,listing) function dirlisting(url,listing,acl_)
local list = {} local list = {}
for _,f in ipairs(listing) do for _,f in ipairs(listing) do
if not string.match(f,"^%.") then if not string.match(f,"^%.") then
...@@ -119,7 +122,7 @@ function dirlisting(url,listing) ...@@ -119,7 +122,7 @@ function dirlisting(url,listing)
</body> </body>
</html>]] </html>]]
end end
return h:file_new(url,"text/html",nil,nil,nil,callback,nil) return h:file_new(url,"text/html",nil,nil,acl_,callback,nil)
end end
function file(h,path,url,acl_,mime) function file(h,path,url,acl_,mime)
...@@ -153,14 +156,17 @@ end ...@@ -153,14 +156,17 @@ end
function rawfile(h,path,url,acl_) function rawfile(h,path,url,acl_)
local filename = path local filename = path
vlc.msg.dbg("Loading `"..filename.."'") local mtime = 0 -- vlc.fd.stat(filename).modification_time
local mtime = 0 -- vlc.fd.stat(filename).modification_time
local page = false -- io.open(filename):read("*a") local page = false -- io.open(filename):read("*a")
local callback = function(data,request) local callback = function(data,request)
local new_mtime = vlc.fd.stat(filename).modification_time local new_mtime = vlc.fd.stat(filename).modification_time
if mtime ~= new_mtime then if mtime ~= new_mtime then
-- Re-read the file if it changed -- Re-read the file if it changed
vlc.msg.dbg("Reloading `"..filename.."'") if mtime == 0 then
vlc.msg.dbg("Loading `"..filename.."'")
else
vlc.msg.dbg("Reloading `"..filename.."'")
end
page = io.open(filename):read("*a") page = io.open(filename):read("*a")
mtime = new_mtime mtime = new_mtime
end end
...@@ -221,15 +227,13 @@ local mimes = { ...@@ -221,15 +227,13 @@ local mimes = {
html = "text/html", html = "text/html",
xml = "text/xml", xml = "text/xml",
js = "text/javascript", js = "text/javascript",
css = "text/css",
png = "image/png", png = "image/png",
ico = "image/x-icon", ico = "image/x-icon",
} }
local function load_dir(dir,root,parent_acl) local function load_dir(dir,root,parent_acl)
local root = root or "/" local root = root or "/"
local has_index = false local has_index = false
if string.match(dir,"/old") then
return
end
local my_acl = parent_acl local my_acl = parent_acl
do do
local af = dir.."/.hosts" local af = dir.."/.hosts"
...@@ -261,10 +265,7 @@ local function load_dir(dir,root,parent_acl) ...@@ -261,10 +265,7 @@ local function load_dir(dir,root,parent_acl)
table.insert(files,rawfile(h,dir.."/"..f,url,my_acl and my_acl.private)) table.insert(files,rawfile(h,dir.."/"..f,url,my_acl and my_acl.private))
end end
elseif s.type == "dir" then elseif s.type == "dir" then
if f == "dialogs" then -- FIXME load_dir(dir.."/"..f,root..f.."/",my_acl)
else
load_dir(dir.."/"..f,root..f.."/",my_acl)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment