Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/service/inbound.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index fa0ecf31..cbfa831a 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -2,7 +2,9 @@ package service
import (
"encoding/json"
+ "errors"
"fmt"
+ "regexp"
"strconv"
"strings"
"time"
@@ -411,6 +413,12 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error) {
return false, err
}
+ email := clients[0].Email
+ valid, err := validateEmail(email)
+ if !valid {
+ return false, err
+ }
+
var settings map[string]interface{}
err = json.Unmarshal([]byte(data.Settings), &settings)
if err != nil {
@@ -601,6 +609,12 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
return false, err
}
+ email := clients[0].Email
+ valid, err := validateEmail(email)
+ if !valid {
+ return false, err
+ }
+
var settings map[string]interface{}
err = json.Unmarshal([]byte(data.Settings), &settings)
if err != nil {
@@ -2007,3 +2021,20 @@ func (s *InboundService) MigrateDB() {
func (s *InboundService) GetOnlineClients() []string {
return p.GetOnlineClients()
}
+
+func validateEmail(email string) (bool, error) {
+ if strings.Contains(email, " ") {
+ return false, errors.New("email contains spaces, please remove them")
+ }
+
+ if email != strings.ToLower(email) {
+ return false, errors.New("email contains uppercase letters, please convert to lowercase")
+ }
+
+ emailPattern := `^[a-z0-9._-]+$`
+ if !regexp.MustCompile(emailPattern).MatchString(email) {
+ return false, errors.New("email contains invalid characters, please use only lowercase letters, digits, dots, dashes, and underscores")
+ }
+
+ return true, nil
+}