From ddb2bca53b58f007756378d6ad783b6364819a37 Mon Sep 17 00:00:00 2001 From: qqq-qqqq <32921374+qqq-qqqq@users.noreply.github.com> Date: Sun, 6 Feb 2022 12:56:48 +0800 Subject: [PATCH] feat: Add port for socks5 proxy with rule (#404) Co-authored-by: mzz2017 --- gui/src/components/modalCustomPorts.vue | 14 ++++++++++++++ gui/src/locales/en.js | 1 + gui/src/locales/zh.js | 1 + service/core/v2ray/templateJson.go | 22 +++++++++++++++++++++- service/core/v2ray/v2rayTmpl.go | 15 +++++++++------ service/db/configure/configure.go | 10 ++++++---- service/db/configure/ports.go | 9 +++++---- service/server/service/ports.go | 10 ++++++++++ 8 files changed, 67 insertions(+), 15 deletions(-) diff --git a/gui/src/components/modalCustomPorts.vue b/gui/src/components/modalCustomPorts.vue index b9d3dc56..15ee8b3f 100644 --- a/gui/src/components/modalCustomPorts.vue +++ b/gui/src/components/modalCustomPorts.vue @@ -44,6 +44,18 @@ required > + + + 0 { if err := service.CheckGrpcSupported(); err != nil { @@ -1448,7 +1451,7 @@ func (t *Template) setVlessGrpcRouting() { for i := range t.Routing.Rules { var bHasRule bool for _, tag := range t.Routing.Rules[i].InboundTag { - if tag == "rule" { + if tag == "rule-http" { bHasRule = true } } diff --git a/service/db/configure/configure.go b/service/db/configure/configure.go index 6cb5fa2c..6c9e29fe 100644 --- a/service/db/configure/configure.go +++ b/service/db/configure/configure.go @@ -33,10 +33,11 @@ func New() *Configure { Setting: NewSetting(), Accounts: map[string]string{}, Ports: Ports{ - Socks5: 20170, - Http: 20171, - HttpWithPac: 20172, - VlessGrpc: 0, + Socks5: 20170, + Socks5WithPac: 0, + Http: 20171, + HttpWithPac: 20172, + VlessGrpc: 0, }, InternalDnsList: nil, ExternalDnsList: nil, @@ -260,6 +261,7 @@ func GetPortsNotNil() *Ports { p = new(Ports) p.Socks5 = 20170 p.Http = 20171 + p.Socks5WithPac = 0 p.HttpWithPac = 20172 p.VlessGrpc = 0 } diff --git a/service/db/configure/ports.go b/service/db/configure/ports.go index 266e13e4..21354fb5 100644 --- a/service/db/configure/ports.go +++ b/service/db/configure/ports.go @@ -1,8 +1,9 @@ package configure type Ports struct { - Socks5 int `json:"socks5"` - Http int `json:"http"` - HttpWithPac int `json:"httpWithPac"` - VlessGrpc int `json:"vlessGrpc"` + Socks5 int `json:"socks5"` + Http int `json:"http"` + Socks5WithPac int `json:"socks5WithPac"` + HttpWithPac int `json:"httpWithPac"` + VlessGrpc int `json:"vlessGrpc"` } diff --git a/service/server/service/ports.go b/service/server/service/ports.go index 45381bb1..0020ff87 100644 --- a/service/server/service/ports.go +++ b/service/server/service/ports.go @@ -24,6 +24,10 @@ func SetPorts(ports *configure.Ports) (err error) { set[ports.Http] = struct{}{} cnt++ } + if ports.Socks5WithPac != 0 { + set[ports.Socks5WithPac] = struct{}{} + cnt++ + } if ports.HttpWithPac != 0 { set[ports.HttpWithPac] = struct{}{} cnt++ @@ -48,6 +52,12 @@ func SetPorts(ports *configure.Ports) (err error) { detectSyntax = append(detectSyntax, strconv.Itoa(origin.Http)+":tcp") } } + if ports.Socks5WithPac != origin.Socks5WithPac { + origin.Socks5WithPac = ports.Socks5WithPac + if origin.Socks5WithPac != 0 { + detectSyntax = append(detectSyntax, strconv.Itoa(origin.Socks5WithPac)+":tcp,udp") + } + } if ports.HttpWithPac != origin.HttpWithPac { origin.HttpWithPac = ports.HttpWithPac if origin.HttpWithPac != 0 {