From 1d599c401b5b9a5f25322b4ec14a5418e01ba740 Mon Sep 17 00:00:00 2001 From: vx3r Date: Tue, 25 Feb 2020 15:56:04 +0900 Subject: [PATCH] add version in back and front #16 / client can ignore global PK #17 / #18 email is now optional --- Dockerfile | 2 +- main.go | 8 ++++++ model/client.go | 33 ++++++++++++------------ template/template.go | 2 +- ui/package-lock.json | 48 ++++++++++++++++++----------------- ui/package.json | 1 + ui/src/App.vue | 8 ++++-- ui/src/components/Clients.vue | 35 +++++++++++++------------ ui/vue.config.js | 3 +++ 9 files changed, 78 insertions(+), 62 deletions(-) diff --git a/Dockerfile b/Dockerfile index f25fe04..a9cdaaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:alpine AS build-back WORKDIR /app COPY . . -RUN go build -o wg-gen-web-linux +RUN GIT_COMMIT=$(git rev-parse --short HEAD) && go build -ldflags "-X main.VersionGitCommit=$GIT_COMMIT" go build -o wg-gen-web-linux FROM node:10-alpine AS build-front WORKDIR /app diff --git a/main.go b/main.go index 4efc003..3f93063 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,10 @@ import ( "path/filepath" ) +var ( + VersionGitCommit string +) + func init() { log.SetFormatter(&log.TextFormatter{}) log.SetOutput(os.Stderr) @@ -22,6 +26,8 @@ func init() { } func main() { + log.Infof("Starting Wg Gen Web version: %s", VersionGitCommit) + // load .env environment variables err := godotenv.Load() if err != nil { @@ -59,6 +65,8 @@ func main() { gin.SetMode(gin.ReleaseMode) // disable console color gin.DisableConsoleColor() + // log level info + log.SetLevel(log.InfoLevel) } // migrate diff --git a/model/client.go b/model/client.go index eb0eb77..87fedbd 100644 --- a/model/client.go +++ b/model/client.go @@ -8,16 +8,17 @@ import ( // Client structure type Client struct { - Id string `json:"id"` - Name string `json:"name"` - Email string `json:"email"` - Enable bool `json:"enable"` - AllowedIPs []string `json:"allowedIPs"` - Address []string `json:"address"` - PrivateKey string `json:"privateKey"` - PublicKey string `json:"publicKey"` - Created time.Time `json:"created"` - Updated time.Time `json:"updated"` + Id string `json:"id"` + Name string `json:"name"` + Email string `json:"email"` + Enable bool `json:"enable"` + IgnorePersistentKeepalive bool `json:"ignorePersistentKeepalive"` + AllowedIPs []string `json:"allowedIPs"` + Address []string `json:"address"` + PrivateKey string `json:"privateKey"` + PublicKey string `json:"publicKey"` + Created time.Time `json:"created"` + Updated time.Time `json:"updated"` } func (a Client) IsValid() []error { @@ -31,13 +32,11 @@ func (a Client) IsValid() []error { if len(a.Name) < 2 || len(a.Name) > 40 { errs = append(errs, fmt.Errorf("name field must be between 2-40 chars")) } - // check if the email empty - if a.Email == "" { - errs = append(errs, fmt.Errorf("email field is required")) - } - // check if email valid - if !util.RegexpEmail.MatchString(a.Email) { - errs = append(errs, fmt.Errorf("email %s is invalid", a.Email)) + // email is not required, but if provided must match regex + if a.Email != "" { + if !util.RegexpEmail.MatchString(a.Email) { + errs = append(errs, fmt.Errorf("email %s is invalid", a.Email)) + } } // check if the allowedIPs empty if len(a.AllowedIPs) == 0 { diff --git a/template/template.go b/template/template.go index 007a083..21d0bd9 100644 --- a/template/template.go +++ b/template/template.go @@ -211,7 +211,7 @@ PublicKey = {{ .Server.PublicKey }} PresharedKey = {{ .Server.PresharedKey }} AllowedIPs = {{ StringsJoin .Client.AllowedIPs ", " }} Endpoint = {{ .Server.Endpoint }} -{{ if ne .Server.PersistentKeepalive 0 -}} +{{ if and (ne .Server.PersistentKeepalive 0) (not .Client.IgnorePersistentKeepalive) -}} PersistentKeepalive = {{.Server.PersistentKeepalive}} {{- end}} ` diff --git a/ui/package-lock.json b/ui/package-lock.json index 5a594d8..2c47d56 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -3561,14 +3561,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3583,20 +3581,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -3713,8 +3708,7 @@ "inherits": { "version": "2.0.4", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -3726,7 +3720,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3741,7 +3734,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3749,14 +3741,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.9.0", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3775,7 +3765,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3865,8 +3854,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -3878,7 +3866,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4000,7 +3987,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4108,6 +4094,23 @@ "assert-plus": "^1.0.0" } }, + "git-describe": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/git-describe/-/git-describe-4.0.4.tgz", + "integrity": "sha512-L1X9OO1e4MusB4PzG9LXeXCQifRvyuoHTpuuZ521Qyxn/B0kWHWEOtsT4LsSfSNacZz0h4ZdYDsDG7f+SrA3hg==", + "requires": { + "lodash": "^4.17.11", + "semver": "^5.6.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "optional": true + } + } + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npm.taobao.org/glob/download/glob-7.1.6.tgz", @@ -5282,8 +5285,7 @@ "lodash": { "version": "4.17.15", "resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz", - "integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=", - "dev": true + "integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=" }, "lodash.defaultsdeep": { "version": "4.6.1", diff --git a/ui/package.json b/ui/package.json index 64aff46..5d2c28e 100644 --- a/ui/package.json +++ b/ui/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "axios": "^0.19.2", + "git-describe": "^4.0.4", "is-cidr": "^3.1.0", "moment": "^2.24.0", "vue": "^2.6.10", diff --git a/ui/src/App.vue b/ui/src/App.vue index b0cb4ef..d63b966 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -27,7 +27,7 @@ - License WTFPL © {{ new Date().getFullYear() }} Created withmdi-heartbyvx3r + License WTFPL © {{ new Date().getFullYear() }} Created withmdi-heartbyvx3rVersion: {{ VersionGitCommit }} @@ -38,9 +38,13 @@ export default { name: 'App', data: () => ({ - // + VersionGitCommit: process.env.VUE_APP_GIT_HASH }), + mounted() { + console.log("Starting Wg Gen Web version: " + process.env.VUE_APP_GIT_HASH) + }, + created () { this.$vuetify.theme.dark = true }, diff --git a/ui/src/components/Clients.vue b/ui/src/components/Clients.vue index 71f71f9..e327b4d 100644 --- a/ui/src/components/Clients.vue +++ b/ui/src/components/Clients.vue @@ -123,27 +123,19 @@ + @@ -219,18 +217,13 @@ + diff --git a/ui/vue.config.js b/ui/vue.config.js index 16260bb..e72673e 100644 --- a/ui/vue.config.js +++ b/ui/vue.config.js @@ -1,3 +1,6 @@ +const {gitDescribe, gitDescribeSync} = require('git-describe'); +process.env.VUE_APP_GIT_HASH = gitDescribeSync().hash + module.exports = { devServer: { port: 8081,