diff --git a/handler/routes.go b/handler/routes.go index 0358750..26d47b4 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -10,6 +10,7 @@ import ( "os" "regexp" "sort" + "strconv" "strings" "time" @@ -385,9 +386,9 @@ func GetClient(db store.IStore) echo.HandlerFunc { } qrCodeSettings := model.QRCodeSettings{ - Enabled: true, - IncludeDNS: true, - IncludeMTU: true, + Enabled: true, + IncludeDNS: true, + IncludeMTU: true, } clientData, err := db.GetClientByID(clientID, qrCodeSettings) @@ -406,6 +407,14 @@ func NewClient(db store.IStore) echo.HandlerFunc { var client model.Client c.Bind(&client) + // Validate Telegram userid if provided + if client.TgUserid != "" { + idNum, err := strconv.ParseInt(client.TgUserid, 10, 64) + if err != nil || idNum == 0 { + return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Telegram userid must be a non-zero number"}) + } + } + // read server information server, err := db.GetServer() if err != nil { @@ -517,9 +526,9 @@ func EmailClient(db store.IStore, mailer emailer.Emailer, emailSubject, emailCon } qrCodeSettings := model.QRCodeSettings{ - Enabled: true, - IncludeDNS: true, - IncludeMTU: true, + Enabled: true, + IncludeDNS: true, + IncludeMTU: true, } clientData, err := db.GetClientByID(payload.ID, qrCodeSettings) if err != nil { @@ -577,6 +586,14 @@ func UpdateClient(db store.IStore) echo.HandlerFunc { return c.JSON(http.StatusNotFound, jsonHTTPResponse{false, "Client not found"}) } + // Validate Telegram userid if provided + if _client.TgUserid != "" { + idNum, err := strconv.ParseInt(_client.TgUserid, 10, 64) + if err != nil || idNum == 0 { + return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Telegram userid must be a non-zero number"}) + } + } + server, err := db.GetServer() if err != nil { return c.JSON(http.StatusBadRequest, jsonHTTPResponse{ @@ -644,6 +661,7 @@ func UpdateClient(db store.IStore) echo.HandlerFunc { // map new data client.Name = _client.Name client.Email = _client.Email + client.TgUserid = _client.TgUserid client.Enabled = _client.Enabled client.UseServerDNS = _client.UseServerDNS client.AllocatedIPs = _client.AllocatedIPs @@ -1115,7 +1133,6 @@ func ApplyServerConfig(db store.IStore, tmplDir fs.FS) echo.HandlerFunc { } } - // GetHashesChanges handler returns if database hashes have changed func GetHashesChanges(db store.IStore) echo.HandlerFunc { return func(c echo.Context) error { diff --git a/model/client.go b/model/client.go index 187ec72..cb00016 100644 --- a/model/client.go +++ b/model/client.go @@ -11,6 +11,7 @@ type Client struct { PublicKey string `json:"public_key"` PresharedKey string `json:"preshared_key"` Name string `json:"name"` + TgUserid string `json:"telegram_userid"` Email string `json:"email"` SubnetRanges []string `json:"subnet_ranges,omitempty"` AllocatedIPs []string `json:"allocated_ips"` @@ -30,7 +31,7 @@ type ClientData struct { } type QRCodeSettings struct { - Enabled bool - IncludeDNS bool - IncludeMTU bool + Enabled bool + IncludeDNS bool + IncludeMTU bool } diff --git a/templates/base.html b/templates/base.html index 7110fd5..c874e8b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -281,6 +281,14 @@ +
+ Additional configuration + +
+ + +
+
+
+ Additional configuration + +
+ + +
+