summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server
diff options
context:
space:
mode:
authorHannu Nyman <hannu.nyman@iki.fi>2019-04-06 19:27:15 +0300
committerGitHub <noreply@github.com>2019-04-06 19:27:15 +0300
commit71d9140680e3b1db7bd1cb2d9be2b472652d673b (patch)
tree101f8a326a8d13aaacf87be6994d01e293100a76 /applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server
parentd679b93bad9ce0ee529b78c791de39a751a78006 (diff)
parentf6a0e3852f4aee2dbe595e5ce05c5217d42dccb8 (diff)
Merge pull request #2404 from rosysong/file-server
luci-app-rosy-file-server: add new application
Diffstat (limited to 'applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server')
-rw-r--r--applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server/rosy-file-server.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server/rosy-file-server.lua b/applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server/rosy-file-server.lua
new file mode 100644
index 0000000000..6c7c492089
--- /dev/null
+++ b/applications/luci-app-rosy-file-server/luasrc/controller/rosy-file-server/rosy-file-server.lua
@@ -0,0 +1,52 @@
+-- Copyright 2018 Rosy Song <rosysong@rosinson.com>
+-- Licensed to the public under the Apache License 2.0.
+
+module("luci.controller.rosy-file-server.rosy-file-server", package.seeall)
+
+function index()
+ if not nixio.fs.access("/etc/config/rosyfs") then
+ return
+ end
+
+ local root = node()
+ if not root.target then
+ root.target = alias("httpfs")
+ root.index = true
+ end
+
+ page = node()
+ page.lock = true
+ page.target = alias("httpfs")
+ page.subindex = true
+ page.index = false
+
+ page = node("httpfs")
+ page.title = _("File-server")
+ page.target = alias("httpfs", "rosy-file-server")
+ page.order = 5
+ page.setuser = "root"
+ page.setgroup = "root"
+ page.index = true
+
+ entry({"httpfs", "rosy-file-server"},
+ form("rosy-file-server/rosy-file-server"), _("Rosy File Server"), 10)
+ entry({"httpfs", "file-server-download"},
+ post("action_download"), nil)
+
+ entry({"admin", "services", "rosyfs"},
+ cbi("rosy-file-server/rosyfs"), _("Rosy File Server"), 61)
+end
+
+function action_download()
+ local p = luci.http.formvalue("path") or ""
+ local n = luci.http.formvalue("name") or ""
+
+ if not p or not n then
+ luci.http.status(400, "Bad Request")
+ return
+ end
+
+ luci.http.header('Content-Disposition', 'attachment; filename="%s"' % n)
+ luci.http.prepare_content("application/octet-stream")
+ luci.sys.process.exec({ "/bin/dd", "if=%s%s" % { p, n }, "conv=fsync,notrunc" }, luci.http.write)
+end