luci-app-frps: add package
This commit is contained in:
parent
8e8872b2b6
commit
1045369f4c
23
package/ctcgfw/luci-app-frps/Makefile
Normal file
23
package/ctcgfw/luci-app-frps/Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Copyright 2020 Weizheng Li <lwz322@qq.com>
|
||||
# Licensed to the public under the MIT License.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-frps
|
||||
PKG_VERSION:=0.0.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_MAINTAINER:=Weizheng Li <lwz322@qq.com>
|
||||
|
||||
LUCI_TITLE:=LuCI support for Frps
|
||||
LUCI_PKGARCH:=all
|
||||
LUCI_DEPENDS:=+frps
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
43
package/ctcgfw/luci-app-frps/luasrc/controller/frps.lua
Normal file
43
package/ctcgfw/luci-app-frps/luasrc/controller/frps.lua
Normal file
@ -0,0 +1,43 @@
|
||||
-- Copyright 2020 Weizheng Li <lwz322@qq.com>
|
||||
-- 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()
|
||||
if not nixio.fs.access("/etc/config/frps") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "services", "frps"},
|
||||
firstchild(), _("Frps")).dependent = false
|
||||
|
||||
entry({"admin", "services", "frps", "common"},
|
||||
cbi("frps/common"), _("Settings"), 1)
|
||||
|
||||
entry({"admin", "services", "frps", "server"},
|
||||
cbi("frps/server"), _("Server"), 2).leaf = true
|
||||
|
||||
entry({"admin", "services", "frps", "status"}, call("action_status"))
|
||||
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
|
||||
})
|
||||
end
|
||||
110
package/ctcgfw/luci-app-frps/luasrc/model/cbi/frps/common.lua
Normal file
110
package/ctcgfw/luci-app-frps/luasrc/model/cbi/frps/common.lua
Normal file
@ -0,0 +1,110 @@
|
||||
-- Copyright 2020 Weizheng Li <lwz322@qq.com>
|
||||
-- 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")
|
||||
|
||||
if not file or file == "" or not fs.stat(file) then
|
||||
return "<em style=\"color: red;\">%s</em>" % 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 "<em style=\"color: red;\">%s</em>" % translate("Can't get client version")
|
||||
end
|
||||
return translatef("Version: %s", version)
|
||||
end
|
||||
|
||||
m = Map("frps", "%s - %s" % { translate("Frps"), translate("Common Settings") },
|
||||
"<p>%s</p><p>%s</p>" % {
|
||||
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",
|
||||
"<a href=\"https://github.com/fatedier/frp\" target=\"_blank\">https://github.com/fatedier/frp</a>")
|
||||
})
|
||||
|
||||
m:append(Template("frps/status_header"))
|
||||
|
||||
s = m:section(NamedSection, "main", "frps")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
s:tab("general", translate("General Options"))
|
||||
s:tab("advanced", translate("Advanced Options"))
|
||||
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.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
|
||||
o:value(user)
|
||||
end
|
||||
|
||||
o = s:taboption("general", Flag, "enable_logging", translate("Enable logging"))
|
||||
|
||||
o = s:taboption("general", Value, "log_file", translate("Log file"))
|
||||
o:depends("enable_logging", "1")
|
||||
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.default = "warn"
|
||||
|
||||
o = s:taboption("general", Value, "log_max_days", translate("Log max days"))
|
||||
o:depends("enable_logging", "1")
|
||||
o.datatype = "uinteger"
|
||||
o.placeholder = '3'
|
||||
|
||||
o = s:taboption("general", Value, "disable_log_color", translate("Disable log color"))
|
||||
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.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.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.datatype = "host"
|
||||
|
||||
o = s:taboption("dashboard", Value, "dashboard_addr", translate("Dashboard addr"), 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.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_pwd", translate("Dashboard password"))
|
||||
o.password = true
|
||||
|
||||
return m
|
||||
@ -0,0 +1,43 @@
|
||||
-- Copyright 2020 Weizheng Li <lwz322@qq.com>
|
||||
-- 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") })
|
||||
|
||||
s = m:section(NamedSection, "main", "frps")
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
o = s:option(Value, "bind_port", translate("Bind port"))
|
||||
o.datatype = "port"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "token", translate("Token"))
|
||||
o.password = true
|
||||
|
||||
o = s:option(Flag, "tcp_mux", translate("TCP mux"))
|
||||
o.enabled = "true"
|
||||
o.disabled = "false"
|
||||
o.defalut = o.enabled
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "bind_udp_port", translate("UDP bind port"),
|
||||
translatef("Optional: udp port to help make udp hole to penetrate nat"))
|
||||
o.datatype = "port"
|
||||
|
||||
o = s:option(Value, "kcp_bind_port", translate("KCP bind port"),
|
||||
translatef("Optional: udp port used for kcp protocol, it can be same with 'bind port'; if not set, kcp is disabled in frps"))
|
||||
o.datatype = "port"
|
||||
|
||||
o = s:option(Value, "vhost_http_port", translate("vhost http port"),
|
||||
translatef("Optional: if you want to support virtual host, you must set the http port for listening"))
|
||||
o.datatype = "port"
|
||||
|
||||
o = s:option(Value, "vhost_https_port", translate("vhost https port"),
|
||||
translatef("Optional: Note: http port and https port can be same with bind_port"))
|
||||
o.datatype = "port"
|
||||
|
||||
return m
|
||||
@ -0,0 +1,29 @@
|
||||
<%#
|
||||
Copyright 2020 Weizheng Li <lwz322@qq.com>
|
||||
Licensed to the public under the MIT License.
|
||||
-%>
|
||||
|
||||
<%
|
||||
local dsp = require "luci.dispatcher"
|
||||
-%>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<p id="frps_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=dsp.build_url("admin/services/frps/status")%>', null,
|
||||
function (x, data) {
|
||||
if (x.status !== 200 || !data) {
|
||||
return;
|
||||
}
|
||||
|
||||
var frpsStatusElm = document.getElementById('frps_status');
|
||||
frpsStatusElm.innerHTML = data.running
|
||||
? '<%:Running%>'
|
||||
: '<%:Not Running%>';
|
||||
}
|
||||
);
|
||||
//]]></script>
|
||||
233
package/ctcgfw/luci-app-frps/po/zh-cn/frps.po
Normal file
233
package/ctcgfw/luci-app-frps/po/zh-cn/frps.po
Normal file
@ -0,0 +1,233 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:54
|
||||
msgid "-- default --"
|
||||
msgstr "-- 默认 --"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:44
|
||||
msgid "Advanced Options"
|
||||
msgstr "高级选项"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:14
|
||||
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 "通用设置"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:45
|
||||
msgid "Dashboard Options"
|
||||
msgstr "面板选项"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:99
|
||||
msgid "Dashboard addr"
|
||||
msgstr "面板绑定地址"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:107
|
||||
msgid "Dashboard password"
|
||||
msgstr "面板登录密码"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:102
|
||||
msgid "Dashboard port"
|
||||
msgstr "面板绑定端口"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:105
|
||||
msgid "Dashboard user"
|
||||
msgstr "面板登录用户名"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:69
|
||||
msgid "Debug"
|
||||
msgstr "调试"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:80
|
||||
msgid "Disable log color"
|
||||
msgstr "禁用日志颜色"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:60
|
||||
msgid "Enable logging"
|
||||
msgstr "启用日志"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:47
|
||||
msgid "Enabled"
|
||||
msgstr "已启用"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:72
|
||||
msgid "Error"
|
||||
msgstr "错误"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:8
|
||||
msgid "FRPS Server setting"
|
||||
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"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:43
|
||||
msgid "General Options"
|
||||
msgstr "常规选项"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:70
|
||||
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绑定端口"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:62
|
||||
msgid "Log file"
|
||||
msgstr "日志文件"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:66
|
||||
msgid "Log level"
|
||||
msgstr "日志等级"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:75
|
||||
msgid "Log max days"
|
||||
msgstr "日志保存天数"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:85
|
||||
msgid "Max pool count"
|
||||
msgstr "最大连接数"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:89
|
||||
msgid "Max ports per-client"
|
||||
msgstr "单客户端最大端口映射数"
|
||||
|
||||
#: luasrc/view/frps/status_header.htm:26
|
||||
msgid "Not Running"
|
||||
msgstr "服务未运行"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:40
|
||||
msgid "Optional: Note: http port and https port can be same with bind_port"
|
||||
msgstr "(可选)提示:http/https端口可以和绑定端口设定为一致"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:36
|
||||
msgid ""
|
||||
"Optional: if you want to support virtual host, you must set the http port "
|
||||
"for listening"
|
||||
msgstr "(可选)如果您希望支持虚拟主机,则必须设定http端口"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:28
|
||||
msgid "Optional: udp port to help make udp hole to penetrate nat"
|
||||
msgstr "(可选)设定UDP端口以帮助UDP协议穿透NAT"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:32
|
||||
msgid ""
|
||||
"Optional: udp port used for kcp protocol, it can be same with 'bind port'; "
|
||||
"if not set, kcp is disabled in frps"
|
||||
msgstr "(可选)UDP端口用于KCP协议,可与绑定端口设定为一致;留空以禁用KCP"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:53
|
||||
msgid "Run daemon as user"
|
||||
msgstr "以用户身份运行"
|
||||
|
||||
#: luasrc/view/frps/status_header.htm:25
|
||||
msgid "Running"
|
||||
msgstr "服务正在运行"
|
||||
|
||||
#: luasrc/controller/frps.lua:22
|
||||
msgid "Server"
|
||||
msgstr "服务端"
|
||||
|
||||
#: luasrc/controller/frps.lua:19
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:95
|
||||
msgid "Subdomain host"
|
||||
msgstr "子域名"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:21
|
||||
msgid "TCP mux"
|
||||
msgstr "TCP 复用"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:18
|
||||
msgid "Token"
|
||||
msgstr "令牌"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:68
|
||||
msgid "Trace"
|
||||
msgstr "追踪"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:27
|
||||
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 "警告"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:99
|
||||
msgid "dashboard addr's default value is same with bind_addr"
|
||||
msgstr "面板地址默认和绑定地址一致"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:102
|
||||
msgid "dashboard is available only if dashboard_port is set"
|
||||
msgstr "仅在设定面板绑定端口后才可使用面板功能"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:105
|
||||
msgid ""
|
||||
"dashboard user and passwd for basic auth protect, if not set, both default "
|
||||
"value is admin"
|
||||
msgstr "面板用户名/密码用于基本安全认证;若留空,则用户名/密码均为admin"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:96
|
||||
msgid ""
|
||||
"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"
|
||||
msgstr "如果subdomain_host不为空,可以在frpc配置文件中设置类型为http(s)的subdomain;subdomain为test,路由将使用test.frps.com"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:90
|
||||
msgid ""
|
||||
"max ports can be used for each client, default value is 0 means no limit"
|
||||
msgstr "每个客户端最多可映射端口数,留空则默认为0(不限制)"
|
||||
|
||||
#: luasrc/model/cbi/frps/common.lua:86
|
||||
msgid ""
|
||||
"pool_count in each proxy will change to max_pool_count if they exceed the "
|
||||
"maximum value"
|
||||
msgstr "代理连接数(pool_count)超过最大值时将变更为最大连接数(max_pool_count)"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:35
|
||||
msgid "vhost http port"
|
||||
msgstr "虚拟主机http绑定端口"
|
||||
|
||||
#: luasrc/model/cbi/frps/server.lua:39
|
||||
msgid "vhost https port"
|
||||
msgstr "虚拟主机https绑定端口"
|
||||
6
package/ctcgfw/luci-app-frps/root/etc/config/frps
Normal file
6
package/ctcgfw/luci-app-frps/root/etc/config/frps
Normal file
@ -0,0 +1,6 @@
|
||||
config frps 'main'
|
||||
option enabled '0'
|
||||
option server 'frps'
|
||||
option client_file '/usr/bin/frps'
|
||||
option bind_port '7000'
|
||||
option tcp_mux 'true'
|
||||
189
package/ctcgfw/luci-app-frps/root/etc/init.d/frps
Executable file
189
package/ctcgfw/luci-app-frps/root/etc/init.d/frps
Executable file
@ -0,0 +1,189 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright 2020 Weizheng Li <lwz322@qq.com>
|
||||
# Licensed to the public under the MIT License.
|
||||
#
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
NAME="frps"
|
||||
CONFIG_FOLDER="/var/etc/$NAME"
|
||||
|
||||
_log() {
|
||||
local level="$1" ; shift
|
||||
local msg="$@"
|
||||
logger -p "daemon.$level" -t "$NAME" "$msg"
|
||||
|
||||
echo "[$level] $msg" >&2
|
||||
}
|
||||
|
||||
_info() {
|
||||
_log "info" $@
|
||||
}
|
||||
|
||||
_err() {
|
||||
_log "err" $@
|
||||
}
|
||||
|
||||
append_options() {
|
||||
local file="$1" ; shift
|
||||
local o v
|
||||
for o in "$@" ; do
|
||||
v="$(eval echo "\$$o")"
|
||||
if [ -n "$v" ] ; then
|
||||
# add brackets when ipv6 address
|
||||
if ( echo "$o" | grep -qE 'addr|ip' ) &&
|
||||
( echo "$v" | grep -q ':' ) ; then
|
||||
v="[$v]"
|
||||
fi
|
||||
|
||||
echo "${o} = $v" >>"$file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
append_setting() {
|
||||
local file="$1" ; shift
|
||||
local s="$1"
|
||||
if [ -n "$s" ] ; then
|
||||
echo "$s" >>"$file"
|
||||
fi
|
||||
}
|
||||
|
||||
frps_scetion_validate() {
|
||||
uci_validate_section "$NAME" "frps" "$1" \
|
||||
'enabled:bool:0' \
|
||||
'client_file:file:/usr/bin/frps' \
|
||||
'run_user:string' \
|
||||
'enable_logging:bool:0' \
|
||||
'log_file:string:/var/log/frps.log' \
|
||||
'log_level:or("trace", "debug", "info", "warn", "error"):warn' \
|
||||
'log_max_days:uinteger:3' \
|
||||
'disable_log_color:or("true", "false")' \
|
||||
'max_pool_count:uinteger' \
|
||||
'max_ports_per_client:uinteger:0' \
|
||||
'subdomain_host:host' \
|
||||
'dashboard_addr:host' \
|
||||
'dashboard_port:port' \
|
||||
'dashboard_user:string' \
|
||||
'dashboard_pwd:string' \
|
||||
'bind_port:port' \
|
||||
'token:string' \
|
||||
'tcp_mux:or("true", "false"):true' \
|
||||
'bind_udp_port:port' \
|
||||
'kcp_bind_port:port' \
|
||||
'vhost_http_port:port' \
|
||||
'vhost_https_port:port'
|
||||
}
|
||||
|
||||
client_file_validate() {
|
||||
local file="$1"
|
||||
|
||||
test -f "$file" || return 1
|
||||
test -x "$file" || chmod 755 "$file"
|
||||
|
||||
eval "$file" -h | grep -q "$NAME"
|
||||
return $?
|
||||
}
|
||||
|
||||
add_rule_extra_option() {
|
||||
append_setting "$2" "$1"
|
||||
}
|
||||
|
||||
create_config_file() {
|
||||
local config_file="$1"
|
||||
local tmp_file="$(mktemp /tmp/frps-XXXXXX)"
|
||||
|
||||
echo "[common]" > "$tmp_file"
|
||||
|
||||
append_options "$tmp_file" \
|
||||
"bind_port" "token" "tcp_mux" "bind_udp_port" "kcp_bind_port" "vhost_http_port" "vhost_https_port"
|
||||
|
||||
|
||||
if [ "x$enable_logging" = "x1" ] ; then
|
||||
if [ -z "$log_file" ]; then
|
||||
log_file="/var/log/frps.log"
|
||||
fi
|
||||
|
||||
append_options "$tmp_file" \
|
||||
"log_file" "log_level" "log_max_days" "disable_log_color"
|
||||
|
||||
if [ -f "$log_file" ] ; then
|
||||
echo > "$log_file"
|
||||
else
|
||||
local log_folder="$(dirname "$log_file")"
|
||||
|
||||
if [ ! -d "$log_folder" ] ; then
|
||||
mkdir -p "$log_folder"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$run_user" ] && ( user_exists "$run_user" ) ; then
|
||||
chmod 644 "$log_file"
|
||||
chown "$run_user" "$log_file"
|
||||
else
|
||||
run_user=""
|
||||
fi
|
||||
fi
|
||||
|
||||
append_options "$tmp_file" \
|
||||
"max_pool_count" "max_ports_per_client" "subdomain_host" "dashboard_addr" "dashboard_port" "dashboard_user" "dashboard_pwd"
|
||||
|
||||
sed '/^$/d' "$tmp_file" >"$config_file"
|
||||
|
||||
if [ "$?" = "0" ] ; then
|
||||
rm -f "$tmp_file"
|
||||
fi
|
||||
}
|
||||
|
||||
start_instance() {
|
||||
local section="$1"
|
||||
|
||||
if ! frps_scetion_validate "$section" ; then
|
||||
_err "Config validate failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "x$enabled" != "x1" ] ; then
|
||||
_info "Instance \"$section\" disabled."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$client_file" ] || ( ! client_file_validate "$client_file" ) ; then
|
||||
_err "Client file not valid."
|
||||
return 1
|
||||
fi
|
||||
|
||||
test -d "$CONFIG_FOLDER" || mkdir -p "$CONFIG_FOLDER"
|
||||
|
||||
local config_file="$CONFIG_FOLDER/frps.$section.ini"
|
||||
|
||||
create_config_file "$config_file"
|
||||
|
||||
if [ ! -f "$config_file" ] ; then
|
||||
_err "Could not create config file: \"$config_file\""
|
||||
return 1
|
||||
fi
|
||||
|
||||
procd_open_instance "$NAME.$section"
|
||||
procd_set_param command "$client_file"
|
||||
procd_append_param command -c "$config_file"
|
||||
procd_set_param respawn
|
||||
procd_set_param file "$config_file"
|
||||
|
||||
if [ -n "$run_user" ] ; then
|
||||
procd_set_param user "$run_user"
|
||||
fi
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$NAME"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "$NAME"
|
||||
config_foreach start_instance "frps"
|
||||
}
|
||||
25
package/ctcgfw/luci-app-frps/root/etc/uci-defaults/40_luci-frps
Executable file
25
package/ctcgfw/luci-app-frps/root/etc/uci-defaults/40_luci-frps
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@frps[-1]
|
||||
add ucitrack frps
|
||||
set ucitrack.@frps[-1].init=frps
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
frps=$(uci -q get frps.@frps[-1])
|
||||
|
||||
if [ -z "$frps" ]; then
|
||||
uci -q add frps frps
|
||||
fi
|
||||
|
||||
if [ "x$frps" != "xmain" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
rename frps.@frps[-1]="main"
|
||||
set frps.main.enabled="0"
|
||||
commit frps
|
||||
EOF
|
||||
fi
|
||||
|
||||
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
|
||||
exit 0
|
||||
Loading…
Reference in New Issue
Block a user