diff --git a/backend/service/server.go b/backend/service/server.go
index a089edd..f12d427 100644
--- a/backend/service/server.go
+++ b/backend/service/server.go
@@ -163,7 +163,7 @@ func (s *ServerService) GenKeypair(keyType string, options string) []string {
case "reality":
return s.generateRealityKeyPair()
case "wireguard":
- return generateWireGuardKey()
+ return generateWireGuardKey(options)
}
return []string{"Failed to generate keypair"}
@@ -195,10 +195,14 @@ func (s *ServerService) generateRealityKeyPair() []string {
return []string{"PrivateKey: " + base64.RawURLEncoding.EncodeToString(privateKey[:]), "PublicKey: " + base64.RawURLEncoding.EncodeToString(publicKey[:])}
}
-func generateWireGuardKey() []string {
- privateKey, err := wgtypes.GeneratePrivateKey()
+func generateWireGuardKey(pk string) []string {
+ if len(pk) > 0 {
+ key, _ := wgtypes.ParseKey(pk)
+ return []string{key.PublicKey().String()}
+ }
+ wgKeys, err := wgtypes.GeneratePrivateKey()
if err != nil {
return []string{"Failed to generate wireguard keypair: ", err.Error()}
}
- return []string{"PrivateKey: " + privateKey.String(), "PublicKey: " + privateKey.PublicKey().String()}
+ return []string{"PrivateKey: " + wgKeys.String(), "PublicKey: " + wgKeys.PublicKey().String()}
}
diff --git a/frontend/src/components/WgPeer.vue b/frontend/src/components/WgPeer.vue
index 695fe3f..c6e037f 100644
--- a/frontend/src/components/WgPeer.vue
+++ b/frontend/src/components/WgPeer.vue
@@ -13,7 +13,7 @@
type="number"
min="0"
hide-details
- v-model="port">
+ v-model.number="port">
@@ -21,8 +21,9 @@
label="KeepAlive"
type="number"
min="0"
+ :suffix="$t('date.s')"
hide-details
- v-model="data.persistent_keepalive_interval">
+ v-model.number="keepAlive">
@@ -72,6 +73,10 @@ export default {
port: {
get() { return this.$props.data.port },
set(v:number) { this.$props.data.port = v > 0 ? v : undefined }
+ },
+ keepAlive: {
+ get() { return this.$props.data.persistent_keepalive_interval?? 0 },
+ set(v:number) { this.$props.data.persistent_keepalive_interval = v > 0 ? v : undefined }
}
}
}
diff --git a/frontend/src/components/protocols/Wireguard.vue b/frontend/src/components/protocols/Wireguard.vue
index d338dc5..1cc0b8d 100644
--- a/frontend/src/components/protocols/Wireguard.vue
+++ b/frontend/src/components/protocols/Wireguard.vue
@@ -10,6 +10,16 @@
hide-details>
+
+
+
+
@@ -59,11 +69,11 @@
-
+
+ v-model="ifName">
@@ -84,9 +94,6 @@
-
-
-
@@ -111,8 +118,8 @@
import Peer from '@/components/WgPeer.vue'
export default {
- props: ['data'],
- emits: ["newWgKey"],
+ props: ['data', 'options'],
+ emits: ['newWgKey', 'getWgPubKey'],
data() {
return {
menu: false,
@@ -125,6 +132,11 @@ export default {
newKey() {
this.$emit('newWgKey')
},
+ getWgPubKey() {
+ const privKey = this.$props.data.private_key
+ if (privKey.length == 0) return
+ this.$emit('getWgPubKey', privKey)
+ },
},
computed: {
optionUdp: {
@@ -143,9 +155,9 @@ export default {
get(): boolean { return this.$props.data.mtu != undefined },
set(v:boolean) { this.$props.data.mtu = v ? 1408 : undefined }
},
- optionInterface: {
- get(): boolean { return this.$props.data.name != undefined },
- set(v:boolean) { this.$props.data.name = v ? "" : undefined }
+ ifName: {
+ get() { return this.$props.data.name?? '' },
+ set(v:string) { this.$props.data.name = v.length > 0 ? v : undefined }
},
address: {
get() { return this.$props.data.address?.join(',') },
diff --git a/frontend/src/layouts/modals/Endpoint.vue b/frontend/src/layouts/modals/Endpoint.vue
index 32a0ae5..82707d7 100644
--- a/frontend/src/layouts/modals/Endpoint.vue
+++ b/frontend/src/layouts/modals/Endpoint.vue
@@ -20,7 +20,7 @@
-
+
@@ -61,9 +61,9 @@ export default {
endpoint: createEndpoint("wireguard",{ "tag": "" }),
title: "add",
tab: "t1",
- link: "",
loading: false,
epTypes: EpTypes,
+ options: {},
}
},
methods: {
@@ -71,21 +71,24 @@ export default {
if (this.$props.id > 0) {
const newData = JSON.parse(this.$props.data)
this.endpoint = createEndpoint(newData.type, newData)
+ this.options = {}
this.title = "edit"
}
else {
const port = RandomUtil.randomIntRange(10000, 60000)
const randomIPoctet = RandomUtil.randomIntRange(1, 255)
+ const wgKeys = (await this.genWgKey())
this.endpoint = createEndpoint("wireguard",{
tag: "wireguard-" + RandomUtil.randomSeq(3),
address: ['10.0.0.'+ randomIPoctet.toString() +'/32','fe80::'+ randomIPoctet.toString(16) +'/128'],
listen_port: port,
- private_key: (await this.genWgKey()).private_key,
+ private_key: wgKeys.private_key,
peers: [{
public_key: (await this.genWgKey()).public_key,
allowed_ips: ['0.0.0.0/0', '::/0']
}]
})
+ this.options.public_key = wgKeys.public_key
this.title = "add"
}
this.tab = "t1"
@@ -130,11 +133,20 @@ export default {
async newWgKey(){
const newKeys = await this.genWgKey()
this.endpoint.private_key = newKeys.private_key
+ this.options.public_key = newKeys.public_key
+ },
+ async getWgPubKey(private_key: string) {
+ this.loading = true
+ const msg = await HttpUtils.get('api/keypairs', { k: "wireguard", o: private_key })
+ if (msg.success) {
+ this.options.public_key = msg.obj
+ }
+ this.loading = false
}
},
watch: {
- visible(newValue) {
- if (newValue) {
+ visible(v) {
+ if (v) {
this.updateData()
}
},