From: Roman Bazalevskiy <rvb@rvb.name>
Date: Wed, 10 Oct 2018 07:17:08 +0000 (+0300)
Subject: Добавлена проверка прав, чтобы не пытаться читать недоступный каталог.
X-Git-Url: https://git.rvb.name/lua-filemanager.git/commitdiff_plain/2ab2f7398805613c07c9d31c2968537928b87a39

Добавлена проверка прав, чтобы не пытаться читать недоступный каталог.
---

diff --git a/www/cgi-bin/fs b/www/cgi-bin/fs
index 669ebd0..cee5f0f 100755
--- a/www/cgi-bin/fs
+++ b/www/cgi-bin/fs
@@ -91,22 +91,25 @@ if action == "list" then
 
   path = fs.realpath(basepath..'/'..params["path"])
   
-  if is_in_dir(path,basepath) then
+  if path and is_in_dir(path,basepath) and fs.access(path,"r") then
     files = {}
     local rec
     for name in fs.dir(path) do
-      fstat=fs.stat(fs.realpath(path..'/'..name))
-      if fstat["type"]=="reg" then
-        ftype="file"
-      elseif fstat["type"]=="dir" then
-        ftype="dir"
-      else
-        ftype=""
-      end      
-      if ftype then
-        rec={name=name,rights=fstat["modestr"],size=fstat["size"],type=ftype,date=os.date('%Y-%m-%d %H:%M:%S',fstat["mtime"])}
-        table.insert(files,rec)
-      end  
+      basename=fs.realpath(path..'/'..name)
+      if basename then
+        fstat=fs.stat(fs.realpath(path..'/'..name))
+        if fstat["type"]=="reg" then
+          ftype="file"
+        elseif fstat["type"]=="dir" then
+          ftype="dir"
+        else
+          ftype=""
+        end      
+        if ftype then
+          rec={name=name,rights=fstat["modestr"],size=fstat["size"],type=ftype,date=os.date('%Y-%m-%d %H:%M:%S',fstat["mtime"])}
+          table.insert(files,rec)
+        end
+      end    
     end
     result = { result = files }
   else