Add preshared key default toggle (#1207)
Some checks are pending
Docker Build and Push / docker_build (push) Waiting to run
Docker Build and Push / docker_scan (push) Blocked by required conditions

* Add previous PR changes

* Import lowercase dayjs

* Build dist

* Revert "Build dist"

This reverts commit 152da2ca10
Dist not to be built at @DaanSelen request
This commit is contained in:
Tom Mills
2026-04-20 09:00:35 +01:00
committed by GitHub
parent d58e082336
commit 18c2568c22
6 changed files with 39 additions and 15 deletions

View File

@@ -51,7 +51,8 @@ class DashboardConfig:
"peer_display_mode": "grid",
"remote_endpoint": GetRemoteEndpoint(),
"peer_MTU": "1420",
"peer_keep_alive": "21"
"peer_keep_alive": "21",
"peer_preshared_key_default": "false"
},
"Other": {
"welcome_session": "true"

View File

@@ -6,18 +6,27 @@ export default {
components: {LocaleText},
props: {
data: Object,
saving: Boolean
saving: Boolean,
defaultEnabled: Boolean
},
data(){
return{
enable: false
}
},
mounted() {
const hasKey = !!(this.data && this.data.preshared_key && this.data.preshared_key.length > 0)
if (hasKey || this.defaultEnabled){
this.enable = true
}
},
watch:{
enable(){
if (this.enable){
this.data.preshared_key = window.wireguard.generateKeypair().presharedKey
}else {
if (this.enable) {
if (!this.data.preshared_key){
this.data.preshared_key = window.wireguard.generateKeypair().presharedKey
}
} else {
this.data.preshared_key = ""
}
}

View File

@@ -32,7 +32,7 @@ const peerData = ref({
keepalive: parseInt(dashboardStore.Configuration.Peers.peer_keep_alive),
mtu: parseInt(dashboardStore.Configuration.Peers.peer_mtu),
preshared_key: "",
preshared_key_bulkAdd: false,
preshared_key_bulkAdd: Boolean(dashboardStore.Configuration.Peers.peer_preshared_key_default),
allowed_ips_validation: true,
})
const availableIp = ref([])
@@ -128,7 +128,7 @@ watch(() => {
<EndpointAllowedIps :saving="saving" :data="peerData"></EndpointAllowedIps>
<div class="row gy-3">
<div class="col-sm" v-if="!peerData.bulkAdd">
<PresharedKeyInput :saving="saving" :data="peerData" :bulk="peerData.bulkAdd"></PresharedKeyInput>
<PresharedKeyInput :saving="saving" :data="peerData" :bulk="peerData.bulkAdd" :defaultEnabled="Boolean(dashboardStore.Configuration.Peers.peer_preshared_key_default)"></PresharedKeyInput>
</div>
<div class="col-sm">

View File

@@ -36,7 +36,7 @@ export default {
keepalive: parseInt(this.dashboardStore.Configuration.Peers.peer_keep_alive),
mtu: parseInt(this.dashboardStore.Configuration.Peers.peer_mtu),
preshared_key: "",
preshared_key_bulkAdd: false,
preshared_key_bulkAdd: Boolean(this.dashboardStore.Configuration.Peers.peer_preshared_key_default),
},
availableIp: undefined,
availableIpSearchString: "",
@@ -133,7 +133,7 @@ export default {
<hr class="mb-0 mt-2">
<div class="row gy-3">
<div class="col-sm" v-if="!this.data.bulkAdd">
<PresharedKeyInput :saving="saving" :data="data" :bulk="this.data.bulkAdd"></PresharedKeyInput>
<PresharedKeyInput :saving="saving" :data="data" :bulk="this.data.bulkAdd" :defaultEnabled="Boolean(this.dashboardStore.Configuration.Peers.peer_preshared_key_default)"></PresharedKeyInput>
</div>
<div class="col-sm">

View File

@@ -22,6 +22,8 @@ import PeersDefaultSettingsInput from "@/components/settingsComponent/peersDefau
targetData="peer_mtu" title="MTU"></PeersDefaultSettingsInput>
<PeersDefaultSettingsInput
targetData="peer_keep_alive" title="Persistent Keepalive"></PeersDefaultSettingsInput>
<PeersDefaultSettingsInput
targetData="peer_preshared_key_default" title="Pre-Shared Key Default"></PeersDefaultSettingsInput>
<PeersDefaultSettingsInput
targetData="remote_endpoint" title="Peer Remote Endpoint"
:warning="true" warningText="This will be changed globally, and will be apply to all peer's QR code and configuration file."

View File

@@ -31,6 +31,11 @@ export default {
mounted() {
this.value = this.store.Configuration.Peers[this.targetData];
},
computed: {
isBoolean(){
return typeof this.value === "boolean"
}
},
methods:{
async useValidation(){
if(this.changed){
@@ -67,7 +72,14 @@ export default {
<LocaleText :t="this.title"></LocaleText>
</small></strong>
</label>
<input type="text" class="form-control"
<div v-if="isBoolean" class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch"
v-model="this.value"
:id="this.uuid"
@change="this.changed = true; useValidation()"
:disabled="this.updating">
</div>
<input v-else type="text" class="form-control"
:class="{'is-invalid': showInvalidFeedback, 'is-valid': isValid}"
:id="this.uuid"
v-model="this.value"