diff --git a/web/controller/inbound.go b/web/controller/inbound.go index c22ce192..6c38b4ac 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -71,7 +71,7 @@ func (a *InboundController) getClientTraffics(c *gin.Context) { email := c.Param("email") clientTraffics, err := a.inboundService.GetClientTrafficByEmail(email) if err != nil { - jsonMsg(c, "Error getting traffics", err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.trafficGetError"), err) return } jsonObj(c, clientTraffics, nil) @@ -81,7 +81,7 @@ func (a *InboundController) getClientTrafficsById(c *gin.Context) { id := c.Param("id") clientTraffics, err := a.inboundService.GetClientTrafficByID(id) if err != nil { - jsonMsg(c, "Error getting traffics", err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.trafficGetError"), err) return } jsonObj(c, clientTraffics, nil) @@ -91,7 +91,7 @@ func (a *InboundController) addInbound(c *gin.Context) { inbound := &model.Inbound{} err := c.ShouldBind(inbound) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.create"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), err) return } user := session.GetLoginUser(c) @@ -104,7 +104,7 @@ func (a *InboundController) addInbound(c *gin.Context) { needRestart := false inbound, needRestart, err = a.inboundService.AddInbound(inbound) - jsonMsgObj(c, I18nWeb(c, "pages.inbounds.create"), inbound, err) + jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), inbound, err) if err == nil && needRestart { a.xrayService.SetToNeedRestart() } @@ -113,12 +113,12 @@ func (a *InboundController) addInbound(c *gin.Context) { func (a *InboundController) delInbound(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { - jsonMsg(c, I18nWeb(c, "delete"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), err) return } needRestart := true needRestart, err = a.inboundService.DelInbound(id) - jsonMsgObj(c, I18nWeb(c, "delete"), id, err) + jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), id, err) if err == nil && needRestart { a.xrayService.SetToNeedRestart() } @@ -127,7 +127,7 @@ func (a *InboundController) delInbound(c *gin.Context) { func (a *InboundController) updateInbound(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } inbound := &model.Inbound{ @@ -135,12 +135,12 @@ func (a *InboundController) updateInbound(c *gin.Context) { } err = c.ShouldBind(inbound) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } needRestart := true inbound, needRestart, err = a.inboundService.UpdateInbound(inbound) - jsonMsgObj(c, I18nWeb(c, "pages.inbounds.update"), inbound, err) + jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), inbound, err) if err == nil && needRestart { a.xrayService.SetToNeedRestart() } @@ -163,17 +163,17 @@ func (a *InboundController) clearClientIps(c *gin.Context) { err := a.inboundService.ClearClientIps(email) if err != nil { - jsonMsg(c, "Update", err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.updateSuccess"), err) return } - jsonMsg(c, "Log Cleared", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.logCleanSuccess"), nil) } func (a *InboundController) addInboundClient(c *gin.Context) { data := &model.Inbound{} err := c.ShouldBind(data) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } @@ -181,10 +181,10 @@ func (a *InboundController) addInboundClient(c *gin.Context) { needRestart, err = a.inboundService.AddInboundClient(data) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } - jsonMsg(c, "Client(s) added", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientAddSuccess"), nil) if needRestart { a.xrayService.SetToNeedRestart() } @@ -193,7 +193,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) { func (a *InboundController) delInboundClient(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } clientId := c.Param("clientId") @@ -202,10 +202,10 @@ func (a *InboundController) delInboundClient(c *gin.Context) { needRestart, err = a.inboundService.DelInboundClient(id, clientId) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } - jsonMsg(c, "Client deleted", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientDeleteSuccess"), nil) if needRestart { a.xrayService.SetToNeedRestart() } @@ -217,7 +217,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) { inbound := &model.Inbound{} err := c.ShouldBind(inbound) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } @@ -225,10 +225,10 @@ func (a *InboundController) updateInboundClient(c *gin.Context) { needRestart, err = a.inboundService.UpdateInboundClient(inbound, clientId) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } - jsonMsg(c, "Client updated", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientUpdateSuccess"), nil) if needRestart { a.xrayService.SetToNeedRestart() } @@ -237,17 +237,17 @@ func (a *InboundController) updateInboundClient(c *gin.Context) { func (a *InboundController) resetClientTraffic(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } email := c.Param("email") needRestart, err := a.inboundService.ResetClientTraffic(id, email) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } - jsonMsg(c, "Traffic has been reset", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetInboundClientTrafficSuccess"), nil) if needRestart { a.xrayService.SetToNeedRestart() } @@ -256,36 +256,36 @@ func (a *InboundController) resetClientTraffic(c *gin.Context) { func (a *InboundController) resetAllTraffics(c *gin.Context) { err := a.inboundService.ResetAllTraffics() if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } else { a.xrayService.SetToNeedRestart() } - jsonMsg(c, "all traffic has been reset", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllTrafficSuccess"), nil) } func (a *InboundController) resetAllClientTraffics(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } err = a.inboundService.ResetAllClientTraffics(id) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } else { a.xrayService.SetToNeedRestart() } - jsonMsg(c, "All traffic from the client has been reset.", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllClientTrafficSuccess"), nil) } func (a *InboundController) importInbound(c *gin.Context) { inbound := &model.Inbound{} err := json.Unmarshal([]byte(c.PostForm("data")), inbound) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } user := session.GetLoginUser(c) @@ -304,7 +304,7 @@ func (a *InboundController) importInbound(c *gin.Context) { needRestart := false inbound, needRestart, err = a.inboundService.AddInbound(inbound) - jsonMsgObj(c, I18nWeb(c, "pages.inbounds.create"), inbound, err) + jsonMsgObj(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), inbound, err) if err == nil && needRestart { a.xrayService.SetToNeedRestart() } @@ -313,15 +313,15 @@ func (a *InboundController) importInbound(c *gin.Context) { func (a *InboundController) delDepletedClients(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { - jsonMsg(c, I18nWeb(c, "pages.inbounds.update"), err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err) return } err = a.inboundService.DelDepletedClients(id) if err != nil { - jsonMsg(c, "Something went wrong!", err) + jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return } - jsonMsg(c, "All depleted clients are deleted", nil) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.delDepletedClientsSuccess"), nil) } func (a *InboundController) onlines(c *gin.Context) { diff --git a/web/controller/server.go b/web/controller/server.go index 5d89e356..e00a1206 100644 --- a/web/controller/server.go +++ b/web/controller/server.go @@ -109,19 +109,19 @@ func (a *ServerController) stopXrayService(c *gin.Context) { a.lastGetStatusTime = time.Now() err := a.serverService.StopXrayService() if err != nil { - jsonMsg(c, "", err) + jsonMsg(c, I18nWeb(c, "pages.xray.stopError"), err) return } - jsonMsg(c, "Xray stopped", err) + jsonMsg(c, I18nWeb(c, "pages.xray.stopSuccess"), err) } func (a *ServerController) restartXrayService(c *gin.Context) { err := a.serverService.RestartXrayService() if err != nil { - jsonMsg(c, "", err) + jsonMsg(c, I18nWeb(c, "pages.xray.restartError"), err) return } - jsonMsg(c, "Xray restarted", err) + jsonMsg(c, I18nWeb(c, "pages.xray.restartSuccess"), err) } func (a *ServerController) getLogs(c *gin.Context) { @@ -135,7 +135,7 @@ func (a *ServerController) getLogs(c *gin.Context) { func (a *ServerController) getConfigJson(c *gin.Context) { configJson, err := a.serverService.GetConfigJson() if err != nil { - jsonMsg(c, "get config.json", err) + jsonMsg(c, I18nWeb(c, "pages.index.getConfigError"), err) return } jsonObj(c, configJson, nil) @@ -144,7 +144,7 @@ func (a *ServerController) getConfigJson(c *gin.Context) { func (a *ServerController) getDb(c *gin.Context) { db, err := a.serverService.GetDb() if err != nil { - jsonMsg(c, "get Database", err) + jsonMsg(c, I18nWeb(c, "pages.index.getDatabaseError"), err) return } @@ -172,7 +172,7 @@ func (a *ServerController) importDB(c *gin.Context) { // Get the file from the request body file, _, err := c.Request.FormFile("db") if err != nil { - jsonMsg(c, "Error reading db file", err) + jsonMsg(c, I18nWeb(c, "pages.index.readDatabaseError"), err) return } defer file.Close() @@ -184,16 +184,16 @@ func (a *ServerController) importDB(c *gin.Context) { // Import it err = a.serverService.ImportDB(file) if err != nil { - jsonMsg(c, "", err) + jsonMsg(c, I18nWeb(c, "pages.index.importDatabaseError"), err) return } - jsonObj(c, "Import DB", nil) + jsonObj(c, I18nWeb(c, "pages.index.importDatabaseSuccess"), nil) } func (a *ServerController) getNewX25519Cert(c *gin.Context) { cert, err := a.serverService.GetNewX25519Cert() if err != nil { - jsonMsg(c, "get x25519 certificate", err) + jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.getNewX25519CertError"), err) return } jsonObj(c, cert, nil) diff --git a/web/controller/setting.go b/web/controller/setting.go index dd99e0f5..ddd9f55a 100644 --- a/web/controller/setting.go +++ b/web/controller/setting.go @@ -80,11 +80,11 @@ func (a *SettingController) updateUser(c *gin.Context) { } user := session.GetLoginUser(c) if user.Username != form.OldUsername || !crypto.CheckPasswordHash(user.Password, form.OldPassword) { - jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifyUser"), errors.New(I18nWeb(c, "pages.settings.toasts.originalUserPassIncorrect"))) + jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifyUserError"), errors.New(I18nWeb(c, "pages.settings.toasts.originalUserPassIncorrect"))) return } if form.NewUsername == "" || form.NewPassword == "" { - jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifyUser"), errors.New(I18nWeb(c, "pages.settings.toasts.userPassMustBeNotEmpty"))) + jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifyUserError"), errors.New(I18nWeb(c, "pages.settings.toasts.userPassMustBeNotEmpty"))) return } err = a.userService.UpdateUser(user.Id, form.NewUsername, form.NewPassword) @@ -98,7 +98,7 @@ func (a *SettingController) updateUser(c *gin.Context) { func (a *SettingController) restartPanel(c *gin.Context) { err := a.panelService.RestartPanel(time.Second * 3) - jsonMsg(c, I18nWeb(c, "pages.settings.restartPanel"), err) + jsonMsg(c, I18nWeb(c, "pages.settings.restartPanelSuccess"), err) } func (a *SettingController) getDefaultXrayConfig(c *gin.Context) { diff --git a/web/controller/util.go b/web/controller/util.go index 40c7a8e9..a77d0e35 100644 --- a/web/controller/util.go +++ b/web/controller/util.go @@ -42,11 +42,11 @@ func jsonMsgObj(c *gin.Context, msg string, obj any, err error) { if err == nil { m.Success = true if msg != "" { - m.Msg = msg + " " + I18nWeb(c, "success") + m.Msg = msg } } else { m.Success = false - m.Msg = msg + " " + I18nWeb(c, "fail") + ": " + err.Error() + m.Msg = msg + " (" + err.Error() + ")" logger.Warning(msg+" "+I18nWeb(c, "fail")+": ", err) } c.JSON(http.StatusOK, m) diff --git a/web/controller/xray_setting.go b/web/controller/xray_setting.go index 3391ad3b..5b2d1036 100644 --- a/web/controller/xray_setting.go +++ b/web/controller/xray_setting.go @@ -93,7 +93,7 @@ func (a *XraySettingController) warp(c *gin.Context) { func (a *XraySettingController) getOutboundsTraffic(c *gin.Context) { outboundsTraffic, err := a.OutboundService.GetOutboundsTraffic() if err != nil { - jsonMsg(c, "Error getting traffics", err) + jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getOutboundTrafficError"), err) return } jsonObj(c, outboundsTraffic, nil) @@ -103,7 +103,7 @@ func (a *XraySettingController) resetOutboundsTraffic(c *gin.Context) { tag := c.PostForm("tag") err := a.OutboundService.ResetOutboundTraffic(tag) if err != nil { - jsonMsg(c, "Error in reset outbound traffics", err) + jsonMsg(c, I18nWeb(c, "pages.settings.toasts.resetOutboundTrafficError"), err) return } jsonObj(c, "", nil) diff --git a/web/html/inbounds.html b/web/html/inbounds.html index cadcb95a..f632a5cc 100644 --- a/web/html/inbounds.html +++ b/web/html/inbounds.html @@ -978,7 +978,7 @@ openAddInbound() { inModal.show({ title: '{{ i18n "pages.inbounds.addInbound"}}', - okText: '{{ i18n "pages.inbounds.create"}}', + okText: '{{ i18n "create"}}', cancelText: '{{ i18n "close" }}', confirm: async (inbound, dbInbound) => { await this.addInbound(inbound, dbInbound, inModal); @@ -991,7 +991,7 @@ const inbound = dbInbound.toInbound(); inModal.show({ title: '{{ i18n "pages.inbounds.modifyInbound"}}', - okText: '{{ i18n "pages.inbounds.update"}}', + okText: '{{ i18n "update"}}', cancelText: '{{ i18n "close" }}', inbound: inbound, dbInbound: dbInbound, diff --git a/web/html/modals/warp_modal.html b/web/html/modals/warp_modal.html index 14426472..4bfb7ca1 100644 --- a/web/html/modals/warp_modal.html +++ b/web/html/modals/warp_modal.html @@ -3,7 +3,7 @@ :confirm-loading="warpModal.confirmLoading" :closable="true" :mask-closable="true" :footer="null" :class="themeSwitcher.currentTheme">