mirror of
https://github.com/hanwckf/immortalwrt-mt798x.git
synced 2025-01-10 03:09:08 +08:00
luci-app-frpc: add package
This commit is contained in:
parent
0e9952380f
commit
7efe55fa62
19
package/lean/luci-app-frpc/Makefile
Normal file
19
package/lean/luci-app-frpc/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI for FRPC
|
||||
LUCI_DEPENDS:=+wget +openwrt-frpc
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
||||
|
18
package/lean/luci-app-frpc/luasrc/controller/frp.lua
Normal file
18
package/lean/luci-app-frpc/luasrc/controller/frp.lua
Normal file
@ -0,0 +1,18 @@
|
||||
module("luci.controller.frp", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/frp") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin","services","frp"},cbi("frp/frp"), _("Frp Setting"),100).dependent=true
|
||||
entry({"admin","services","frp","config"},cbi("frp/config")).leaf=true
|
||||
entry({"admin","services","frp","status"},call("status")).leaf=true
|
||||
end
|
||||
|
||||
function status()
|
||||
local e={}
|
||||
e.running=luci.sys.call("pidof frpc > /dev/null")==0
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
BIN
package/lean/luci-app-frpc/luasrc/i18n/frp.zh-cn.lmo
Normal file
BIN
package/lean/luci-app-frpc/luasrc/i18n/frp.zh-cn.lmo
Normal file
Binary file not shown.
116
package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua
Normal file
116
package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua
Normal file
@ -0,0 +1,116 @@
|
||||
local n="frp"
|
||||
local i=require"luci.dispatcher"
|
||||
local o=require"luci.model.network".init()
|
||||
local m=require"nixio.fs"
|
||||
local a,t,e
|
||||
arg[1]=arg[1]or""
|
||||
a=Map(n,translate("Frp Domain Config"))
|
||||
a.redirect=i.build_url("admin","services","frp")
|
||||
t=a:section(NamedSection,arg[1],"frp",translate("Config Frp Protocol"))
|
||||
t.addremove=false
|
||||
t.dynamic=false
|
||||
t:tab("base",translate("Basic Settings"))
|
||||
t:tab("other",translate("Other Settings"))
|
||||
e=t:taboption("base",ListValue,"enable",translate("Enable State"))
|
||||
e.default="1"
|
||||
e.rmempty=false
|
||||
e:value("1",translate("Enable"))
|
||||
e:value("0",translate("Disable"))
|
||||
e=t:taboption("base",ListValue, "type", translate("Frp Protocol Type"))
|
||||
e:value("http",translate("HTTP"))
|
||||
e:value("https",translate("HTTPS"))
|
||||
e:value("tcp",translate("TCP"))
|
||||
e:value("udp",translate("UDP"))
|
||||
e:value("stcp",translate("STCP"))
|
||||
e = t:taboption("base",ListValue, "domain_type", translate("Domain Type"))
|
||||
e.default = "custom_domains"
|
||||
e:value("custom_domains",translate("Custom Domains"))
|
||||
e:value("subdomain",translate("SubDomain"))
|
||||
e:value("both_dtype",translate("Both the above two Domain types"))
|
||||
e:depends("type","http")
|
||||
e:depends("type","https")
|
||||
e = t:taboption("base",Value, "custom_domains", translate("Custom Domains"), translate("If SubDomain is used, Custom Domains couldn't be subdomain or wildcard domain of the maindomain(subdomain_host)."))
|
||||
e:depends("domain_type","custom_domains")
|
||||
e:depends("domain_type","both_dtype")
|
||||
e = t:taboption("base",Value, "subdomain", translate("SubDomain"), translate("subdomain_host must be configured in server: frps in advance."))
|
||||
e:depends("domain_type","subdomain")
|
||||
e:depends("domain_type","both_dtype")
|
||||
e = t:taboption("base",ListValue, "stcp_role", translate("STCP Role"))
|
||||
e.default = "server"
|
||||
e:value("server",translate("STCP Server"))
|
||||
e:value("vistor",translate("STCP Vistor"))
|
||||
e:depends("type","stcp")
|
||||
e = t:taboption("base",Value, "remote_port", translate("Remote Port"))
|
||||
e.datatype = "port"
|
||||
e:depends("type","tcp")
|
||||
e:depends("type","udp")
|
||||
e = t:taboption("other",Flag, "enable_plugin", translate("Use Plugin"),translate("If plugin is defined, local_ip and local_port is useless, plugin will handle connections got from frps."))
|
||||
e.default = "0"
|
||||
e:depends("type","tcp")
|
||||
e = t:taboption("base",Value, "local_ip", translate("Local Host Address"))
|
||||
luci.sys.net.ipv4_hints(function(x,d)
|
||||
e:value(x,"%s (%s)"%{x,d})
|
||||
end)
|
||||
e.datatype = "ip4addr"
|
||||
e:depends("type","udp")
|
||||
e:depends("type","http")
|
||||
e:depends("type","https")
|
||||
e:depends("enable_plugin",0)
|
||||
e = t:taboption("base",Value, "local_port", translate("Local Host Port"))
|
||||
e.datatype = "port"
|
||||
e:depends("type","udp")
|
||||
e:depends("type","http")
|
||||
e:depends("type","https")
|
||||
e:depends("enable_plugin",0)
|
||||
e = t:taboption("base",Value, "stcp_secretkey", translate("STCP Screct Key"))
|
||||
e.default = "abcdefg"
|
||||
e:depends("type","stcp")
|
||||
e = t:taboption("base",Value, "stcp_servername", translate("STCP Server Name"), translate("STCP Server Name is Service Remark Name of STCP Server"))
|
||||
e.default = "secret_tcp"
|
||||
e:depends("stcp_role","vistor")
|
||||
e = t:taboption("other",Flag, "enable_locations", translate("Enable URL routing"), translate("Frp support forward http requests to different backward web services by url routing."))
|
||||
e:depends("type","http")
|
||||
e = t:taboption("other",Value, "locations ", translate("URL routing"), translate("Http requests with url prefix /news will be forwarded to this service."))
|
||||
e.default="locations=/"
|
||||
e:depends("enable_locations",1)
|
||||
e = t:taboption("other",ListValue, "plugin", translate("Choose Plugin"))
|
||||
e:value("http_proxy",translate("http_proxy"))
|
||||
e:value("socks5",translate("socks5"))
|
||||
e:value("unix_domain_socket",translate("unix_domain_socket"))
|
||||
e:depends("enable_plugin",1)
|
||||
e = t:taboption("other",Flag, "enable_plugin_httpuserpw", translate("Proxy Authentication"),translate("Other PCs could access the Internet through frpc's network by using http_proxy plugin."))
|
||||
e.default = "0"
|
||||
e:depends("plugin","http_proxy")
|
||||
e = t:taboption("other",Value, "plugin_http_user", translate("HTTP Proxy UserName"))
|
||||
e.default = "abc"
|
||||
e:depends("enable_plugin_httpuserpw",1)
|
||||
e = t:taboption("other",Value, "plugin_http_passwd", translate("HTTP Proxy Password"))
|
||||
e.default = "abc"
|
||||
e:depends("enable_plugin_httpuserpw",1)
|
||||
e = t:taboption("other",Value, "plugin_unix_path", translate("Plugin Unix Sock Path"))
|
||||
e.default = "/var/run/docker.sock"
|
||||
e:depends("plugin","unix_domain_socket")
|
||||
e = t:taboption("other",Flag, "enable_http_auth", translate("Password protecting your web service"), translate("Http username and password are safety certification for http protocol."))
|
||||
e.default = "0"
|
||||
e:depends("type","http")
|
||||
e = t:taboption("other",Value, "http_user", translate("HTTP UserName"))
|
||||
e.default = "frp"
|
||||
e:depends("enable_http_auth",1)
|
||||
e = t:taboption("other",Value, "http_pwd", translate("HTTP PassWord"))
|
||||
e.default = "frp"
|
||||
e:depends("enable_http_auth",1)
|
||||
e = t:taboption("other",Flag, "enable_host_header_rewrite", translate("Rewriting the Host Header"), translate("Frp can rewrite http requests with a modified Host header."))
|
||||
e.default = "0"
|
||||
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("base",Flag, "use_encryption", translate("Use Encryption"), translate("Encrypted the communication between frpc and frps, will effectively prevent the traffic intercepted."))
|
||||
e.default = "1"
|
||||
e.rmempty = false
|
||||
e = t:taboption("base",Flag, "use_compression", translate("Use Compression"), translate("The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources."))
|
||||
e.default = "1"
|
||||
e.rmempty = false
|
||||
e = t:taboption("base",Value, "remark", translate("Service Remark Name"), translate("<font color=\"red\">Please ensure the remark name is unique.</font>"))
|
||||
e.rmempty = false
|
||||
return a
|
160
package/lean/luci-app-frpc/luasrc/model/cbi/frp/frp.lua
Normal file
160
package/lean/luci-app-frpc/luasrc/model/cbi/frp/frp.lua
Normal file
@ -0,0 +1,160 @@
|
||||
local o=require"luci.dispatcher"
|
||||
local e=require("luci.model.ipkg")
|
||||
local s=require"nixio.fs"
|
||||
local e=luci.model.uci.cursor()
|
||||
local i="frp"
|
||||
local a,t,e
|
||||
local n={}
|
||||
a=Map(i,translate("Frp Setting"), translate("Frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet."))
|
||||
a:section(SimpleSection).template="frp/frp_status"
|
||||
t=a:section(NamedSection,"common","frp",translate("Global Setting"))
|
||||
t.anonymous=true
|
||||
t.addremove=false
|
||||
t:tab("base",translate("Basic Settings"))
|
||||
t:tab("other",translate("Other Settings"))
|
||||
t:tab("log",translate("Client Log"))
|
||||
e=t:taboption("base",Flag, "enabled", translate("Enabled"))
|
||||
e.rmempty=false
|
||||
e=t:taboption("base",Value, "server_addr", translate("Server"))
|
||||
e.optional=false
|
||||
e.rmempty=false
|
||||
e=t:taboption("base",Value, "server_port", translate("Port"))
|
||||
e.datatype = "port"
|
||||
e.optional=false
|
||||
e.rmempty=false
|
||||
e=t:taboption("base",Value, "token", translate("Token"), translate("Time duration between server of frpc and frps mustn't exceed 15 minutes."))
|
||||
e.optional=false
|
||||
e.password=true
|
||||
e.rmempty=false
|
||||
e=t:taboption("base",Value, "vhost_http_port", translate("Vhost HTTP Port"))
|
||||
e.datatype = "port"
|
||||
e.rmempty=false
|
||||
e=t:taboption("base",Value, "vhost_https_port", translate("Vhost HTTPS Port"))
|
||||
e.datatype = "port"
|
||||
e.rmempty=false
|
||||
e=t:taboption("other",Flag, "login_fail_exit", translate("Exit program when first login failed"),translate("decide if exit program when first login failed, otherwise continuous relogin to frps."))
|
||||
e.default = "1"
|
||||
e.rmempty=false
|
||||
e=t:taboption("other",Flag, "tcp_mux", translate("TCP Stream Multiplexing"), translate("Default is Ture. This feature in frps.ini and frpc.ini must be same."))
|
||||
e.default = "1"
|
||||
e.rmempty=false
|
||||
e=t:taboption("other",ListValue, "protocol", translate("Protocol Type"),translate("Frp support kcp protocol since v0.12.0"))
|
||||
e.default = "tcp"
|
||||
e:value("tcp",translate("TCP Protocol"))
|
||||
e:value("kcp",translate("KCP Protocol"))
|
||||
e=t:taboption("other",Flag, "enable_http_proxy", translate("Connect frps by HTTP PROXY"), translate("frpc can connect frps using HTTP PROXY"))
|
||||
e.default = "0"
|
||||
e.rmempty=false
|
||||
e:depends("protocol","tcp")
|
||||
e=t:taboption("other",Value, "http_proxy", translate("HTTP PROXY"))
|
||||
e.datatype="uinteger"
|
||||
e.placeholder="http://user:pwd@192.168.1.128:8080"
|
||||
e:depends("enable_http_proxy",1)
|
||||
e.optional=false
|
||||
e=t:taboption("other",Flag, "enable_cpool", translate("Enable Connection Pool"), translate("This feature is fit for a large number of short connections."))
|
||||
e.rmempty=false
|
||||
e=t:taboption("other",Value, "pool_count", translate("Connection Pool"), translate("Connections will be established in advance."))
|
||||
e.datatype="uinteger"
|
||||
e.default = "1"
|
||||
e:depends("enable_cpool",1)
|
||||
e.optional=false
|
||||
e=t:taboption("base",Value,"time",translate("Service registration interval"),translate("0 means disable this feature, unit: min"))
|
||||
e.datatype="range(0,59)"
|
||||
e.default=30
|
||||
e.rmempty=false
|
||||
e=t:taboption("other",ListValue, "log_level", translate("Log Level"))
|
||||
e.default = "warn"
|
||||
e:value("trace",translate("Trace"))
|
||||
e:value("debug",translate("Debug"))
|
||||
e:value("info",translate("Info"))
|
||||
e:value("warn",translate("Warning"))
|
||||
e:value("error",translate("Error"))
|
||||
e=t:taboption("other",Value, "log_max_days", translate("Log Keepd Max Days"))
|
||||
e.datatype = "uinteger"
|
||||
e.default = "3"
|
||||
e.rmempty=false
|
||||
e.optional=false
|
||||
e=t:taboption("log",TextValue,"log")
|
||||
e.rows=26
|
||||
e.wrap="off"
|
||||
e.readonly=true
|
||||
e.cfgvalue=function(t,t)
|
||||
return s.readfile("/var/etc/frp/frpc.log")or""
|
||||
end
|
||||
e.write=function(e,e,e)
|
||||
end
|
||||
t=a:section(TypedSection,"proxy",translate("Services List"))
|
||||
t.anonymous=true
|
||||
t.addremove=true
|
||||
t.template="cbi/tblsection"
|
||||
t.extedit=o.build_url("admin","services","frp","config","%s")
|
||||
function t.create(e,t)
|
||||
new=TypedSection.create(e,t)
|
||||
luci.http.redirect(e.extedit:format(new))
|
||||
end
|
||||
function t.remove(e,t)
|
||||
e.map.proceed=true
|
||||
e.map:del(t)
|
||||
luci.http.redirect(o.build_url("admin","services","frp"))
|
||||
end
|
||||
local o=""
|
||||
e=t:option(DummyValue,"remark",translate("Service Remark Name"))
|
||||
e.width="10%"
|
||||
e=t:option(DummyValue,"type",translate("Frp Protocol Type"))
|
||||
e.width="10%"
|
||||
e=t:option(DummyValue,"custom_domains",translate("Domain/Subdomain"))
|
||||
e.width="20%"
|
||||
e.cfgvalue=function(t,n)
|
||||
local t=a.uci:get(i,n,"domain_type")or""
|
||||
local m=a.uci:get(i,n,"type")or""
|
||||
if t=="custom_domains" then
|
||||
local b=a.uci:get(i,n,"custom_domains")or"" return b end
|
||||
if t=="subdomain" then
|
||||
local b=a.uci:get(i,n,"subdomain")or"" return b end
|
||||
if t=="both_dtype" then
|
||||
local b=a.uci:get(i,n,"custom_domains")or""
|
||||
local c=a.uci:get(i,n,"subdomain")or""
|
||||
b="%s/%s"%{b,c} return b end
|
||||
if m=="tcp" or m=="udp" then
|
||||
local b=a.uci:get(i,"common","server_addr")or"" return b end
|
||||
end
|
||||
e=t:option(DummyValue,"remote_port",translate("Remote Port"))
|
||||
e.width="10%"
|
||||
e.cfgvalue=function(t,b)
|
||||
local t=a.uci:get(i,b,"type")or""
|
||||
if t==""or b==""then return""end
|
||||
if t=="http" then
|
||||
local b=a.uci:get(i,"common","vhost_http_port")or"" return b end
|
||||
if t=="https" then
|
||||
local b=a.uci:get(i,"common","vhost_https_port")or"" return b end
|
||||
if t=="tcp" or t=="udp" then
|
||||
local b=a.uci:get(i,b,"remote_port")or"" return b end
|
||||
end
|
||||
e=t:option(DummyValue,"local_ip",translate("Local Host Address"))
|
||||
e.width="15%"
|
||||
e=t:option(DummyValue,"local_port",translate("Local Host Port"))
|
||||
e.width="10%"
|
||||
e=t:option(DummyValue,"use_encryption",translate("Use Encryption"))
|
||||
e.width="15%"
|
||||
e.cfgvalue=function(t,n)
|
||||
local t=a.uci:get(i,n,"use_encryption")or""
|
||||
local b
|
||||
if t==""or b==""then return""end
|
||||
if t=="1" then b="ON"
|
||||
else b="OFF" end
|
||||
return b
|
||||
end
|
||||
e=t:option(DummyValue,"use_compression",translate("Use Compression"))
|
||||
e.width="15%"
|
||||
e.cfgvalue=function(t,n)
|
||||
local t=a.uci:get(i,n,"use_compression")or""
|
||||
local b
|
||||
if t==""or b==""then return""end
|
||||
if t=="1" then b="ON"
|
||||
else b="OFF" end
|
||||
return b
|
||||
end
|
||||
e=t:option(Flag,"enable",translate("Enable State"))
|
||||
e.width="10%"
|
||||
e.rmempty=false
|
||||
return a
|
23
package/lean/luci-app-frpc/luasrc/view/frp/frp_status.htm
Normal file
23
package/lean/luci-app-frpc/luasrc/view/frp/frp_status.htm
Normal file
@ -0,0 +1,23 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=url([[admin]], [[services]], [[frp]], [[status]])%>', null,
|
||||
function(x, data) {
|
||||
var tb = document.getElementById('frp_status');
|
||||
if (data && tb) {
|
||||
if (data.running) {
|
||||
var links = '<em><b><font color=green><%:The Frp service is running.%></font></b></em>';
|
||||
tb.innerHTML = links;
|
||||
} else {
|
||||
tb.innerHTML = '<em><b><font color=red><%:The Frp service is not running.%></font></b></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:Frp Status%></legend>
|
||||
<p id="frp_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
16
package/lean/luci-app-frpc/root/etc/config/frp
Normal file
16
package/lean/luci-app-frpc/root/etc/config/frp
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
config frp 'common'
|
||||
option log_max_days '3'
|
||||
option login_fail_exit '0'
|
||||
option enable_cpool '0'
|
||||
option time '40'
|
||||
option tcp_mux '1'
|
||||
option enabled '0'
|
||||
option vhost_http_port '80'
|
||||
option vhost_https_port '443'
|
||||
option server_addr 'yourdomain.com'
|
||||
option server_port '7000'
|
||||
option token '1234567'
|
||||
option log_level 'info'
|
||||
option enable_http_proxy '0'
|
||||
option protocol 'tcp'
|
214
package/lean/luci-app-frpc/root/etc/init.d/frp
Executable file
214
package/lean/luci-app-frpc/root/etc/init.d/frp
Executable file
@ -0,0 +1,214 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#Author: monokoo <realstones2012@gmail.com>
|
||||
#Thanks to FW867's help
|
||||
|
||||
START=99
|
||||
SERVICE_WRITE_PID=1
|
||||
SERVICE_DAEMONIZE=1
|
||||
|
||||
LOGFILE="/var/etc/frp/frpc.log"
|
||||
|
||||
echo_date(){
|
||||
local log=$1
|
||||
echo $(date +%Y/%m/%d\ %X): "$log" >> $LOGFILE
|
||||
}
|
||||
|
||||
Reduce_Log(){
|
||||
local log=$1
|
||||
[ ! -f "$log" ] && return
|
||||
local sc=200
|
||||
[ -n "$2" ] && sc=$2
|
||||
local count=$(grep -c "" $log)
|
||||
if [ $count -gt $sc ];then
|
||||
let count=count-$sc
|
||||
sed -i "1,$count d" $log
|
||||
fi
|
||||
}
|
||||
|
||||
conf_proxy_add() {
|
||||
|
||||
local cfg="$1"
|
||||
local tmpconf="$2"
|
||||
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 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
|
||||
|
||||
config_get_bool enable "$cfg" enable 1
|
||||
[ "$enable" -gt 0 ] || return 1
|
||||
|
||||
config_get type "$cfg" type
|
||||
config_get custom_domains "$cfg" custom_domains
|
||||
config_get subdomain "$cfg" subdomain
|
||||
config_get remote_port "$cfg" remote_port
|
||||
config_get local_ip "$cfg" local_ip
|
||||
config_get local_port "$cfg" local_port
|
||||
config_get locations "$cfg" locations
|
||||
config_get host_header_rewrite "$cfg" host_header_rewrite
|
||||
config_get http_user "$cfg" http_user
|
||||
config_get http_pwd "$cfg" http_pwd
|
||||
config_get remark "$cfg" remark
|
||||
config_get plugin "$cfg" plugin
|
||||
config_get plugin_http_user "$cfg" plugin_http_user
|
||||
config_get plugin_http_passwd "$cfg" plugin_http_passwd
|
||||
config_get plugin_unix_path "$cfg" plugin_unix_path
|
||||
config_get stcp_role "$cfg" stcp_role
|
||||
config_get stcp_secretkey "$cfg" stcp_secretkey
|
||||
config_get stcp_servername "$cfg" stcp_servername
|
||||
|
||||
|
||||
[ -n "$remark" ] && [ -n "$type" ] || return 1
|
||||
|
||||
echo "" >>$tmpconf
|
||||
echo "[$remark]" >>$tmpconf
|
||||
echo "type=$type" >>$tmpconf
|
||||
[ -n "$custom_domains" ] && echo "custom_domains=$custom_domains" >>$tmpconf
|
||||
[ -n "$subdomain" ] && echo "subdomain=$subdomain" >>$tmpconf
|
||||
[ -n "$remote_port" ] && echo "remote_port=$remote_port" >>$tmpconf
|
||||
[ -z "$stcp_role" ] && [ -n "$local_ip" ] && echo "local_ip=$local_ip" >>$tmpconf
|
||||
[ -z "$stcp_role" ] && [ -n "$local_port" ] && echo "local_port=$local_port" >>$tmpconf
|
||||
[ -n "$locations" ] && echo "locations=$locations" >>$tmpconf
|
||||
[ -n "$http_user" -a -n "$http_pwd" ] && {
|
||||
echo "http_user=$http_user" >>$tmpconf
|
||||
echo "http_pwd=$http_pwd" >>$tmpconf
|
||||
}
|
||||
[ -n "$host_header_rewrite" ] && echo "host_header_rewrite=$host_header_rewrite" >>$tmpconf
|
||||
[ -n "$plugin" ] && echo "plugin=$plugin" >>$tmpconf
|
||||
[ -n "$plugin_http_user" -a -n "$plugin_http_passwd" ] && {
|
||||
echo "plugin_http_user=$plugin_http_user" >>$tmpconf
|
||||
echo "plugin_http_passwd=$plugin_http_passwd" >>$tmpconf
|
||||
}
|
||||
[ -n "$plugin_unix_path" ] && echo "plugin_unix_path=$plugin_unix_path" >>$tmpconf
|
||||
|
||||
[ -n "$stcp_role" ] && {
|
||||
if [ "$stcp_role" == "vistor" ]; then
|
||||
echo "role=$stcp_role" >>$tmpconf
|
||||
[ -n "$local_ip" ] && echo "bind_addr=$local_ip" >>$tmpconf
|
||||
[ -n "$local_port" ] && echo "bind_port=$local_port" >>$tmpconf
|
||||
[ -n "$stcp_servername" ] && echo "server_name=$stcp_servername" >>$tmpconf || return 1
|
||||
else
|
||||
[ -n "$local_ip" ] && echo "local_ip=$local_ip" >>$tmpconf
|
||||
[ -n "$local_port" ] && echo "local_port=$local_port" >>$tmpconf
|
||||
fi
|
||||
[ -n "$stcp_secretkey" ] && echo "sk=$stcp_secretkey" >>$tmpconf || return 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
frp_write_bool use_encryption $cfg 1
|
||||
frp_write_bool use_compression $cfg 1
|
||||
|
||||
}
|
||||
|
||||
frp_write_bool() {
|
||||
local opt="$1"
|
||||
local config="$2"
|
||||
local def="$3"
|
||||
local val
|
||||
|
||||
config_get_bool val $config "$opt" "$def"
|
||||
if [ "$val" -eq 0 ]; then
|
||||
echo "${opt}=false" >> $tmpconf
|
||||
else
|
||||
echo "${opt}=true" >> $tmpconf
|
||||
fi
|
||||
}
|
||||
|
||||
frp_add_cru(){
|
||||
time=$1
|
||||
if [ ! -f "/etc/crontabs/root" ] || [ -z "$(cat /etc/crontabs/root | grep frp)" ]; then
|
||||
sed -i '/frp/d' /etc/crontabs/root >/dev/null 2>&1
|
||||
echo "*/$time * * * * /etc/init.d/frp restart" >> /etc/crontabs/root
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
frp_del_cru(){
|
||||
if [ ! -f "/etc/crontabs/root" ] || [ -n "$(cat /etc/crontabs/root | grep frp)" ]; then
|
||||
sed -i '/frp/d' /etc/crontabs/root >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
download_binary(){
|
||||
echo_date "开始下载frpc二进制文件..."
|
||||
/usr/bin/wget --no-check-certificate --timeout=10 --tries=1 -o $LOGFILE https://github.com/fatedier/frp/releases/download/v0.13.0/frp_0.13.0_linux_arm.tar.gz -O /tmp/frp_0.13.0_linux_arm.tar.gz
|
||||
[ ! -s "/tmp/frp_0.13.0_linux_arm.tar.gz" ] && /usr/bin/wget -q --no-check-certificate --timeout=10 --tries=1 https://any.mokoo.xyz/app/frp_0.13.0_linux_arm.tar.gz -O /tmp/frp_0.13.0_linux_arm.tar.gz
|
||||
[ -f "/tmp/frp_0.13.0_linux_arm.tar.gz" ] && tar -xf /tmp/frp_0.13.0_linux_arm.tar.gz -C /tmp && \
|
||||
mv /tmp/frp_0.13.0_linux_arm/frpc /usr/bin/frpc
|
||||
rm -rf /tmp/frp_0.13.0_linux_arm*
|
||||
if [ -f "/usr/bin/frpc" ]; then
|
||||
chmod +x /usr/bin/frpc && echo_date "成功下载frpc二进制文件"
|
||||
else
|
||||
echo_date "下载frpc二进制文件失败,请重试!"
|
||||
fi
|
||||
}
|
||||
|
||||
boot() {
|
||||
sleep 10s
|
||||
start
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
config_load "frp"
|
||||
local enabled server_addr server_port time privilege_token tcp_mux enable_cpool
|
||||
local pool_count log_level log_max_days login_fail_exit http_proxy protocol
|
||||
|
||||
config_get_bool enabled common enabled 1
|
||||
|
||||
[ "$enabled" -gt 0 ] || return 1
|
||||
|
||||
config_get server_addr common server_addr
|
||||
config_get server_port common server_port
|
||||
config_get token common token
|
||||
config_get enable_cpool common enable_cpool
|
||||
config_get pool_count common pool_count
|
||||
config_get log_level common log_level
|
||||
config_get log_max_days common log_max_days
|
||||
config_get http_proxy common http_proxy
|
||||
config_get protocol common protocol
|
||||
config_get time common time
|
||||
|
||||
mkdir -p /var/etc/frp
|
||||
[ ! -f "$LOGFILE" ] && touch $LOGFILE
|
||||
|
||||
[ ! -f "/usr/bin/frpc" ] && download_binary
|
||||
[ ! -f "/usr/bin/frpc" ] && logger -t Frp 'Download frpc failed, please retry.' && exit 0
|
||||
|
||||
local tmpconf="/var/etc/frp/frpc.conf"
|
||||
|
||||
echo "[common]" >$tmpconf
|
||||
echo "server_addr=${server_addr}" >>$tmpconf
|
||||
echo "server_port=${server_port}" >>$tmpconf
|
||||
echo "token=${token}" >>$tmpconf
|
||||
echo "log_level=${log_level}" >>$tmpconf
|
||||
echo "log_max_days=${log_max_days}" >>$tmpconf
|
||||
echo "protocol=${protocol}" >>$tmpconf
|
||||
echo "log_file=$LOGFILE" >>$tmpconf
|
||||
[ -n "$http_proxy" ] && echo "http_proxy=$http_proxy" >>$tmpconf
|
||||
[ -n "$pool_count" ] && echo "pool_count=$pool_count" >>$tmpconf
|
||||
|
||||
config_load "frp"
|
||||
frp_write_bool tcp_mux common 1
|
||||
frp_write_bool login_fail_exit common 1
|
||||
config_foreach conf_proxy_add proxy "$tmpconf"
|
||||
|
||||
[ "$(cat "$tmpconf" | grep -c "type=")" -gt 0 ] || (echo_date "frp服务启动失败,请首先添加服务列表!" && exit 0)
|
||||
logger -t FRPC 'Starting frp service'
|
||||
SERVICE_DAEMONIZE=1 \
|
||||
service_start /usr/bin/frpc -c $tmpconf
|
||||
|
||||
[ "$time" -gt 0 ] && frp_add_cru $time
|
||||
[ -z "$(pgrep /usr/bin/frpc)" ] && echo_date "frp服务启动失败,请检查服务端 “TCP多路复用(tcp_mux)”设置,确保与客户端完全一致!"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
stop() {
|
||||
frp_del_cru
|
||||
if [ -n "`pidof frpc`" ]; then
|
||||
logger -t FRPC 'Shutting down frp service'
|
||||
service_stop /usr/bin/frpc
|
||||
Reduce_Log $LOGFILE
|
||||
fi
|
||||
return 0
|
||||
}
|
11
package/lean/luci-app-frpc/root/etc/uci-defaults/luci-frp
Executable file
11
package/lean/luci-app-frpc/root/etc/uci-defaults/luci-frp
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@frp[-1]
|
||||
add ucitrack frp
|
||||
set ucitrack.@frp[-1].init=frp
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user