fix wireguard and peer data types
This commit is contained in:
@@ -163,7 +163,7 @@ func (s *ServerService) GenKeypair(keyType string, options string) []string {
|
|||||||
case "reality":
|
case "reality":
|
||||||
return s.generateRealityKeyPair()
|
return s.generateRealityKeyPair()
|
||||||
case "wireguard":
|
case "wireguard":
|
||||||
return generateWireGuardKey()
|
return generateWireGuardKey(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{"Failed to generate keypair"}
|
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[:])}
|
return []string{"PrivateKey: " + base64.RawURLEncoding.EncodeToString(privateKey[:]), "PublicKey: " + base64.RawURLEncoding.EncodeToString(publicKey[:])}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateWireGuardKey() []string {
|
func generateWireGuardKey(pk string) []string {
|
||||||
privateKey, err := wgtypes.GeneratePrivateKey()
|
if len(pk) > 0 {
|
||||||
|
key, _ := wgtypes.ParseKey(pk)
|
||||||
|
return []string{key.PublicKey().String()}
|
||||||
|
}
|
||||||
|
wgKeys, err := wgtypes.GeneratePrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{"Failed to generate wireguard keypair: ", err.Error()}
|
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()}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
hide-details
|
hide-details
|
||||||
v-model="port">
|
v-model.number="port">
|
||||||
</v-text-field>
|
</v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="12" sm="6" md="4">
|
<v-col cols="12" sm="6" md="4">
|
||||||
@@ -21,8 +21,9 @@
|
|||||||
label="KeepAlive"
|
label="KeepAlive"
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
|
:suffix="$t('date.s')"
|
||||||
hide-details
|
hide-details
|
||||||
v-model="data.persistent_keepalive_interval">
|
v-model.number="keepAlive">
|
||||||
</v-text-field>
|
</v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -72,6 +73,10 @@ export default {
|
|||||||
port: {
|
port: {
|
||||||
get() { return this.$props.data.port },
|
get() { return this.$props.data.port },
|
||||||
set(v:number) { this.$props.data.port = v > 0 ? v : undefined }
|
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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,16 @@
|
|||||||
hide-details>
|
hide-details>
|
||||||
</v-text-field>
|
</v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
<v-col cols="12" sm="8">
|
||||||
|
<v-text-field
|
||||||
|
v-model="options.public_key"
|
||||||
|
disabled
|
||||||
|
:label="$t('tls.pubKey')"
|
||||||
|
append-icon="mdi-refresh"
|
||||||
|
@click:append="getWgPubKey()"
|
||||||
|
hide-details>
|
||||||
|
</v-text-field>
|
||||||
|
</v-col>
|
||||||
<v-col cols="12" sm="8">
|
<v-col cols="12" sm="8">
|
||||||
<v-text-field v-model="address" :label="$t('types.wg.localIp') + ' ' + $t('commaSeparated')" hide-details></v-text-field>
|
<v-text-field v-model="address" :label="$t('types.wg.localIp') + ' ' + $t('commaSeparated')" hide-details></v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -59,11 +69,11 @@
|
|||||||
<v-col cols="12" sm="6" md="4">
|
<v-col cols="12" sm="6" md="4">
|
||||||
<v-switch v-model="data.system" color="primary" :label="$t('types.wg.sysIf')" hide-details></v-switch>
|
<v-switch v-model="data.system" color="primary" :label="$t('types.wg.sysIf')" hide-details></v-switch>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="12" sm="6" md="4" v-if="data.name != undefined">
|
<v-col cols="12" sm="6" md="4" v-if="data.system">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
:label="$t('types.wg.ifName')"
|
:label="$t('types.wg.ifName')"
|
||||||
hide-details
|
hide-details
|
||||||
v-model="data.name">
|
v-model="ifName">
|
||||||
</v-text-field>
|
</v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -84,9 +94,6 @@
|
|||||||
<v-list-item>
|
<v-list-item>
|
||||||
<v-switch v-model="optionMtu" color="primary" label="MTU" hide-details></v-switch>
|
<v-switch v-model="optionMtu" color="primary" label="MTU" hide-details></v-switch>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionInterface" color="primary" :label="$t('types.wg.ifName')" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-menu>
|
</v-menu>
|
||||||
@@ -111,8 +118,8 @@
|
|||||||
import Peer from '@/components/WgPeer.vue'
|
import Peer from '@/components/WgPeer.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['data'],
|
props: ['data', 'options'],
|
||||||
emits: ["newWgKey"],
|
emits: ['newWgKey', 'getWgPubKey'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
menu: false,
|
menu: false,
|
||||||
@@ -125,6 +132,11 @@ export default {
|
|||||||
newKey() {
|
newKey() {
|
||||||
this.$emit('newWgKey')
|
this.$emit('newWgKey')
|
||||||
},
|
},
|
||||||
|
getWgPubKey() {
|
||||||
|
const privKey = this.$props.data.private_key
|
||||||
|
if (privKey.length == 0) return
|
||||||
|
this.$emit('getWgPubKey', privKey)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
optionUdp: {
|
optionUdp: {
|
||||||
@@ -143,9 +155,9 @@ export default {
|
|||||||
get(): boolean { return this.$props.data.mtu != undefined },
|
get(): boolean { return this.$props.data.mtu != undefined },
|
||||||
set(v:boolean) { this.$props.data.mtu = v ? 1408 : undefined }
|
set(v:boolean) { this.$props.data.mtu = v ? 1408 : undefined }
|
||||||
},
|
},
|
||||||
optionInterface: {
|
ifName: {
|
||||||
get(): boolean { return this.$props.data.name != undefined },
|
get() { return this.$props.data.name?? '' },
|
||||||
set(v:boolean) { this.$props.data.name = v ? "" : undefined }
|
set(v:string) { this.$props.data.name = v.length > 0 ? v : undefined }
|
||||||
},
|
},
|
||||||
address: {
|
address: {
|
||||||
get() { return this.$props.data.address?.join(',') },
|
get() { return this.$props.data.address?.join(',') },
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<v-text-field v-model="endpoint.tag" :label="$t('objects.tag')" hide-details></v-text-field>
|
<v-text-field v-model="endpoint.tag" :label="$t('objects.tag')" hide-details></v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
<Wireguard v-if="endpoint.type == epTypes.Wireguard" :data="endpoint" @newWgKey="newWgKey" />
|
<Wireguard v-if="endpoint.type == epTypes.Wireguard" :data="endpoint" :options="options" @getWgPubKey="getWgPubKey" @newWgKey="newWgKey" />
|
||||||
<Dial :dial="endpoint" :outTags="tags" />
|
<Dial :dial="endpoint" :outTags="tags" />
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
@@ -61,9 +61,9 @@ export default {
|
|||||||
endpoint: createEndpoint("wireguard",{ "tag": "" }),
|
endpoint: createEndpoint("wireguard",{ "tag": "" }),
|
||||||
title: "add",
|
title: "add",
|
||||||
tab: "t1",
|
tab: "t1",
|
||||||
link: "",
|
|
||||||
loading: false,
|
loading: false,
|
||||||
epTypes: EpTypes,
|
epTypes: EpTypes,
|
||||||
|
options: <any>{},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -71,21 +71,24 @@ export default {
|
|||||||
if (this.$props.id > 0) {
|
if (this.$props.id > 0) {
|
||||||
const newData = JSON.parse(this.$props.data)
|
const newData = JSON.parse(this.$props.data)
|
||||||
this.endpoint = createEndpoint(newData.type, newData)
|
this.endpoint = createEndpoint(newData.type, newData)
|
||||||
|
this.options = {}
|
||||||
this.title = "edit"
|
this.title = "edit"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const port = RandomUtil.randomIntRange(10000, 60000)
|
const port = RandomUtil.randomIntRange(10000, 60000)
|
||||||
const randomIPoctet = RandomUtil.randomIntRange(1, 255)
|
const randomIPoctet = RandomUtil.randomIntRange(1, 255)
|
||||||
|
const wgKeys = (await this.genWgKey())
|
||||||
this.endpoint = createEndpoint("wireguard",{
|
this.endpoint = createEndpoint("wireguard",{
|
||||||
tag: "wireguard-" + RandomUtil.randomSeq(3),
|
tag: "wireguard-" + RandomUtil.randomSeq(3),
|
||||||
address: ['10.0.0.'+ randomIPoctet.toString() +'/32','fe80::'+ randomIPoctet.toString(16) +'/128'],
|
address: ['10.0.0.'+ randomIPoctet.toString() +'/32','fe80::'+ randomIPoctet.toString(16) +'/128'],
|
||||||
listen_port: port,
|
listen_port: port,
|
||||||
private_key: (await this.genWgKey()).private_key,
|
private_key: wgKeys.private_key,
|
||||||
peers: [{
|
peers: [{
|
||||||
public_key: (await this.genWgKey()).public_key,
|
public_key: (await this.genWgKey()).public_key,
|
||||||
allowed_ips: ['0.0.0.0/0', '::/0']
|
allowed_ips: ['0.0.0.0/0', '::/0']
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
this.options.public_key = wgKeys.public_key
|
||||||
this.title = "add"
|
this.title = "add"
|
||||||
}
|
}
|
||||||
this.tab = "t1"
|
this.tab = "t1"
|
||||||
@@ -130,11 +133,20 @@ export default {
|
|||||||
async newWgKey(){
|
async newWgKey(){
|
||||||
const newKeys = await this.genWgKey()
|
const newKeys = await this.genWgKey()
|
||||||
this.endpoint.private_key = newKeys.private_key
|
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: {
|
watch: {
|
||||||
visible(newValue) {
|
visible(v) {
|
||||||
if (newValue) {
|
if (v) {
|
||||||
this.updateData()
|
this.updateData()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user