luci-app-aliyundrive-webdav: add package (#7967)

Signed-off-by: Beginner-Go <70857188+Beginner-Go@users.noreply.github.com>

Co-authored-by: messense <messense@icloud.com>
This commit is contained in:
Beginner 2021-10-01 22:16:24 +08:00 committed by GitHub
parent 687407acdc
commit dd63907371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 348 additions and 0 deletions

View File

@ -0,0 +1,76 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=aliyundrive-webdav
PKG_VERSION:=0.4.0
PKG_RELEASE:=1
PKG_LICENSE:=MIT
PKG_MAINTAINER:=messense <messense@icloud.com>
PKG_LIBC:=musl
ifeq ($(ARCH),arm)
PKG_LIBC:=musleabi
ARM_CPU_FEATURES:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
ifneq ($(filter $(ARM_CPU_FEATURES),vfp vfpv2),)
PKG_LIBC:=musleabihf
endif
endif
PKG_ARCH=$(ARCH)
ifeq ($(ARCH),i386)
PKG_ARCH:=i686
endif
PKG_SOURCE:=aliyundrive-webdav-$(PKG_ARCH)-unknown-linux-$(PKG_LIBC).tar.gz
PKG_SOURCE_URL:=https://github.com/messense/aliyundrive-webdav/releases/download/v$(PKG_VERSION)/
PKG_HASH:=skip
include $(INCLUDE_DIR)/package.mk
define Package/aliyundrive-webdav
SECTION:=multimedia
CATEGORY:=Multimedia
TITLE:=WebDAV server for AliyunDrive
URL:=https://github.com/messense/aliyundrive-webdav
endef
define Package/aliyundrive-webdav/description
WebDAV server for AliyunDrive.
endef
define Package/aliyundrive-webdav/conffiles
/etc/config/aliyundrive-webdav
endef
define Download/sha256sum
FILE:=$(PKG_SOURCE).sha256
URL_FILE:=$(FILE)
URL:=$(PKG_SOURCE_URL)
HASH:=skip
endef
$(eval $(call Download,sha256sum))
define Build/Prepare
mv $(DL_DIR)/$(PKG_SOURCE).sha256 .
cp $(DL_DIR)/$(PKG_SOURCE) .
shasum -a 256 -c $(PKG_SOURCE).sha256
rm $(PKG_SOURCE).sha256 $(PKG_SOURCE)
tar -C $(PKG_BUILD_DIR)/ -zxf $(DL_DIR)/$(PKG_SOURCE)
endef
define Build/Compile
echo "aliyundrive-webdav using precompiled binary."
endef
define Package/aliyundrive-webdav/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/aliyundrive-webdav $(1)/usr/bin/aliyundrive-webdav
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/aliyundrive-webdav.init $(1)/etc/init.d/aliyundrive-webdav
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/aliyundrive-webdav.config $(1)/etc/config/aliyundrive-webdav
endef
$(eval $(call BuildPackage,aliyundrive-webdav))

View File

@ -0,0 +1,11 @@
config server
option enable '0'
option debug '0'
option refresh_token ''
option host '0.0.0.0'
option port '8080'
option auth_user ''
option auth_password ''
option read_buffer_size '10485760'
option cache_size '1000'
option root '/'

View File

@ -0,0 +1,47 @@
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=99
STOP=15
NAME=aliyundrive-webdav
uci_get_by_type() {
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
echo ${ret:=$3}
}
start_service() {
local enable=$(uci_get_by_type server enable)
case "$enable" in
1|on|true|yes|enabled)
local refresh_token=$(uci_get_by_type server refresh_token)
local auth_user=$(uci_get_by_type server auth_user)
local auth_password=$(uci_get_by_type server auth_password)
local read_buf_size=$(uci_get_by_type server read_buffer_size 10485760)
local cache_size=$(uci_get_by_type server cache_size 1000)
local host=$(uci_get_by_type server host 127.0.0.1)
local port=$(uci_get_by_type server port 8080)
local root=$(uci_get_by_type server root /)
procd_open_instance
procd_set_param command /bin/sh -c "/usr/bin/$NAME -I --host $host --port $port --root $root -S $read_buf_size --cache-size $cache_size --workdir /var/run/$NAME >>/var/log/$NAME.log 2>&1"
procd_set_param pidfile /var/run/$NAME.pid
procd_set_param env REFRESH_TOKEN="$refresh_token"
[[ ! -z "$auth_user" ]] && procd_append_param env WEBDAV_AUTH_USER="$auth_user"
[[ ! -z "$auth_password" ]] && procd_append_param env WEBDAV_AUTH_PASSWORD="$auth_password"
case $(uci_get_by_type server debug) in
1|on|true|yes|enabled)
procd_append_param env RUST_LOG="aliyundrive_webdav=debug" ;;
*) ;;
esac
procd_close_instance ;;
*)
stop_service ;;
esac
}
service_triggers() {
procd_add_reload_trigger "/etc/config/$NAME"
}

