1
1
package controller
2
2
3
3
import (
4
- "errors"
5
4
"encoding/json"
6
5
"fmt"
7
6
"strconv"
7
+
8
8
"x-ui/database/model"
9
9
"x-ui/web/service"
10
10
"x-ui/web/session"
@@ -33,13 +33,9 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
33
33
g .POST ("/clientIps/:email" , a .getClientIps )
34
34
g .POST ("/clearClientIps/:email" , a .clearClientIps )
35
35
g .POST ("/addClient" , a .addInboundClient )
36
- g .POST ("/addGroupClient" , a .addGroupInboundClient )
37
36
g .POST ("/:id/delClient/:clientId" , a .delInboundClient )
38
- g .POST ("/delGroupClients" , a .delGroupClients )
39
37
g .POST ("/updateClient/:clientId" , a .updateInboundClient )
40
- g .POST ("/updateClients" , a .updateGroupInboundClient )
41
38
g .POST ("/:id/resetClientTraffic/:email" , a .resetClientTraffic )
42
- g .POST ("/resetGroupClientTraffic" , a .resetGroupClientTraffic )
43
39
g .POST ("/resetAllTraffics" , a .resetAllTraffics )
44
40
g .POST ("/resetAllClientTraffics/:id" , a .resetAllClientTraffics )
45
41
g .POST ("/delDepletedClients/:id" , a .delDepletedClients )
@@ -194,34 +190,6 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
194
190
}
195
191
}
196
192
197
- func (a * InboundController ) addGroupInboundClient (c * gin.Context ) {
198
- var requestData []model.Inbound
199
-
200
- err := c .ShouldBindJSON (& requestData )
201
-
202
- if err != nil {
203
- jsonMsg (c , I18nWeb (c , "pages.inbounds.update" ), err )
204
- return
205
- }
206
-
207
- needRestart := true
208
-
209
- for _ , data := range requestData {
210
-
211
- needRestart , err = a .inboundService .AddInboundClient (& data )
212
- if err != nil {
213
- jsonMsg (c , "Something went wrong!" , err )
214
- return
215
- }
216
- }
217
-
218
- jsonMsg (c , "Client(s) added" , nil )
219
- if err == nil && needRestart {
220
- a .xrayService .SetToNeedRestart ()
221
- }
222
-
223
- }
224
-
225
193
func (a * InboundController ) delInboundClient (c * gin.Context ) {
226
194
id , err := strconv .Atoi (c .Param ("id" ))
227
195
if err != nil {
@@ -243,38 +211,6 @@ func (a *InboundController) delInboundClient(c *gin.Context) {
243
211
}
244
212
}
245
213
246
- func (a * InboundController ) delGroupClients (c * gin.Context ) {
247
- var requestData []struct {
248
- InboundID int `json:"inboundId"`
249
- ClientID string `json:"clientId"`
250
- }
251
-
252
- if err := c .ShouldBindJSON (& requestData ); err != nil {
253
- jsonMsg (c , "Invalid request data" , err )
254
- return
255
- }
256
-
257
- needRestart := false
258
-
259
- for _ , req := range requestData {
260
- needRestartTmp , err := a .inboundService .DelInboundClient (req .InboundID , req .ClientID )
261
- if err != nil {
262
- jsonMsg (c , "Failed to delete client" , err )
263
- return
264
- }
265
-
266
- if needRestartTmp {
267
- needRestart = true
268
- }
269
- }
270
-
271
- jsonMsg (c , "Clients deleted successfully" , nil )
272
-
273
- if needRestart {
274
- a .xrayService .SetToNeedRestart ()
275
- }
276
- }
277
-
278
214
func (a * InboundController ) updateInboundClient (c * gin.Context ) {
279
215
clientId := c .Param ("clientId" )
280
216
@@ -298,56 +234,6 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
298
234
}
299
235
}
300
236
301
- func (a * InboundController ) updateGroupInboundClient (c * gin.Context ) {
302
- var requestData []map [string ]interface {}
303
-
304
- if err := c .ShouldBindJSON (& requestData ); err != nil {
305
- jsonMsg (c , I18nWeb (c , "pages.inbounds.update" ), err )
306
- return
307
- }
308
-
309
- needRestart := false
310
-
311
- for _ , item := range requestData {
312
-
313
- inboundMap , ok := item ["inbound" ].(map [string ]interface {})
314
- if ! ok {
315
- jsonMsg (c , "Something went wrong!" , errors .New ("Failed to convert 'inbound' to map" ))
316
- return
317
- }
318
-
319
- clientId , ok := item ["clientId" ].(string )
320
- if ! ok {
321
- jsonMsg (c , "Something went wrong!" , errors .New ("Failed to convert 'clientId' to string" ))
322
- return
323
- }
324
-
325
- inboundJSON , err := json .Marshal (inboundMap )
326
- if err != nil {
327
- jsonMsg (c , "Something went wrong!" , err )
328
- return
329
- }
330
-
331
- var inboundModel model.Inbound
332
- if err := json .Unmarshal (inboundJSON , & inboundModel ); err != nil {
333
- jsonMsg (c , "Something went wrong!" , err )
334
- return
335
- }
336
-
337
- if restart , err := a .inboundService .UpdateInboundClient (& inboundModel , clientId ); err != nil {
338
- jsonMsg (c , "Something went wrong!" , err )
339
- return
340
- } else {
341
- needRestart = needRestart || restart
342
- }
343
- }
344
-
345
- jsonMsg (c , "Client updated" , nil )
346
- if needRestart {
347
- a .xrayService .SetToNeedRestart ()
348
- }
349
- }
350
-
351
237
func (a * InboundController ) resetClientTraffic (c * gin.Context ) {
352
238
id , err := strconv .Atoi (c .Param ("id" ))
353
239
if err != nil {
@@ -367,44 +253,6 @@ func (a *InboundController) resetClientTraffic(c *gin.Context) {
367
253
}
368
254
}
369
255
370
- func (a * InboundController ) resetGroupClientTraffic (c * gin.Context ) {
371
- var requestData []struct {
372
- InboundID int `json:"inboundId"` // Map JSON "inboundId" to struct field "InboundID"
373
- Email string `json:"email"` // Map JSON "email" to struct field "Email"
374
- }
375
-
376
- // Parse JSON body directly using ShouldBindJSON
377
- if err := c .ShouldBindJSON (& requestData ); err != nil {
378
- jsonMsg (c , "Invalid request data" , err )
379
- return
380
- }
381
-
382
- needRestart := false
383
-
384
- // Process each request data
385
- for _ , req := range requestData {
386
- needRestartTmp , err := a .inboundService .ResetClientTraffic (req .InboundID , req .Email )
387
- if err != nil {
388
- jsonMsg (c , "Failed to reset client traffic" , err )
389
- return
390
- }
391
-
392
- // If any request requires a restart, set needRestart to true
393
- if needRestartTmp {
394
- needRestart = true
395
- }
396
- }
397
-
398
- // Send response back to the client
399
- jsonMsg (c , "Traffic reset for all clients" , nil )
400
-
401
- // Restart the service if required
402
- if needRestart {
403
- a .xrayService .SetToNeedRestart ()
404
- }
405
- }
406
-
407
-
408
256
func (a * InboundController ) resetAllTraffics (c * gin.Context ) {
409
257
err := a .inboundService .ResetAllTraffics ()
410
258
if err != nil {
0 commit comments