From c2ed5616ef3d82e3718bc1f9887b8ed843e476a8 Mon Sep 17 00:00:00 2001 From: Beginner <70857188+Beginner-Go@users.noreply.github.com> Date: Fri, 26 Nov 2021 18:19:23 +0800 Subject: [PATCH] luci-app-frps: fix status bar (#8315) --- package/lean/luci-app-frps/Makefile | 14 +--- .../luci-app-frps/luasrc/controller/frps.lua | 23 ++---- .../luasrc/model/cbi/frps/common.lua | 72 +++++++------------ .../luasrc/model/cbi/frps/server.lua | 6 +- .../luasrc/view/frps/frps_status.htm | 21 ++++++ .../luasrc/view/frps/status_header.htm | 29 -------- package/lean/luci-app-frps/po/zh-cn/frps.po | 47 +++--------- 7 files changed, 64 insertions(+), 148 deletions(-) create mode 100644 package/lean/luci-app-frps/luasrc/view/frps/frps_status.htm delete mode 100644 package/lean/luci-app-frps/luasrc/view/frps/status_header.htm diff --git a/package/lean/luci-app-frps/Makefile b/package/lean/luci-app-frps/Makefile index 1933daf22..89ddcba79 100644 --- a/package/lean/luci-app-frps/Makefile +++ b/package/lean/luci-app-frps/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-frps PKG_VERSION:=0.0.2 -PKG_RELEASE:=3 +PKG_RELEASE:=4 PKG_LICENSE:=MIT PKG_LICENSE_FILES:=LICENSE @@ -24,16 +24,4 @@ endef include $(TOPDIR)/feeds/luci/luci.mk -define Package/$(PKG_NAME)/postinst -#!/bin/sh -if [ -z "$${IPKG_INSTROOT}" ]; then - ( . /etc/uci-defaults/40_luci-frps ) && rm -f /etc/uci-defaults/40_luci-frps -fi - -chmod 755 "$${IPKG_INSTROOT}/etc/init.d/frps" >/dev/null 2>&1 -ln -sf "../init.d/frps" \ - "$${IPKG_INSTROOT}/etc/rc.d/S99frps" >/dev/null 2>&1 -exit 0 -endef - # call BuildPackage - OpenWrt buildroot signature diff --git a/package/lean/luci-app-frps/luasrc/controller/frps.lua b/package/lean/luci-app-frps/luasrc/controller/frps.lua index 6662ea6cf..d4c4ab058 100644 --- a/package/lean/luci-app-frps/luasrc/controller/frps.lua +++ b/package/lean/luci-app-frps/luasrc/controller/frps.lua @@ -1,10 +1,6 @@ -- Copyright 2020 lwz322 -- Licensed to the public under the MIT License. -local http = require "luci.http" -local uci = require "luci.model.uci".cursor() -local sys = require "luci.sys" - module("luci.controller.frps", package.seeall) function index() @@ -22,18 +18,9 @@ end function action_status() - local running = false - - local client = uci:get("frps", "main", "client_file") - if client and client ~= "" then - local file_name = client:match(".*/([^/]+)$") or "" - if file_name ~= "" then - running = sys.call("pidof %s >/dev/null" % file_name) == 0 - end - end - - http.prepare_content("application/json") - http.write_json({ - running = running - }) + local e = {} + e.running = luci.sys.call("pidof frps >/dev/null") == 0 + e.bin_version = luci.sys.exec("frps -v") + luci.http.prepare_content("application/json") + luci.http.write_json(e) end diff --git a/package/lean/luci-app-frps/luasrc/model/cbi/frps/common.lua b/package/lean/luci-app-frps/luasrc/model/cbi/frps/common.lua index c5c0d0256..08dae4ba8 100644 --- a/package/lean/luci-app-frps/luasrc/model/cbi/frps/common.lua +++ b/package/lean/luci-app-frps/luasrc/model/cbi/frps/common.lua @@ -1,40 +1,13 @@ -- Copyright 2020 lwz322 -- Licensed to the public under the MIT License. -local uci = require "luci.model.uci".cursor() -local util = require "luci.util" -local fs = require "nixio.fs" -local sys = require "luci.sys" - local m, s, o -local server_table = { } -local function frps_version() - local file = uci:get("frps", "main", "client_file") +m = Map("frps") +m.title = translate("Frps - Common Settings") +m.description = translate("Frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.
Project GitHub URL") - if not file or file == "" or not fs.stat(file) then - return "%s" % translate("Invalid client file") - end - - if not fs.access(file, "rwx", "rx", "rx") then - fs.chmod(file, 755) - end - - local version = util.trim(sys.exec("%s -v 2>/dev/null" % file)) - if version == "" then - return "%s" % translate("Can't get client version") - end - return translatef("Version: %s", version) -end - -m = Map("frps", "%s - %s" % { translate("Frps"), translate("Common Settings") }, -"

%s

%s

" % { - translate("Frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet."), - translatef("For more information, please visit: %s", - "https://github.com/fatedier/frp") -}) - -m:append(Template("frps/status_header")) +m:section(SimpleSection).template = "frps/frps_status" s = m:section(NamedSection, "main", "frps") s.addremove = false @@ -46,14 +19,14 @@ s:tab("dashboard", translate("Dashboard Options")) o = s:taboption("general", Flag, "enabled", translate("Enabled")) -o = s:taboption("general", Value, "client_file", translate("Client file"), frps_version()) -o.datatype = "file" +o = s:taboption("general", Value, "client_file", translate("Client file")) +o.default = "/usr/bin/frps" o.rmempty = false o = s:taboption("general", ListValue, "run_user", translate("Run daemon as user")) o:value("", translate("-- default --")) local user -for user in util.execi("cat /etc/passwd | cut -d':' -f1") do +for user in luci.util.execi("cat /etc/passwd | cut -d':' -f1") do o:value(user) end @@ -65,11 +38,11 @@ o.placeholder = "/var/log/frps.log" o = s:taboption("general", ListValue, "log_level", translate("Log level")) o:depends("enable_logging", "1") -o:value("trace", translate("Trace")) -o:value("debug", translate("Debug")) -o:value("info", translate("Info")) -o:value("warn", translate("Warn")) -o:value("error", translate("Error")) +o:value("trace", "Trace") +o:value("debug", "Debug") +o:value("info", "Info") +o:value("warn", "Warn") +o:value("error", "Error") o.default = "warn" o = s:taboption("general", Value, "log_max_days", translate("Log max days")) @@ -82,27 +55,30 @@ o:depends("enable_logging", "1") o.enabled = "true" o.disabled = "false" -o = s:taboption("advanced", Value, "max_pool_count", translate("Max pool count"), - translate("pool_count in each proxy will change to max_pool_count if they exceed the maximum value")) +o = s:taboption("advanced", Value, "max_pool_count", translate("Max pool count")) +o.description = translate("pool_count in each proxy will change to max_pool_count if they exceed the maximum value") o.datatype = "uinteger" -o = s:taboption("advanced", Value, "max_ports_per_client", translate("Max ports per-client"), - translate("max ports can be used for each client, default value is 0 means no limit")) +o = s:taboption("advanced", Value, "max_ports_per_client", translate("Max ports per-client")) +o.description = translate("max ports can be used for each client, default value is 0 means no limit") o.datatype = "uinteger" o.defalut = '0' o.placeholder = '0' -o = s:taboption("advanced", Value, "subdomain_host", translate("Subdomain host"), - translatef("if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file; when subdomain is test, the host used by routing is test.frps.com")) +o = s:taboption("advanced", Value, "subdomain_host", translate("Subdomain host")) +o.description = translatef("if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file; when subdomain is test, the host used by routing is test.frps.com") o.datatype = "host" -o = s:taboption("dashboard", Value, "dashboard_addr", translate("Dashboard addr"), translatef("dashboard addr's default value is same with bind_addr")) +o = s:taboption("dashboard", Value, "dashboard_addr", translate("Dashboard addr")) +o.description = translatef("dashboard addr's default value is same with bind_addr") o.datatype = "host" -o = s:taboption("dashboard", Value, "dashboard_port", translate("Dashboard port"), translatef("dashboard is available only if dashboard_port is set")) +o = s:taboption("dashboard", Value, "dashboard_port", translate("Dashboard port")) +o.description = translatef("dashboard is available only if dashboard_port is set") o.datatype = "port" -o = s:taboption("dashboard", Value, "dashboard_user", translate("Dashboard user"), translatef("dashboard user and passwd for basic auth protect, if not set, both default value is admin")) +o = s:taboption("dashboard", Value, "dashboard_user", translate("Dashboard user")) +o.description = translatef("dashboard user and passwd for basic auth protect, if not set, both default value is admin") o = s:taboption("dashboard", Value, "dashboard_pwd", translate("Dashboard password")) o.password = true diff --git a/package/lean/luci-app-frps/luasrc/model/cbi/frps/server.lua b/package/lean/luci-app-frps/luasrc/model/cbi/frps/server.lua index 7fca105c1..2201468f6 100644 --- a/package/lean/luci-app-frps/luasrc/model/cbi/frps/server.lua +++ b/package/lean/luci-app-frps/luasrc/model/cbi/frps/server.lua @@ -1,11 +1,11 @@ -- Copyright 2020 lwz322 -- Licensed to the public under the MIT License. -local dsp = require "luci.dispatcher" - local m, s, o -m = Map("frps", "%s - %s" % { translate("Frps"), translate("FRPS Server setting") }) +m = Map("frps") +m.title = translate("Frps - Server Settings") +m.description = translate("FRPS Server Settings") s = m:section(NamedSection, "main", "frps") s.anonymous = true diff --git a/package/lean/luci-app-frps/luasrc/view/frps/frps_status.htm b/package/lean/luci-app-frps/luasrc/view/frps/frps_status.htm new file mode 100644 index 000000000..f0fdbe3fc --- /dev/null +++ b/package/lean/luci-app-frps/luasrc/view/frps/frps_status.htm @@ -0,0 +1,21 @@ + + +
+

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

+
diff --git a/package/lean/luci-app-frps/luasrc/view/frps/status_header.htm b/package/lean/luci-app-frps/luasrc/view/frps/status_header.htm deleted file mode 100644 index a5bd6a0b2..000000000 --- a/package/lean/luci-app-frps/luasrc/view/frps/status_header.htm +++ /dev/null @@ -1,29 +0,0 @@ -<%# - Copyright 2020 lwz322 - Licensed to the public under the MIT License. --%> - -<% -local dsp = require "luci.dispatcher" --%> - -
-

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

-
- - diff --git a/package/lean/luci-app-frps/po/zh-cn/frps.po b/package/lean/luci-app-frps/po/zh-cn/frps.po index 0ca602d69..e4f7a477c 100644 --- a/package/lean/luci-app-frps/po/zh-cn/frps.po +++ b/package/lean/luci-app-frps/po/zh-cn/frps.po @@ -13,21 +13,13 @@ msgstr "高级选项" msgid "Bind port" msgstr "绑定端口" -#: luasrc/model/cbi/frps/common.lua:25 -msgid "Can't get client version" -msgstr "无法获取到客户端版本" - #: luasrc/model/cbi/frps/common.lua:49 msgid "Client file" msgstr "客户端文件" -#: luasrc/view/frps/status_header.htm:12 -msgid "Collecting data..." -msgstr "正在收集数据..." - #: luasrc/model/cbi/frps/common.lua:30 -msgid "Common Settings" -msgstr "通用设置" +msgid "Frps - Common Settings" +msgstr "Frps - 通用设置" #: luasrc/model/cbi/frps/common.lua:45 msgid "Dashboard Options" @@ -70,23 +62,16 @@ msgid "Error" msgstr "错误" #: luasrc/model/cbi/frps/server.lua:8 -msgid "FRPS Server setting" +msgid "Frps - Server Settings" +msgstr "Frps - 服务器设定" + +#: luasrc/model/cbi/frps/server.lua:8 +msgid "FRPS Server Settings" msgstr "Frps 服务器设定" -#: luasrc/model/cbi/frps/common.lua:33 -msgid "For more information, please visit: %s" -msgstr "获取更多信息,请访问:%s" - #: luasrc/model/cbi/frps/common.lua:32 -msgid "" -"Frp is a fast reverse proxy to help you expose a local server behind a NAT " -"or firewall to the internet." -msgstr "Frp 是一个可用于内网穿透的高性能的反向代理应用。" - -#: luasrc/controller/frps.lua:16 luasrc/model/cbi/frps/common.lua:30 -#: luasrc/model/cbi/frps/server.lua:8 -msgid "Frps" -msgstr "Frps" +msgid "Frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.
Project GitHub URL" +msgstr "Frp 是一个可用于内网穿透的高性能的反向代理应用。
Github 项目地址" #: luasrc/model/cbi/frps/common.lua:43 msgid "General Options" @@ -96,10 +81,6 @@ msgstr "常规选项" msgid "Info" msgstr "信息" -#: luasrc/model/cbi/frps/common.lua:16 -msgid "Invalid client file" -msgstr "客户端文件无效" - #: luasrc/model/cbi/frps/server.lua:31 msgid "KCP bind port" msgstr "KCP绑定端口" @@ -152,10 +133,6 @@ msgstr "(可选)UDP端口用于KCP协议,可与绑定端口设定为一致 msgid "Run daemon as user" msgstr "以用户身份运行" -#: luasrc/view/frps/status_header.htm:25 -msgid "Running" -msgstr "服务正在运行" - #: luasrc/controller/frps.lua:22 msgid "Server" msgstr "服务端" @@ -192,10 +169,6 @@ msgstr "追踪" msgid "UDP bind port" msgstr "UDP绑定端口" -#: luasrc/model/cbi/frps/common.lua:27 -msgid "Version: %s" -msgstr "版本:%s" - #: luasrc/model/cbi/frps/common.lua:71 msgid "Warn" msgstr "警告" @@ -246,4 +219,4 @@ msgstr "额外设置" #: luasrc/model/cbi/frps/server.lua:51 msgid "List of extra settings will be added to config file. Format: option=value, eg. detailed_errors_to_client=false.(NO SPACE!)" -msgstr "额外设置列表将会被添加到config文件中。 格式:option=value,如:detailed_errors_to_client=false.(不含空格!)" \ No newline at end of file +msgstr "额外设置列表将会被添加到config文件中。 格式:option=value,如:detailed_errors_to_client=false.(不含空格!)"