diff --git a/web/controller/base.go b/web/controller/base.go
index f0cbd1ae6b..6ed2f0efda 100644
--- a/web/controller/base.go
+++ b/web/controller/base.go
@@ -23,7 +23,7 @@ func (a *BaseController) checkLogin(c *gin.Context) {
}
-func I18n(c *gin.Context , name string, data ...string) string{
+func I18n(c *gin.Context , name string) string{
anyfunc, _ := c.Get("I18n")
i18n, _ := anyfunc.(func(key string, params ...string) (string, error))
diff --git a/web/html/xui/form/protocol/vless.html b/web/html/xui/form/protocol/vless.html
index ad18bec56a..db577c4ce0 100644
--- a/web/html/xui/form/protocol/vless.html
+++ b/web/html/xui/form/protocol/vless.html
@@ -7,7 +7,19 @@
Account is (Expired|Traffic Ended) And Disabled
-
+
+
+ Email
+
+
+ The email must be completely unique
+
+
+
+
+
diff --git a/web/html/xui/form/protocol/vmess.html b/web/html/xui/form/protocol/vmess.html
index 582b7598fc..9c27e561d8 100644
--- a/web/html/xui/form/protocol/vmess.html
+++ b/web/html/xui/form/protocol/vmess.html
@@ -6,7 +6,19 @@
Account is (Expired|Traffic Ended) And Disabled
-
+
+
+ Email
+
+
+ The email must be completely unique
+
+
+
+
+
diff --git a/web/html/xui/inbound_modal.html b/web/html/xui/inbound_modal.html
index 9f9cd92a58..99399b98d6 100644
--- a/web/html/xui/inbound_modal.html
+++ b/web/html/xui/inbound_modal.html
@@ -163,9 +163,17 @@
return email + (this.isClientEnable(email) == true ? ' Active' : ' Deactive')
},
-
+ getNewEmail(client) {
+ var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
+ var string = '';
+ var len = 6 + Math.floor(Math.random() * 5)
+ for(var ii=0; ii
-{{end}}
\ No newline at end of file
+{{end}}
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 7775df5d91..37a73eae0c 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -50,6 +50,64 @@ func (s *InboundService) checkPortExist(port int, ignoreId int) (bool, error) {
return count > 0, nil
}
+func (s *InboundService) getClients(inbound *model.Inbound) ([]model.Client, error) {
+ settings := map[string][]model.Client{}
+ json.Unmarshal([]byte(inbound.Settings), &settings)
+ if settings == nil {
+ return nil, fmt.Errorf("Setting is null")
+ }
+
+ clients := settings["clients"]
+ if clients == nil {
+ return nil, nil
+ }
+ return clients, nil
+}
+
+func (s *InboundService) checkEmailsExist(emails map[string] bool, ignoreId int) (string, error) {
+ db := database.GetDB()
+ var inbounds []*model.Inbound
+ db = db.Model(model.Inbound{}).Where("Protocol in ?", []model.Protocol{model.VMess, model.VLESS})
+ if (ignoreId > 0) {
+ db = db.Where("id != ?", ignoreId)
+ }
+ db = db.Find(&inbounds)
+ if db.Error != nil {
+ return "", db.Error
+ }
+
+ for _, inbound := range inbounds {
+ clients, err := s.getClients(inbound)
+ if err != nil {
+ return "", err
+ }
+
+ for _, client := range clients {
+ if emails[client.Email] {
+ return client.Email, nil
+ }
+ }
+ }
+ return "", nil
+}
+
+func (s *InboundService) checkEmailExistForInbound(inbound *model.Inbound) (string, error) {
+ clients, err := s.getClients(inbound)
+ if err != nil {
+ return "", err
+ }
+ emails := make(map[string] bool)
+ for _, client := range clients {
+ if (client.Email != "") {
+ if emails[client.Email] {
+ return client.Email, nil
+ }
+ emails[client.Email] = true;
+ }
+ }
+ return s.checkEmailsExist(emails, inbound.Id)
+}
+
func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound,error) {
exist, err := s.checkPortExist(inbound.Port, 0)
if err != nil {
@@ -58,6 +116,15 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound,erro
if exist {
return inbound, common.NewError("端口已存在:", inbound.Port)
}
+
+ existEmail, err := s.checkEmailExistForInbound(inbound)
+ if err != nil {
+ return inbound, err
+ }
+ if existEmail != "" {
+ return inbound, common.NewError("Duplicate email:", existEmail)
+ }
+
db := database.GetDB()
err = db.Save(inbound).Error
@@ -122,6 +189,14 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
if exist {
return inbound, common.NewError("端口已存在:", inbound.Port)
}
+
+ existEmail, err := s.checkEmailExistForInbound(inbound)
+ if err != nil {
+ return inbound, err
+ }
+ if existEmail != "" {
+ return inbound, common.NewError("Duplicate email:", existEmail)
+ }
oldInbound, err := s.GetInbound(inbound.Id)
if err != nil {