Skip to content

Commit d18a1a3

Browse files
authored
revert group management (#2656)
* Revert "json post base path bug fixed (#2647)" This reverts commit 04cf250. * Revert "Group Management of Subscription Clients" * Revert "fix getSubGroupClients for enable/disable and edit clients." * Revert "Enhance database initialization in db.go (#2645)" This reverts commit 66fe841. * Revert "Add checkpoint handling in CloseDB function (#2646)" This reverts commit 4dd40f6. * Revert "Improved database model migration and added indexing (#2655)" This reverts commit b922d98.
1 parent 04c6b27 commit d18a1a3

31 files changed

+96
-890
lines changed

database/db.go

+6-48
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,20 @@ const (
2626
)
2727

2828
func initModels() error {
29-
// Order matters: first create tables without dependencies
30-
baseModels := []interface{}{
29+
models := []interface{}{
3130
&model.User{},
32-
&model.Setting{},
33-
}
34-
35-
// Migrate base models
36-
for _, model := range baseModels {
37-
if err := db.AutoMigrate(model); err != nil {
38-
log.Printf("Error auto migrating base model: %v", err)
39-
return err
40-
}
41-
}
42-
43-
// Then migrate models with dependencies
44-
dependentModels := []interface{}{
4531
&model.Inbound{},
4632
&model.OutboundTraffics{},
33+
&model.Setting{},
4734
&model.InboundClientIps{},
4835
&xray.ClientTraffic{},
4936
}
50-
51-
for _, model := range dependentModels {
37+
for _, model := range models {
5238
if err := db.AutoMigrate(model); err != nil {
53-
log.Printf("Error auto migrating dependent model: %v", err)
39+
log.Printf("Error auto migrating model: %v", err)
5440
return err
5541
}
5642
}
57-
5843
return nil
5944
}
6045

@@ -97,31 +82,9 @@ func InitDB(dbPath string) error {
9782
}
9883

9984
c := &gorm.Config{
100-
Logger: gormLogger,
101-
SkipDefaultTransaction: true,
102-
PrepareStmt: true,
85+
Logger: gormLogger,
10386
}
104-
105-
dsn := dbPath + "?cache=shared&_journal_mode=WAL&_synchronous=NORMAL"
106-
db, err = gorm.Open(sqlite.Open(dsn), c)
107-
if err != nil {
108-
return err
109-
}
110-
111-
sqlDB, err := db.DB()
112-
if err != nil {
113-
return err
114-
}
115-
116-
_, err = sqlDB.Exec("PRAGMA cache_size = -64000;")
117-
if err != nil {
118-
return err
119-
}
120-
_, err = sqlDB.Exec("PRAGMA temp_store = MEMORY;")
121-
if err != nil {
122-
return err
123-
}
124-
_, err = sqlDB.Exec("PRAGMA foreign_keys = ON;")
87+
db, err = gorm.Open(sqlite.Open(dbPath), c)
12588
if err != nil {
12689
return err
12790
}
@@ -138,11 +101,6 @@ func InitDB(dbPath string) error {
138101

139102
func CloseDB() error {
140103
if db != nil {
141-
142-
if err := Checkpoint(); err != nil {
143-
log.Printf("error executing checkpoint: %v", err)
144-
}
145-
146104
sqlDB, err := db.DB()
147105
if err != nil {
148106
return err

database/model/model.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ type User struct {
2929

3030
type Inbound struct {
3131
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
32-
UserId int `json:"-" gorm:"index"`
32+
UserId int `json:"-"`
3333
Up int64 `json:"up" form:"up"`
3434
Down int64 `json:"down" form:"down"`
3535
Total int64 `json:"total" form:"total"`
3636
Remark string `json:"remark" form:"remark"`
3737
Enable bool `json:"enable" form:"enable"`
3838
ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
39-
ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id;constraint:OnDelete:CASCADE" json:"clientStats"`
39+
ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"`
4040

4141
// config part
4242
Listen string `json:"listen" form:"listen"`

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,4 @@ install_x-ui() {
283283

284284
echo -e "${green}Running...${plain}"
285285
install_base
286-
install_x-ui $1
286+
install_x-ui $1

web/assets/js/model/setting.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class AllSetting {
2626
this.xrayTemplateConfig = "";
2727
this.secretEnable = false;
2828
this.subEnable = false;
29-
this.subSyncEnable = true;
3029
this.subListen = "";
3130
this.subPort = 2096;
3231
this.subPath = "/sub/";

web/assets/js/util/utils.js

-35
Original file line numberDiff line numberDiff line change
@@ -70,41 +70,6 @@ class HttpUtil {
7070
}
7171
return msg;
7272
}
73-
74-
static async jsonPost(url, data) {
75-
let msg;
76-
try {
77-
const requestOptions = {
78-
method: 'POST',
79-
headers: {
80-
'Content-Type': 'application/json',
81-
},
82-
body: JSON.stringify(data),
83-
};
84-
const resp = await fetch(basePath + url.replace(/^\/+|\/+$/g, ''), requestOptions);
85-
const response = await resp.json();
86-
87-
msg = this._respToMsg({data : response});
88-
} catch (e) {
89-
msg = new Msg(false, e.toString());
90-
}
91-
this._handleMsg(msg);
92-
return msg;
93-
}
94-
95-
static async postWithModalJson(url, data, modal) {
96-
if (modal) {
97-
modal.loading(true);
98-
}
99-
const msg = await this.jsonPost(url, data);
100-
if (modal) {
101-
modal.loading(false);
102-
if (msg instanceof Msg && msg.success) {
103-
modal.close();
104-
}
105-
}
106-
return msg;
107-
}
10873
}
10974

11075
class PromiseUtil {

web/controller/inbound.go

+1-153
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package controller
22

33
import (
4-
"errors"
54
"encoding/json"
65
"fmt"
76
"strconv"
7+
88
"x-ui/database/model"
99
"x-ui/web/service"
1010
"x-ui/web/session"
@@ -33,13 +33,9 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
3333
g.POST("/clientIps/:email", a.getClientIps)
3434
g.POST("/clearClientIps/:email", a.clearClientIps)
3535
g.POST("/addClient", a.addInboundClient)
36-
g.POST("/addGroupClient", a.addGroupInboundClient)
3736
g.POST("/:id/delClient/:clientId", a.delInboundClient)
38-
g.POST("/delGroupClients", a.delGroupClients)
3937
g.POST("/updateClient/:clientId", a.updateInboundClient)
40-
g.POST("/updateClients", a.updateGroupInboundClient)
4138
g.POST("/:id/resetClientTraffic/:email", a.resetClientTraffic)
42-
g.POST("/resetGroupClientTraffic", a.resetGroupClientTraffic)
4339
g.POST("/resetAllTraffics", a.resetAllTraffics)
4440
g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics)
4541
g.POST("/delDepletedClients/:id", a.delDepletedClients)
@@ -194,34 +190,6 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
194190
}
195191
}
196192

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-
225193
func (a *InboundController) delInboundClient(c *gin.Context) {
226194
id, err := strconv.Atoi(c.Param("id"))
227195
if err != nil {
@@ -243,38 +211,6 @@ func (a *InboundController) delInboundClient(c *gin.Context) {
243211
}
244212
}
245213

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-
278214
func (a *InboundController) updateInboundClient(c *gin.Context) {
279215
clientId := c.Param("clientId")
280216

@@ -298,56 +234,6 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
298234
}
299235
}
300236

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-
351237
func (a *InboundController) resetClientTraffic(c *gin.Context) {
352238
id, err := strconv.Atoi(c.Param("id"))
353239
if err != nil {
@@ -367,44 +253,6 @@ func (a *InboundController) resetClientTraffic(c *gin.Context) {
367253
}
368254
}
369255

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-
408256
func (a *InboundController) resetAllTraffics(c *gin.Context) {
409257
err := a.inboundService.ResetAllTraffics()
410258
if err != nil {

web/entity/entity.go

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type AllSetting struct {
4040
TimeLocation string `json:"timeLocation" form:"timeLocation"`
4141
SecretEnable bool `json:"secretEnable" form:"secretEnable"`
4242
SubEnable bool `json:"subEnable" form:"subEnable"`
43-
SubSyncEnable bool `json:"subSyncEnable" form:"subSyncEnable"`
4443
SubListen string `json:"subListen" form:"subListen"`
4544
SubPort int `json:"subPort" form:"subPort"`
4645
SubPath string `json:"subPath" form:"subPath"`

0 commit comments

Comments
 (0)