mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5115] [Feature]: Outbound proxy for mtg #3593
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3593
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ld-Hagen on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5115
Is your feature request related to a problem?
As far as I know, the MtProto protocol isn't as resistant to DPI detection as the VPN protocols supported by 3x-ui.
So it seems like a good idea to use mtg on an internal server and route traffic across the border via VPN tunnels.
However, with the current implementation of mtg, it's not possible to specify a proxy for outgoing traffic.
Describe the solution you'd like
Add the option to select a Socks5 proxy for outbound traffic to the mtg settings. If possible, allow users to select it from existing mixed inbound connections. So all TG traffic will be routed using xray-core using outbound rules from panel.
Alternatives you've considered
No response
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
Frontend (UI / panel pages)
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jun 9, 2026):
Thanks for the well-described request. Here is exactly what would need to change to implement it.
Current state
mtg processes are launched via
mtproto/manager.go. The config file written for each instance (writeConfig, line 285) currently contains only:No proxy section. The
Instancestruct only carriesId,Tag,Listen,Port,Secret— no proxy field. The settings JSON parsed from the inbound (InstanceFromInbound) reads onlysecret; likewise the frontend schema (MtprotoInboundSettingsSchemainfrontend/src/schemas/protocols/inbound/mtproto.ts) only exposesfakeTlsDomainandsecret.The bundled binary is mtg v2.2.8 (
9seconds/mtg). mtg v2 supports a SOCKS5 proxy via its TOML config (the exact key should be verified against the mtg v2 docs, but it is typically a[network]section with aproxiesarray).What a PR would need to touch
Backend (
mtproto/)Instancestruct (manager.go) — add aProxy stringfield (the SOCKS5 URL, e.g.socks5://user:pass@127.0.0.1:1080).writeConfig— wheninst.Proxy \!= "", append the mtg v2 proxy config block to the generated TOML.InstanceFromInbound— extend theparsedstruct to also decode aproxykey fromib.SettingsJSON and populateInstance.Proxy.Frontend
frontend/src/schemas/protocols/inbound/mtproto.ts— add an optionalproxyfield (e.g.z.string().optional()).frontend/src/pages/inbounds/form/protocols/mtproto.tsx— add an input for the SOCKS5 URL. For the "select from existing mixed inbound" UX you described, the form would need to query the inbound list, filter forprotocol === "mixed"entries, and construct the URL from the selected inbound's listen address, port, and credentials.Note on the "select from mixed inbound" idea
Mixedinbounds (database/model/model.go,Protocol = "mixed") combine HTTP+SOCKS and have optionalaccounts(user/pass). Building the SOCKS5 URL from a selected mixed inbound is feasible but adds some complexity: the inbound might usenoauth(no credentials needed) orpasswordauth (credentials required in the URL). The simplest first step would be a free-text SOCKS5 URL input; the "pick from existing inbounds" convenience could be added on top.If you or someone else plans to open a PR, the files to start with are
mtproto/manager.go(backend config generation) andfrontend/src/schemas/protocols/inbound/mtproto.ts+frontend/src/pages/inbounds/form/protocols/mtproto.tsx(frontend schema and form).@JohniGo76 commented on GitHub (Jun 9, 2026):
I tried using Mixed Inbound with UDP support as a proxy for the Telegram client. Text messages get through, but voice calls don't. HTTP Proxy Inbound works similarly. As outbound for cascade proxy I tried VLES+RAW and Hysteria.
Therefore, I don't think routing MTProxy to local Socks (Mixed) will help.
@deepru commented on GitHub (Jun 9, 2026):
This request would also be very useful for a reverse-proxy / Double-Hop MTProto setup.
I opened a related feature request here: #5126
That issue covers the inbound side of the deployment:
This issue covers the outbound side:
So together, #5126 + this request would allow a clean managed MTG setup like:
This is useful when the Entry server is the public connection point, but the actual Telegram egress should go through another server or another Xray route.
I agree that SOCKS5 is probably the most practical first step, because
mtgalready supports proxy chaining and many 3x-ui/Xray deployments can expose a local SOCKS5 or mixed inbound on127.0.0.1.For 3x-ui, the useful MTProto settings could be something like:
Expected generated MTG config would include the corresponding proxy/chaining section supported by
mtg.Important behavior:
Instance.fingerprint()so the MTG sidecar restarts when proxy settings change;This is not the same as #5126, but the two features complement each other:
@MHSanaei commented on GitHub (Jul 3, 2026):
This has been implemented since the issue was opened. Edit (or create) an MTProto inbound and enable Route through Xray: the panel injects a loopback SOCKS5 bridge into the Xray config and points the mtg sidecar at it, so all Telegram egress follows your Xray routing rules — and you can pick a specific outbound tag for that traffic in the same form.
This covers the requested SOCKS5 chaining without manually maintaining a mixed inbound. Closing as implemented — please open a new issue if your HAProxy scenario needs something the current toggle doesn't cover.