0e223a933fde031837be562a3267f16f3b7ee0e6
[project/luci.git] / libs / cbi / luasrc / view / cbi / filebrowser.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15
16 <?xml version="1.0" encoding="UTF-8"?>
17 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
18 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
19 <head>
20     <title>Filebrowser - LuCI</title>
21         <style type="text/css">
22                 #path, #listing {
23                         font-size: 85%;
24                 }
25
26                 ul {
27                         padding-left: 0;
28                         list-style-type: none;
29                 }
30
31                 li img {
32                         vertical-align: bottom;
33                         margin-right: 0.2em;
34                 }
35         </style>
36
37         <script type="text/javascript">
38                 function callback(path) {
39                         if( window.opener ) {
40                                 var input = window.opener.document.getElementById('<%=luci.http.formvalue('field')%>');
41                                 if( input ) {
42                                         input.value = path;
43                                         window.close();
44                                 }
45                         }
46                 }
47         </script>
48 </head>
49 <body>
50         <%
51                 require("luci.fs")
52                 require("luci.http")
53                 require("luci.dispatcher")
54
55                 local field   = luci.http.formvalue('field')
56                 local request = luci.dispatcher.context.path
57                 local path    = { '' }
58
59                 for i = 3, #request do
60                         if request[i] ~= '..' and #request[i] > 0 then
61                                 path[#path+1] = request[i]
62                         end
63                 end
64
65                 local filepath = table.concat( path, '/' )
66                 local filestat = luci.fs.stat( filepath )
67                 local baseurl  = luci.dispatcher.build_url('admin', 'filebrowser')
68
69                 if filestat and filestat.type == "regular" then
70                         table.remove( path, #path )
71                         filepath = table.concat( path, '/' ) .. '/'
72                 elseif not ( filestat and filestat.type == "directory" ) then
73                         path     = { '' }
74                         filepath = '/'
75                 else
76                         filepath = filepath .. '/'
77                 end
78
79                 local entries = luci.fs.dir(filepath)
80         -%>
81     <div id="path">
82                 Location:
83                 <% for i, dir in ipairs(path) do %>
84                         <% if i == 1 then %>
85                                 <a href="<%=baseurl%>?field=<%=field%>">(root)</a>
86                         <% elseif next(path, i) then %>
87                                 <% baseurl = baseurl .. '/' .. dir %>
88                                 / <a href="<%=baseurl%>?field=<%=field%>"><%=dir%></a>
89                         <% else %>
90                                 <% baseurl = baseurl .. '/' .. dir %>
91                                 / <%=dir%>
92                         <% end %>
93                 <% end %>
94         </div>
95
96         <hr />
97
98         <div id="listing">
99                 <ul>
100                         <% for _, e in luci.util.vspairs(entries) do
101                             local stat = luci.fs.stat(filepath..e)
102                                 if e ~= '.' and e ~= '..' and stat and stat.type == 'directory' then
103                         -%>
104                                 <li class="dir">
105                                         <img src="/luci-static/resources/cbi/folder.png" alt="Directory" />
106                                         <a href="<%=baseurl%>/<%=e%>?field=<%=field%>"><%=e%>/</a>
107                                 </li>
108                         <% end end -%>
109
110                         <% for _, e in luci.util.vspairs(entries) do
111                             local stat = luci.fs.stat(filepath..e)
112                                 if stat and stat.type ~= 'directory' then
113                         -%>
114                                 <li class="file">
115                                         <img src="/luci-static/resources/cbi/file.png" alt="File" />
116                                         <a href="#" onclick="callback('<%=filepath..e%>')"><%=e%></a>
117                                 </li>
118                         <% end end -%>
119                 </ul>
120         </div>
121 </body>
122 </html>