View File

@ -0,0 +1,16 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-aliyundrive-webdav
PKG_VERSION:=0.4.0
PKG_RELEASE:=1
PKG_LICENSE:=MIT
PKG_MAINTAINER:=messense <messense@icloud.com>
LUCI_TITLE:=LuCI Support for aliyundrive-webdav
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+aliyundrive-webdav +lua +libuci-lua
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,35 @@
module("luci.controller.aliyundrive-webdav", package.seeall)
function index()
if not nixio.fs.access("/etc/config/aliyundrive-webdav") then
return
end
entry({"admin", "services", "aliyundrive-webdav"}, alias("admin", "services", "aliyundrive-webdav", "client"),_("AliyunDrive WebDAV"), 10).dependent = true -- 首页
entry({"admin", "services", "aliyundrive-webdav", "client"}, cbi("aliyundrive-webdav/client"),_("Settings"), 10).leaf = true -- 客户端配置
entry({"admin", "services", "aliyundrive-webdav", "log"}, form("aliyundrive-webdav/log"),_("Log"), 30).leaf = true -- 日志页面
entry({"admin", "services", "aliyundrive-webdav", "status"}, call("action_status")).leaf = true
entry({"admin", "services", "aliyundrive-webdav", "logtail"}, call("action_logtail")).leaf = true
end
function action_status()
local e = {}
e.running = luci.sys.call("pidof aliyundrive-webdav >/dev/null") == 0
e.application = luci.sys.exec("aliyundrive-webdav --version")
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function action_logtail()
local fs = require "nixio.fs"
local log_path = "/var/log/aliyundrive-webdav.log"
local e = {}
e.running = luci.sys.call("pidof aliyundrive-webdav >/dev/null") == 0
if fs.access(log_path) then
e.log = luci.sys.exec("tail -n 100 %s | sed 's/\\x1b\\[[0-9;]*m//g'" % log_path)
else
e.log = ""
end
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@ -0,0 +1,48 @@
local uci = luci.model.uci.cursor()
local m, e
m = Map("aliyundrive-webdav", translate("AliyunDrive WebDAV"),
translate("<a href=\"https://github.com/messense/aliyundrive-webdav\" target=\"_blank\">Project GitHub URL</a>"))
m:section(SimpleSection).template = "aliyundrive-webdav/aliyundrive-webdav_status"
e = m:section(TypedSection, "server")
e.anonymous = true
enable = e:option(Flag, "enable", translate("Enable"))
enable.rmempty = false
refresh_token = e:option(Value, "refresh_token", translate("Refresh Token"),
translate("<a href=\"https://github.com/messense/aliyundrive-webdav#%E8%8E%B7%E5%8F%96-refresh_token\" target=\"_blank\">How to get refresh token</a>"))
root = e:option(Value, "root", translate("Root Directory"))
root.default = "/"
host = e:option(Value, "host", translate("Host"))
host.default = "0.0.0.0"
host.datatype = "ipaddr"
port = e:option(Value, "port", translate("Port"))
port.default = "8080"
port.datatype = "port"
auth_user = e:option(Value, "auth_user", translate("Username"))
auth_password = e:option(Value, "auth_password", translate("Password"))
auth_password.password = true
read_buffer_size = e:option(Value, "read_buffer_size", translate("Read Buffer Size"))
read_buffer_size.default = "10485760"
read_buffer_size.datatype = "uinteger"
cache_size = e:option(Value, "cache_size", translate("Cache Size"))
cache_size.default = "1000"
cache_size.datatype = "uinteger"
debug = e:option(Flag, "debug", translate("Debug Mode"))
debug.rmempty = false
local e = luci.http.formvalue("cbi.apply")
if e then
io.popen("/etc/init.d/aliyundrive-webdav restart")
end
return m

