0
0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2024-12-18 00:13:23 +00:00

add version in back and front #16 / client can ignore global PK #17 / #18 email is now optional

This commit is contained in:
vx3r 2020-02-25 15:56:04 +09:00
parent 2f2b27c499
commit 1d599c401b
9 changed files with 78 additions and 62 deletions

View File

@ -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

View File

@ -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

View File

@ -12,6 +12,7 @@ type Client struct {
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"`
@ -31,14 +32,12 @@ 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
// 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 {
errs = append(errs, fmt.Errorf("allowedIPs field is required"))

View File

@ -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}}
`

48
ui/package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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> &copy; {{ 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> &copy; {{ 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
},

View File

@ -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>

View File

@ -1,3 +1,6 @@
const {gitDescribe, gitDescribeSync} = require('git-describe');
process.env.VUE_APP_GIT_HASH = gitDescribeSync().hash

module.exports = {
devServer: {
port: 8081,