From 51eead14e8af4a7e9fc3c2678ea112af05fdf587 Mon Sep 17 00:00:00 2001 From: LEAN-ESX Date: Sat, 9 Nov 2019 07:18:58 -0800 Subject: [PATCH] luci-app-qbittorrent: update luci --- package/lean/luci-app-qbittorrent/Makefile | 2 +- .../luasrc/controller/qbittorrent.lua | 14 +++++++- .../luasrc/model/cbi/qbittorrent.lua | 34 ++++++------------- .../view/qbittorrent/qbittorrent_status.htm | 22 ++++++++++++ .../po/zh-cn/qbittorrent.po | 6 ++-- .../root/etc/config/qbittorrent | 8 +++++ .../root/etc/init.d/qbittorrent | 16 +++++++-- .../root/etc/uci-defaults/qbittorrent | 12 +++++++ 8 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 package/lean/luci-app-qbittorrent/luasrc/view/qbittorrent/qbittorrent_status.htm create mode 100755 package/lean/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent diff --git a/package/lean/luci-app-qbittorrent/Makefile b/package/lean/luci-app-qbittorrent/Makefile index 70f4703b6..c064fdc6b 100644 --- a/package/lean/luci-app-qbittorrent/Makefile +++ b/package/lean/luci-app-qbittorrent/Makefile @@ -10,7 +10,7 @@ LUCI_DEPENDS:=+qBittorrent LUCI_PKGARCH:=all PKG_NAME:=luci-app-qbittorrent PKG_VERSION=1.0 -PKG_RELEASE:=4 +PKG_RELEASE:=8 include $(TOPDIR)/feeds/luci/luci.mk diff --git a/package/lean/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua b/package/lean/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua index 5363ac978..999836836 100755 --- a/package/lean/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua +++ b/package/lean/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua @@ -1,4 +1,16 @@ module("luci.controller.qbittorrent",package.seeall) + function index() - entry({"admin","nas","qbittorrent"},cbi("qbittorrent"),_("qbittorrent")) + if not nixio.fs.access("/etc/config/qbittorrent")then + return + end + entry({"admin","nas","qBittorrent"},cbi("qbittorrent"),_("qbittorrent")) + entry({"admin","nas","qBittorrent","status"},call("act_status")).leaf=true +end + +function act_status() + local e={} + e.running=luci.sys.call("pgrep qbittorrent-nox >/dev/null")==0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) end diff --git a/package/lean/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua b/package/lean/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua index af37d8fb3..b5dbe9d7e 100755 --- a/package/lean/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua +++ b/package/lean/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua @@ -1,44 +1,32 @@ -require("luci.sys") local e=require"luci.model.uci".cursor() -local o=e:get_first("qbittorrent","Preferences","port")or 8080 +local o=e:get_first("qbittorrent","Preferences","port") or 8080 + local a=(luci.sys.call("pidof qbittorrent-nox > /dev/null")==0) + local t="" -local e="" if a then -t="      " -end -if a then -e=""..translate("Running").."" -else -e=""..translate("Not running").."" +t="

" end -m = Map("qbittorrent", translate("qbittorrent"), translate("A BT/PT downloader base on Qt")..t -.."

"..translate("qbittorrent Run Status").." : "..e.."
") +m = Map("qbittorrent", translate("qBittorrent"), translate("qBittorrent is a cross-platform free and open-source BitTorrent client")..t) + +m:section(SimpleSection).template="qbittorrent/qbittorrent_status" s_basic = m:section(TypedSection, "basic", translate("Basic Settings")) s_basic.anonymous = true + enable = s_basic:option(Flag, "enable", translate("Enable")) profile_dir = s_basic:option(Value,"profile_dir",translate("profile_dir"),translate("Store configuration files in the Path")) -profile_dir.default = "/tmp" -program_dir = s_basic:option(Value,"program_dir",translate("program_dir"),translate("Store Program files in the Path")) -program_dir.default = "/usr/bin" -library_dir = s_basic:option(Value,"library_dir",translate("library_dir"),translate("Store Library in the Path")) -library_dir.default = "/usr/lib" +profile_dir.default = "/root" s_download = m:section(TypedSection, "Preferences", translate("Download Settings")) s_download.anonymous = true download_dir = s_download:option(Value,"download_dir",translate("download_dir"),translate("Store download files in the Path")) -download_dir.default = "/tmp/download" +download_dir.default = "/root/download" s_webui = m:section(TypedSection, "Preferences", translate("WEBUI Settings")) s_webui.anonymous = true port = s_webui:option(Value,"port",translate("port"),translate("WEBUI listening port")) port.default = "8080" -local apply = luci.http.formvalue("cbi.apply") -if apply then - io.popen("/etc/init.d/qbittorrent restart") -end - -return m +return m \ No newline at end of file diff --git a/package/lean/luci-app-qbittorrent/luasrc/view/qbittorrent/qbittorrent_status.htm b/package/lean/luci-app-qbittorrent/luasrc/view/qbittorrent/qbittorrent_status.htm new file mode 100644 index 000000000..13ebe1c97 --- /dev/null +++ b/package/lean/luci-app-qbittorrent/luasrc/view/qbittorrent/qbittorrent_status.htm @@ -0,0 +1,22 @@ + + +
+

