filebrowser.htm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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('<%=luci.http.formvalue('field')%>');
  23. if( input ) {
  24. input.value = 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 filepath = table.concat( path, '/' )
  46. local filestat = nixio.fs.stat( filepath )
  47. local baseurl = luci.dispatcher.build_url('admin', 'filebrowser')
  48. if filestat and filestat.type == "reg" then
  49. table.remove( path, #path )
  50. filepath = table.concat( path, '/' ) .. '/'
  51. elseif not ( filestat and filestat.type == "dir" ) then
  52. path = { '' }
  53. filepath = '/'
  54. else
  55. filepath = filepath .. '/'
  56. end
  57. local entries = nixio.util.consume((nixio.fs.dir(filepath)))
  58. -%>
  59. <div id="path">
  60. Location:
  61. <% for i, dir in ipairs(path) do %>
  62. <% if i == 1 then %>
  63. <a href="<%=baseurl%>?field=<%=field%>">(root)</a>
  64. <% elseif next(path, i) then %>
  65. <% baseurl = baseurl .. '/' .. dir %>
  66. / <a href="<%=baseurl%>?field=<%=field%>"><%=dir%></a>
  67. <% else %>
  68. <% baseurl = baseurl .. '/' .. dir %>
  69. / <%=dir%>
  70. <% end %>
  71. <% end %>
  72. </div>
  73. <hr />
  74. <div id="listing">
  75. <ul>
  76. <% for _, e in luci.util.vspairs(entries) do
  77. local stat = nixio.fs.stat(filepath..e)
  78. if stat and stat.type == 'dir' then
  79. -%>
  80. <li class="dir">
  81. <img src="<%=resource%>/cbi/folder.gif" alt="<%:Directory%>" />
  82. <a href="<%=baseurl%>/<%=e%>?field=<%=field%>"><%=e%>/</a>
  83. </li>
  84. <% end end -%>
  85. <% for _, e in luci.util.vspairs(entries) do
  86. local stat = nixio.fs.stat(filepath..e)
  87. if stat and stat.type ~= 'dir' then
  88. -%>
  89. <li class="file">
  90. <img src="<%=resource%>/cbi/file.gif" alt="<%:File%>" />
  91. <a href="#" onclick="callback('<%=filepath..e%>')"><%=e%></a>
  92. </li>
  93. <% end end -%>
  94. </ul>
  95. </div>
  96. </body>
  97. </html>