From b008ff4ad236f20f0937dd02e747ca6581e776f3 Mon Sep 17 00:00:00 2001 From: Sanaei Date: Sun, 7 Sep 2025 22:35:38 +0200 Subject: [PATCH] Vlessenc (#3426) * mlkem768 * VlessEnc --- database/model/model.go | 7 ++++ sub/subController.go | 5 +-- sub/subJsonService.go | 14 +++++-- sub/subService.go | 6 +++ web/assets/js/model/inbound.js | 45 +++++++++++++++++----- web/assets/js/model/outbound.js | 8 ++-- web/controller/server.go | 10 +++++ web/html/form/outbound.html | 5 +++ web/html/form/protocol/vless.html | 24 +++++++++++- web/html/form/tls_settings.html | 8 ++-- web/html/inbounds.html | 6 +-- web/html/modals/inbound_info_modal.html | 6 +++ web/html/modals/inbound_modal.html | 48 ++++++++++++++++++------ web/service/server.go | 50 +++++++++++++++++++++++++ web/translation/translate.ar_EG.toml | 1 + web/translation/translate.en_US.toml | 1 + web/translation/translate.es_ES.toml | 1 + web/translation/translate.fa_IR.toml | 1 + web/translation/translate.id_ID.toml | 1 + web/translation/translate.ja_JP.toml | 1 + web/translation/translate.pt_BR.toml | 1 + web/translation/translate.ru_RU.toml | 1 + web/translation/translate.tr_TR.toml | 1 + web/translation/translate.uk_UA.toml | 1 + web/translation/translate.vi_VN.toml | 3 +- web/translation/translate.zh_CN.toml | 1 + web/translation/translate.zh_TW.toml | 1 + 27 files changed, 215 insertions(+), 42 deletions(-) diff --git a/database/model/model.go b/database/model/model.go index 18211ef8..7d0a977c 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -106,3 +106,10 @@ type Client struct { CreatedAt int64 `json:"created_at,omitempty"` UpdatedAt int64 `json:"updated_at,omitempty"` } + +type VLESSSettings struct { + Clients []Client `json:"clients"` + Decryption string `json:"decryption"` + Encryption string `json:"encryption"` + Fallbacks []any `json:"fallbacks"` +} diff --git a/sub/subController.go b/sub/subController.go index 2f22ecab..3f053740 100644 --- a/sub/subController.go +++ b/sub/subController.go @@ -53,7 +53,6 @@ func (a *SUBController) initRouter(g *gin.RouterGroup) { gJson := g.Group(a.subJsonPath) gLink.GET(":subid", a.subs) - gJson.GET(":subid", a.subJsons) } @@ -85,7 +84,7 @@ func (a *SUBController) subs(c *gin.Context) { // Add headers c.Writer.Header().Set("Subscription-Userinfo", header) c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval) - c.Writer.Header().Set("Profile-Title", "base64:" + base64.StdEncoding.EncodeToString([]byte(a.subTitle))) + c.Writer.Header().Set("Profile-Title", "base64:"+base64.StdEncoding.EncodeToString([]byte(a.subTitle))) if a.subEncrypt { c.String(200, base64.StdEncoding.EncodeToString([]byte(result))) @@ -119,7 +118,7 @@ func (a *SUBController) subJsons(c *gin.Context) { // Add headers c.Writer.Header().Set("Subscription-Userinfo", header) c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval) - c.Writer.Header().Set("Profile-Title", "base64:" + base64.StdEncoding.EncodeToString([]byte(a.subTitle))) + c.Writer.Header().Set("Profile-Title", "base64:"+base64.StdEncoding.EncodeToString([]byte(a.subTitle))) c.String(200, jsonSub) } diff --git a/sub/subJsonService.go b/sub/subJsonService.go index 680a01c0..def8b855 100644 --- a/sub/subJsonService.go +++ b/sub/subJsonService.go @@ -184,8 +184,14 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client, var newOutbounds []json_util.RawMessage switch inbound.Protocol { - case "vmess", "vless": - newOutbounds = append(newOutbounds, s.genVnext(inbound, streamSettings, client)) + case "vmess": + newOutbounds = append(newOutbounds, s.genVnext(inbound, streamSettings, client, "")) + case "vless": + var vlessSettings model.VLESSSettings + _ = json.Unmarshal([]byte(inbound.Settings), &vlessSettings) + + newOutbounds = append(newOutbounds, + s.genVnext(inbound, streamSettings, client, vlessSettings.Encryption)) case "trojan", "shadowsocks": newOutbounds = append(newOutbounds, s.genServer(inbound, streamSettings, client)) } @@ -284,7 +290,7 @@ func (s *SubJsonService) realityData(rData map[string]any) map[string]any { return rltyData } -func (s *SubJsonService) genVnext(inbound *model.Inbound, streamSettings json_util.RawMessage, client model.Client) json_util.RawMessage { +func (s *SubJsonService) genVnext(inbound *model.Inbound, streamSettings json_util.RawMessage, client model.Client, encryption string) json_util.RawMessage { outbound := Outbound{} usersData := make([]UserVnext, 1) @@ -295,7 +301,7 @@ func (s *SubJsonService) genVnext(inbound *model.Inbound, streamSettings json_ut } if inbound.Protocol == model.VLESS { usersData[0].Flow = client.Flow - usersData[0].Encryption = "none" + usersData[0].Encryption = encryption } vnextData := make([]VnextSetting, 1) diff --git a/sub/subService.go b/sub/subService.go index dfb0863e..e6e25e3a 100644 --- a/sub/subService.go +++ b/sub/subService.go @@ -313,6 +313,9 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string { if inbound.Protocol != model.VLESS { return "" } + var vlessSettings model.VLESSSettings + _ = json.Unmarshal([]byte(inbound.Settings), &vlessSettings) + var stream map[string]any json.Unmarshal([]byte(inbound.StreamSettings), &stream) clients, _ := s.inboundService.GetClients(inbound) @@ -327,6 +330,9 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string { port := inbound.Port streamNetwork := stream["network"].(string) params := make(map[string]string) + if vlessSettings.Encryption != "" { + params["encryption"] = vlessSettings.Encryption + } params["type"] = streamNetwork switch streamNetwork { diff --git a/web/assets/js/model/inbound.js b/web/assets/js/model/inbound.js index c91dbd11..1fc8ea19 100644 --- a/web/assets/js/model/inbound.js +++ b/web/assets/js/model/inbound.js @@ -1301,6 +1301,7 @@ class Inbound extends XrayCommonClass { const security = forceTls == 'same' ? this.stream.security : forceTls; const params = new Map(); params.set("type", this.stream.network); + params.set("encryption", this.settings.encryption); switch (type) { case "tcp": const tcp = this.stream.tcp; @@ -1859,13 +1860,16 @@ Inbound.VLESSSettings = class extends Inbound.Settings { constructor( protocol, vlesses = [new Inbound.VLESSSettings.VLESS()], - decryption = 'none', - fallbacks = [] + decryption = "none", + encryption = "", + fallbacks = [], ) { super(protocol); this.vlesses = vlesses; this.decryption = decryption; + this.encryption = encryption; this.fallbacks = fallbacks; + this.selectedAuth = "X25519, not Post-Quantum"; } addFallback() { @@ -1876,22 +1880,43 @@ Inbound.VLESSSettings = class extends Inbound.Settings { this.fallbacks.splice(index, 1); } - // decryption should be set to static value static fromJson(json = {}) { - return new Inbound.VLESSSettings( + const obj = new Inbound.VLESSSettings( Protocols.VLESS, - json.clients.map(client => Inbound.VLESSSettings.VLESS.fromJson(client)), - json.decryption || 'none', - Inbound.VLESSSettings.Fallback.fromJson(json.fallbacks),); + (json.clients || []).map(client => Inbound.VLESSSettings.VLESS.fromJson(client)), + json.decryption, + json.encryption, + Inbound.VLESSSettings.Fallback.fromJson(json.fallbacks || []) + ); + obj.selectedAuth = json.selectedAuth || "X25519, not Post-Quantum"; + return obj; } + toJson() { - return { + const json = { clients: Inbound.VLESSSettings.toJsonArray(this.vlesses), - decryption: this.decryption, - fallbacks: Inbound.VLESSSettings.toJsonArray(this.fallbacks), }; + + if (this.decryption) { + json.decryption = this.decryption; + } + + if (this.encryption) { + json.encryption = this.encryption; + } + + if (this.fallbacks && this.fallbacks.length > 0) { + json.fallbacks = Inbound.VLESSSettings.toJsonArray(this.fallbacks); + } + if (this.selectedAuth) { + json.selectedAuth = this.selectedAuth; + } + + return json; } + + }; Inbound.VLESSSettings.VLESS = class extends XrayCommonClass { diff --git a/web/assets/js/model/outbound.js b/web/assets/js/model/outbound.js index ee78795f..2d5660fb 100644 --- a/web/assets/js/model/outbound.js +++ b/web/assets/js/model/outbound.js @@ -813,7 +813,7 @@ class Outbound extends CommonClass { var settings; switch (protocol) { case Protocols.VLESS: - settings = new Outbound.VLESSSettings(address, port, userData, url.searchParams.get('flow') ?? ''); + settings = new Outbound.VLESSSettings(address, port, userData, url.searchParams.get('flow') ?? '', url.searchParams.get('encryption') ?? 'none'); break; case Protocols.Trojan: settings = new Outbound.TrojanSettings(address, port, userData); @@ -1046,13 +1046,13 @@ Outbound.VmessSettings = class extends CommonClass { } }; Outbound.VLESSSettings = class extends CommonClass { - constructor(address, port, id, flow, encryption = 'none') { + constructor(address, port, id, flow, encryption) { super(); this.address = address; this.port = port; this.id = id; this.flow = flow; - this.encryption = encryption + this.encryption = encryption; } static fromJson(json = {}) { @@ -1071,7 +1071,7 @@ Outbound.VLESSSettings = class extends CommonClass { vnext: [{ address: this.address, port: this.port, - users: [{ id: this.id, flow: this.flow, encryption: 'none', }], + users: [{ id: this.id, flow: this.flow, encryption: this.encryption }], }], }; } diff --git a/web/controller/server.go b/web/controller/server.go index 2d2f741e..b1174b8f 100644 --- a/web/controller/server.go +++ b/web/controller/server.go @@ -55,6 +55,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) { g.POST("/getNewX25519Cert", a.getNewX25519Cert) g.POST("/getNewmldsa65", a.getNewmldsa65) g.POST("/getNewEchCert", a.getNewEchCert) + g.POST("/getNewVlessEnc", a.getNewVlessEnc) } func (a *ServerController) refreshStatus() { @@ -266,3 +267,12 @@ func (a *ServerController) getNewEchCert(c *gin.Context) { } jsonObj(c, cert, nil) } + +func (a *ServerController) getNewVlessEnc(c *gin.Context) { + out, err := a.serverService.GetNewVlessEnc() + if err != nil { + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.getNewVlessEncError"), err) + return + } + jsonObj(c, out, nil) +} diff --git a/web/html/form/outbound.html b/web/html/form/outbound.html index c7a786b7..cfaaafd7 100644 --- a/web/html/form/outbound.html +++ b/web/html/form/outbound.html @@ -226,6 +226,11 @@ +