[GH-ISSUE #6990] [Bug]: Telegram bot (v3.11.0): "Ban log" no longer sends the current 3xipl-banned.log #4609

Closed
opened 2026-10-31 20:40:53 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @yukh975 on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6990

Describe the bug

Since v3.11.0 (the bot rewrite in #6760) the admin's 📄 Ban log button only sends 3xipl-banned.prev.log. The current 3xipl-banned.log is no longer sent.

In v3.10.2, sendBanLogs (tgbot_report.go) sent both files: prev, then current. In v3.11.0, sendBanLogsFile (internal/web/service/tgbot/screen_views.go) opens only xray.GetIPLimitBannedPrevLogPath(). ClearLogsJob rotates current → prev only @daily, so bans from the current day are invisible in the bot until the next rotation.

A second, smaller regression in the same function: the old code skipped an empty file. The new code passes it straight to SendDocument. Telegram rejects empty documents, so when the prev log exists but is empty the admin gets only the Hostname/DateTime notice. No file arrives and no "No results" reply is sent; only a Failed to upload the ban log warning is logged.

The commit message of #6760 does not mention either change, so I assume both are unintentional.

How to reproduce the problem

  1. Enable an IP limit on a client and let it get banned (an entry appears in 3xipl-banned.log).
  2. Before the daily log rotation, open the bot as admin → Maintenance → 📄 Ban log.
  3. You get the Hostname/DateTime notice and the previous day's file (or nothing at all if that file is empty), but not today's bans.

Expected behavior

As in v3.10.2: both 3xipl-banned.prev.log and 3xipl-banned.log are sent, empty files are skipped, and "No results" is shown when there is nothing to send.

Actual behavior

Only 3xipl-banned.prev.log is sent. When that file is empty, nothing is sent and the admin gets no reply.

3x-ui version

v3.11.0

Which parts of the panel are affected?

Telegram bot

Originally created by @yukh975 on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6990 ### Describe the bug Since v3.11.0 (the bot rewrite in #6760) the admin's **📄 Ban log** button only sends `3xipl-banned.prev.log`. The current `3xipl-banned.log` is no longer sent. In v3.10.2, `sendBanLogs` (`tgbot_report.go`) sent both files: prev, then current. In v3.11.0, `sendBanLogsFile` (`internal/web/service/tgbot/screen_views.go`) opens only `xray.GetIPLimitBannedPrevLogPath()`. `ClearLogsJob` rotates current → prev only `@daily`, so bans from the current day are invisible in the bot until the next rotation. A second, smaller regression in the same function: the old code skipped an empty file. The new code passes it straight to `SendDocument`. Telegram rejects empty documents, so when the prev log exists but is empty the admin gets only the Hostname/DateTime notice. No file arrives and no "No results" reply is sent; only a `Failed to upload the ban log` warning is logged. The commit message of #6760 does not mention either change, so I assume both are unintentional. ### How to reproduce the problem 1. Enable an IP limit on a client and let it get banned (an entry appears in `3xipl-banned.log`). 2. Before the daily log rotation, open the bot as admin → Maintenance → 📄 Ban log. 3. You get the Hostname/DateTime notice and the previous day's file (or nothing at all if that file is empty), but not today's bans. ### Expected behavior As in v3.10.2: both `3xipl-banned.prev.log` and `3xipl-banned.log` are sent, empty files are skipped, and "No results" is shown when there is nothing to send. ### Actual behavior Only `3xipl-banned.prev.log` is sent. When that file is empty, nothing is sent and the admin gets no reply. ### 3x-ui version v3.11.0 ### Which parts of the panel are affected? Telegram bot
Author
Owner

@github-actions[bot] commented on GitHub (Oct 28, 2026):

You're right on both points. Since v3.11.0 the bot's 📄 Ban log button only sends 3xipl-banned.prev.log, so today's bans don't show up until the @daily rotation runs. It also no longer skips an empty file. The bot rewrite in #6760 lost both behaviours, and both are still present on the default branch.

Until it's fixed, the current file is still readable on the server with x-ui banlog (x-ui.sh:99 points it at ${log_folder}/3xipl-banned.log), or with cat /var/log/x-ui/3xipl-banned.log.

One correction to the expected behaviour you describe: v3.10.2 never sent "No results" when both files were empty. It logged a warning per file and sent only the Hostname/DateTime message. The "No results" notice in v3.11.0 is new, and it only appears when the prev file can't be opened at all.

Verdict:        Confirmed bug
Severity:       Medium
Confidence:     High
Root cause:     internal/web/service/tgbot/screen_views.go:318-337, sendBanLogsFile, opens only
                xray.GetIPLimitBannedPrevLogPath() and never xray.GetIPLimitBannedLogPath(). It also
                passes the file to SendDocument with no size check, so an empty prev log goes to
                Telegram and the upload fails (only a "Failed to upload the ban log:" warning is logged).
                Introduced in 15fee2a0 "feat(tgbot): rebuild the Telegram bot around editable screens
                and inline lists (#6760)", first released in v3.11.0.
Same class:     None found. screenBanLogs (screen_views.go:286, reached from tgbot_router.go:1000)
                is the only caller, and nothing else in the bot sends the ban logs.
Already fixed:  Still present on the default branch (tip is c621ba90, tagged v3.11.0).
Duplicate of:   None
Evidence:       - screen_views.go:319  `file, err := os.Open(xray.GetIPLimitBannedPrevLogPath())`.
                  This is the only file the function opens.
                - screen_views.go:330-334  SendDocument is called with `tu.File(file)` and no Stat()/Size() check.
                - v3.10.2 (15fee2a0^:internal/web/service/tgbot/tgbot_report.go, sendBanLogs) opened the
                  prev log, then `os.Open(xray.GetIPLimitBannedLogPath())`, and wrapped each upload in
                  `if fileInfo.Size() > 0 { ... } else { logger.Warning("... file is empty, not uploading.") }`.
                - internal/web/web.go:378  `s.cron.AddJob("@daily", job.NewClearLogsJob())`.
                  internal/web/job/clear_logs_job.go:61-89 copies 3xipl-banned.log to
                  3xipl-banned.prev.log and then truncates the current file, so until that job runs,
                  today's bans exist only in the file the bot no longer reads.
                - No test in internal/web/service/tgbot/ covers which files sendBanLogsFile sends.
Not determined: The exact Telegram error text for an empty upload. The panel log line
                "Failed to upload the ban log:" right after pressing the button would show it.

Suggested fix: in sendBanLogsFile, loop over GetIPLimitBannedPrevLogPath() and GetIPLimitBannedLogPath(), in that order. Skip any file that can't be opened or has size 0, and send tgbot.noResult only if neither file was uploaded. That fixes both regressions in their only caller.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:6469084859 --> @github-actions[bot] commented on GitHub (Oct 28, 2026): You're right on both points. Since v3.11.0 the bot's **📄 Ban log** button only sends `3xipl-banned.prev.log`, so today's bans don't show up until the `@daily` rotation runs. It also no longer skips an empty file. The bot rewrite in #6760 lost both behaviours, and both are still present on the default branch. Until it's fixed, the current file is still readable on the server with `x-ui banlog` (`x-ui.sh:99` points it at `${log_folder}/3xipl-banned.log`), or with `cat /var/log/x-ui/3xipl-banned.log`. One correction to the expected behaviour you describe: v3.10.2 never sent "No results" when both files were empty. It logged a warning per file and sent only the Hostname/DateTime message. The "No results" notice in v3.11.0 is new, and it only appears when the prev file can't be opened at all. ``` Verdict: Confirmed bug Severity: Medium Confidence: High Root cause: internal/web/service/tgbot/screen_views.go:318-337, sendBanLogsFile, opens only xray.GetIPLimitBannedPrevLogPath() and never xray.GetIPLimitBannedLogPath(). It also passes the file to SendDocument with no size check, so an empty prev log goes to Telegram and the upload fails (only a "Failed to upload the ban log:" warning is logged). Introduced in 15fee2a0 "feat(tgbot): rebuild the Telegram bot around editable screens and inline lists (#6760)", first released in v3.11.0. Same class: None found. screenBanLogs (screen_views.go:286, reached from tgbot_router.go:1000) is the only caller, and nothing else in the bot sends the ban logs. Already fixed: Still present on the default branch (tip is c621ba90, tagged v3.11.0). Duplicate of: None Evidence: - screen_views.go:319 `file, err := os.Open(xray.GetIPLimitBannedPrevLogPath())`. This is the only file the function opens. - screen_views.go:330-334 SendDocument is called with `tu.File(file)` and no Stat()/Size() check. - v3.10.2 (15fee2a0^:internal/web/service/tgbot/tgbot_report.go, sendBanLogs) opened the prev log, then `os.Open(xray.GetIPLimitBannedLogPath())`, and wrapped each upload in `if fileInfo.Size() > 0 { ... } else { logger.Warning("... file is empty, not uploading.") }`. - internal/web/web.go:378 `s.cron.AddJob("@daily", job.NewClearLogsJob())`. internal/web/job/clear_logs_job.go:61-89 copies 3xipl-banned.log to 3xipl-banned.prev.log and then truncates the current file, so until that job runs, today's bans exist only in the file the bot no longer reads. - No test in internal/web/service/tgbot/ covers which files sendBanLogsFile sends. Not determined: The exact Telegram error text for an empty upload. The panel log line "Failed to upload the ban log:" right after pressing the button would show it. ``` Suggested fix: in `sendBanLogsFile`, loop over `GetIPLimitBannedPrevLogPath()` and `GetIPLimitBannedLogPath()`, in that order. Skip any file that can't be opened or has size 0, and send `tgbot.noResult` only if neither file was uploaded. That fixes both regressions in their only caller. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
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#4609
No description provided.