From 3b2eae63a33b02d0a75378e919a93f75e94c4042 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 30 Jun 2008 12:06:49 +0000 Subject: [PATCH] * libs/httpd: also handle missing directory permissions correctly --- libs/httpd/luasrc/httpd/handler/file.lua | 81 +++++++++++++++++--------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/libs/httpd/luasrc/httpd/handler/file.lua b/libs/httpd/luasrc/httpd/handler/file.lua index 4cbfa412c..db8a476d4 100644 --- a/libs/httpd/luasrc/httpd/handler/file.lua +++ b/libs/httpd/luasrc/httpd/handler/file.lua @@ -137,49 +137,54 @@ function Simple.handle_get(self, request, sourcein, sinkerr) local entries = luci.fs.dir( file ) - for i, e in luci.util.spairs( - entries, function(a,b) - if entries[a] == '..' then - return true - elseif entries[b] == '..' then - return false - else - return ( entries[a] < entries[b] ) + if type(entries) == "table" then + for i, e in luci.util.spairs( + entries, function(a,b) + if entries[a] == '..' then + return true + elseif entries[b] == '..' then + return false + else + return ( entries[a] < entries[b] ) + end end - end - ) do - if e ~= '.' and ( e == '..' or e:sub(1,1) ~= '.' ) then - local estat = luci.fs.stat( file .. "/" .. e ) - - if estat.type == "directory" then - html = html .. string.format( - '
  • %s/ ' .. - '(directory)
    ' .. - 'Changed: %s

  • ', - ruri, self.proto.urlencode( e ), e, - self.date.to_http( estat.mtime ) - ) - else - html = html .. string.format( - '
  • %s ' .. - '(%s)
    ' .. - 'Size: %i Bytes | Changed: %s

  • ', - ruri, self.proto.urlencode( e ), e, - self.mime.to_mime( e ), - estat.size, self.date.to_http( estat.mtime ) - ) + ) do + if e ~= '.' and ( e == '..' or e:sub(1,1) ~= '.' ) then + local estat = luci.fs.stat( file .. "/" .. e ) + + if estat.type == "directory" then + html = html .. string.format( + '
  • %s/ ' .. + '(directory)
    ' .. + 'Changed: %s

  • ', + ruri, self.proto.urlencode( e ), e, + self.date.to_http( estat.mtime ) + ) + else + html = html .. string.format( + '
  • %s ' .. + '(%s)
    ' .. + 'Size: %i Bytes | ' .. + 'Changed: %s

  • ', + ruri, self.proto.urlencode( e ), e, + self.mime.to_mime( e ), + estat.size, self.date.to_http( estat.mtime ) + ) + end end end - end - html = html .. '
    ' + html = html .. '
    ' - return Response( - 200, { - ["Date"] = self.date.to_http( os.time() ); - ["Content-Type"] = "text/html; charset=ISO-8859-15"; - } - ), ltn12.source.string(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 else return self:failure(403, "Unable to transmit " .. stat.type .. " " .. file) end -- 2.11.0