mirror of https://github.com/wg-easy/wg-easy
12 changed files with 206 additions and 55 deletions
@ -1,9 +1,59 @@ |
|||||
<template> |
<template> |
||||
<div> |
<main v-if="data"> |
||||
<FormGroup> |
<FormElement @submit.prevent="submit"> |
||||
<FormNumberField id="session" label="Session Timeout" /> |
<FormGroup> |
||||
</FormGroup> |
<FormNumberField |
||||
</div> |
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> |
</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> |
<template> |
||||
<div> |
<main v-if="data"> |
||||
<FormGroup> |
<FormElement @submit.prevent="submit"> |
||||
<FormHeading>Interface Settings</FormHeading> |
<FormGroup> |
||||
<FormNumberField id="mtu" label="MTU" /> |
<FormHeading>Interface Settings</FormHeading> |
||||
<FormNumberField id="port" label="Port" /> |
<FormNumberField id="mtu" v-model="data.mtu" label="MTU" /> |
||||
<FormTextField id="device" label="Device" /> |
<FormNumberField id="port" v-model="data.port" label="Port" /> |
||||
</FormGroup> |
<FormTextField id="device" v-model="data.device" label="Device" /> |
||||
<FormGroup> |
</FormGroup> |
||||
<FormHeading>Scripts</FormHeading> |
<FormGroup> |
||||
<FormTextField id="mtu" label="PreUp" /> |
<FormHeading>Actions</FormHeading> |
||||
<FormTextField id="port" label="PostUp" /> |
<FormActionField type="submit" label="Save" /> |
||||
<FormTextField id="device" label="PreDown" /> |
<FormActionField label="Revert" @click="revert" /> |
||||
<FormTextField id="device" label="PostDown" /> |
</FormGroup> |
||||
</FormGroup> |
</FormElement> |
||||
</div> |
</main> |
||||
</template> |
</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