feat(inbounds): row action to delete all clients of an inbound

Adds POST /panel/api/inbounds/:id/delAllClients that collects every
client email from settings.clients[] and runs ClientService.BulkDelete
in one pass. Row action lives in the More menu as a danger item, only
shown for multi-user inbounds that currently have at least one client;
confirmation modal displays the live client count.
This commit is contained in:
MHSanaei
2026-05-27 18:17:44 +02:00
parent 93eda06878
commit e23599cb18
17 changed files with 127 additions and 5 deletions
+36
View File
@@ -19,6 +19,7 @@ import (
// InboundController handles HTTP requests related to Xray inbounds management.
type InboundController struct {
inboundService service.InboundService
clientService service.ClientService
xrayService service.XrayService
fallbackService service.FallbackService
}
@@ -72,6 +73,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
g.POST("/update/:id", a.updateInbound)
g.POST("/setEnable/:id", a.setInboundEnable)
g.POST("/:id/resetTraffic", a.resetInboundTraffic)
g.POST("/:id/delAllClients", a.delAllInboundClients)
g.POST("/resetAllTraffics", a.resetAllTraffics)
g.POST("/import", a.importInbound)
g.POST("/:id/fallbacks", a.setFallbacks)
@@ -276,6 +278,40 @@ func (a *InboundController) resetInboundTraffic(c *gin.Context) {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetInboundTrafficSuccess"), nil)
}
// delAllInboundClients removes every client attached to a specific inbound
// while keeping the inbound itself. Internally collects the current email
// list from settings.clients[] and feeds it into ClientService.BulkDelete,
// which handles per-inbound JSON rewriting, runtime user removal, traffic
// row cleanup, and the SyncInbound mapping pass in one optimized cycle.
func (a *InboundController) delAllInboundClients(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
emails, err := a.inboundService.EmailsByInbound(id)
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
if len(emails) == 0 {
jsonObj(c, service.BulkDeleteResult{}, nil)
return
}
result, needRestart, err := a.clientService.BulkDelete(&a.inboundService, emails, false)
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
jsonObj(c, result, nil)
if needRestart {
a.xrayService.SetToNeedRestart()
}
user := session.GetLoginUser(c)
a.broadcastInboundsUpdate(user.Id)
notifyClientsChanged()
}
// resetAllTraffics resets all traffic counters across all inbounds.
func (a *InboundController) resetAllTraffics(c *gin.Context) {
err := a.inboundService.ResetAllTraffics()
+21
View File
@@ -2415,6 +2415,27 @@ func (s *InboundService) ResetInboundTraffic(id int) error {
})
}
// EmailsByInbound returns the list of client emails currently configured on
// an inbound's settings.clients[]. Used by the "delete all clients" flow on
// the inbounds page, which then feeds the list into ClientService.BulkDelete.
func (s *InboundService) EmailsByInbound(inboundId int) ([]string, error) {
inbound, err := s.GetInbound(inboundId)
if err != nil {
return nil, err
}
clients, err := s.GetClients(inbound)
if err != nil {
return nil, err
}
emails := make([]string, 0, len(clients))
for _, c := range clients {
if e := strings.TrimSpace(c.Email); e != "" {
emails = append(emails, e)
}
}
return emails, nil
}
func (s *InboundService) DelDepletedClients(id int) (err error) {
db := database.GetDB()
tx := db.Begin()
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "يعيد عدادات الإرسال/الاستقبال لهذا الإدخال إلى 0.",
"cloneConfirmTitle": "نسخ الإدخال \"{remark}\"؟",
"cloneConfirmContent": "ينشئ نسخة بمنفذ جديد وقائمة عملاء فارغة.",
"delAllClients": "حذف جميع العملاء",
"delAllClientsConfirmTitle": "حذف جميع العملاء البالغ عددهم {count} من \"{remark}\"؟",
"delAllClientsConfirmContent": "يزيل كل عميل من هذا الإدخال ويحذف سجلات حركة المرور الخاصة بهم. يتم الاحتفاظ بالإدخال نفسه. لا يمكن التراجع عن هذا.",
"exportLinksTitle": "تصدير روابط الإدخال",
"exportSubsTitle": "تصدير روابط الاشتراك",
"exportAllLinksTitle": "تصدير كل روابط الإدخالات",
+3
View File
@@ -295,6 +295,9 @@
"resetConfirmContent": "Resets up/down counters to 0 for this inbound.",
"cloneConfirmTitle": "Clone inbound \"{remark}\"?",
"cloneConfirmContent": "Creates a copy with a new port and an empty client list.",
"delAllClients": "Delete All Clients",
"delAllClientsConfirmTitle": "Delete all {count} clients from \"{remark}\"?",
"delAllClientsConfirmContent": "This removes every client from this inbound and drops their traffic records. The inbound itself is kept. This cannot be undone.",
"exportLinksTitle": "Export inbound links",
"exportSubsTitle": "Export subscription links",
"exportAllLinksTitle": "Export all inbound links",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Restablece los contadores de subida/bajada a 0 para este inbound.",
"cloneConfirmTitle": "¿Clonar el inbound \"{remark}\"?",
"cloneConfirmContent": "Crea una copia con un puerto nuevo y una lista de clientes vacía.",
"delAllClients": "Eliminar todos los clientes",
"delAllClientsConfirmTitle": "¿Eliminar los {count} clientes de \"{remark}\"?",
"delAllClientsConfirmContent": "Elimina todos los clientes de este inbound y sus registros de tráfico. El inbound se mantiene. Esto no se puede deshacer.",
"exportLinksTitle": "Exportar enlaces del inbound",
"exportSubsTitle": "Exportar enlaces de suscripción",
"exportAllLinksTitle": "Exportar todos los enlaces de inbound",
+3
View File
@@ -290,6 +290,9 @@
"resetConfirmContent": "شمارنده‌های ارسال/دریافت این اینباند به صفر برمی‌گردد.",
"cloneConfirmTitle": "اینباند «{remark}» کپی شود؟",
"cloneConfirmContent": "یک نسخه با پورت جدید و لیست کلاینت خالی ساخته می‌شود.",
"delAllClients": "حذف همه کلاینت‌ها",
"delAllClientsConfirmTitle": "حذف هر {count} کلاینت اینباند «{remark}»؟",
"delAllClientsConfirmContent": "تمام کلاینت‌های این اینباند به همراه رکوردهای ترافیک‌شان حذف می‌شوند. خود اینباند باقی می‌ماند. این عمل غیرقابل بازگشت است.",
"exportLinksTitle": "خروجی لینک‌های اینباند",
"exportSubsTitle": "خروجی لینک‌های ساب",
"exportAllLinksTitle": "خروجی لینک‌های همه اینباندها",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Mengatur ulang counter unggah/unduh ke 0 untuk inbound ini.",
"cloneConfirmTitle": "Klon inbound \"{remark}\"?",
"cloneConfirmContent": "Membuat salinan dengan port baru dan daftar klien kosong.",
"delAllClients": "Hapus Semua Klien",
"delAllClientsConfirmTitle": "Hapus semua {count} klien dari \"{remark}\"?",
"delAllClientsConfirmContent": "Menghapus setiap klien dari inbound ini dan menghapus catatan trafiknya. Inbound itu sendiri dipertahankan. Tindakan ini tidak dapat dibatalkan.",
"exportLinksTitle": "Ekspor tautan inbound",
"exportSubsTitle": "Ekspor tautan langganan",
"exportAllLinksTitle": "Ekspor semua tautan inbound",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "このインバウンドの送受信カウンタを 0 にリセットします。",
"cloneConfirmTitle": "インバウンド「{remark}」を複製しますか?",
"cloneConfirmContent": "新しいポートと空のクライアント一覧でコピーを作成します。",
"delAllClients": "すべてのクライアントを削除",
"delAllClientsConfirmTitle": "「{remark}」から {count} 件のクライアントをすべて削除しますか?",
"delAllClientsConfirmContent": "このインバウンドからすべてのクライアントを削除し、トラフィックレコードも破棄します。インバウンド自体は保持されます。この操作は取り消せません。",
"exportLinksTitle": "インバウンドリンクのエクスポート",
"exportSubsTitle": "サブスクリプションリンクのエクスポート",
"exportAllLinksTitle": "全インバウンドリンクのエクスポート",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Zera os contadores de envio/recebimento para este inbound.",
"cloneConfirmTitle": "Clonar o inbound \"{remark}\"?",
"cloneConfirmContent": "Cria uma cópia com uma nova porta e lista de clientes vazia.",
"delAllClients": "Excluir todos os clientes",
"delAllClientsConfirmTitle": "Excluir todos os {count} clientes de \"{remark}\"?",
"delAllClientsConfirmContent": "Remove todos os clientes deste inbound e descarta seus registros de tráfego. O inbound em si é mantido. Esta ação não pode ser desfeita.",
"exportLinksTitle": "Exportar links do inbound",
"exportSubsTitle": "Exportar links de assinatura",
"exportAllLinksTitle": "Exportar todos os links de inbound",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Сбрасывает счётчики отправки/получения этого подключения до 0.",
"cloneConfirmTitle": "Клонировать подключение \"{remark}\"?",
"cloneConfirmContent": "Создаёт копию с новым портом и пустым списком клиентов.",
"delAllClients": "Удалить всех клиентов",
"delAllClientsConfirmTitle": "Удалить всех {count} клиентов из \"{remark}\"?",
"delAllClientsConfirmContent": "Удаляет всех клиентов этого подключения и сбрасывает их записи трафика. Само подключение сохраняется. Это действие нельзя отменить.",
"exportLinksTitle": "Экспортировать ссылки подключения",
"exportSubsTitle": "Экспортировать ссылки подписки",
"exportAllLinksTitle": "Экспортировать все ссылки подключений",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Bu inbound için gönderme/alma sayaçlarını 0'a sıfırlar.",
"cloneConfirmTitle": "\"{remark}\" inbound klonlansın mı?",
"cloneConfirmContent": "Yeni bir port ve boş istemci listesiyle bir kopya oluşturur.",
"delAllClients": "Tüm istemcileri sil",
"delAllClientsConfirmTitle": "\"{remark}\" içindeki {count} istemcinin tamamı silinsin mi?",
"delAllClientsConfirmContent": "Bu inbound'a ait tüm istemcileri ve trafik kayıtlarını siler. Inbound'un kendisi korunur. Bu işlem geri alınamaz.",
"exportLinksTitle": "Inbound bağlantılarını dışa aktar",
"exportSubsTitle": "Abonelik bağlantılarını dışa aktar",
"exportAllLinksTitle": "Tüm inbound bağlantılarını dışa aktar",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Скидає лічильники відправки/отримання цього вхідного до 0.",
"cloneConfirmTitle": "Клонувати вхідні \"{remark}\"?",
"cloneConfirmContent": "Створює копію з новим портом і порожнім списком клієнтів.",
"delAllClients": "Видалити всіх клієнтів",
"delAllClientsConfirmTitle": "Видалити всіх {count} клієнтів із \"{remark}\"?",
"delAllClientsConfirmContent": "Видаляє всіх клієнтів цього вхідного й скидає їхні записи трафіку. Сам вхідний зберігається. Цю дію не можна скасувати.",
"exportLinksTitle": "Експортувати посилання вхідних",
"exportSubsTitle": "Експортувати посилання підписок",
"exportAllLinksTitle": "Експортувати всі посилання вхідних",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "Đặt lại bộ đếm lên/xuống về 0 cho inbound này.",
"cloneConfirmTitle": "Sao chép inbound \"{remark}\"?",
"cloneConfirmContent": "Tạo bản sao với cổng mới và danh sách khách hàng trống.",
"delAllClients": "Xóa tất cả khách hàng",
"delAllClientsConfirmTitle": "Xóa toàn bộ {count} khách hàng khỏi \"{remark}\"?",
"delAllClientsConfirmContent": "Xóa mọi khách hàng khỏi inbound này và hủy bản ghi lưu lượng của họ. Bản thân inbound vẫn được giữ lại. Hành động này không thể hoàn tác.",
"exportLinksTitle": "Xuất liên kết inbound",
"exportSubsTitle": "Xuất liên kết đăng ký",
"exportAllLinksTitle": "Xuất tất cả liên kết inbound",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "将此入站的上/下行计数器清零。",
"cloneConfirmTitle": "克隆入站 \"{remark}\"",
"cloneConfirmContent": "使用新端口和空客户端列表创建副本。",
"delAllClients": "删除所有客户端",
"delAllClientsConfirmTitle": "从 \"{remark}\" 中删除全部 {count} 个客户端?",
"delAllClientsConfirmContent": "从此入站中移除每个客户端并丢弃其流量记录。入站本身将保留。此操作无法撤销。",
"exportLinksTitle": "导出入站链接",
"exportSubsTitle": "导出订阅链接",
"exportAllLinksTitle": "导出所有入站链接",
+3
View File
@@ -289,6 +289,9 @@
"resetConfirmContent": "將此入站的上/下行計數器歸零。",
"cloneConfirmTitle": "複製入站「{remark}」?",
"cloneConfirmContent": "使用新連接埠和空客戶端清單建立副本。",
"delAllClients": "刪除所有客戶端",
"delAllClientsConfirmTitle": "從「{remark}」中刪除全部 {count} 個客戶端?",
"delAllClientsConfirmContent": "從此入站中移除每個客戶端並捨棄其流量記錄。入站本身將保留。此操作無法復原。",
"exportLinksTitle": "匯出入站連結",
"exportSubsTitle": "匯出訂閱連結",
"exportAllLinksTitle": "匯出所有入站連結",