diff --git a/Dockerfile b/Dockerfile index 3d73d38..88fa7e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,9 @@ RUN mkdir -p assets/plugins && \ /build/node_modules/jquery-tags-input/ \ assets/plugins/ +# Move custom assets +RUN cp -r /build/custom/ assets/ + # Get go modules and build tool RUN go mod download && \ go get github.com/GeertJohan/go.rice/rice diff --git a/custom/js/helper.js b/custom/js/helper.js new file mode 100644 index 0000000..b911ba7 --- /dev/null +++ b/custom/js/helper.js @@ -0,0 +1,59 @@ +function renderClientList(data) { + $.each(data, function(index, obj) { + // render client status css tag style + let clientStatusHtml = '>' + if (obj.Client.enabled) { + clientStatusHtml = `style="visibility: hidden;">` + } + + // render client allocated ip addresses + let allocatedIpsHtml = ""; + $.each(obj.Client.allocated_ips, function(index, obj) { + allocatedIpsHtml += `${obj}`; + }) + + // render client allowed ip addresses + let allowedIpsHtml = ""; + $.each(obj.Client.allowed_ips, function(index, obj) { + allowedIpsHtml += `${obj}`; + }) + + // render client html content + let html = `
+
+
+
+ +
+
+ + + + +
+
+ ${obj.Client.name} + ${obj.Client.email} + + ${obj.Client.created_at} + + ${obj.Client.updated_at} + IP Allocation` + + allocatedIpsHtml + + `Allowed IPs` + + allowedIpsHtml + +`
+
+
` + + // add the client html elements to the list + $('#client-list').append(html); + }); +} diff --git a/handler/routes.go b/handler/routes.go index a3f5494..39b3ceb 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -107,6 +107,22 @@ func GetClients() echo.HandlerFunc { } } +// GetClient handler return a of Wireguard client data +func GetClient() echo.HandlerFunc { + return func(c echo.Context) error { + // access validation + validSession(c) + + clientID := c.Param("id") + clientData, err := util.GetClientByID(clientID, true) + if err != nil { + return c.JSON(http.StatusNotFound, jsonHTTPResponse{false, "Client not found"}) + } + + return c.JSON(http.StatusOK, clientData) + } +} + // NewClient handler func NewClient() echo.HandlerFunc { return func(c echo.Context) error { @@ -215,15 +231,16 @@ func DownloadClient() echo.HandlerFunc { return c.JSON(http.StatusNotFound, jsonHTTPResponse{false, "Missing clientid parameter"}) } - client, err := util.GetClientByID(clientID) + clientData, err := util.GetClientByID(clientID, false) if err != nil { log.Errorf("Cannot generate client id %s config file for downloading: %v", clientID, err) return c.JSON(http.StatusNotFound, jsonHTTPResponse{false, "Client not found"}) } + // build config server, _ := util.GetServer() globalSettings, _ := util.GetGlobalSettings() - config := util.BuildClientConfig(client, server, globalSettings) + config := util.BuildClientConfig(*clientData.Client, server, globalSettings) // create io reader from string reader := strings.NewReader(config) diff --git a/main.go b/main.go index ed15b7f..95ce032 100644 --- a/main.go +++ b/main.go @@ -58,6 +58,7 @@ func main() { app.GET("/global-settings", handler.GlobalSettings()) app.POST("/global-settings", handler.GlobalSettingSubmit()) app.GET("/api/clients", handler.GetClients()) + app.GET("/api/client/:id", handler.GetClient()) 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/prepare_assets.sh b/prepare_assets.sh index 801da8c..31dd1bb 100755 --- a/prepare_assets.sh +++ b/prepare_assets.sh @@ -11,6 +11,9 @@ mkdir -p "${DIR}/assets/dist/js" "${DIR}/assets/dist/css" && \ cp -r "${DIR}/node_modules/admin-lte/dist/js/adminlte.min.js" "${DIR}/assets/dist/js/adminlte.min.js" && \ cp -r "${DIR}/node_modules/admin-lte/dist/css/adminlte.min.css" "${DIR}/assets/dist/css/adminlte.min.css" +# Copy helper js +cp -r "${DIR}/custom" "${DIR}/assets" + # Copy plugins mkdir -p "${DIR}/assets/plugins" && \ cp -r "${DIR}/node_modules/admin-lte/plugins/jquery" \ diff --git a/templates/base.html b/templates/base.html index 75e0efe..681bb45 100644 --- a/templates/base.html +++ b/templates/base.html @@ -246,7 +246,28 @@ + + -