Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / modules / luci-base / luasrc / view / cbi / filebrowser.htm
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
11                 ul {
12                         padding-left: 0;
13                         list-style-type: none;
14                 }
15
16                 li img {
17                         vertical-align: bottom;
18                         margin-right: 0.2em;
19                 }
20         </style>
21
22         <script type="text/javascript">
23                 function callback(path) {
24                         if( window.opener ) {
25                                 var input = window.opener.document.getElementById(decodeURIComponent('<%=luci.http.urlencode(luci.http.formvalue('field'))%>'));
26                                 if( input ) {
27                                         input.value = decodeURIComponent(path);
28                                         window.close();
29                                 }
30                         }
31                 }
32         </script>
33 </head>
34 <body>
35         <%
36                 require("nixio.fs")
37                 require("nixio.util")
38                 require("luci.http")
39                 require("luci.dispatcher")
40
41                 local field   = luci.http.formvalue('field')
42                 local request = luci.dispatcher.context.args
43                 local path    = { '' }
44
45                 for i = 1, #request do
46                         if request[i] ~= '..' and #request[i] > 0 then
47                                 path[#path+1] = request[i]
48                         end
49                 end
50
51                 local filestat = nixio.fs.stat(table.concat(path, '/'))
52                 local baseurl  = { 'admin', 'filebrowser' }
53
54                 if filestat and filestat.type == "reg" then
55                         path[#path] = ''
56                 elseif not (filestat and filestat.type == "dir") then
57                         path = { '', '' }
58                 else
59                         path[#path+1] = ''
60                 end
61
62                 filepath = table.concat(path, '/')
63
64                 local entries = {}
65                 local _, e
66                 for _, e in luci.util.vspairs(nixio.util.consume((nixio.fs.dir(filepath)))) do
67                         local p = filepath .. e
68                         local s = nixio.fs.stat(p)
69                         if s then
70                                 entries[#entries+1] = {
71                                         name = e,
72                                         path = p,
73                                         type = s.type
74                                 }
75                         end
76                 end
77         -%>
78         <div id="path">
79                 Location:
80                 <% for i, dir in ipairs(path) do %>
81                         <% if i == 1 then %>
82                                 <a href="<%=url(unpack(baseurl))%>?field=<%=luci.http.urlencode(field)%>">(root)</a>
83                         <% elseif next(path, i) then %>
84                                 <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %>
85                                 / <a href="<%=url(unpack(baseurl))%>?field=<%=luci.http.urlencode(field)%>"><%=pcdata(dir)%></a>
86                         <% else %>
87                                 <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %>
88                                 / <%=pcdata(dir)%>
89                         <% end %>
90                 <% end %>
91         </div>
92
93         <hr />
94
95         <div id="listing">
96                 <ul>
97                         <% for _, e in ipairs(entries) do if e.type == 'dir' then -%>
98                                 <li class="dir">
99                                         <img src="<%=resource%>/cbi/folder.gif" alt="<%:Directory%>" />
100                                         <a href="<%=url(unpack(baseurl))%>/<%=luci.http.urlencode(e.name)%>?field=<%=luci.http.urlencode(field)%>"><%=pcdata(e.name)%>/</a>
101                                 </li>
102                         <% end end -%>
103
104                         <% for _, e in ipairs(entries) do if e.type ~= 'dir' then -%>
105                                 <li class="file">
106                                         <img src="<%=resource%>/cbi/file.gif" alt="<%:File%>" />
107                                         <a href="#" onclick="callback('<%=luci.http.urlencode(e.path)%>')"><%=pcdata(e.name)%></a>
108                                 </li>
109                         <% end end -%>
110                 </ul>
111         </div>
112 </body>
113 </html>