mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-16 12:35:54 +00:00
fix: comprehensive bug fixes - wrong toast messages, duplicate calls, hardcoded strings
Bugs Fixed (17 total across 3 files): == web/controller/inbound.go == 1-11. Fix 11 error paths showing success toast messages: - addInbound: inboundCreateSuccess → somethingWentWrong - delInbound: inboundDeleteSuccess → somethingWentWrong - updateInbound (2x): inboundUpdateSuccess → somethingWentWrong - clearClientIps: updateSuccess → somethingWentWrong - addInboundClient: inboundUpdateSuccess → somethingWentWrong - delInboundClient: inboundUpdateSuccess → somethingWentWrong - updateInboundClient: inboundUpdateSuccess → somethingWentWrong - resetClientTraffic: inboundUpdateSuccess → somethingWentWrong - resetAllClientTraffics: inboundUpdateSuccess → somethingWentWrong - delDepletedClients: inboundUpdateSuccess → somethingWentWrong 12. Remove duplicate xrayService.SetToNeedRestart() in resetAllTraffics 13. Remove duplicate xrayService.SetToNeedRestart() in resetAllClientTraffics 14-16. Replace hardcoded strings in delInboundClientByEmail with I18n == web/controller/server.go == 17. Replace hardcoded strings with I18n in: - getNewUUID, getNewmlkem768, getNewEchCert == web/service/inbound.go == 18. Remove duplicate 'User not found' nested if-check in disableInvalidClients Related to PR #3974 (same class of bugs extended to all error paths)
This commit is contained in:
parent
38d87230d3
commit
71dc7d983d
3 changed files with 22 additions and 28 deletions
|
|
@ -107,7 +107,7 @@ func (a *InboundController) addInbound(c *gin.Context) {
|
||||||
inbound := &model.Inbound{}
|
inbound := &model.Inbound{}
|
||||||
err := c.ShouldBind(inbound)
|
err := c.ShouldBind(inbound)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user := session.GetLoginUser(c)
|
user := session.GetLoginUser(c)
|
||||||
|
|
@ -136,7 +136,7 @@ func (a *InboundController) addInbound(c *gin.Context) {
|
||||||
func (a *InboundController) delInbound(c *gin.Context) {
|
func (a *InboundController) delInbound(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
needRestart, err := a.inboundService.DelInbound(id)
|
needRestart, err := a.inboundService.DelInbound(id)
|
||||||
|
|
@ -158,7 +158,7 @@ func (a *InboundController) delInbound(c *gin.Context) {
|
||||||
func (a *InboundController) updateInbound(c *gin.Context) {
|
func (a *InboundController) updateInbound(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
inbound := &model.Inbound{
|
inbound := &model.Inbound{
|
||||||
|
|
@ -166,7 +166,7 @@ func (a *InboundController) updateInbound(c *gin.Context) {
|
||||||
}
|
}
|
||||||
err = c.ShouldBind(inbound)
|
err = c.ShouldBind(inbound)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
inbound, needRestart, err := a.inboundService.UpdateInbound(inbound)
|
inbound, needRestart, err := a.inboundService.UpdateInbound(inbound)
|
||||||
|
|
@ -234,7 +234,7 @@ func (a *InboundController) clearClientIps(c *gin.Context) {
|
||||||
|
|
||||||
err := a.inboundService.ClearClientIps(email)
|
err := a.inboundService.ClearClientIps(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.updateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.logCleanSuccess"), nil)
|
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.logCleanSuccess"), nil)
|
||||||
|
|
@ -245,7 +245,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
|
||||||
data := &model.Inbound{}
|
data := &model.Inbound{}
|
||||||
err := c.ShouldBind(data)
|
err := c.ShouldBind(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -264,7 +264,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
|
||||||
func (a *InboundController) delInboundClient(c *gin.Context) {
|
func (a *InboundController) delInboundClient(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
clientId := c.Param("clientId")
|
clientId := c.Param("clientId")
|
||||||
|
|
@ -287,7 +287,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
|
||||||
inbound := &model.Inbound{}
|
inbound := &model.Inbound{}
|
||||||
err := c.ShouldBind(inbound)
|
err := c.ShouldBind(inbound)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,7 +306,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
|
||||||
func (a *InboundController) resetClientTraffic(c *gin.Context) {
|
func (a *InboundController) resetClientTraffic(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
email := c.Param("email")
|
email := c.Param("email")
|
||||||
|
|
@ -328,9 +328,8 @@ func (a *InboundController) resetAllTraffics(c *gin.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
a.xrayService.SetToNeedRestart()
|
|
||||||
}
|
}
|
||||||
|
a.xrayService.SetToNeedRestart()
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllTrafficSuccess"), nil)
|
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllTrafficSuccess"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,7 +337,7 @@ func (a *InboundController) resetAllTraffics(c *gin.Context) {
|
||||||
func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
|
func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,9 +345,8 @@ func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
a.xrayService.SetToNeedRestart()
|
|
||||||
}
|
}
|
||||||
|
a.xrayService.SetToNeedRestart()
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllClientTrafficSuccess"), nil)
|
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllClientTrafficSuccess"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -386,7 +384,7 @@ func (a *InboundController) importInbound(c *gin.Context) {
|
||||||
func (a *InboundController) delDepletedClients(c *gin.Context) {
|
func (a *InboundController) delDepletedClients(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = a.inboundService.DelDepletedClients(id)
|
err = a.inboundService.DelDepletedClients(id)
|
||||||
|
|
@ -421,7 +419,7 @@ func (a *InboundController) updateClientTraffic(c *gin.Context) {
|
||||||
var request TrafficUpdateRequest
|
var request TrafficUpdateRequest
|
||||||
err := c.ShouldBindJSON(&request)
|
err := c.ShouldBindJSON(&request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -438,18 +436,18 @@ func (a *InboundController) updateClientTraffic(c *gin.Context) {
|
||||||
func (a *InboundController) delInboundClientByEmail(c *gin.Context) {
|
func (a *InboundController) delInboundClientByEmail(c *gin.Context) {
|
||||||
inboundId, err := strconv.Atoi(c.Param("id"))
|
inboundId, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "Invalid inbound ID", err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
email := c.Param("email")
|
email := c.Param("email")
|
||||||
needRestart, err := a.inboundService.DelInboundClientByEmail(inboundId, email)
|
needRestart, err := a.inboundService.DelInboundClientByEmail(inboundId, email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "Failed to delete client by email", err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonMsg(c, "Client deleted successfully", nil)
|
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientDeleteSuccess"), nil)
|
||||||
if needRestart {
|
if needRestart {
|
||||||
a.xrayService.SetToNeedRestart()
|
a.xrayService.SetToNeedRestart()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ func (a *ServerController) getNewEchCert(c *gin.Context) {
|
||||||
sni := c.PostForm("sni")
|
sni := c.PostForm("sni")
|
||||||
cert, err := a.serverService.GetNewEchCert(sni)
|
cert, err := a.serverService.GetNewEchCert(sni)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "get ech certificate", err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jsonObj(c, cert, nil)
|
jsonObj(c, cert, nil)
|
||||||
|
|
@ -345,7 +345,7 @@ func (a *ServerController) getNewVlessEnc(c *gin.Context) {
|
||||||
func (a *ServerController) getNewUUID(c *gin.Context) {
|
func (a *ServerController) getNewUUID(c *gin.Context) {
|
||||||
uuidResp, err := a.serverService.GetNewUUID()
|
uuidResp, err := a.serverService.GetNewUUID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "Failed to generate UUID", err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -356,7 +356,7 @@ func (a *ServerController) getNewUUID(c *gin.Context) {
|
||||||
func (a *ServerController) getNewmlkem768(c *gin.Context) {
|
func (a *ServerController) getNewmlkem768(c *gin.Context) {
|
||||||
out, err := a.serverService.GetNewmlkem768()
|
out, err := a.serverService.GetNewmlkem768()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "Failed to generate mlkem768 keys", err)
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jsonObj(c, out, nil)
|
jsonObj(c, out, nil)
|
||||||
|
|
|
||||||
|
|
@ -1280,12 +1280,8 @@ func (s *InboundService) disableInvalidClients(tx *gorm.DB) (bool, int64, error)
|
||||||
if strings.Contains(err1.Error(), fmt.Sprintf("User %s not found.", result.Email)) {
|
if strings.Contains(err1.Error(), fmt.Sprintf("User %s not found.", result.Email)) {
|
||||||
logger.Debug("User is already disabled. Nothing to do more...")
|
logger.Debug("User is already disabled. Nothing to do more...")
|
||||||
} else {
|
} else {
|
||||||
if strings.Contains(err1.Error(), fmt.Sprintf("User %s not found.", result.Email)) {
|
logger.Debug("Error in disabling client by api:", err1)
|
||||||
logger.Debug("User is already disabled. Nothing to do more...")
|
needRestart = true
|
||||||
} else {
|
|
||||||
logger.Debug("Error in disabling client by api:", err1)
|
|
||||||
needRestart = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue