From b43a6ade973b16ea94e5839d7b7754bc8de93fee Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sat, 18 Jan 2025 10:34:42 +0100 Subject: [PATCH] shadowtls users only in v3 --- backend/service/inbounds.go | 30 +++++++++++++++++++ .../src/components/protocols/ShadowTls.vue | 6 +--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/backend/service/inbounds.go b/backend/service/inbounds.go index 480bbfb..39e24de 100644 --- a/backend/service/inbounds.go +++ b/backend/service/inbounds.go @@ -48,6 +48,7 @@ func (s *InboundService) GetAll() (*[]map[string]interface{}, error) { } var data []map[string]interface{} for _, inbound := range inbounds { + var shadowtls_version uint inbData := map[string]interface{}{ "id": inbound.Id, "type": inbound.Type, @@ -61,7 +62,25 @@ func (s *InboundService) GetAll() (*[]map[string]interface{}, error) { } inbData["listen"] = restFields["listen"] inbData["listen_port"] = restFields["listen_port"] + if inbound.Type == "shadowtls" { + json.Unmarshal(restFields["version"], &shadowtls_version) + } } + switch inbound.Type { + case "mixed", "socks", "http", "shadowsocks", "vmess", "trojan", "naive", "hysteria", "shadowtls", "tuic", "hysteria2", "vless": + if inbound.Type == "shadowtls" && shadowtls_version < 3 { + break + } + var users []string + err = db.Raw("SELECT clients.name FROM clients, json_each(clients.inbounds) as je WHERE je.value = ?", inbound.Id).Scan(&users).Error + if err != nil { + return nil, err + } + if len(users) > 0 || inbound.Type != "shadowsocks" { + inbData["users"] = users + } + } + data = append(data, inbData) } return &data, nil @@ -214,6 +233,13 @@ func (s *InboundService) addUsers(db *gorm.DB, inboundJson []byte, inboundId uin if err != nil { return nil, err } + + if inboundType == "shadowtls" { + version, _ := inbound["version"].(float64) + if int(version) < 3 { + return inboundJson, nil + } + } if inboundType == "shadowsocks" { method, _ := inbound["method"].(string) if method == "2022-blake3-aes-128-gcm" { @@ -233,6 +259,10 @@ func (s *InboundService) addUsers(db *gorm.DB, inboundJson []byte, inboundId uin usersJson = append(usersJson, json.RawMessage(user)) } + if len(usersJson) > 0 || inboundType != "shadowsocks" { + inbound["users"] = usersJson + } + inbound["users"] = usersJson return json.Marshal(inbound) } diff --git a/frontend/src/components/protocols/ShadowTls.vue b/frontend/src/components/protocols/ShadowTls.vue index 2296136..cd86197 100644 --- a/frontend/src/components/protocols/ShadowTls.vue +++ b/frontend/src/components/protocols/ShadowTls.vue @@ -6,6 +6,7 @@ hide-details :items="[1,2,3]" :label="$t('version')" + :disabled="data.id > 0" v-model="version"> @@ -115,23 +116,18 @@ export default { switch (newValue) { case 1: delete this.Inbound.password - delete this.Inbound.users delete this.Inbound.handshake_for_server_name break; case 2: if (!this.Inbound.password) { this.Inbound.password = "" } - delete this.Inbound.users if (!this.Inbound.handshake_for_server_name) { this.Inbound.handshake_for_server_name = {} } break; case 3: delete this.Inbound.password - if (!Object.hasOwn(this.Inbound, 'users')) { - this.Inbound.users = [] - } if (!this.Inbound.handshake_for_server_name) { this.Inbound.handshake_for_server_name = {} }