Skip to content

Commit

Permalink
Merge pull request #28 from gngpp/dev
Browse files Browse the repository at this point in the history
feat: add launcher log status
  • Loading branch information
0x676e67 authored May 8, 2023
2 parents 1041e0f + 7d34fe8 commit 69d4ec3
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xunlei"
version = "3.5.2-5"
version = "3.5.2-6"
edition = "2021"
description = "Synology Nas Thunder runs on Linux"
license = "MIT"
Expand Down
3 changes: 1 addition & 2 deletions openwrt/luci-app-xunlei/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-xunlei
PKG_VERSION:=1.0.1
PKG_RELEASE:=3
PKG_VERSION:=1.0.1-4

PKG_MAINTAINER:=gngpp <[email protected]>

Expand Down
22 changes: 21 additions & 1 deletion openwrt/luci-app-xunlei/luasrc/controller/xunlei.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,36 @@ function index()
return
end

local page = entry({"admin", "nas", "xunlei"}, cbi("xunlei"), _("Xunlei"), 100)
local page
page = entry({ "admin", "nas", "xunlei" }, alias("admin", "nas", "xunlei", "client"), _("Xunlei"), 10)
page.dependent = true
page.acl_depends = { "luci-app-xunlei" }

entry({ "admin", "nas", "xunlei", "client" }, cbi("xunlei/client"), _("Settings"), 10).leaf = true
entry({ "admin", "nas", "xunlei", "log" }, form("xunlei/log"), _("Log"), 30).leaf = true

entry({"admin", "nas", "xunlei", "status"}, call("act_status")).leaf = true
entry({ "admin", "nas", "xunlei", "logtail" }, call("action_logtail")).leaf = true
end

function act_status()
local e = {}
e.running = sys.call("pgrep -f xunlei >/dev/null") == 0
e.application = luci.sys.exec("xunlei --version")
http.prepare_content("application/json")
http.write_json(e)
end

function action_logtail()
local fs = require "nixio.fs"
local log_path = "/var/log/xunlei.log"
local e = {}
e.running = luci.sys.call("pidof xunlei >/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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local m, s

m = Map("xunlei", translate("Xunlei"))
m.description = translate("<a>NAS Xunlei DSM 7.x Beta Version, Invitation code (3H9F7Y6D)</a> | <a href=\"https://github.com/gngpp/nas-xunlei\" target=\"_blank\">Project GitHub URL</a>")
m.description = translate("<a>NAS Xunlei DSM 7.x Beta Version</a> | <a href=\"https://github.com/gngpp/nas-xunlei\" target=\"_blank\">Project GitHub URL</a>")

m:section(SimpleSection).template = "xunlei/xunlei_status"

Expand Down
9 changes: 9 additions & 0 deletions openwrt/luci-app-xunlei/luasrc/model/cbi/xunlei/log.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
log = SimpleForm("logview")
log.submit = false
log.reset = false

t = log:field(DummyValue, '', '')
t.rawhtml = true
t.template = 'xunlei/xunlei_log'

return log
15 changes: 15 additions & 0 deletions openwrt/luci-app-xunlei/luasrc/view/xunlei/xunlei_log.htm
Original file line number Diff line number Diff line change
@@ -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", "nas", "xunlei", "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%>
4 changes: 2 additions & 2 deletions openwrt/luci-app-xunlei/luasrc/view/xunlei/xunlei_status.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
{
if (data.running)
{
tb.innerHTML = '<em style=\"color:green\"><b><%:Xunlei%> <%:RUNNING%></b></em>' + "<input class=\"cbi-button cbi-button-reload mar-10\" type=\"button\" value=\" <%:Open Web Interface%> \" onclick=\"window.open('//" + window.location.hostname + ":" + <%=luci.sys.exec("uci -q get xunlei.@xunlei[0].port"):gsub("^%s*(.-)%s*$", "%1")%> + "/')\"/>";
tb.innerHTML = '<em style=\"color:green\"><b>' + data.application + '<%:RUNNING%></b></em>' + "<input class=\"cbi-button cbi-button-reload mar-10\" type=\"button\" value=\" <%:Open Web Interface%> \" onclick=\"window.open('//" + window.location.hostname + ":" + <%=luci.sys.exec("uci -q get xunlei.@xunlei[0].port"):gsub("^%s*(.-)%s*$", "%1")%> + "/')\"/>";
}
else
{
tb.innerHTML = '<em style=\"color:red\"><b><%:Xunlei%> <%:NOT RUNNING%></b></em>';
tb.innerHTML = '<em style=\"color:red\"><b>' + data.application + '<%:NOT RUNNING%></b></em>';
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions openwrt/luci-app-xunlei/po/zh-cn/xunlei.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ msgstr "Content-Type: text/plain; charset=UTF-8\n"
msgid "Xunlei"
msgstr "迅雷"

msgid "<a>NAS Xunlei DSM 7.x Beta Version, Invitation code (3H9F7Y6D)</a> | <a href=\"https://github.com/gngpp/nas-xunlei\" target=\"_blank\">Project GitHub URL</a>"
msgstr "<a>NAS 迅雷 DSM 7.x 内测版,邀请码(3H9F7Y6D)</a> | <a href=\"https://github.com/gngpp/nas-xunlei\" target=\"_blank\">GitHub 项目地址</a>"
msgid "<a>NAS Xunlei DSM 7.x Beta Version</a> | <a href=\"https://github.com/gngpp/nas-xunlei\" target=\"_blank\">Project GitHub URL</a>"
msgstr "<a>NAS 迅雷 DSM 7.x 内测版</a> | <a href=\"https://github.com/gngpp/nas-xunlei\" target=\"_blank\">GitHub 项目地址</a>"

msgid "Enabled"
msgstr "启用"
Expand Down Expand Up @@ -34,6 +34,12 @@ msgstr "用户名"
msgid "Password"
msgstr "密码"

msgid "Settings"
msgstr "设置"

msgid "Log"
msgstr "日志"

msgid "Data Storage Path"
msgstr "数据储存路径"

Expand Down
2 changes: 1 addition & 1 deletion openwrt/xunlei/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=xunlei

PKG_VERSION:=3.5.2-5
PKG_VERSION:=3.5.2-6

PKG_LICENSE:=MIT
PKG_MAINTAINER:=gngpp <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion openwrt/xunlei/files/xunlei.init
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ start_service() {
args="$args -U $auth_user -W $auth_password"
fi
procd_open_instance
procd_set_param command $PROG launch $args
procd_set_param command /bin/sh -c "$PROG launch $args >>/var/log/xunlei.log 2>&1"
procd_set_param stdout 0
procd_set_param stderr 0
procd_set_param pidfile /var/run/xunlei.pid
Expand Down

0 comments on commit 69d4ec3

Please sign in to comment.