[PR #6070] [CLOSED] fix(mtproto): attribute access logs to clients #6069

Closed
opened 2026-11-02 04:06:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6070
Author: @EgorRU
Created: 7/22/2026
Status: ❌ Closed

Base: main ← Head: agent/fix-mtproto-client-logging


📝 Commits (4)

  • 05872cd fix(mtproto): attribute access logs to clients
  • 6e7fa07 Merge branch 'main' into agent/fix-mtproto-client-logging
  • 6b6fd1a Merge branch 'main' into agent/fix-mtproto-client-logging
  • 68ece73 Merge branch 'main' into agent/fix-mtproto-client-logging

📊 Changes

8 files changed (+290 additions, -21 deletions)

View changed files

➕ internal/mtproto/access_log.go (+59 -0)
➕ internal/mtproto/access_log_test.go (+45 -0)
📝 internal/mtproto/manager.go (+111 -19)
📝 internal/mtproto/manager_mutation_test.go (+10 -0)
📝 internal/mtproto/manager_test.go (+4 -1)
📝 internal/web/job/mtproto_job.go (+11 -1)
📝 internal/web/service/access_log_parse_test.go (+23 -0)
📝 internal/web/service/server.go (+27 -0)

📄 Description

Summary

  • consume authenticated MTProto access events from the mtg-multi management stats response
  • append attributed Xray access-log rows as from IP:port accepted tcp:target [inbound >> outbound] email: client
  • hide the raw loopback SOCKS bridge rows for routed MTProto inbounds and keep the merged log ordered by event time
  • depend on the additive sidecar support proposed in MHSanaei/mtg-multi#2

Why

When an MTProto inbound routes Telegram traffic through Xray, Xray sees only the local SOCKS bridge. The access log therefore reports tcp:127.0.0.1:<port> with an empty email, making every client in a multi-client inbound indistinguishable.

The sidecar already authenticates the FakeTLS secret before dialing Telegram. Consuming its bounded access events lets the panel show the actual client socket and email while retaining the selected inbound, outbound, and Telegram target.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • go test ./...
  • go build ./...
  • go test ./internal/mtproto ./internal/web/service -run 'TestAppendAccessLog|TestScrapeStats|TestParseAccessLogFields|TestIsMtprotoBridgeLog'
  • built and ran the Windows panel with a routed multi-client MTProto inbound and the companion mtg-multi change
  • verified /panel/api/server/xraylogs/1000 returned FromAddress: [::1]:50284, ToAddress: tcp:[2a0a:...]:443, and the client email
  • verified raw loopback bridge rows were excluded and no attributed row used the intermediate from tcp:... format

Breaking changes

None. The stats response change is additive. A release containing MHSanaei/mtg-multi#2 is required before attributed events are available; older sidecars continue to run but do not emit them.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: not applicable; no frontend files changed.
  • I updated the Wiki / README / API docs if user-facing behavior changed (not required; no config or public API changed).
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6070 **Author:** [@EgorRU](https://github.com/EgorRU) **Created:** 7/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `agent/fix-mtproto-client-logging` --- ### 📝 Commits (4) - [`05872cd`](https://github.com/MHSanaei/3x-ui/commit/05872cd44c8d7a3bab27b90c2c28fc5582170647) fix(mtproto): attribute access logs to clients - [`6e7fa07`](https://github.com/MHSanaei/3x-ui/commit/6e7fa0774142f17e5e564bf77cbc3539f8b5a0fa) Merge branch 'main' into agent/fix-mtproto-client-logging - [`6b6fd1a`](https://github.com/MHSanaei/3x-ui/commit/6b6fd1a2ce252c3f73abd9813cf7bbc15914f12b) Merge branch 'main' into agent/fix-mtproto-client-logging - [`68ece73`](https://github.com/MHSanaei/3x-ui/commit/68ece73a17106c8ed85d735d1efbacd7a56e57dc) Merge branch 'main' into agent/fix-mtproto-client-logging ### 📊 Changes **8 files changed** (+290 additions, -21 deletions) <details> <summary>View changed files</summary> ➕ `internal/mtproto/access_log.go` (+59 -0) ➕ `internal/mtproto/access_log_test.go` (+45 -0) 📝 `internal/mtproto/manager.go` (+111 -19) 📝 `internal/mtproto/manager_mutation_test.go` (+10 -0) 📝 `internal/mtproto/manager_test.go` (+4 -1) 📝 `internal/web/job/mtproto_job.go` (+11 -1) 📝 `internal/web/service/access_log_parse_test.go` (+23 -0) 📝 `internal/web/service/server.go` (+27 -0) </details> ### 📄 Description ## Summary - consume authenticated MTProto access events from the `mtg-multi` management stats response - append attributed Xray access-log rows as `from IP:port accepted tcp:target [inbound >> outbound] email: client` - hide the raw loopback SOCKS bridge rows for routed MTProto inbounds and keep the merged log ordered by event time - depend on the additive sidecar support proposed in MHSanaei/mtg-multi#2 ## Why When an MTProto inbound routes Telegram traffic through Xray, Xray sees only the local SOCKS bridge. The access log therefore reports `tcp:127.0.0.1:<port>` with an empty email, making every client in a multi-client inbound indistinguishable. The sidecar already authenticates the FakeTLS secret before dialing Telegram. Consuming its bounded access events lets the panel show the actual client socket and email while retaining the selected inbound, outbound, and Telegram target. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [x] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - `go test ./...` - `go build ./...` - `go test ./internal/mtproto ./internal/web/service -run 'TestAppendAccessLog|TestScrapeStats|TestParseAccessLogFields|TestIsMtprotoBridgeLog'` - built and ran the Windows panel with a routed multi-client MTProto inbound and the companion `mtg-multi` change - verified `/panel/api/server/xraylogs/1000` returned `FromAddress: [::1]:50284`, `ToAddress: tcp:[2a0a:...]:443`, and the client email - verified raw loopback bridge rows were excluded and no attributed row used the intermediate `from tcp:...` format ## Breaking changes None. The stats response change is additive. A release containing MHSanaei/mtg-multi#2 is required before attributed events are available; older sidecars continue to run but do not emit them. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: not applicable; no frontend files changed. - [x] I updated the Wiki / README / API docs if user-facing behavior changed (not required; no config or public API changed). - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:09 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6069
No description provided.