From 88eab032be7197dd87d0b4c9864af4b6b4fd820b Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Sun, 18 Jan 2026 16:47:01 +0100 Subject: [PATCH] Add TUN protocol for inbound Introduces TUN protocol to inbound.js, including a new TunSettings class. Updates inbound form to support TUN protocol and adds a dedicated form template for TUN settings. Translation files are updated with TUN-related strings for all supported languages. --- web/assets/js/model/inbound.js | 34 +++++++++++++++ web/html/form/inbound.html | 62 ++++++++++++++++++++-------- web/html/form/protocol/tun.html | 44 ++++++++++++++++++++ web/translation/translate.ar_EG.toml | 6 +++ web/translation/translate.en_US.toml | 6 +++ web/translation/translate.es_ES.toml | 6 +++ web/translation/translate.fa_IR.toml | 6 +++ web/translation/translate.id_ID.toml | 6 +++ web/translation/translate.ja_JP.toml | 6 +++ web/translation/translate.pt_BR.toml | 6 +++ web/translation/translate.ru_RU.toml | 6 +++ web/translation/translate.tr_TR.toml | 6 +++ web/translation/translate.uk_UA.toml | 6 +++ web/translation/translate.vi_VN.toml | 6 +++ web/translation/translate.zh_CN.toml | 6 +++ web/translation/translate.zh_TW.toml | 6 +++ 16 files changed, 200 insertions(+), 18 deletions(-) create mode 100644 web/html/form/protocol/tun.html diff --git a/web/assets/js/model/inbound.js b/web/assets/js/model/inbound.js index 8d4b6819..e5fe368f 100644 --- a/web/assets/js/model/inbound.js +++ b/web/assets/js/model/inbound.js @@ -7,6 +7,7 @@ const Protocols = { MIXED: 'mixed', HTTP: 'http', WIREGUARD: 'wireguard', + TUN: 'tun', }; const SSMethods = { @@ -1739,6 +1740,7 @@ Inbound.Settings = class extends XrayCommonClass { case Protocols.MIXED: return new Inbound.MixedSettings(protocol); case Protocols.HTTP: return new Inbound.HttpSettings(protocol); case Protocols.WIREGUARD: return new Inbound.WireguardSettings(protocol); + case Protocols.TUN: return new Inbound.TunSettings(protocol); default: return null; } } @@ -1753,6 +1755,7 @@ Inbound.Settings = class extends XrayCommonClass { case Protocols.MIXED: return Inbound.MixedSettings.fromJson(json); case Protocols.HTTP: return Inbound.HttpSettings.fromJson(json); case Protocols.WIREGUARD: return Inbound.WireguardSettings.fromJson(json); + case Protocols.TUN: return Inbound.TunSettings.fromJson(json); default: return null; } } @@ -2586,3 +2589,34 @@ Inbound.WireguardSettings.Peer = class extends XrayCommonClass { }; } }; + +Inbound.TunSettings = class extends Inbound.Settings { + constructor( + protocol, + name = 'xray0', + mtu = 1500, + userLevel = 0 + ) { + super(protocol); + this.name = name; + this.mtu = mtu; + this.userLevel = userLevel; + } + + static fromJson(json = {}) { + return new Inbound.TunSettings( + Protocols.TUN, + json.name ?? 'xray0', + json.mtu ?? json.MTU ?? 1500, + json.userLevel ?? 0 + ); + } + + toJson() { + return { + name: this.name || 'xray0', + mtu: this.mtu || 1500, + userLevel: this.userLevel || 0, + }; + } +}; diff --git a/web/html/form/inbound.html b/web/html/form/inbound.html index fdd381b0..8b59dc28 100644 --- a/web/html/form/inbound.html +++ b/web/html/form/inbound.html @@ -1,6 +1,7 @@ {{define "form/inbound"}} - + @@ -9,8 +10,10 @@ - - [[ p ]] + + [[ p + ]] @@ -28,7 +31,8 @@ - + @@ -41,29 +45,42 @@ - + - - {{ i18n "pages.inbounds.periodicTrafficReset.never" }} - {{ i18n "pages.inbounds.periodicTrafficReset.daily" }} - {{ i18n "pages.inbounds.periodicTrafficReset.weekly" }} - {{ i18n "pages.inbounds.periodicTrafficReset.monthly" }} + + {{ i18n + "pages.inbounds.periodicTrafficReset.never" }} + {{ i18n + "pages.inbounds.periodicTrafficReset.daily" }} + {{ i18n + "pages.inbounds.periodicTrafficReset.weekly" + }} + {{ i18n + "pages.inbounds.periodicTrafficReset.monthly" + }} @@ -71,16 +88,20 @@ - - @@ -126,6 +147,11 @@ {{template "form/wireguard"}} + + +