mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-29 22:47:14 +00:00
feat(notifications): event bus architecture with Telegram and SMTP subscribers (#5326)
* feat(notifications): event bus architecture with Telegram and SMTP subscribers
- Event bus core with buffered channel, fan-out, panic recovery
- Telegram subscriber with HTML formatting and rate limiting
- Email subscriber with SMTP/TLS/STARTTLS support and stage diagnostics
- 5 event types: outbound.down/up, xray.crash, cpu.high, login.attempt
- CPU threshold checks per subscriber (tgCpu for TG, smtpCpu for Email)
- SystemMetricData struct for raw metric values in events
- i18n keys for en-US, ru-RU, and English defaults for other locales
* fix
* fix(notifications): repair crash/CPU alerts, harden secrets, add node alerts
Bug fixes:
- Xray crash notifications were permanently suppressed after the first crash:
XrayStateTracker latched state="down" with no reset and no recovery event,
so only the first crash per process lifetime ever notified. Removed the
tracker; the existing 1/min rate limiter already dedupes crash-loop spam.
- Email CPU alerts could never fire unless Telegram was also enabled, because
the CPU job was registered only inside the tgbot block. Register it whenever
either Telegram or SMTP wants cpu.high (new cpuAlarmWanted gate) and relax
the cadence to @every 1m (cpu.Percent already samples over a full minute).
- SMTP password (and, pre-existing, all other secrets) were shipped to the
browser in plaintext: GetAllSettingView was dead code and /setting/all
returned the raw model. Wire getAllSetting -> GetAllSettingView, redact
smtpPassword with a hasSmtpPassword presence flag, and preserve it on blank
save. Closes the leak for tgBotToken/ldapPassword/2FA token too.
Polish:
- email Send: use nil SMTP auth when no credentials (Go refuses PlainAuth over
the unencrypted "none" transport).
- Remove unused EventClientDepleted; fix inaccurate bus.go doc comments; drop
stale tgBotLoginNotify from the frontend schema; gofmt alignment.
Feature - node online/offline alerts:
- Emit node.down/node.up from the heartbeat job on a real status transition
(with a startup-spam guard), reusing NodeHealthData. Formatted by both the
Telegram and email subscribers and selectable in the settings UI.
Regenerated frontend types (hasSmtpPassword). New i18n keys added to en-US;
other locales fall back to English (bundle default) until translated.
* fix(settings): use antd Space orientation instead of deprecated direction
Ant Design 6 deprecated Space's `direction` prop in favor of `orientation`,
which logged a console warning from the Telegram/Email notification tabs. Brings
these two tabs in line with the rest of the codebase, which already uses
`orientation`.
* i18n(notifications): translate the notification feature into all locales
The notifications PR shipped ~99 new strings (SMTP settings, event labels,
Telegram/email message templates) as English placeholders in every non-English
locale. Translate them — plus the node-alert keys added during this review —
into all 12 locales: Arabic, Spanish, Persian, Indonesian, Japanese,
Portuguese-BR, Russian, Turkish, Ukrainian, Vietnamese, and Simplified/
Traditional Chinese.
Go-template placeholders ({{ .Tag }}, {{ .Name }}, etc.) are preserved exactly;
tgbot message values carry no leading status emoji (the bot/email code adds
those, so an emoji in the value would duplicate it); product/protocol names
(SMTP, STARTTLS, TLS, CPU, Xray, Telegram) are kept as-is.
---------
Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
@@ -1200,7 +1200,69 @@
|
||||
"userPassMustBeNotEmpty": "O novo nome de usuário e senha não podem estar vazios",
|
||||
"getOutboundTrafficError": "Erro ao obter tráfego de saída",
|
||||
"resetOutboundTrafficError": "Erro ao redefinir tráfego de saída"
|
||||
}
|
||||
},
|
||||
"emailNotifications": "Notificações",
|
||||
"emailSettings": "E-mail",
|
||||
"eventCPUHigh": "CPU alta (%)",
|
||||
"eventGroupOutbound": "Outbound",
|
||||
"eventGroupSecurity": "Segurança",
|
||||
"eventGroupSystem": "Sistema",
|
||||
"eventGroupXray": "Núcleo Xray",
|
||||
"eventLoginAttempt": "Tentativa de login",
|
||||
"eventOutboundDown": "Inativo",
|
||||
"eventOutboundUp": "Ativo",
|
||||
"eventXrayCrash": "Falha",
|
||||
"requestFailed": "Falha na requisição",
|
||||
"smtpEnable": "Ativar notificações por e-mail",
|
||||
"smtpEnableDesc": "Ativar notificações por e-mail via SMTP",
|
||||
"smtpEncryption": "Criptografia",
|
||||
"smtpEncryptionDesc": "Método de criptografia da conexão SMTP",
|
||||
"smtpEncryptionNone": "Nenhuma (texto puro)",
|
||||
"smtpEncryptionStartTLS": "STARTTLS",
|
||||
"smtpEncryptionTLS": "TLS (implícito)",
|
||||
"smtpEventBusNotify": "Notificações de eventos por e-mail",
|
||||
"smtpEventBusNotifyDesc": "Selecione quais eventos disparam notificações por e-mail",
|
||||
"smtpHost": "Servidor SMTP",
|
||||
"smtpHostDesc": "Nome do host do servidor SMTP (ex.: smtp.gmail.com)",
|
||||
"smtpHostNotConfigured": "Servidor SMTP não configurado",
|
||||
"smtpNoRecipients": "Nenhum destinatário configurado",
|
||||
"smtpNotInitialized": "SMTP não inicializado",
|
||||
"smtpPassword": "Senha SMTP",
|
||||
"smtpPasswordDesc": "Senha para autenticação SMTP",
|
||||
"smtpPort": "Porta SMTP",
|
||||
"smtpPortDesc": "Porta do servidor SMTP (padrão: 587)",
|
||||
"smtpSettings": "Configurações SMTP",
|
||||
"smtpStageAuth": "Autenticação",
|
||||
"smtpStageConnect": "Conexão",
|
||||
"smtpStageSend": "Envio",
|
||||
"smtpTestSuccess": "E-mail de teste enviado com sucesso",
|
||||
"smtpTo": "Destinatários",
|
||||
"smtpToDesc": "Endereços de e-mail dos destinatários separados por vírgula",
|
||||
"smtpUsername": "Usuário SMTP",
|
||||
"smtpUsernameDesc": "Nome de usuário para autenticação SMTP",
|
||||
"telegramTokenConfigured": "Configurado; deixe em branco para manter o token atual.",
|
||||
"telegramTokenPlaceholder": "Configurado - insira um novo token para substituir",
|
||||
"testSmtp": "Enviar e-mail de teste",
|
||||
"testTgBot": "Enviar mensagem de teste",
|
||||
"tgBotNotEnabled": "O bot do Telegram não está ativado",
|
||||
"tgBotNotRunning": "O bot do Telegram não está em execução",
|
||||
"tgEventBusNotify": "Notificações de eventos no Telegram",
|
||||
"tgEventBusNotifyDesc": "Selecione quais eventos disparam notificações no Telegram",
|
||||
"tgTestFailed": "Falha no teste do Telegram",
|
||||
"tgTestSuccess": "Mensagem de teste enviada ao Telegram",
|
||||
"smtpErrorAuth": "Falha na autenticação — verifique o nome de usuário e a senha",
|
||||
"smtpErrorStarttls": "O servidor requer STARTTLS — altere o tipo de criptografia",
|
||||
"smtpErrorTls": "O servidor requer TLS — altere o tipo de criptografia",
|
||||
"smtpErrorRefused": "Conexão recusada — verifique o host e a porta",
|
||||
"smtpErrorTimeout": "Tempo de conexão esgotado — host inacessível",
|
||||
"smtpErrorRelay": "O servidor rejeita o envio a partir deste endereço",
|
||||
"smtpErrorEof": "Conexão encerrada pelo servidor",
|
||||
"smtpErrorUnknown": "Erro de SMTP: {{ .Error }}",
|
||||
"eventGroupNode": "Nós",
|
||||
"eventNodeDown": "Inativo",
|
||||
"eventNodeUp": "Ativo",
|
||||
"smtpPasswordConfigured": "Configurada; deixe em branco para manter a senha atual.",
|
||||
"smtpPasswordPlaceholder": "Configurada - insira uma nova senha para substituir"
|
||||
},
|
||||
"xray": {
|
||||
"title": "Configurações Xray",
|
||||
@@ -1703,7 +1765,18 @@
|
||||
"AreYouSure": "Você tem certeza? 🤔",
|
||||
"SuccessResetTraffic": "📧 Email: {{ .ClientEmail }}\n🏁 Resultado: ✅ Sucesso",
|
||||
"FailedResetTraffic": "📧 Email: {{ .ClientEmail }}\n🏁 Resultado: ❌ Falhou \n\n🛠️ Erro: [ {{ .ErrorMessage }} ]",
|
||||
"FinishProcess": "🔚 Processo de redefinição de tráfego concluído para todos os clientes."
|
||||
"FinishProcess": "🔚 Processo de redefinição de tráfego concluído para todos os clientes.",
|
||||
"eventCPUHigh": "CPU alta",
|
||||
"eventCPUHighDetail": "CPU: {{ .Detail }}",
|
||||
"eventDelayDetail": "Latência: {{ .Delay }}ms",
|
||||
"eventErrorDetail": "Erro: {{ .Error }}",
|
||||
"eventLoginFallback": "Falha de login a partir de {{ .Source }}",
|
||||
"eventOutboundDown": "O outbound {{ .Tag }} está INATIVO",
|
||||
"eventOutboundUp": "O outbound {{ .Tag }} está ATIVO",
|
||||
"eventXrayCrash": "O Xray FALHOU",
|
||||
"eventXrayCrashError": "Erro: {{ .Error }}",
|
||||
"eventNodeDown": "O nó {{ .Name }} está INATIVO",
|
||||
"eventNodeUp": "O nó {{ .Name }} está ATIVO"
|
||||
},
|
||||
"buttons": {
|
||||
"closeKeyboard": "❌ Fechar teclado",
|
||||
@@ -1773,5 +1846,57 @@
|
||||
"chooseClient": "Escolha um cliente para Inbound {{ .Inbound }}",
|
||||
"chooseInbound": "Escolha um Inbound"
|
||||
}
|
||||
},
|
||||
"email": {
|
||||
"labelDelay": "Latência",
|
||||
"labelDetail": "Detalhe",
|
||||
"labelError": "Erro",
|
||||
"labelIP": "IP",
|
||||
"labelOutbound": "Outbound",
|
||||
"labelReason": "Motivo",
|
||||
"labelSource": "Origem",
|
||||
"labelStatus": "Status",
|
||||
"labelTime": "Horário",
|
||||
"labelUsername": "Nome de usuário",
|
||||
"statusBanned": "BANNED",
|
||||
"statusCrashed": "FALHOU",
|
||||
"statusDown": "INATIVO",
|
||||
"statusFailed": "FALHOU",
|
||||
"statusFull": "FULL",
|
||||
"statusHigh": "ALTA",
|
||||
"statusOffline": "OFFLINE",
|
||||
"statusOnline": "ONLINE",
|
||||
"statusRunning": "Em execução",
|
||||
"statusSuccess": "SUCESSO",
|
||||
"statusUp": "ATIVO",
|
||||
"statusXrayDown": "Xray DOWN",
|
||||
"statusXrayUp": "Xray UP",
|
||||
"subjectCPUHigh": "CPU alta",
|
||||
"subjectDiskFull": "Disk full",
|
||||
"subjectIPBanned": "IP banned: {{ .IP }}",
|
||||
"subjectLoginFailed": "Falha de login",
|
||||
"subjectLoginSuccess": "Login bem-sucedido",
|
||||
"subjectNodeOffline": "Node {{ .Node }} is OFFLINE",
|
||||
"subjectNodeOnline": "Node {{ .Node }} is ONLINE",
|
||||
"subjectNodeXrayDown": "Node {{ .Node }} Xray is DOWN",
|
||||
"subjectNodeXrayUp": "Node {{ .Node }} Xray is UP",
|
||||
"subjectOutboundDown": "O outbound {{ .Tag }} está INATIVO",
|
||||
"subjectOutboundUp": "O outbound {{ .Tag }} está ATIVO",
|
||||
"subjectXrayCrash": "O Xray FALHOU",
|
||||
"subjectXrayUp": "Xray is UP",
|
||||
"titleCPUHigh": "CPU alta",
|
||||
"titleDiskFull": "Disk full",
|
||||
"titleIPBanned": "IP banned",
|
||||
"titleLoginFailed": "Falha de login",
|
||||
"titleLoginSuccess": "Login bem-sucedido",
|
||||
"titleNodeOffline": "Node OFFLINE",
|
||||
"titleNodeOnline": "Node ONLINE",
|
||||
"titleNodeXrayDown": "Node Xray DOWN",
|
||||
"titleNodeXrayUp": "Node Xray UP",
|
||||
"titleOutboundDown": "Outbound INATIVO",
|
||||
"titleOutboundUp": "Outbound ATIVO",
|
||||
"titleXrayCrash": "O Xray FALHOU",
|
||||
"titleXrayUp": "Xray UP",
|
||||
"labelNode": "Nó"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user