diff --git a/luci-app-qbittorrent/Makefile b/luci-app-qbittorrent/Makefile index 7ae7354..896a35f 100644 --- a/luci-app-qbittorrent/Makefile +++ b/luci-app-qbittorrent/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-qbittorrent -PKG_VERSION:=1.0.0 +PKG_VERSION:=1.0.1 PKG_RELEASE:=1 LUCI_TITLE:=LuCI support for qBittorrent diff --git a/luci-app-qbittorrent/htdocs/luci-static/resources/view/qbittorrent.js b/luci-app-qbittorrent/htdocs/luci-static/resources/view/qbittorrent.js new file mode 100644 index 0000000..2aa4e2a --- /dev/null +++ b/luci-app-qbittorrent/htdocs/luci-static/resources/view/qbittorrent.js @@ -0,0 +1,85 @@ +'use strict'; +'require form'; +'require poll'; +'require rpc'; +'require uci'; +'require view'; + +var callServiceList = rpc.declare({ + object: 'service', + method: 'list', + params: ['name'], + expect: { '': {} } +}); + +function getServiceStatus() { + return L.resolveDefault(callServiceList('qbittorrent'), {}).then(function (res) { + var isRunning = false; + try { + isRunning = res['qbittorrent']['instances']['instance1']['running']; + } catch (e) { } + return isRunning; + }); +} + +function renderStatus(isRunning, webport) { + var spanTemp = '%s %s'; + var renderHTML; + if (isRunning) { + var button = String.format('', + _('Open Web Interface'), window.location.hostname, webport); + renderHTML = spanTemp.format('green', _('qBittorrent'), _('RUNNING')) + button; + } else { + renderHTML = spanTemp.format('red', _('qBittorrent'), _('NOT RUNNING')); + } + + return renderHTML; +} + +return view.extend({ + load: function() { + return Promise.all([ + uci.load('qbittorrent') + ]); + }, + + render: function(data) { + var m, s, o; + var webport = uci.get(data[0], 'config', 'port') || '8080'; + + m = new form.Map('qbittorrent', _('qBittorrent'), + _('qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin')); + + s = m.section(form.TypedSection); + s.anonymous = true; + s.render = function () { + poll.add(function () { + return L.resolveDefault(getServiceStatus()).then(function (res) { + var view = document.getElementById('service_status'); + view.innerHTML = renderStatus(res, webport); + }); + }); + + return E('div', { class: 'cbi-section', id: 'status_bar' }, [ + E('p', { id: 'service_status' }, _('Collecting data...')) + ]); + } + + s = m.section(form.NamedSection, 'config', 'qbittorrent'); + + o = s.option(form.Flag, 'enabled', _('Enable')); + o.default = o.disabled; + o.rmempty = false; + + o = s.option(form.Value, 'port', _('WebUI Listen port')); + o.datatype = 'port'; + o.default = '8080'; + o.rmempty = false; + + o = s.option(form.Value, 'profile_dir', _('Configuration files Path')); + o.default = '/etc/qbittorrent'; + o.rmempty = false; + + return m.render(); + } +}); diff --git a/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua b/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua deleted file mode 100644 index 4dfc602..0000000 --- a/luci-app-qbittorrent/luasrc/controller/qbittorrent.lua +++ /dev/null @@ -1,24 +0,0 @@ -module("luci.controller.qbittorrent", package.seeall) - -function index() - if not nixio.fs.access("/etc/config/qbittorrent") then - return - end - - entry({"admin", "services", "qbittorrent"}, cbi("qbittorrent"), _("qBittorrent"), 20).dependent = true - entry({"admin", "services", "qbittorrent_status"}, call("qbittorrent_status")) -end - -function qbittorrent_status() - local sys = require "luci.sys" - local uci = require "luci.model.uci".cursor() - local port = tonumber(uci:get_first("qbittorrent", "qbittorrent", "port")) - - local status = { - running = (sys.call("pidof qbittorrent-nox >/dev/null") == 0), - port = (port or 8080) - } - - luci.http.prepare_content("application/json") - luci.http.write_json(status) -end diff --git a/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua b/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua deleted file mode 100644 index 6c28c18..0000000 --- a/luci-app-qbittorrent/luasrc/model/cbi/qbittorrent.lua +++ /dev/null @@ -1,15 +0,0 @@ -local m, s - -m = Map("qbittorrent", translate("qBittorrent"), translate("qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin")) - -m:section(SimpleSection).template = "qbittorrent_status" - -s=m:section(TypedSection, "qbittorrent", translate("Global settings")) -s.addremove=false -s.anonymous=true - -s:option(Flag, "enabled", translate("Enable")).rmempty=false -s:option(Value, "port", translate("WebUI Port")).rmempty=false -s:option(Value, "profile_dir", translate("Configuration files Path")).rmempty=false - -return m diff --git a/luci-app-qbittorrent/luasrc/view/qbittorrent_status.htm b/luci-app-qbittorrent/luasrc/view/qbittorrent_status.htm deleted file mode 100644 index 1f52601..0000000 --- a/luci-app-qbittorrent/luasrc/view/qbittorrent_status.htm +++ /dev/null @@ -1,26 +0,0 @@ - - - -
-