View File

@ -0,0 +1,9 @@
log = SimpleForm("logview")
log.submit = false
log.reset = false
t = log:field(DummyValue, '', '')
t.rawhtml = true
t.template = 'aliyundrive-webdav/aliyundrive-webdav_log'
return log

View File

@ -0,0 +1,15 @@
<%+cbi/valueheader%>
<textarea id="logview" class="cbi-input-textarea" style="width: 100%" rows="30" readonly="readonly"></textarea>
<script type="text/javascript">
const LOG_URL = '<%=luci.dispatcher.build_url("admin", "services", "aliyundrive-webdav", "logtail")%>';
XHR.poll(1, LOG_URL, null, (x, d) => {
let logview = document.getElementById("logview");
if (!d.running) {
XHR.halt();
}
logview.value = d.log;
logview.scrollTop = logview.scrollHeight;
});
</script>
<%+cbi/valuefooter%>

View File

@ -0,0 +1,21 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[aliyundrive-webdav]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('aliyundrive-webdav_status');
if (data && tb) {
if (data.running) {
tb.innerHTML = '<em><b><font color=green>' + data.application + '<%:RUNNING%></font></b></em>';
} else {
tb.innerHTML = '<em><b><font color=red>' + data.application + '<%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="aliyundrive-webdav_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -0,0 +1,59 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
msgid "AliyunDrive"
msgstr "阿里云盘"
msgid "AliyunDrive WebDAV"
msgstr "阿里云盘 WebDAV"
msgid "Enable"
msgstr "启用"
msgid "Refresh Token"
msgstr "Refresh Token"
msgid "Root Directory"
msgstr "根目录"
msgid "Host"
msgstr "监听主机"
msgid "Port"
msgstr "监听端口"
msgid "Username"
msgstr "用户名"
msgid "Password"
msgstr "密码"
msgid "Read Buffer Size"
msgstr "下载缓冲大小(bytes)"
msgid "Cache Size"
msgstr "目录缓存大小"
msgid "Collecting data..."
msgstr "获取数据中..."
msgid "RUNNING"
msgstr "运行中"
msgid "NOT RUNNING"
msgstr "未运行"
msgid "Settings"
msgstr "设置"
msgid "Log"
msgstr "日志"
msgid "Debug Mode"
msgstr "调试模式"
msgid "<a href=\"https://github.com/messense/aliyundrive-webdav\" target=\"_blank\">Project GitHub URL</a>"
msgstr "<a href=\"https://github.com/messense/aliyundrive-webdav\" target=\"_blank\">GitHub 项目地址</a>"
msgid "<a href=\"https://github.com/messense/aliyundrive-webdav#%E8%8E%B7%E5%8F%96-refresh_token\" target=\"_blank\">How to get refresh token</a>"
msgstr "<a href=\"https://github.com/messense/aliyundrive-webdav#%E8%8E%B7%E5%8F%96-refresh_token\" target=\"_blank\">查看获取 refresh token 的方法</a>"

View File

@ -0,0 +1,11 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@aliyundrive-webdav[-1]
add ucitrack aliyundrive-webdav
set ucitrack.@aliyundrive-webdav[-1].init=aliyundrive-webdav
commit ucitrack
EOF
rm -f /tmp/luci-indexcache
exit 0