From 38dbea4a2a462990690b136341cfd6b4f891c004 Mon Sep 17 00:00:00 2001 From: nitezs Date: Sun, 17 Sep 2023 13:21:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=AA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E8=8A=82=E7=82=B9=E9=93=BE=E6=8E=A5=E6=97=B6=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=E7=9A=84=E9=97=AE=E9=A2=98=20fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dssr=E5=88=86=E4=BA=AB=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E6=97=B6=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20fix:=20=E4=BF=AE=E5=A4=8Dssr?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E7=BC=BA=E5=B0=91Name=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20fix:=20=E4=BF=AE=E5=A4=8Dssr?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=97=B6=E6=B2=A1=E6=9C=89=E8=A7=A3=E7=A0=81?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/default.go | 4 ++-- parser/ssr.go | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api/controller/default.go b/api/controller/default.go index 6b96337..1225494 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -18,8 +18,8 @@ func BuildSub(clashType model.ClashType, query validator.SubQuery, template stri *model.Subscription, error, ) { // 定义变量 - var temp *model.Subscription - var sub *model.Subscription + var temp = &model.Subscription{} + var sub = &model.Subscription{} var err error var templateBytes []byte // 加载模板 diff --git a/parser/ssr.go b/parser/ssr.go index e485dfa..0c6f749 100644 --- a/parser/ssr.go +++ b/parser/ssr.go @@ -14,6 +14,7 @@ func ParseShadowsocksR(proxy string) (model.Proxy, error) { return model.Proxy{}, fmt.Errorf("无效的 ssr Url") } var err error + proxy = strings.TrimPrefix(proxy, "ssr://") if !strings.Contains(proxy, ":") { proxy, err = DecodeBase64(strings.TrimPrefix(proxy, "ssr://")) if err != nil { @@ -21,7 +22,7 @@ func ParseShadowsocksR(proxy string) (model.Proxy, error) { } } // 分割 - detailsAndParams := strings.SplitN(strings.TrimPrefix(proxy, "ssr://"), "/?", 2) + detailsAndParams := strings.SplitN(proxy, "/?", 2) parts := strings.Split(detailsAndParams[0], ":") params, err := url.ParseQuery(detailsAndParams[1]) if err != nil { @@ -32,7 +33,21 @@ func ParseShadowsocksR(proxy string) (model.Proxy, error) { if err != nil { return model.Proxy{}, err } + var obfsParam string + var protoParam string + var remarks string + if params.Get("obfsparam") != "" { + obfsParam, err = DecodeBase64(params.Get("obfsparam")) + } + if params.Get("protoparam") != "" { + protoParam, err = DecodeBase64(params.Get("protoparam")) + } + if params.Get("remarks") != "" { + remarks, err = DecodeBase64(params.Get("remarks")) + } + result := model.Proxy{ + Name: remarks, Type: "ssr", Server: parts[0], Port: port, @@ -40,8 +55,13 @@ func ParseShadowsocksR(proxy string) (model.Proxy, error) { Cipher: parts[3], Obfs: parts[4], Password: parts[5], - ObfsParam: params.Get("obfsparam"), - ProtocolParam: params.Get("protoparam"), + ObfsParam: obfsParam, + ProtocolParam: protoParam, } + + if result.Name == "" { + result.Name = result.Server + } + return result, nil }