From 64c72766f4b009ea7af803ccdd36f2a77a7cb624 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Fri, 19 Oct 2018 13:16:11 +0800 Subject: [PATCH] re-add luci app frpc --- package/lean/luci-app-frpc/Makefile | 19 ++ .../luci-app-frpc/luasrc/controller/frp.lua | 17 ++ .../luci-app-frpc/luasrc/i18n/frp.zh-cn.lmo | Bin 0 -> 4004 bytes .../luasrc/model/cbi/frp/config.lua | 116 ++++++++++ .../luasrc/model/cbi/frp/frp.lua | 160 +++++++++++++ .../luasrc/view/frp/frp_status.htm | 23 ++ .../lean/luci-app-frpc/root/etc/config/frp | 16 ++ .../lean/luci-app-frpc/root/etc/init.d/frp | 214 ++++++++++++++++++ .../root/etc/uci-defaults/luci-frp | 11 + 9 files changed, 576 insertions(+) create mode 100644 package/lean/luci-app-frpc/Makefile create mode 100644 package/lean/luci-app-frpc/luasrc/controller/frp.lua create mode 100644 package/lean/luci-app-frpc/luasrc/i18n/frp.zh-cn.lmo create mode 100644 package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua create mode 100644 package/lean/luci-app-frpc/luasrc/model/cbi/frp/frp.lua create mode 100644 package/lean/luci-app-frpc/luasrc/view/frp/frp_status.htm create mode 100644 package/lean/luci-app-frpc/root/etc/config/frp create mode 100755 package/lean/luci-app-frpc/root/etc/init.d/frp create mode 100755 package/lean/luci-app-frpc/root/etc/uci-defaults/luci-frp diff --git a/package/lean/luci-app-frpc/Makefile b/package/lean/luci-app-frpc/Makefile new file mode 100644 index 000000000..9d6ce7484 --- /dev/null +++ b/package/lean/luci-app-frpc/Makefile @@ -0,0 +1,19 @@ +# +# Copyright (C) 2008-2014 The LuCI Team +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI for FRPC +LUCI_DEPENDS:=+wget +frpc +LUCI_PKGARCH:=all +PKG_VERSION:=1.1 +PKG_RELEASE:=1 + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature + + diff --git a/package/lean/luci-app-frpc/luasrc/controller/frp.lua b/package/lean/luci-app-frpc/luasrc/controller/frp.lua new file mode 100644 index 000000000..a6d2ff561 --- /dev/null +++ b/package/lean/luci-app-frpc/luasrc/controller/frp.lua @@ -0,0 +1,17 @@ +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"),5).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 diff --git a/package/lean/luci-app-frpc/luasrc/i18n/frp.zh-cn.lmo b/package/lean/luci-app-frpc/luasrc/i18n/frp.zh-cn.lmo new file mode 100644 index 0000000000000000000000000000000000000000..f3b95348f88a98819790b4e8ff91847fd3378504 GIT binary patch literal 4004 zcmZ`*2~jhfgdF&gdBe)ru0iLIP7ocq0d@4tNi zc9$k6(M+xE$(0+tK8=|yO-_;u9imesIvc6kA?MYLuAKfSW75&ztJ4e{_!t)Wco_|4*^*X7vnRaVv zodH%+S3Ye^_i2hnZxt8C?euB%lA%FJh)eQIq}i1|O$D=%5FA&$S=>LxTQ23)2wReq zQV9OV3BC8(5rKIltX;QeLySO=7}ZmP;w@3Cj9ex6i%TLTdfiGv=>)%Rgoqw5coX`6 zVsY?`mnyp?lU;FiN^R*Ny!RMAnZfTXo@Q#!rMgzpiBK3>Oe{H|l5@(u5KkItZMtO4 zqV{58M`GNj)a{A8QeK_8D}HYZ<3(2_=`~WRUKK66YXo&iV8q$lA&=|!9rlRb#Y%Nk zpF+i3ge>XPLv6)?@Pd}M(lQMMDTX$wAj_w*QgbKOW%`Qqn7Z2ZM~!%H=BC)h-Khfj z=F+6&^)%Dyv$o?3AulLZ^|H++*QS9c_#jz3_yL+-fh=S)P5Gk7bhEpdX*p5>IXpgk z4K1ygN?o+5zAq;5weKUGgD~ikOPsXR4hA7l>Cm!xM$8eoG&K>_e6tmUa%wZd48>8y zwfo$Kirq#ntW;nLzWcN$*<<%rb*XB46Z?pf+N&j9Crfg#)>q{gy=5p8RGO02&U1|m z;aMiNRdV@i4yIEJQdv)Jb-paKT+zbM@VLMM7AcE^@Cf^=GpMeFx?TJbb1}aa*ZiCy zhU|n^2SOf}o!cch8I%*9Tm-+sBClpVvre+sP_I?7w^C2O+@hCVb%ZEhkK$}Z%=+z7 zTLW$rLUm=RI=RS=^VHU+wAWD6ai2y*vs`k$fx2K0k(-<0zSLaxgJZ32{g1KWT56G^ zv^5iS$?g`~TBbPiam81ZDX3+lHV=eYwUYy#6*4S`3sIsee6x8h^bqF{hx_xh}M!ov^R(I@x@VZL&wcs3Fac<)rQ8c{`J zm!5z0_n$r*kWh?uHA(%c!ivbB$Xp%_;+LnU?2g@>xO3C?UGHp5Oi7(a&FL`2pU-GI z<)x3_bY(vFGE=K7dc-_ll;DrHm17n?_Obv%ANrsxP&8WUcnPasm1_pdn)c%SVg`&8s zNke|gm1&Y*ZHa0hz>MKjjvK0y`p|ClKYmx8-~N(NWkm1VzE4=67?*1E}jgRF7sxpL!B01(qiRiUUd0oOX&c-)!3A=!TzBgOa#l}fyl zsakZp*cj1tqh}zKc$9E055z+|A6c$@t9JnSuj#}9SYVoUU7 zvd18s7-iH}Aa&>zjg`F(T_r+X(r!UHks-M(s*d?v5_hEvafv$;lV6>f9KU(u0x%<2 z*)iq%8ZdmJdF*Y8*W>(|?7{-lHx&60AyUgRj7`OB!Mh2}<2}&G0XRZW<7+v)1EC^H zOD)aKMjfdGmvub#X~|m<ljDs{>y|6yac>DaGYnsz&i^@5b^}W!vkl&@|)mMQ%(^w$Ot@oSb5OxgSuZ$z&ZrK zgrF6_5lZu`|@s7XG7)@>`z{3_@TM_@t)Z$5m45mI1+iyYtXTTG5+x}>%8!-JNQ1c65)6okvg0CLZLf;@8@Ra<+ z!^&e9%^eJWnLPo8F}hKa&xWspd>!z{;seI{T~7zD#`%|k-z+)(;@0Qx?)x$9W&EwL z=sdA0fP4|Sp>ycUofq|QV?Ce{c!g`t z26J=APv6Fx*%Nl=gTO13Hs$^es+Ix2c;@@Il{^2r<5T#@{0aN?ua{zs_YZ7@zSn_A zoc;N@>_J5qw?OGZgy&0~~T8WY6rEEt+_ouLKUgOhy*Y7+*0D@_T?M zUAY-NTOT2U?uItd33LGGQSaRythhHK-;=64XEslXxM_Dl-b9bWPs&VS4HZ=cVxe5c~$sR^$wxdQ)~ kJwbQwji<5pF!&cR7&!V~%1@5od*=2lu%Gc6gc2nG1u%dr4*&oF literal 0 HcmV?d00001 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 new file mode 100644 index 000000000..e9499c8c9 --- /dev/null +++ b/package/lean/luci-app-frpc/luasrc/model/cbi/frp/config.lua @@ -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("Please ensure the remark name is unique.")) +e.rmempty = false +return a diff --git a/package/lean/luci-app-frpc/luasrc/model/cbi/frp/frp.lua b/package/lean/luci-app-frpc/luasrc/model/cbi/frp/frp.lua new file mode 100644 index 000000000..531dd84f6 --- /dev/null +++ b/package/lean/luci-app-frpc/luasrc/model/cbi/frp/frp.lua @@ -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 diff --git a/package/lean/luci-app-frpc/luasrc/view/frp/frp_status.htm b/package/lean/luci-app-frpc/luasrc/view/frp/frp_status.htm new file mode 100644 index 000000000..a34467172 --- /dev/null +++ b/package/lean/luci-app-frpc/luasrc/view/frp/frp_status.htm @@ -0,0 +1,23 @@ + + +
+ <%:Frp Status%> +

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

+
diff --git a/package/lean/luci-app-frpc/root/etc/config/frp b/package/lean/luci-app-frpc/root/etc/config/frp new file mode 100644 index 000000000..736e571f9 --- /dev/null +++ b/package/lean/luci-app-frpc/root/etc/config/frp @@ -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' diff --git a/package/lean/luci-app-frpc/root/etc/init.d/frp b/package/lean/luci-app-frpc/root/etc/init.d/frp new file mode 100755 index 000000000..66f7881dc --- /dev/null +++ b/package/lean/luci-app-frpc/root/etc/init.d/frp @@ -0,0 +1,214 @@ +#!/bin/sh /etc/rc.common +#Author: monokoo +#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 +} diff --git a/package/lean/luci-app-frpc/root/etc/uci-defaults/luci-frp b/package/lean/luci-app-frpc/root/etc/uci-defaults/luci-frp new file mode 100755 index 000000000..46016e1c5 --- /dev/null +++ b/package/lean/luci-app-frpc/root/etc/uci-defaults/luci-frp @@ -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