<% require("nixio.fs") require("nixio.util") require("luci.http") require("luci.dispatcher") local field = luci.http.formvalue('field') local request = luci.dispatcher.context.args local path = { '' } for i = 1, #request do if request[i] ~= '..' and #request[i] > 0 then path[#path+1] = request[i] end end local filestat = nixio.fs.stat(table.concat(path, '/')) local baseurl = { 'admin', 'filebrowser' } if filestat and filestat.type == "reg" then path[#path] = '' elseif not (filestat and filestat.type == "dir") then path = { '', '' } else path[#path+1] = '' end filepath = table.concat(path, '/') local entries = {} local _, e for _, e in luci.util.vspairs(nixio.util.consume((nixio.fs.dir(filepath)))) do local p = filepath .. e local s = nixio.fs.stat(p) if s then entries[#entries+1] = { name = e, path = p, type = s.type } end end -%>
Location: <% for i, dir in ipairs(path) do %> <% if i == 1 then %> (root) <% elseif next(path, i) then %> <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %> / <%=pcdata(dir)%> <% else %> <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %> / <%=pcdata(dir)%> <% end %> <% end %>