+ <%:Collecting data...%> +

+
\ No newline at end of file diff --git a/package/lean/luci-app-qbittorrent/po/zh-cn/qbittorrent.po b/package/lean/luci-app-qbittorrent/po/zh-cn/qbittorrent.po index d7a834ede..51013dab4 100644 --- a/package/lean/luci-app-qbittorrent/po/zh-cn/qbittorrent.po +++ b/package/lean/luci-app-qbittorrent/po/zh-cn/qbittorrent.po @@ -1,5 +1,5 @@ msgid "qbittorrent" -msgstr "BT下载器-qb" +msgstr "qbittorrent" msgid "Running" msgstr "运行中" @@ -16,8 +16,8 @@ msgstr "基本设置" msgid "Enable" msgstr "启用" -msgid "A BT/PT downloader base on Qt" -msgstr "一个基于QT的BT/PT下载器" +msgid "qBittorrent is a cross-platform free and open-source BitTorrent client" +msgstr "qBittorrent是一个基于 QT 的跨平台的开源 BitTorrent 客户端" msgid "profile_dir" msgstr "配置文件目录" diff --git a/package/lean/luci-app-qbittorrent/root/etc/config/qbittorrent b/package/lean/luci-app-qbittorrent/root/etc/config/qbittorrent index b4fe940c3..1de5a8ff0 100644 --- a/package/lean/luci-app-qbittorrent/root/etc/config/qbittorrent +++ b/package/lean/luci-app-qbittorrent/root/etc/config/qbittorrent @@ -1,3 +1,11 @@ + config basic + option program_dir '/usr/bin' + option library_dir '/usr/lib' + option profile_dir '/root' + option enable '0' config Preferences + option download_dir '/root/download' + option port '8080' + diff --git a/package/lean/luci-app-qbittorrent/root/etc/init.d/qbittorrent b/package/lean/luci-app-qbittorrent/root/etc/init.d/qbittorrent index 383317165..2f55f48ab 100755 --- a/package/lean/luci-app-qbittorrent/root/etc/init.d/qbittorrent +++ b/package/lean/luci-app-qbittorrent/root/etc/init.d/qbittorrent @@ -1,6 +1,11 @@ #!/bin/sh /etc/rc.common START=99 +get_config() +{ + config_get_bool enable $1 enable 0 +} + config_qbittorrent() { local download_dir @@ -24,9 +29,11 @@ Accepted=true Cookies=@Invalid() [Preferences] +General\Locale=zh Downloads\SavePath=$download_dir General\Locale=zh WebUI\Port=$port +WebUI\CSRFProtection=false EOF fi } @@ -39,7 +46,7 @@ run_qbittorrent() if [ $enable ]; then local profile_dir config_get profile_dir $1 profile_dir - config_foreach config_qbittorrent 'Preferences' $profile_dir + config_foreach config_qbittorrent 'Preferences' $profile_dir if [ "$profile_dir" != "" ]; then config_get library_dir $1 library_dir config_get program_dir $1 program_dir @@ -55,13 +62,16 @@ run_qbittorrent() start() { + stop local profile_path - config_load 'qbittorrent' + config_load 'qbittorrent' + config_foreach get_config basic + [ $enable -eq 0 ] && exit 0 config_foreach run_qbittorrent 'basic' } stop() { - killall qbittorrent-nox + killall qbittorrent-nox >/dev/null 2>&1 return 0 } diff --git a/package/lean/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent b/package/lean/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent new file mode 100755 index 000000000..c9995c156 --- /dev/null +++ b/package/lean/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent @@ -0,0 +1,12 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@qbittorrent[-1] + add ucitrack qbittorrent + set ucitrack.@qbittorrent[-1].init=qbittorrent + commit ucitrack +EOF + +/etc/init.d/qbittorrent stop +rm -f /tmp/luci-indexcache +exit 0