diff --git a/handler/routes.go b/handler/routes.go index 156e701..bdc5caf 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -160,6 +160,12 @@ func NewClient(db store.IStore) echo.HandlerFunc { return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Allowed IPs must be in CIDR format"}) } + // validate extra AllowedIPs + if util.ValidateAllowedIPs(client.ExtraAllowedIPs) == false { + log.Warnf("Invalid Extra AllowedIPs input from user: %v", client.ExtraAllowedIPs) + return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Extra AllowedIPs must be in CIDR format"}) + } + // gen ID guid := xid.New() client.ID = guid.String() @@ -274,6 +280,13 @@ func UpdateClient(db store.IStore) echo.HandlerFunc { return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Allowed IPs must be in CIDR format"}) } + log.Infof("array length: %d", len(_client.ExtraAllowedIPs) ) + log.Infof("extraAllowedIPs: %v", _client.ExtraAllowedIPs) + if len(_client.ExtraAllowedIPs) > 0 && util.ValidateAllowedIPs(_client.ExtraAllowedIPs) == false { + log.Warnf("Invalid Allowed IPs input from user: %v", _client.ExtraAllowedIPs) + return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Extra Allowed IPs must be in CIDR format"}) + } + // map new data client.Name = _client.Name client.Email = _client.Email @@ -281,6 +294,7 @@ func UpdateClient(db store.IStore) echo.HandlerFunc { client.UseServerDNS = _client.UseServerDNS client.AllocatedIPs = _client.AllocatedIPs client.AllowedIPs = _client.AllowedIPs + client.ExtraAllowedIPs = _client.ExtraAllowedIPs client.UpdatedAt = time.Now().UTC() // write to the database diff --git a/model/client.go b/model/client.go index 8e6ba52..c1c7487 100644 --- a/model/client.go +++ b/model/client.go @@ -6,18 +6,19 @@ import ( // Client model type Client struct { - ID string `json:"id"` - PrivateKey string `json:"private_key"` - PublicKey string `json:"public_key"` - PresharedKey string `json:"preshared_key"` - Name string `json:"name"` - Email string `json:"email"` - AllocatedIPs []string `json:"allocated_ips"` - AllowedIPs []string `json:"allowed_ips"` - UseServerDNS bool `json:"use_server_dns"` - Enabled bool `json:"enabled"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + ID string `json:"id"` + PrivateKey string `json:"private_key"` + PublicKey string `json:"public_key"` + PresharedKey string `json:"preshared_key"` + Name string `json:"name"` + Email string `json:"email"` + AllocatedIPs []string `json:"allocated_ips"` + AllowedIPs []string `json:"allowed_ips"` + ExtraAllowedIPs []string `json:"extra_allowed_ips"` + UseServerDNS bool `json:"use_server_dns"` + Enabled bool `json:"enabled"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } // ClientData includes the Client and extra data diff --git a/templates/base.html b/templates/base.html index 6705c6d..a1d16ba 100644 --- a/templates/base.html +++ b/templates/base.html @@ -163,6 +163,11 @@ +