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 FROM golang:alpine AS build-back
WORKDIR /app WORKDIR /app
COPY . . 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 FROM node:10-alpine AS build-front
WORKDIR /app WORKDIR /app

View File

@ -15,6 +15,10 @@ import (
"path/filepath" "path/filepath"
) )


var (
VersionGitCommit string
)

func init() { func init() {
log.SetFormatter(&log.TextFormatter{}) log.SetFormatter(&log.TextFormatter{})
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
@ -22,6 +26,8 @@ func init() {
} }


func main() { func main() {
log.Infof("Starting Wg Gen Web version: %s", VersionGitCommit)

// load .env environment variables // load .env environment variables
err := godotenv.Load() err := godotenv.Load()
if err != nil { if err != nil {
@ -59,6 +65,8 @@ func main() {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
// disable console color // disable console color
gin.DisableConsoleColor() gin.DisableConsoleColor()
// log level info
log.SetLevel(log.InfoLevel)
} }


// migrate // migrate

View File

@ -8,16 +8,17 @@ import (


// Client structure // Client structure
type Client struct { type Client struct {
Id string `json:"id"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Enable bool `json:"enable"` Enable bool `json:"enable"`
AllowedIPs []string `json:"allowedIPs"` IgnorePersistentKeepalive bool `json:"ignorePersistentKeepalive"`
Address []string `json:"address"` AllowedIPs []string `json:"allowedIPs"`
PrivateKey string `json:"privateKey"` Address []string `json:"address"`
PublicKey string `json:"publicKey"` PrivateKey string `json:"privateKey"`
Created time.Time `json:"created"` PublicKey string `json:"publicKey"`
Updated time.Time `json:"updated"` Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
} }


func (a Client) IsValid() []error { func (a Client) IsValid() []error {
@ -31,13 +32,11 @@ func (a Client) IsValid() []error {
if len(a.Name) < 2 || len(a.Name) > 40 { if len(a.Name) < 2 || len(a.Name) > 40 {
errs = append(errs, fmt.Errorf("name field must be between 2-40 chars")) errs = append(errs, fmt.Errorf("name field must be between 2-40 chars"))
} }
// check if the email empty // email is not required, but if provided must match regex
if a.Email == "" { if a.Email != "" {
errs = append(errs, fmt.Errorf("email field is required")) if !util.RegexpEmail.MatchString(a.Email) {
} errs = append(errs, fmt.Errorf("email %s is invalid", a.Email))
// check if email valid }
if !util.RegexpEmail.MatchString(a.Email) {
errs = append(errs, fmt.Errorf("email %s is invalid", a.Email))
} }
// check if the allowedIPs empty // check if the allowedIPs empty
if len(a.AllowedIPs) == 0 { if len(a.AllowedIPs) == 0 {

View File

@ -211,7 +211,7 @@ PublicKey = {{ .Server.PublicKey }}
PresharedKey = {{ .Server.PresharedKey }} PresharedKey = {{ .Server.PresharedKey }}
AllowedIPs = {{ StringsJoin .Client.AllowedIPs ", " }} AllowedIPs = {{ StringsJoin .Client.AllowedIPs ", " }}
Endpoint = {{ .Server.Endpoint }} Endpoint = {{ .Server.Endpoint }}
{{ if ne .Server.PersistentKeepalive 0 -}} {{ if and (ne .Server.PersistentKeepalive 0) (not .Client.IgnorePersistentKeepalive) -}}
PersistentKeepalive = {{.Server.PersistentKeepalive}} PersistentKeepalive = {{.Server.PersistentKeepalive}}
{{- end}} {{- end}}
` `

48
ui/package-lock.json generated
View File

@ -3561,14 +3561,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -3583,20 +3581,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -3713,8 +3708,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -3726,7 +3720,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -3741,7 +3734,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -3749,14 +3741,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -3775,7 +3765,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -3865,8 +3854,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -3878,7 +3866,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -4000,7 +3987,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@ -4108,6 +4094,23 @@
"assert-plus": "^1.0.0" "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": { "glob": {
"version": "7.1.6", "version": "7.1.6",
"resolved": "https://registry.npm.taobao.org/glob/download/glob-7.1.6.tgz", "resolved": "https://registry.npm.taobao.org/glob/download/glob-7.1.6.tgz",
@ -5282,8 +5285,7 @@
"lodash": { "lodash": {
"version": "4.17.15", "version": "4.17.15",
"resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz", "resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz",
"integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=", "integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg="
"dev": true
}, },
"lodash.defaultsdeep": { "lodash.defaultsdeep": {
"version": "4.6.1", "version": "4.6.1",

View File

@ -8,6 +8,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.2", "axios": "^0.19.2",
"git-describe": "^4.0.4",
"is-cidr": "^3.1.0", "is-cidr": "^3.1.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"vue": "^2.6.10", "vue": "^2.6.10",

View File

@ -27,7 +27,7 @@
</v-content> </v-content>


<v-footer app> <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-footer>


</v-app> </v-app>
@ -38,9 +38,13 @@ export default {
name: 'App', name: 'App',


data: () => ({ data: () => ({
// VersionGitCommit: process.env.VUE_APP_GIT_HASH
}), }),


mounted() {
console.log("Starting Wg Gen Web version: " + process.env.VUE_APP_GIT_HASH)
},

created () { created () {
this.$vuetify.theme.dark = true this.$vuetify.theme.dark = true
}, },

View File

@ -123,27 +123,19 @@
<v-text-field <v-text-field
v-model="client.name" v-model="client.name"
label="Client friendly name" label="Client friendly name"
:rules="[ :rules="[ v => !!v || 'Client name is required', ]"
v => !!v || 'Client name is required',
]"
required required
/> />
<v-text-field <v-text-field
v-model="client.email" v-model="client.email"
label="Client email" label="Client email"
:rules="[ :rules="[ v => (/.+@.+\..+/.test(v) || v === '') || 'E-mail must be valid',]"
v => !!v || 'E-mail is required',
v => /.+@.+\..+/.test(v) || 'E-mail must be valid',
]"
required
/> />
<v-select <v-select
v-model="client.address" v-model="client.address"
:items="server.address" :items="server.address"
label="Client IP will be chosen from these networks" label="Client IP will be chosen from these networks"
:rules="[ :rules="[ v => !!v || 'Network is required', ]"
v => !!v || 'Network is required',
]"
multiple multiple
chips chips
persistent-hint persistent-hint
@ -176,6 +168,12 @@
inset inset
:label="client.enable ? 'Enable client after creation': 'Disable client after creation'" :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-form>
</v-col> </v-col>
</v-row> </v-row>
@ -219,18 +217,13 @@
<v-text-field <v-text-field
v-model="client.name" v-model="client.name"
label="Friendly name" label="Friendly name"
:rules="[ :rules="[ v => !!v || 'Client name is required',]"
v => !!v || 'Client name is required',
]"
required required
/> />
<v-text-field <v-text-field
v-model="client.email" v-model="client.email"
label="Email" label="Email"
:rules="[ :rules="[ v => (/.+@.+\..+/.test(v) || v === '') || 'E-mail must be valid',]"
v => !!v || 'Email is required',
v => /.+@.+\..+/.test(v) || 'Email must be valid',
]"
required required
/> />
<v-combobox <v-combobox
@ -273,6 +266,12 @@
</v-chip> </v-chip>
</template> </template>
</v-combobox> </v-combobox>
<v-switch
v-model="client.ignorePersistentKeepalive"
color="red"
inset
:label="'Ignore global persistent keepalive: ' + (client.ignorePersistentKeepalive ? 'Yes': 'NO')"
/>
</v-form> </v-form>
</v-col> </v-col>
</v-row> </v-row>

View File

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

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