diff --git a/Dockerfile b/Dockerfile index f25fe04a4aa2333270d17ff3f423f00ec9f40c65..a9cdaaac7a728a530d7661a72c98df186363a76e 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 4efc00348d97b05c458755cb8043c0effa1d0ea4..3f93063b1737758d763dd8d19e9fefece469a437 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 eb0eb77044b013aeb6415fe0237e31a690f36338..87fedbdbbbace5d73f80d0279fbb5000b8f2ab8a 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 007a0831a2fafd0bd67726dfe33eb061fb6ab681..21d0bd913bcd24431df8222f4f46b1334bb25338 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 5a594d82a1da2bf4485d0462b7e79e5e94b0156d..2c47d56163e4650a91e187f408f48e72837a6de2 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 64aff469864f89d8328a5731333ddd2708378aa1..5d2c28e76ded1575b3fa11542b9d4c6e58b6821a 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 b0cb4ef762746ca73cd69a050445b4cc40e6dd82..d63b966e1813c3425e3a6dbea45f9020bac49197 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -27,7 +27,7 @@ </v-content> <v-footer app> - <span>License <a class="pr-1 pl-1" href="http://www.wtfpl.net/" target="_blank">WTFPL</a> © {{ new Date().getFullYear() }} Created with</span><v-icon class="pr-1 pl-1">mdi-heart</v-icon><span>by</span><a class="pr-1 pl-1" href="mailto:vx3r@127-0-0-1.fr">vx3r</a> + <span>License <a class="pr-1 pl-1" href="http://www.wtfpl.net/" target="_blank">WTFPL</a> © {{ new Date().getFullYear() }} Created with</span><v-icon class="pr-1 pl-1">mdi-heart</v-icon><span>by</span><a class="pr-1 pl-1" href="mailto:vx3r@127-0-0-1.fr">vx3r</a><v-spacer></v-spacer><span>Version: {{ VersionGitCommit }}</span> </v-footer> </v-app> @@ -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 71f71f92c119f723617f0562511493dec0c7a916..e327b4ddd0c385b9f57a1dbfc3426e1ac49f92a8 100644 --- a/ui/src/components/Clients.vue +++ b/ui/src/components/Clients.vue @@ -123,27 +123,19 @@ <v-text-field v-model="client.name" label="Client friendly name" - :rules="[ - v => !!v || 'Client name is required', - ]" + :rules="[ v => !!v || 'Client name is required', ]" required /> <v-text-field v-model="client.email" label="Client email" - :rules="[ - v => !!v || 'E-mail is required', - v => /.+@.+\..+/.test(v) || 'E-mail must be valid', - ]" - required + :rules="[ v => (/.+@.+\..+/.test(v) || v === '') || 'E-mail must be valid',]" /> <v-select v-model="client.address" :items="server.address" label="Client IP will be chosen from these networks" - :rules="[ - v => !!v || 'Network is required', - ]" + :rules="[ v => !!v || 'Network is required', ]" multiple chips persistent-hint @@ -176,6 +168,12 @@ inset :label="client.enable ? 'Enable client after creation': 'Disable client after creation'" /> + <v-switch + v-model="client.ignorePersistentKeepalive" + color="red" + inset + :label="'Ignore global persistent keepalive: ' + (client.ignorePersistentKeepalive ? 'Yes': 'NO')" + /> </v-form> </v-col> </v-row> @@ -219,18 +217,13 @@ <v-text-field v-model="client.name" label="Friendly name" - :rules="[ - v => !!v || 'Client name is required', - ]" + :rules="[ v => !!v || 'Client name is required',]" required /> <v-text-field v-model="client.email" label="Email" - :rules="[ - v => !!v || 'Email is required', - v => /.+@.+\..+/.test(v) || 'Email must be valid', - ]" + :rules="[ v => (/.+@.+\..+/.test(v) || v === '') || 'E-mail must be valid',]" required /> <v-combobox @@ -273,6 +266,12 @@ </v-chip> </template> </v-combobox> + <v-switch + v-model="client.ignorePersistentKeepalive" + color="red" + inset + :label="'Ignore global persistent keepalive: ' + (client.ignorePersistentKeepalive ? 'Yes': 'NO')" + /> </v-form> </v-col> </v-row> diff --git a/ui/vue.config.js b/ui/vue.config.js index 16260bbafba37f413c235e2f58f86ae8fe223ac2..e72673ee7090997b4483972f74bd07d8e08f91c1 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,