mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-31 11:05:13 +08:00
update 2026-09-24 16:56:26
This commit is contained in:
1 parent
b31a5c3878
commit
e4cee331e9
6885 files changed
+3240523
No files matched your search
@@ -0,0 +1,39 @@
|
||||
module("luci.controller.baidudrive", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/baidudrive") then return end
|
||||
entry({"admin", "services", "baidudrive"}, cbi("baidudrive"), _("BaiduDrive"), 100).dependent = true
|
||||
entry({"admin", "services", "baidudrive_status"}, call("baidudrive_status"))
|
||||
|
||||
local open = entry({"admin", "services", "baidudrive", "open"}, call("baidudrive_open"))
|
||||
open.leaf = true
|
||||
open.dependent = false
|
||||
open.sysauth = "root"
|
||||
open.sysauth_authenticator = "htmlauth"
|
||||
end
|
||||
|
||||
local function compat()
|
||||
local dispatcher = require "luci.dispatcher"
|
||||
return require("luci.model.linkease.apps_compat").new({
|
||||
http = require "luci.http",
|
||||
resolver = require("luci.model.linkease.apps_openwrt").new(),
|
||||
auth_url = dispatcher.build_url("admin", "services", "linkease_auth", "auth")
|
||||
})
|
||||
end
|
||||
|
||||
function baidudrive_status()
|
||||
local sys = require "luci.sys"
|
||||
local uci = require("luci.model.uci").cursor()
|
||||
local app_running = sys.call("pidof baidudrive >/dev/null") == 0
|
||||
local sdk_running = sys.call("pidof baiduNas >/dev/null") == 0
|
||||
compat():legacy_status("baidudrive", {
|
||||
running = app_running and sdk_running,
|
||||
app_running = app_running,
|
||||
sdk_running = sdk_running,
|
||||
port = uci:get_first("baidudrive", "baidudrive", "port") or "10780"
|
||||
})
|
||||
end
|
||||
|
||||
function baidudrive_open()
|
||||
compat():open("baidudrive")
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
local jsonc = require "luci.jsonc"
|
||||
|
||||
local baidudrive = {}
|
||||
|
||||
baidudrive.blocks = function()
|
||||
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
|
||||
local vals = {}
|
||||
if f then
|
||||
local ret = f:read("*all")
|
||||
f:close()
|
||||
local obj = jsonc.parse(ret)
|
||||
for _, val in pairs(obj and obj["blockdevices"] or {}) do
|
||||
local fsize = val["fssize"]
|
||||
if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then
|
||||
vals[#vals + 1] = val["mountpoint"]
|
||||
end
|
||||
end
|
||||
end
|
||||
return vals
|
||||
end
|
||||
|
||||
baidudrive.home = function()
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local home_dirs = {}
|
||||
home_dirs["main_dir"] = uci:get_first("quickstart", "main", "main_dir", "/root")
|
||||
home_dirs["Configs"] = uci:get_first("quickstart", "main", "conf_dir", home_dirs["main_dir"] .. "/Configs")
|
||||
home_dirs["Public"] = uci:get_first("quickstart", "main", "pub_dir", home_dirs["main_dir"] .. "/Public")
|
||||
home_dirs["Downloads"] = uci:get_first("quickstart", "main", "dl_dir", home_dirs["Public"] .. "/Downloads")
|
||||
home_dirs["Caches"] = uci:get_first("quickstart", "main", "tmp_dir", home_dirs["main_dir"] .. "/Caches")
|
||||
return home_dirs
|
||||
end
|
||||
|
||||
baidudrive.find_paths = function(blocks, home_dirs, path_name)
|
||||
local default_path = ""
|
||||
local paths = {}
|
||||
|
||||
default_path = home_dirs[path_name] .. "/BaiduDrive"
|
||||
if #blocks == 0 then
|
||||
table.insert(paths, default_path)
|
||||
else
|
||||
for _, val in pairs(blocks) do
|
||||
table.insert(paths, val .. "/" .. path_name .. "/BaiduDrive")
|
||||
end
|
||||
local without_conf_dir = "/root/" .. path_name .. "/BaiduDrive"
|
||||
if default_path == without_conf_dir then
|
||||
default_path = paths[1]
|
||||
end
|
||||
end
|
||||
|
||||
return paths, default_path
|
||||
end
|
||||
|
||||
return baidudrive
|
||||
@@ -0,0 +1,32 @@
|
||||
local m, s
|
||||
|
||||
m = Map("baidudrive", translate("BaiduDrive"), translate("BaiduDrive provides a Baidu Netdisk Web UI."))
|
||||
m:section(SimpleSection).template = "baidudrive/baidudrive_status"
|
||||
|
||||
s = m:section(TypedSection, "baidudrive", translate("Global settings"))
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
s:option(Flag, "enabled", translate("Enable")).rmempty = false
|
||||
|
||||
local baidudrive_model = require "luci.model.baidudrive"
|
||||
local blocks = baidudrive_model.blocks()
|
||||
local home = baidudrive_model.home()
|
||||
|
||||
local data_dir = s:option(Value, "data_dir", translate("Data directory"))
|
||||
data_dir.rmempty = false
|
||||
data_dir.description = translate("Required. BaiduDrive stores its config, session and task data under this directory.")
|
||||
|
||||
local paths, default_path = baidudrive_model.find_paths(blocks, home, "Configs")
|
||||
for _, val in pairs(paths) do
|
||||
data_dir:value(val, val)
|
||||
end
|
||||
data_dir.default = default_path
|
||||
|
||||
local port = s:option(Value, "port", translate("Listen port"))
|
||||
port.default = "10780"
|
||||
port.rmempty = false
|
||||
port.datatype = "port"
|
||||
port.description = translate("Port for BaiduDrive HTTP server.")
|
||||
|
||||
return m
|
||||
@@ -0,0 +1,23 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=url("admin/services/baidudrive_status")%>', null, function(x, st) {
|
||||
var el = document.getElementById('baidudrive_status');
|
||||
if (st && el) {
|
||||
if (!st.running) {
|
||||
el.innerHTML = '<br/><em style=\"color:red\"><%:The BaiduDrive service is not running.%></em>'
|
||||
+ '<br/><small>baidudrive: ' + (st.app_running ? 'running' : 'stopped')
|
||||
+ ', baiduNas: ' + (st.sdk_running ? 'running' : 'stopped') + '</small>';
|
||||
}
|
||||
if (st.running) {
|
||||
el.innerHTML = '<br/><em style=\"color:green\"><%:The BaiduDrive service is running.%></em>'
|
||||
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:Click to open BaiduDrive%> \" onclick=\"window.open('<%=url("admin/services/baidudrive/open")%>')\"/>";
|
||||
}
|
||||
}
|
||||
});
|
||||
//]]></script>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:Status%></legend>
|
||||
<p id="baidudrive_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
Reference in new issue
Block a user