* libs/httpd: also handle missing directory permissions correctly
This commit is contained in:
parent
d7697624c4
commit
3b2eae63a3
1 changed files with 43 additions and 38 deletions
|
@ -137,49 +137,54 @@ function Simple.handle_get(self, request, sourcein, sinkerr)
|
||||||
|
|
||||||
local entries = luci.fs.dir( file )
|
local entries = luci.fs.dir( file )
|
||||||
|
|
||||||
for i, e in luci.util.spairs(
|
if type(entries) == "table" then
|
||||||
entries, function(a,b)
|
for i, e in luci.util.spairs(
|
||||||
if entries[a] == '..' then
|
entries, function(a,b)
|
||||||
return true
|
if entries[a] == '..' then
|
||||||
elseif entries[b] == '..' then
|
return true
|
||||||
return false
|
elseif entries[b] == '..' then
|
||||||
else
|
return false
|
||||||
return ( entries[a] < entries[b] )
|
else
|
||||||
|
return ( entries[a] < entries[b] )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
) do
|
||||||
) do
|
if e ~= '.' and ( e == '..' or e:sub(1,1) ~= '.' ) then
|
||||||
if e ~= '.' and ( e == '..' or e:sub(1,1) ~= '.' ) then
|
local estat = luci.fs.stat( file .. "/" .. e )
|
||||||
local estat = luci.fs.stat( file .. "/" .. e )
|
|
||||||
|
|
||||||
if estat.type == "directory" then
|
if estat.type == "directory" then
|
||||||
html = html .. string.format(
|
html = html .. string.format(
|
||||||
'<li><p><a href="%s/%s/">%s/</a> ' ..
|
'<li><p><a href="%s/%s/">%s/</a> ' ..
|
||||||
'<small>(directory)</small><br />' ..
|
'<small>(directory)</small><br />' ..
|
||||||
'<small>Changed: %s</small></li>',
|
'<small>Changed: %s</small></li>',
|
||||||
ruri, self.proto.urlencode( e ), e,
|
ruri, self.proto.urlencode( e ), e,
|
||||||
self.date.to_http( estat.mtime )
|
self.date.to_http( estat.mtime )
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
html = html .. string.format(
|
html = html .. string.format(
|
||||||
'<li><p><a href="%s/%s">%s</a> ' ..
|
'<li><p><a href="%s/%s">%s</a> ' ..
|
||||||
'<small>(%s)</small><br />' ..
|
'<small>(%s)</small><br />' ..
|
||||||
'<small>Size: %i Bytes | Changed: %s</small></li>',
|
'<small>Size: %i Bytes | ' ..
|
||||||
ruri, self.proto.urlencode( e ), e,
|
'Changed: %s</small></li>',
|
||||||
self.mime.to_mime( e ),
|
ruri, self.proto.urlencode( e ), e,
|
||||||
estat.size, self.date.to_http( estat.mtime )
|
self.mime.to_mime( e ),
|
||||||
)
|
estat.size, self.date.to_http( estat.mtime )
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
html = html .. '</ul><hr /></body></html>'
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
200, {
|
||||||
|
["Date"] = self.date.to_http( os.time() );
|
||||||
|
["Content-Type"] = "text/html; charset=ISO-8859-15";
|
||||||
|
}
|
||||||
|
), ltn12.source.string(html)
|
||||||
|
else
|
||||||
|
return self:failure(403, "Permission denied")
|
||||||
end
|
end
|
||||||
|
|
||||||
html = html .. '</ul><hr /></body></html>'
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
200, {
|
|
||||||
["Date"] = self.date.to_http( os.time() );
|
|
||||||
["Content-Type"] = "text/html; charset=ISO-8859-15";
|
|
||||||
}
|
|
||||||
), ltn12.source.string(html)
|
|
||||||
else
|
else
|
||||||
return self:failure(403, "Unable to transmit " .. stat.type .. " " .. file)
|
return self:failure(403, "Unable to transmit " .. stat.type .. " " .. file)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue