mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/MHSanaei/3x-ui.git
synced 2026-09-20 08:04:05 +08:00
* feat(discord): add Discord notification bot service, settings UI, and event subscriber - internal/web/service/discord: implement lightweight Discord REST API v10 client and EventBus subscriber - internal/web/service/setting: add discordBotEnable, discordBotToken, discordChannelId, discordEnabledEvents, discordCpu, discordMemory settings and secret protection - internal/web/controller: register POST /panel/api/setting/testDiscord endpoint - frontend: add Discord settings tab, notifications configuration, sidebar navigation, and command palette integration - translation: add localization keys across all 13 locales - tests: add comprehensive unit tests with httptest server and verify route/i18n contracts * fix(discord): address PR review findings on concurrency, linting, i18n, and stories - subscriber: eliminate unbounded goroutines, sending inline per EventBus contract - discord: accept context.Context in SendMessage, SendEmbed, SendTest with http.NewRequestWithContext - format: apply gofumpt to controller and entity struct alignments - i18n: localize testDiscord controller responses across all 13 locales - storybook: add DiscordNotifications.stories.tsx component story * docs: add Discord bot setup and operations guide - add docs/content/docs/en/operations/discord-bot.mdx with setup steps, event indicators, settings, and troubleshooting - add docs/content/docs/ru/operations/discord-bot.mdx with localized instructions - update operations/meta.json across en, ru, zh, fa - link Discord bot from panel configuration overview * feat(discord): add discordLang, discordRunTime, discordBotBackup settings and update settings UI - internal/web/entity: add DiscordRunTime, DiscordBotBackup, DiscordLang fields to AllSetting - internal/web/service/setting: add defaultValueMap entries, getters, and setters - frontend: update AllSetting schema, model defaults, and generate OpenAPI / Zod contracts - frontend: extract shared NotifyTimeField component and update DiscordTab with General and Notifications tabs - translation: add localization keys across all 13 locales * feat(discord): implement scheduled status reports and database backup attachments - internal/web/service/discord: add SendMessageWithFiles supporting multipart uploads - internal/web/service/discord: implement BuildReport and SendReport generating rich status embeds - internal/web/service/discord: attach database backup (and config.json) when discordBotBackup is enabled - internal/web/job: implement DiscordNotifyJob scheduled via robfig/cron - internal/web/locale: add LocalizerFor and I18nForLang helpers - internal/web/controller: trigger reloadDiscordFunc to dynamically reschedule cron upon setting changes - internal/web/web: register and reschedule DiscordNotifyJob - tests: comprehensive unit tests for multipart uploads, status reporting, and job execution * feat(discord): add interactive bot commands via Gateway WebSocket and update documentation - internal/web/service/discord/gateway: connect to Discord Gateway v10 via WebSocket (gorilla/websocket) - internal/web/service/discord/gateway: handle heartbeat loop, reconnection, and command dispatch - commands: implement !status, !report, !backup, !usage <email>, !inbounds, !restart, !help (with ! and / prefixes) - internal/web/web: start/stop Gateway client with server and reload dynamically on setting updates - docs: update operations guide (en, ru) with scheduled reports, backups, commands, and privileged intents - tests: add end-to-end WebSocket Gateway test verifying command handling * style(discord): fix goimports formatting and add 3x-ui to gitignore * fix(discord): stop gateway panics, reconnect storms and proxy bypass The Gateway client wrote to its websocket from both the heartbeat ticker and the read loop answering server-requested op 1 heartbeats. gorilla panics on concurrent writes and neither goroutine recovers, so a colliding heartbeat took the whole panel process down; writes now share writeMu. It also reconnected every 5s forever after close codes Discord marks non-reconnectable (4004 bad token, 4010-4014, including 4014 when Message Content Intent is off), re-identifying and logging a warning each time. The loop now stops on those codes; the docs say to restart the panel. The gateway dialed with websocket.DefaultDialer, bypassing the panel egress proxy the REST client already uses, so where Discord is filtered notifications arrived but commands never connected. * fix(discord): deliver the scheduled report when the backup upload fails SendReport posted the report embed and the x-ui.db/config.json attachments in one multipart request. Once the database outgrows Discord's upload cap (20 MiB by default) the request is rejected and the report embed is lost with it on every run, leaving only a log warning. Send the embed first and the attachments as a second message. * chore(discord): delete tests that pass whether or not the code works TestDiscordNotifyJob_NilServiceNoPanic and TestHandleEvent_NilDiscordService feed a nil DiscordService that web.go never passes, and TestDiscordNotifyJob_DisabledNoPanic passes with or without the enable guard because Xray is not running under test. * fix(discord): require admin user IDs for bot commands and honor discordLang Any member who could post in the configured channel could run !backup (the whole x-ui.db and config.json, even with discordBotBackup off), !restart and !usage. Commands now run only for the Discord user IDs in the new discordAdminIds setting; an empty list turns commands off. discordLang was saved and offered in the UI, but nothing read it, so every embed stayed English. The test message, alerts, the scheduled report and command replies now render through I18nForLang in the chosen language, with a discord section in all 13 locales. InitLocalizer takes an fs.FS so tests load the real translation files. --------- Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
114 lines
7.9 KiB
Plaintext
114 lines
7.9 KiB
Plaintext
---
|
|
title: Settings
|
|
description: Panel configuration and user credentials. All endpoints live under
|
|
/panel/api/setting and require a logged-in session or Bearer token.
|
|
full: true
|
|
_openapi:
|
|
preload:
|
|
- ./public/openapi.json
|
|
toc:
|
|
- depth: 2
|
|
title: 'Return every panel setting: web server, Telegram bot, subscription,
|
|
security, LDAP. The full JSON blob that the Settings page edits.'
|
|
url: '#return-every-panel-setting-web-server-telegram-bot-subscription-security-ldap-the-full-json-blob-that-the-settings-page-edits'
|
|
- depth: 2
|
|
title: Return the computed default settings based on the request host. Useful to
|
|
preview what a fresh install would use.
|
|
url: '#return-the-computed-default-settings-based-on-the-request-host-useful-to-preview-what-a-fresh-install-would-use'
|
|
- depth: 2
|
|
title: Return the shipped (factory) default value per browser-safe setting key,
|
|
so clients can tell a stored value apart from the default it would fall
|
|
back to. Per-install material (secret, panelGuid, mTLS keys) and
|
|
credential fields are never included.
|
|
url: '#return-the-shipped-factory-default-value-per-browser-safe-setting-key-so-clients-can-tell-a-stored-value-apart-from-the-default-it-would-fall-back-to-per-install-material-secret-panelguid-mtls-keys-and-credential-fields-are-never-included'
|
|
- depth: 2
|
|
title: Persist every setting at once. The body mirrors the shape returned by
|
|
/all. Invalid values (bad ports, missing cert pairs, etc.) are rejected
|
|
before write.
|
|
url: '#persist-every-setting-at-once-the-body-mirrors-the-shape-returned-by-all-invalid-values-bad-ports-missing-cert-pairs-etc-are-rejected-before-write'
|
|
- depth: 2
|
|
title: Validate any regular expression with the backend Go RE2 compiler without
|
|
saving it.
|
|
url: '#validate-any-regular-expression-with-the-backend-go-re2-compiler-without-saving-it'
|
|
- depth: 2
|
|
title: Change the panel admin username and password. Requires the current
|
|
credentials for verification. The session is refreshed with the new
|
|
values on success.
|
|
url: '#change-the-panel-admin-username-and-password-requires-the-current-credentials-for-verification-the-session-is-refreshed-with-the-new-values-on-success'
|
|
- depth: 2
|
|
title: Restart the entire 3x-ui process after a 3-second grace period. The
|
|
connection drops immediately; the panel comes back online ~5-10 seconds
|
|
later.
|
|
url: '#restart-the-entire-3x-ui-process-after-a-3-second-grace-period-the-connection-drops-immediately-the-panel-comes-back-online-5-10-seconds-later'
|
|
- depth: 2
|
|
title: Test SMTP connection with stage-by-stage reporting (connect, auth, send).
|
|
Returns structured result with stage and message.
|
|
url: '#test-smtp-connection-with-stage-by-stage-reporting-connect-auth-send-returns-structured-result-with-stage-and-message'
|
|
- depth: 2
|
|
title: Test Telegram bot connection by sending a test message to the configured
|
|
chat.
|
|
url: '#test-telegram-bot-connection-by-sending-a-test-message-to-the-configured-chat'
|
|
- depth: 2
|
|
title: Test Discord bot connection by sending a test embed to the configured
|
|
channel.
|
|
url: '#test-discord-bot-connection-by-sending-a-test-embed-to-the-configured-channel'
|
|
- depth: 2
|
|
title: Return the built-in default Xray JSON config template that ships with
|
|
this panel version.
|
|
url: '#return-the-built-in-default-xray-json-config-template-that-ships-with-this-panel-version'
|
|
structuredData:
|
|
headings:
|
|
- content: 'Return every panel setting: web server, Telegram bot, subscription,
|
|
security, LDAP. The full JSON blob that the Settings page edits.'
|
|
id: return-every-panel-setting-web-server-telegram-bot-subscription-security-ldap-the-full-json-blob-that-the-settings-page-edits
|
|
- content: Return the computed default settings based on the request host. Useful
|
|
to preview what a fresh install would use.
|
|
id: return-the-computed-default-settings-based-on-the-request-host-useful-to-preview-what-a-fresh-install-would-use
|
|
- content: Return the shipped (factory) default value per browser-safe setting
|
|
key, so clients can tell a stored value apart from the default it
|
|
would fall back to. Per-install material (secret, panelGuid, mTLS
|
|
keys) and credential fields are never included.
|
|
id: return-the-shipped-factory-default-value-per-browser-safe-setting-key-so-clients-can-tell-a-stored-value-apart-from-the-default-it-would-fall-back-to-per-install-material-secret-panelguid-mtls-keys-and-credential-fields-are-never-included
|
|
- content: Persist every setting at once. The body mirrors the shape returned by
|
|
/all. Invalid values (bad ports, missing cert pairs, etc.) are
|
|
rejected before write.
|
|
id: persist-every-setting-at-once-the-body-mirrors-the-shape-returned-by-all-invalid-values-bad-ports-missing-cert-pairs-etc-are-rejected-before-write
|
|
- content: Validate any regular expression with the backend Go RE2 compiler
|
|
without saving it.
|
|
id: validate-any-regular-expression-with-the-backend-go-re2-compiler-without-saving-it
|
|
- content: Change the panel admin username and password. Requires the current
|
|
credentials for verification. The session is refreshed with the new
|
|
values on success.
|
|
id: change-the-panel-admin-username-and-password-requires-the-current-credentials-for-verification-the-session-is-refreshed-with-the-new-values-on-success
|
|
- content: Restart the entire 3x-ui process after a 3-second grace period. The
|
|
connection drops immediately; the panel comes back online ~5-10
|
|
seconds later.
|
|
id: restart-the-entire-3x-ui-process-after-a-3-second-grace-period-the-connection-drops-immediately-the-panel-comes-back-online-5-10-seconds-later
|
|
- content: Test SMTP connection with stage-by-stage reporting (connect, auth,
|
|
send). Returns structured result with stage and message.
|
|
id: test-smtp-connection-with-stage-by-stage-reporting-connect-auth-send-returns-structured-result-with-stage-and-message
|
|
- content: Test Telegram bot connection by sending a test message to the
|
|
configured chat.
|
|
id: test-telegram-bot-connection-by-sending-a-test-message-to-the-configured-chat
|
|
- content: Test Discord bot connection by sending a test embed to the configured
|
|
channel.
|
|
id: test-discord-bot-connection-by-sending-a-test-embed-to-the-configured-channel
|
|
- content: Return the built-in default Xray JSON config template that ships with
|
|
this panel version.
|
|
id: return-the-built-in-default-xray-json-config-template-that-ships-with-this-panel-version
|
|
contents: []
|
|
---
|
|
|
|
{/* This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again. */}
|
|
|
|
export default function Layout(props) {
|
|
const { APIPage, OpenAPIPage } = props.components ?? {};
|
|
// "APIPage" is the old name from v10, this allows both for backward compatibility
|
|
const Comp = OpenAPIPage ?? APIPage;
|
|
return (
|
|
<>
|
|
{props.children}
|
|
<Comp document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/setting/all","method":"post"},{"path":"/panel/api/setting/defaultSettings","method":"post"},{"path":"/panel/api/setting/factoryDefaults","method":"post"},{"path":"/panel/api/setting/update","method":"post"},{"path":"/panel/api/setting/validateRegex","method":"post"},{"path":"/panel/api/setting/updateUser","method":"post"},{"path":"/panel/api/setting/restartPanel","method":"post"},{"path":"/panel/api/setting/testSmtp","method":"post"},{"path":"/panel/api/setting/testTgBot","method":"post"},{"path":"/panel/api/setting/testDiscord","method":"post"},{"path":"/panel/api/setting/getDefaultJsonConfig","method":"get"}]} showTitle />
|
|
</>
|
|
);
|
|
} |