summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-09-03 19:34:33 +0200
committerJo-Philipp Wich <jo@mein.io>2019-09-10 15:28:16 +0200
commit3f93650901caf9e4094aeaee6a47d68efafeac97 (patch)
treed47615a249b781bc8b1508a9f1b3fc8120371c25 /modules/luci-base/luasrc
parent1fcf34510a6c7994df3ca95e2e754db19870ce4b (diff)
luci-base: use cgi-io and rpcd-mod-file to handle file upload and browsing
Remove the old server side support for file browsing and file uploading and switch to a client side widget instead which uses XMLHTTPRequests to upload files via cgi-io and RPC calls for file listing and status queries. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r--modules/luci-base/luasrc/view/cbi/filebrowser.htm113
-rw-r--r--modules/luci-base/luasrc/view/cbi/upload.htm30
2 files changed, 10 insertions, 133 deletions
diff --git a/modules/luci-base/luasrc/view/cbi/filebrowser.htm b/modules/luci-base/luasrc/view/cbi/filebrowser.htm
deleted file mode 100644
index 806b1b5f4..000000000
--- a/modules/luci-base/luasrc/view/cbi/filebrowser.htm
+++ /dev/null
@@ -1,113 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>Filebrowser - LuCI</title>
- <style type="text/css">
- #path, #listing {
- font-size: 85%;
- }
-
- ul {
- padding-left: 0;
- list-style-type: none;
- }
-
- li img {
- vertical-align: bottom;
- margin-right: 0.2em;
- }
- </style>
-
- <script type="text/javascript">
- function callback(path) {
- if( window.opener ) {
- var input = window.opener.document.getElementById(decodeURIComponent('<%=luci.http.urlencode(luci.http.formvalue('field'))%>'));
- if( input ) {
- input.value = decodeURIComponent(path);
- window.close();
- }
- }
- }
- </script>
-</head>
-<body>
- <%
- 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
- -%>
- <div id="path">
- Location:
- <% for i, dir in ipairs(path) do %>
- <% if i == 1 then %>
- <a href="<%=url(unpack(baseurl))%>?field=<%=luci.http.urlencode(field)%>">(root)</a>
- <% elseif next(path, i) then %>
- <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %>
- / <a href="<%=url(unpack(baseurl))%>?field=<%=luci.http.urlencode(field)%>"><%=pcdata(dir)%></a>
- <% else %>
- <% baseurl[#baseurl+1] = luci.http.urlencode(dir) %>
- / <%=pcdata(dir)%>
- <% end %>
- <% end %>
- </div>
-
- <hr />
-
- <div id="listing">
- <ul>
- <% for _, e in ipairs(entries) do if e.type == 'dir' then -%>
- <li class="dir">
- <img src="<%=resource%>/cbi/folder.gif" alt="<%:Directory%>" />
- <a href="<%=url(unpack(baseurl))%>/<%=luci.http.urlencode(e.name)%>?field=<%=luci.http.urlencode(field)%>"><%=pcdata(e.name)%>/</a>
- </li>
- <% end end -%>
-
- <% for _, e in ipairs(entries) do if e.type ~= 'dir' then -%>
- <li class="file">
- <img src="<%=resource%>/cbi/file.gif" alt="<%:File%>" />
- <a href="#" onclick="callback('<%=luci.http.urlencode(e.path)%>')"><%=pcdata(e.name)%></a>
- </li>
- <% end end -%>
- </ul>
- </div>
-</body>
-</html>
diff --git a/modules/luci-base/luasrc/view/cbi/upload.htm b/modules/luci-base/luasrc/view/cbi/upload.htm
index 3c3d82b65..e61049538 100644
--- a/modules/luci-base/luasrc/view/cbi/upload.htm
+++ b/modules/luci-base/luasrc/view/cbi/upload.htm
@@ -1,24 +1,14 @@
-<%
- local t = require("luci.tools.webadmin")
- local v = self:cfgvalue(section)
- local s = v and nixio.fs.stat(v)
--%>
<%+cbi/valueheader%>
- <% if s then %>
- <%:Uploaded File%> (<%=t.byte_format(s.size)%>)
- <% if self.unsafeupload then %>
- <input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
- <input class="cbi-button cbi-button-image" type="image" value="<%:Replace entry%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:Replace entry%>" title="<%:Replace entry%>" src="<%=resource%>/cbi/reload.gif" />
- <% end %>
- <% end %>
- <% if not self.unsafeupload then %>
- <input type="hidden"<%= attr("value", v) .. attr("name", "cbi.rlf." .. section .. "." .. self.option) .. attr("id", "cbi.rlf." .. section .. "." .. self.option) %> />
- <% end %>
+<div<%=attr("data-ui-widget", luci.util.serialize_json({
+ "FileUpload", self:cfgvalue(section) or self.default, {
+ id = cbid,
+ name = cbid,
+ show_hidden = self.show_hidden,
+ enable_remove = self.enable_remove,
+ enable_upload = self.enable_upload,
+ root_directory = "/" --self.root_directory
+ }
+}))%>></div>
- <% if (not s) or (s and not self.unsafeupload) then %>
- <input class="cbi-input-file" type="file"<%= attr("name", cbid) .. attr("id", cbid) %> />
- <% end %>
- <input type="text" class="cbi-input-text" data-update="change"<%=
- attr("name", cbid .. ".textbox") .. attr("id", cbid .. ".textbox") .. attr("value", luci.cbi.AbstractValue.cfgvalue(self, section) or self.default) .. ifattr(self.size, "size") .. ifattr(self.placeholder, "placeholder") .. ifattr(self.readonly, "readonly") .. ifattr(self.maxlength, "maxlength") %> />
<%+cbi/valuefooter%>