diff --git a/handler/routes.go b/handler/routes.go index 156fecc..a3f5494 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -92,6 +92,21 @@ func WireGuardClients() echo.HandlerFunc { } } +// GetClients handler return a list of Wireguard client data +func GetClients() echo.HandlerFunc { + return func(c echo.Context) error { + // access validation + validSession(c) + + clientDataList, err := util.GetClients(true) + if err != nil { + return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, fmt.Sprintf("Cannot get client list: %v", err)}) + } + + return c.JSON(http.StatusOK, clientDataList) + } +} + // NewClient handler func NewClient() echo.HandlerFunc { return func(c echo.Context) error { diff --git a/main.go b/main.go index 0022951..ed15b7f 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ func main() { app.POST("wg-server/keypair", handler.WireGuardServerKeyPair()) app.GET("/global-settings", handler.GlobalSettings()) app.POST("/global-settings", handler.GlobalSettingSubmit()) + app.GET("/api/clients", handler.GetClients()) app.GET("/api/machine-ips", handler.MachineIPAddresses()) app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation()) app.GET("/api/apply-wg-config", handler.ApplyServerConfig(tmplBox)) diff --git a/templates/base.html b/templates/base.html index 542aca7..75e0efe 100644 --- a/templates/base.html +++ b/templates/base.html @@ -56,16 +56,17 @@ - -