mirror of https://github.com/wg-easy/wg-easy
12 changed files with 206 additions and 55 deletions
@ -1,9 +1,59 @@ |
|||
<template> |
|||
<div> |
|||
<FormGroup> |
|||
<FormNumberField id="session" label="Session Timeout" /> |
|||
</FormGroup> |
|||
</div> |
|||
<main v-if="data"> |
|||
<FormElement @submit.prevent="submit"> |
|||
<FormGroup> |
|||
<FormNumberField |
|||
id="session" |
|||
v-model="data.sessionTimeout" |
|||
label="Session Timeout" |
|||
/> |
|||
</FormGroup> |
|||
<FormGroup> |
|||
<FormHeading>Actions</FormHeading> |
|||
<FormActionField type="submit" label="Save" /> |
|||
<FormActionField label="Revert" @click="revert" /> |
|||
</FormGroup> |
|||
</FormElement> |
|||
</main> |
|||
</template> |
|||
|
|||
<script setup lang="ts"></script> |
|||
<script setup lang="ts"> |
|||
const toast = useToast(); |
|||
|
|||
const { data: _data, refresh } = await useFetch(`/api/admin/general`, { |
|||
method: 'get', |
|||
}); |
|||
|
|||
const data = toRef(_data.value); |
|||
|
|||
async function submit() { |
|||
try { |
|||
const res = await $fetch(`/api/admin/general`, { |
|||
method: 'post', |
|||
body: data.value, |
|||
}); |
|||
toast.showToast({ |
|||
type: 'success', |
|||
title: 'Success', |
|||
message: 'Saved', |
|||
}); |
|||
if (!res.success) { |
|||
throw new Error('Failed to save'); |
|||
} |
|||
await refreshNuxtData(); |
|||
} catch (e) { |
|||
if (e instanceof Error) { |
|||
toast.showToast({ |
|||
type: 'error', |
|||
title: 'Error', |
|||
message: e.message, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function revert() { |
|||
await refresh(); |
|||
data.value = toRef(_data.value).value; |
|||
} |
|||
</script> |
|||
|
@ -1,19 +1,58 @@ |
|||
<template> |
|||
<div> |
|||
<FormGroup> |
|||
<FormHeading>Interface Settings</FormHeading> |
|||
<FormNumberField id="mtu" label="MTU" /> |
|||
<FormNumberField id="port" label="Port" /> |
|||
<FormTextField id="device" label="Device" /> |
|||
</FormGroup> |
|||
<FormGroup> |
|||
<FormHeading>Scripts</FormHeading> |
|||
<FormTextField id="mtu" label="PreUp" /> |
|||
<FormTextField id="port" label="PostUp" /> |
|||
<FormTextField id="device" label="PreDown" /> |
|||
<FormTextField id="device" label="PostDown" /> |
|||
</FormGroup> |
|||
</div> |
|||
<main v-if="data"> |
|||
<FormElement @submit.prevent="submit"> |
|||
<FormGroup> |
|||
<FormHeading>Interface Settings</FormHeading> |
|||
<FormNumberField id="mtu" v-model="data.mtu" label="MTU" /> |
|||
<FormNumberField id="port" v-model="data.port" label="Port" /> |
|||
<FormTextField id="device" v-model="data.device" label="Device" /> |
|||
</FormGroup> |
|||
<FormGroup> |
|||
<FormHeading>Actions</FormHeading> |
|||
<FormActionField type="submit" label="Save" /> |
|||
<FormActionField label="Revert" @click="revert" /> |
|||
</FormGroup> |
|||
</FormElement> |
|||
</main> |
|||
</template> |
|||
|
|||
<script setup lang="ts"></script> |
|||
<script setup lang="ts"> |
|||
const toast = useToast(); |
|||
|
|||
const { data: _data, refresh } = await useFetch(`/api/admin/interface`, { |
|||
method: 'get', |
|||
}); |
|||
|
|||
const data = toRef(_data.value); |
|||
|
|||
async function submit() { |
|||
try { |
|||
const res = await $fetch(`/api/admin/interface`, { |
|||
method: 'post', |
|||
body: data.value, |
|||
}); |
|||
toast.showToast({ |
|||
type: 'success', |
|||
title: 'Success', |
|||
message: 'Saved', |
|||
}); |
|||
if (!res.success) { |
|||
throw new Error('Failed to save'); |
|||
} |
|||
await refreshNuxtData(); |
|||
} catch (e) { |
|||
if (e instanceof Error) { |
|||
toast.showToast({ |
|||
type: 'error', |
|||
title: 'Error', |
|||
message: e.message, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function revert() { |
|||
await refresh(); |
|||
data.value = toRef(_data.value).value; |
|||
} |
|||
</script> |
|||
|
@ -0,0 +1,8 @@ |
|||
export default defineEventHandler(async (event) => { |
|||
const data = await readValidatedBody( |
|||
event, |
|||
validateZod(generalUpdateType, event) |
|||
); |
|||
await Database.system.updateGeneral(data); |
|||
return { success: true }; |
|||
}); |
@ -0,0 +1,5 @@ |
|||
export default defineEventHandler(async () => { |
|||
const system = await Database.system.get(); |
|||
// TODO: handle through wireguard to update conf accordingly
|
|||
return system.interface; |
|||
}); |
@ -0,0 +1,8 @@ |
|||
export default defineEventHandler(async (event) => { |
|||
const data = await readValidatedBody( |
|||
event, |
|||
validateZod(interfaceUpdateType, event) |
|||
); |
|||
await Database.system.updateInterface(data); |
|||
return { success: true }; |
|||
}); |
Loading…
Reference in new issue