Skip to content

Commit

Permalink
fix: 修复只提供节点链接时空指针的问题
Browse files Browse the repository at this point in the history
fix: 修复ssr分享链接加密时无法解析的问题
fix: 修复ssr解析缺少Name属性的问题
fix: 修复ssr解析时没有解码参数的问题
  • Loading branch information
nitezs committed Sep 17, 2023
1 parent 1788541 commit 38dbea4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/controller/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 加载模板
Expand Down
26 changes: 23 additions & 3 deletions parser/ssr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ 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 {
return model.Proxy{}, err
}
}
// 分割
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 {
Expand All @@ -32,16 +33,35 @@ 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,
Protocol: parts[2],
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
}

0 comments on commit 38dbea4

Please sign in to comment.