- <%:Collecting data...%> -

-
diff --git a/luci-app-qbittorrent/po/zh_Hans/qbittorrent.po b/luci-app-qbittorrent/po/zh_Hans/qbittorrent.po index c6fcdb6..7d4c803 100644 --- a/luci-app-qbittorrent/po/zh_Hans/qbittorrent.po +++ b/luci-app-qbittorrent/po/zh_Hans/qbittorrent.po @@ -10,10 +10,7 @@ msgstr "打开 Web 界面" msgid "qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin" msgstr "qBittorrent 是一个基于 QT 的跨平台的开源 BitTorrent 客户端。默认用户名 & 密码:admin / adminadmin" -msgid "Global settings" -msgstr "全局设置" - -msgid "WebUI Port" +msgid "WebUI Listen port" msgstr "WebUI 监听端口" msgid "Configuration files Path" diff --git a/luci-app-qbittorrent/root/etc/uci-defaults/50_luci-qbittorrent b/luci-app-qbittorrent/root/etc/uci-defaults/50_luci-qbittorrent deleted file mode 100755 index e0aedf7..0000000 --- a/luci-app-qbittorrent/root/etc/uci-defaults/50_luci-qbittorrent +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -rm -f /tmp/luci-indexcache* -exit 0 diff --git a/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent b/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent new file mode 100755 index 0000000..0cdbab3 --- /dev/null +++ b/luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@qbittorrent[-1] + add ucitrack qbittorrent + set ucitrack.@qbittorrent[-1].init=qbittorrent + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache* +exit 0 diff --git a/luci-app-qbittorrent/root/usr/share/luci/menu.d/luci-app-qbittorrent.json b/luci-app-qbittorrent/root/usr/share/luci/menu.d/luci-app-qbittorrent.json new file mode 100644 index 0000000..f6ed76f --- /dev/null +++ b/luci-app-qbittorrent/root/usr/share/luci/menu.d/luci-app-qbittorrent.json @@ -0,0 +1,14 @@ +{ + "admin/services/qbittorrent": { + "title": "qBittorrent", + "order": 20, + "action": { + "type": "view", + "path": "qbittorrent" + }, + "depends": { + "acl": [ "luci-app-qbittorrent" ], + "uci": { "qbittorrent": true } + } + } +} diff --git a/luci-app-qbittorrent/root/usr/share/rpcd/acl.d/luci-app-qbittorrent.json b/luci-app-qbittorrent/root/usr/share/rpcd/acl.d/luci-app-qbittorrent.json index c46f3c9..5d8c1f2 100644 --- a/luci-app-qbittorrent/root/usr/share/rpcd/acl.d/luci-app-qbittorrent.json +++ b/luci-app-qbittorrent/root/usr/share/rpcd/acl.d/luci-app-qbittorrent.json @@ -2,6 +2,9 @@ "luci-app-qbittorrent": { "description": "Grant UCI access for luci-app-qbittorrent", "read": { + "ubus": { + "service": [ "list" ] + }, "uci": [ "qbittorrent" ] }, "write": {