1
0

filebrowser.htm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>Filebrowser - LuCI</title>
  6. <style type="text/css">
  7. #path, #listing {
  8. font-size: 85%;
  9. }
  10. ul {
  11. padding-left: 0;
  12. list-style-type: none;
  13. }
  14. li img {
  15. vertical-align: bottom;
  16. margin-right: 0.2em;
  17. }
  18. </style>
  19. <script type="text/javascript">
  20. function callback(path) {
  21. if( window.opener ) {
  22. var input = window.opener.document.getElementById(decodeURIComponent('<%=luci.http.urlencode(luci.http.formvalue('field'))%>'));
  23. if( input ) {
  24. input.value = decodeURIComponent(path);
  25. window.close();
  26. }
  27. }
  28. }
  29. </script>
  30. </head>
  31. <body>
  32. <%
  33. require("nixio.fs")
  34. require("nixio.util")
  35. require("luci.http")
  36. require("luci.dispatcher")
  37. local field = luci.http.formvalue('field')
  38. local request = luci.dispatcher.context.args
  39. local path = { '' }
  40. for i = 1, #request do
  41. if request[i] ~= '..' and #request[i] > 0 then
  42. path[#path+1] = request[i]
  43. end
  44. end
  45. local filestat = nixio.fs.stat(table.concat(path, '/'))
  46. local baseurl = { 'admin', 'filebrowser' }
  47. if filestat and filestat.type == "reg" then
  48. path[#path] = ''
  49. elseif not (filestat and filestat.type == "dir") then
  50. path = { '', '' }
  51. else
  52. path[#path+1] = ''
  53. end
  54. filepath = table.concat(path, '/')
  55. local entries = {}
  56. local _, e
  57. for _, e in luci.util.vspairs(nixio.util.consume((nixio.fs.dir(filepath)))) do
  58. local p = filepath .. e
  59. local s = nixio.fs.stat(p)
  60. if s then
  61. entries[#entries+1] = {
  62. name = e,
  63. path = p,
  64. type = s.type
  65. }
  66. end
  67. end
  68. -%>
  69. <div id="path">
  70. Location:
  71. <% for i, dir in ipairs(path) do %>
  72. <% if i == 1 then %>
  73. <a href="<%=url(unpack(baseurl))%>?field=<%=luci.http.urlencode(field)%>">(root)</a>
  74. <% elseif next(path, i) then %>
  75. <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %>
  76. / <a href="<%=url(unpack(baseurl))%>?field=<%=luci.http.urlencode(field)%>"><%=pcdata(dir)%></a>
  77. <% else %>
  78. <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %>
  79. / <%=pcdata(dir)%>
  80. <% end %>
  81. <% end %>
  82. </div>
  83. <hr />
  84. <div id="listing">
  85. <ul>
  86. <% for _, e in ipairs(entries) do if e.type == 'dir' then -%>
  87. <li class="dir">
  88. <img src="<%=resource%>/cbi/folder.gif" alt="<%:Directory%>" />
  89. <a href="<%=url(unpack(baseurl))%>/<%=luci.http.urlencode(e.name)%>?field=<%=luci.http.urlencode(field)%>"><%=pcdata(e.name)%>/</a>
  90. </li>
  91. <% end end -%>
  92. <% for _, e in ipairs(entries) do if e.type ~= 'dir' then -%>
  93. <li class="file">
  94. <img src="<%=resource%>/cbi/file.gif" alt="<%:File%>" />
  95. <a href="#" onclick="callback('<%=luci.http.urlencode(e.path)%>')"><%=pcdata(e.name)%></a>
  96. </li>
  97. <% end end -%>
  98. </ul>
  99. </div>
  100. </body>
  101. </html>