From bae6e7fc28b8645e6f96df80a0b57ae2387cd847 Mon Sep 17 00:00:00 2001
From: hyird <31695447+hyird@users.noreply.github.com>
Date: Tue, 9 Jun 2020 16:11:41 +0800
Subject: [PATCH] luci-app-frpc: add plugin "https2http" (#4754)
* Update config.lua
* Update frp
* Update frp.po
---
.../luasrc/model/cbi/frp/config.lua | 21 +++++++++++++++++++
package/lean/luci-app-frpc/po/zh-cn/frp.po | 17 ++++++++++++++-
.../lean/luci-app-frpc/root/etc/init.d/frp | 16 ++++++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua b/package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua
index b015ff7ad..039d1ae40 100644
--- a/package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua
+++ b/package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua
@@ -105,6 +105,27 @@ e:depends("type","http")
e = t:taboption("other",Value, "host_header_rewrite", translate("Host Header"), translate("The Host header will be rewritten to match the hostname portion of the forwarding address."))
e.default = "dev.yourdomain.com"
e:depends("enable_host_header_rewrite",1)
+e=t:taboption("other",Flag,"enable_https_plugin",translate("Use Plugin"))
+e.default="0"
+e:depends("type","https")
+e=t:taboption("other",ListValue,"https_plugin",translate("Choose Plugin"),translate("If plugin is defined, local_ip and local_port is useless, plugin will handle connections got from frps."))
+e:value("https2http",translate("https2http"))
+e:depends("enable_https_plugin",1)
+e=t:taboption("other",Value,"plugin_local_addr",translate("Plugin_Local_Addr"))
+e.default="127.0.0.1:80"
+e:depends("https_plugin","https2http")
+e=t:taboption("other",Value,"plugin_crt_path",translate("plugin_crt_path"))
+e.default="./server.crt"
+e:depends("https_plugin","https2http")
+e=t:taboption("other",Value,"plugin_key_path",translate("plugin_key_path"))
+e.default="./server.key"
+e:depends("https_plugin","https2http")
+e=t:taboption("other",Value,"plugin_host_header_rewrite",translate("plugin_host_header_rewrite"))
+e.default="127.0.0.1"
+e:depends("https_plugin","https2http")
+e=t:taboption("other",Value,"plugin_header_X_From_Where",translate("plugin_header_X-From-Where"))
+e.default="frp"
+e:depends("https_plugin","https2http")
e = t:taboption("base",ListValue, "proxy_protocol_version", translate("Proxy-Protocol Version"), translate("Proxy Protocol to send user's real IP to local services."))
e.default = "disable"
e:value("disable",translate("Disable"))
diff --git a/package/lean/luci-app-frpc/po/zh-cn/frp.po b/package/lean/luci-app-frpc/po/zh-cn/frp.po
index 13f7f9add..17f775a70 100644
--- a/package/lean/luci-app-frpc/po/zh-cn/frp.po
+++ b/package/lean/luci-app-frpc/po/zh-cn/frp.po
@@ -252,4 +252,19 @@ msgid "STCP Server Name is Service Remark Name of STCP Server"
msgstr "STCP服务器别名"
msgid "Please ensure the remark name is unique."
-msgstr "确保备注名唯一"
\ No newline at end of file
+msgstr "确保备注名唯一"
+
+msgid "Plugin_Local_Addr"
+msgstr "插件本地地址(格式 IP:Port)"
+
+msgid "plugin_crt_path"
+msgstr "插件证书路径"
+
+msgid "plugin_key_path"
+msgstr "插件私钥路径"
+
+msgid "plugin_host_header_rewrite"
+msgstr "插件 Host Header 重写"
+
+msgid "plugin_header_X-From-Where"
+msgstr "插件X-From-Where请求头"
diff --git a/package/lean/luci-app-frpc/root/etc/init.d/frp b/package/lean/luci-app-frpc/root/etc/init.d/frp
index cde1c0ebe..53fee3ba3 100755
--- a/package/lean/luci-app-frpc/root/etc/init.d/frp
+++ b/package/lean/luci-app-frpc/root/etc/init.d/frp
@@ -32,6 +32,7 @@ conf_proxy_add() {
local enable type domain_type custom_domains remote_port local_ip local_port enable_http_auth enable_host_header_rewrite host_header_rewrite
local subdomain proxy_protocol_version use_encryption use_compression http_user http_pwd remark locations
local enable_plugin plugin plugin_http_user plugin_http_passwd plugin_unix_path stcp_role stcp_secretkey stcp_servername
+ local enable_https_plugin https_plugin plugin_local_addr plugin_crt_path plugin_key_path plugin_host_header_rewrite plugin_header_X_From_Where
config_get_bool enable "$cfg" enable 1
[ "$enable" -gt 0 ] || return 1
@@ -55,6 +56,12 @@ conf_proxy_add() {
config_get stcp_secretkey "$cfg" stcp_secretkey
config_get stcp_servername "$cfg" stcp_servername
config_get proxy_protocol_version "$cfg" proxy_protocol_version
+ config_get https_plugin "$cfg" https_plugin
+ config_get plugin_local_addr "$cfg" plugin_local_addr
+ config_get plugin_crt_path "$cfg" plugin_crt_path
+ config_get plugin_key_path "$cfg" plugin_key_path
+ config_get plugin_host_header_rewrite "$cfg" plugin_host_header_rewrite
+ config_get plugin_header_X_From_Where "$cfg" plugin_header_X_From_Where
[ -n "$remark" ] && [ -n "$type" ] || return 1
@@ -99,6 +106,15 @@ conf_proxy_add() {
fi
}
+ [ -n "$https_plugin" ] && echo "plugin=$https_plugin" >>$tmpconf
+ [ -n "$plugin_local_addr" ] && echo "plugin_local_addr=$plugin_local_addr" >>$tmpconf
+ [ -n "$plugin_crt_path" -a -n "$plugin_key_path" ] && {
+ echo "plugin_crt_path=$plugin_crt_path" >>$tmpconf
+ echo "plugin_key_path=$plugin_key_path" >>$tmpconf
+ }
+ [ -n "$plugin_host_header_rewrite" ] && echo "plugin_host_header_rewrite=$plugin_host_header_rewrite" >>$tmpconf
+ [ -n "$plugin_header_X_From_Where" ] && echo "plugin_header_X_From_Where=$plugin_header_X_From_Where" >>$tmpconf
+
frp_write_bool use_encryption $cfg 1
frp_write_bool use_compression $cfg 1