Добавлена проверка прав, чтобы не пытаться читать недоступный каталог.
authorRoman Bazalevskiy <rvb@rvb.name>
Wed, 10 Oct 2018 07:17:08 +0000 (10:17 +0300)
committerRoman Bazalevskiy <rvb@rvb.name>
Wed, 10 Oct 2018 07:17:08 +0000 (10:17 +0300)
www/cgi-bin/fs

index 669ebd0364261ca7193445e192a6d80d3d664450..cee5f0f88942f7f038739d2e3d2092c08378983b 100755 (executable)
@@ -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