diff options
| author | Ho3ein <ho3ein.sanaei@gmail.com> | 2023-04-11 22:43:22 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-11 22:43:22 +0300 |
| commit | 2c7b8d1d36f23e0e32512f1a2c43200acda973be (patch) | |
| tree | 97048fb65c7f9f8d5570ed0ba0bb6bd95a948297 /web/service | |
| parent | de8ba292534e1ade2d7665a1e91734d7070ae085 (diff) | |
| parent | c38d75f3d901e7a3f550ab05aef711f95421cae6 (diff) | |
Merge pull request #214 from MHSanaei/dev
bug fixed + reality for trojan
Diffstat (limited to 'web/service')
| -rw-r--r-- | web/service/inbound.go | 19 | ||||
| -rw-r--r-- | web/service/sub.go | 44 |
2 files changed, 47 insertions, 16 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go index 74765ab3..2372e574 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -453,12 +453,10 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr } continue } - // get settings clients - settings := map[string]interface{}{} - json.Unmarshal([]byte(inbound.Settings), &settings) - clients, ok := settings["clients"].([]model.Client) + // get clients + clients, err := s.getClients(inbound) needUpdate := false - if ok { + if err == nil { for client_index, client := range clients { if traffic.Email == client.Email { if client.ExpiryTime < 0 { @@ -473,7 +471,16 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr } if needUpdate { - settings["clients"] = clients + settings := map[string]interface{}{} + json.Unmarshal([]byte(inbound.Settings), &settings) + + // Convert clients to []interface to update clients in settings + var clientsInterface []interface{} + for _, c := range clients { + clientsInterface = append(clientsInterface, interface{}(c)) + } + + settings["clients"] = clientsInterface modifiedSettings, err := json.MarshalIndent(settings, "", " ") if err != nil { return nil, err diff --git a/web/service/sub.go b/web/service/sub.go index d1891e14..f0a5a160 100644 --- a/web/service/sub.go +++ b/web/service/sub.go @@ -300,7 +300,7 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string { if security == "xtls" { params["security"] = "xtls" - xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{}) + xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{}) alpns, _ := xtlsSetting["alpn"].([]interface{}) var alpn []string for _, a := range alpns { @@ -310,15 +310,15 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string { params["alpn"] = strings.Join(alpn, ",") } - xtlsSettings, _ := searchKey(xtlsSetting, "settings") + XTLSSettings, _ := searchKey(xtlsSetting, "settings") if xtlsSetting != nil { - if sniValue, ok := searchKey(xtlsSettings, "serverName"); ok { + if sniValue, ok := searchKey(XTLSSettings, "serverName"); ok { params["sni"], _ = sniValue.(string) } - if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok { + if fpValue, ok := searchKey(XTLSSettings, "fingerprint"); ok { params["fp"], _ = fpValue.(string) } - if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok { + if insecure, ok := searchKey(XTLSSettings, "allowInsecure"); ok { if insecure.(bool) { params["allowInsecure"] = "1" } @@ -442,9 +442,33 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string } } + if security == "reality" { + params["security"] = "reality" + realitySetting, _ := stream["realitySettings"].(map[string]interface{}) + realitySettings, _ := searchKey(realitySetting, "settings") + if realitySetting != nil { + if sniValue, ok := searchKey(realitySettings, "serverName"); ok { + params["sni"], _ = sniValue.(string) + } + if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok { + params["pbk"], _ = pbkValue.(string) + } + if sidValue, ok := searchKey(realitySettings, "shortIds"); ok { + params["sid"], _ = sidValue.(string) + } + if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok { + params["fp"], _ = fpValue.(string) + } + } + serverName, _ := realitySetting["serverName"].(string) + if serverName != "" { + address = serverName + } + } + if security == "xtls" { params["security"] = "xtls" - xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{}) + xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{}) alpns, _ := xtlsSetting["alpn"].([]interface{}) var alpn []string for _, a := range alpns { @@ -454,15 +478,15 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string params["alpn"] = strings.Join(alpn, ",") } - xtlsSettings, _ := searchKey(xtlsSetting, "settings") + XTLSSettings, _ := searchKey(xtlsSetting, "settings") if xtlsSetting != nil { - if sniValue, ok := searchKey(xtlsSettings, "serverName"); ok { + if sniValue, ok := searchKey(XTLSSettings, "serverName"); ok { params["sni"], _ = sniValue.(string) } - if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok { + if fpValue, ok := searchKey(XTLSSettings, "fingerprint"); ok { params["fp"], _ = fpValue.(string) } - if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok { + if insecure, ok := searchKey(XTLSSettings, "allowInsecure"); ok { if insecure.(bool) { params["allowInsecure"] = "1" } |
