feat(mtproto): per-client ad-tags, management-API auth, and record secret sync

Catch the panel up to the mtg-multi README (v1.14.0):

- Each client can now carry its own 32-hex advertising tag overriding the
  inbound-level one. The tag lives on the client (settings JSON is the
  source of truth, clients.ad_tag is the UI projection), is rendered into
  the fork's [secret-ad-tags] section for active secrets only (mtg rejects
  a config whose override names an unknown secret), is pushed per entry
  through PUT /secrets, and is part of the reload fingerprint so a tag
  edit hot-applies without dropping connections.
- The loopback management API can replace the whole secret set, so every
  mtg process now gets a random per-process api-token; the manager sends
  it as a bearer token on PUT /secrets and GET /stats and reuses it across
  config rewrites, because mtg reads the token only at startup.
- Malformed tags are rejected at every save path and additionally dropped
  in InstanceFromInbound: one bad tag would otherwise fail the whole
  generated config and take every client of the inbound down with it.
- SyncInbound never copied a re-keyed mtproto secret into the canonical
  clients table, so the clients page and subscription links kept serving
  the old secret, which mtg then rejects. It is now guarded-copied like
  the other credentials.
This commit is contained in:
MHSanaei committed 2026-07-07 12:00:43 +02:00 Unverified
1 parent 659f0f404c
commit 43500a5470
33 files changed
+361 -54

No files matched your search

+5 -3
View File
@@ -14,9 +14,11 @@ file locations when it can answer in one hop.
API. MTProto inbounds run a second managed child — the `mtg-multi` binary
(`github.com/mhsanaei/mtg-multi`, a multi-secret fork built from source;
`internal/mtproto/`) — outside Xray, one process per inbound serving each
client's FakeTLS secret via the fork's `[secrets]` section. Client edits are
hot-applied through the fork's `POST /reload` so connections survive; the
manager falls back to a process restart on older binaries.
client's FakeTLS secret via the fork's `[secrets]` section (plus per-client
ad-tags via `[secret-ad-tags]`). Client and ad-tag edits are hot-applied
through the fork's management API (`PUT /secrets`, bearer-token guarded) so
connections survive; the manager falls back to a process restart on older
binaries.
- Storage: SQLite by default (`/etc/x-ui/x-ui.db` on Linux; the executable dir on
Windows), PostgreSQL optional (`XUI_DB_TYPE` / `XUI_DB_DSN`). The CGo SQLite
driver (`mattn/go-sqlite3`) needs a C compiler — `CGO_ENABLED=0` builds fail.
+4 -3
View File
@@ -22,9 +22,10 @@ separate HTTP server serves **subscription links** to end users.
The panel supervises **two managed child processes**: Xray-core itself and — when MTProto
inbounds exist — the `mtg-multi` Telegram-proxy binary (`github.com/mhsanaei/mtg-multi`, a
multi-secret fork built from source; `internal/mtproto/`). One process per inbound serves
every attached client's FakeTLS secret through the fork's `[secrets]` section. A client edit
is hot-applied via the fork's `POST /reload` endpoint (connections survive), with a process
restart as the fallback on older binaries.
every attached client's FakeTLS secret through the fork's `[secrets]` section, plus optional
per-client sponsored-channel ad-tags via `[secret-ad-tags]`. A client or ad-tag edit is
hot-applied via the fork's management API (`PUT /secrets`, guarded by a per-process bearer
token), with a process restart as the fallback on older binaries.
Servers and processes, all launched from `main.go`:
+8
View File
@@ -1092,6 +1092,10 @@
"Client": {
"description": "Client represents a client configuration for Xray inbounds with traffic limits and settings.",
"properties": {
"adTag": {
"example": "0123456789abcdef0123456789abcdef",
"type": "string"
},
"allowedIPs": {
"items": {
"type": "string"
@@ -1231,6 +1235,9 @@
},
"ClientRecord": {
"properties": {
"adTag": {
"type": "string"
},
"allowedIPs": {
"type": "string"
},
@@ -1306,6 +1313,7 @@
}
},
"required": [
"adTag",
"allowedIPs",
"auth",
"comment",
Loaded 3 of 33 files, more files were not shown because too many files have changed in this diff. Show more