diff options
author | Rosy Song <rosysong@rosinson.com> | 2018-12-28 10:47:02 +0800 |
---|---|---|
committer | Rosy Song <rosysong@rosinson.com> | 2019-01-02 16:31:59 +0800 |
commit | f6a0e3852f4aee2dbe595e5ce05c5217d42dccb8 (patch) | |
tree | 84ba3a39bc62540ec699b7e5bb6dc974e018c6fc /applications/luci-app-rosy-file-server/luasrc/model | |
parent | 1893892581707fcd83e684a7a03dd6b5d3c2c3a2 (diff) |
luci-app-rosy-file-server: add new application
Signed-off-by: Rosy Song <rosysong@rosinson.com>
Diffstat (limited to 'applications/luci-app-rosy-file-server/luasrc/model')
2 files changed, 98 insertions, 0 deletions
diff --git a/applications/luci-app-rosy-file-server/luasrc/model/cbi/rosy-file-server/rosy-file-server.lua b/applications/luci-app-rosy-file-server/luasrc/model/cbi/rosy-file-server/rosy-file-server.lua new file mode 100644 index 0000000000..703b4defc0 --- /dev/null +++ b/applications/luci-app-rosy-file-server/luasrc/model/cbi/rosy-file-server/rosy-file-server.lua @@ -0,0 +1,72 @@ +-- Copyright 2018 Rosy Song <rosysong@rosinson.com> +-- Licensed to the public under the Apache License 2.0. + +local uci = require "luci.model.uci".cursor() +local dis = uci:get("rosyfs", "default", "disabled") + +local targets = {} +local server_root = luci.http.formvalue("server_root") or "/www/rosyfs-share/" +local buffer = io.popen("/bin/busybox ls -ahLlp %s" % server_root) +if dis ~= '1' and buffer then + for l in buffer:lines() do + local _p, i, u, g, sz, mm, dd, tt, nm = l:match( + "^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+(.+)" + ) + local p = _p and string.sub(_p, 1, 1) or nil + if p and (p == '-' or p == 'd') and nm and (nm ~= "./") and + not (server_root == "/www/rosyfs-share/" and nm == "../") and + not (server_root == "/www/rosyfs-share/" and nm == "rosyfs-share/") then + targets[nm] = { + ['type'] = p, + ['size'] = sz, + ['last'] = "%s %s %s" % { mm, dd, tt }, + ['name'] = nm + } + end + end +end + +local title = uci:get("rosyfs", "default", "title") or nil + +m = SimpleForm("rosyfs", title or translate("Rosy File Server"), translate("This is rosy file server for luci.<br /><strong>Note: targets will be mapped at /www/rosyfs-share !</strong>")) +m.reset = false +m.submit = false + + +s = m:section(Table, targets) + +t = s:option(DummyValue, "type", translate("Type")) + +n = s:option(DummyValue, "name", translate("Name")) +n.rawhtml = true + +function n.cfgvalue(self, section) + local v = DummyValue.cfgvalue(self, section) + local hv = (v == "../") and "Parent Directory" or v + local t = targets[v]['type'] + + if t and t ~='d' then + -- File + return translatef("<a href='%s%s'>%s</a>", + string.sub(server_root, 5, #server_root), hv, hv); + elseif t then + -- Directory + if v == "../" then + local dir = luci.util.trim(luci.util.exec("dirname " .. server_root)) + + if dir ~= "/" then dir = dir .. "/" end + + return translatef("<a href='%s?server_root=%s'>%s</a>", + luci.dispatcher.build_url("httpfs/rosy-file-server"), dir, hv) + else + return translatef("<a href='%s?server_root=%s%s'>%s</a>", + luci.dispatcher.build_url("httpfs/rosy-file-server"), + server_root, hv, hv) + end + end +end + +l = s:option(DummyValue, "last", translate("Last Modified")) +sz = s:option(DummyValue, "size", translate("Size")) + +return m diff --git a/applications/luci-app-rosy-file-server/luasrc/model/cbi/rosy-file-server/rosyfs.lua b/applications/luci-app-rosy-file-server/luasrc/model/cbi/rosy-file-server/rosyfs.lua new file mode 100644 index 0000000000..51efa9e814 --- /dev/null +++ b/applications/luci-app-rosy-file-server/luasrc/model/cbi/rosy-file-server/rosyfs.lua @@ -0,0 +1,26 @@ +-- Copyright 2019 Rosy Song <rosysong@rosinson.com> +-- Licensed to the public under the Apache License 2.0. + +local uci = require("luci.model.uci").cursor() +local dis = uci:get("rosyfs", "default", "disabled") +local tgt = uci:get("rosyfs", "default", "target") +local tlt = uci:get("rosyfs", "default", "title") + +m = Map("rosyfs", translate("Rosy File Server Settings")) + +s = m:section(TypedSection, "rosyfs", nil) +s.addremove = false +s.anonymous = true + +e = s:option(Flag, "disabled", translate("Disable"), translate("Disable Rosy File Server")) +e.default = dis or e.disabled +e.rmempty = false + +a = s:option(Value, "target", translate("Target"), translate("Specify path to be mapped")) +a.default = tgt or "/www" +a.datatype = "directory" + +t = s:option(Value, "title", translate("Title"), translate("Title to be shown")) +t.default = tlt or "Rosy File Server" + +return m |