mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 19:08:20 +00:00
Add NTP Server Frontend
This commit is contained in:
parent
afbfed5cb6
commit
76b74be877
4 changed files with 149 additions and 0 deletions
|
@ -11,6 +11,7 @@ import ISNAT from '~icons/mdi/arrow-expand-right';
|
||||||
import IDNAT from '~icons/mdi/arrow-collapse-right';
|
import IDNAT from '~icons/mdi/arrow-collapse-right';
|
||||||
import IConfig from '~icons/grommet-icons/document-config';
|
import IConfig from '~icons/grommet-icons/document-config';
|
||||||
import IStaticRoutes from '~icons/material-symbols/drive-folder-upload-outline-sharp';
|
import IStaticRoutes from '~icons/material-symbols/drive-folder-upload-outline-sharp';
|
||||||
|
import ITimeServer from '~icons/carbon/server-time';
|
||||||
|
|
||||||
enum NavState { Open, Reduced, Collapsed };
|
enum NavState { Open, Reduced, Collapsed };
|
||||||
const NavStateCount = 3;
|
const NavStateCount = 3;
|
||||||
|
@ -25,6 +26,7 @@ const navRoutes = {
|
||||||
"/object/addresses": { icon: IAddress, caption: "Addresses" },
|
"/object/addresses": { icon: IAddress, caption: "Addresses" },
|
||||||
"/object/services": { icon: IService, caption: "Services" },
|
"/object/services": { icon: IService, caption: "Services" },
|
||||||
"/service/dhcpv4servers": { icon: IService, caption: "DHCP v4" },
|
"/service/dhcpv4servers": { icon: IService, caption: "DHCP v4" },
|
||||||
|
"/service/ntpservers": { icon: ITimeServer, caption: "NTP Server" },
|
||||||
"/config/config": { icon: IConfig, caption: "Config" },
|
"/config/config": { icon: IConfig, caption: "Config" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -177,5 +177,20 @@ export const editTypes: { [key: string]: { [key: string]: any } } = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
"ntpservers": {
|
||||||
|
name: "NTPServer",
|
||||||
|
validationSchema: toFormValidator(
|
||||||
|
zod.object({
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
fields: [
|
||||||
|
{ key: "interface", label: "Interface", as: "SingleSelect", props: { searchProvider: GetInterfaces } },
|
||||||
|
{ key: "comment", label: "Comment", as: "MultilineTextBox" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
51
client/src/pages/service/NTPServers.vue
Normal file
51
client/src/pages/service/NTPServers.vue
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { apiCall } from "../../api";
|
||||||
|
import getPlugins from '../../plugins';
|
||||||
|
const p = getPlugins();
|
||||||
|
|
||||||
|
let servers = $ref([]);
|
||||||
|
let loading = $ref(false);
|
||||||
|
let selection = $ref([] as number[]);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{heading: 'Interface', path: 'interface'},
|
||||||
|
{heading: 'Comment', path: 'comment'},
|
||||||
|
];
|
||||||
|
|
||||||
|
async function load(){
|
||||||
|
let res = await apiCall("Service.GetNTPServers", {});
|
||||||
|
if (res.Error === null) {
|
||||||
|
servers = res.Data.ntp_servers;
|
||||||
|
console.debug("rules", servers);
|
||||||
|
} else {
|
||||||
|
console.debug("error", res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteRule(){
|
||||||
|
let res = await apiCall("Service.DeleteNTPServer", {index: selection[0]});
|
||||||
|
if (res.Error === null) {
|
||||||
|
console.debug("deleted server");
|
||||||
|
p.toast.success("Deleted NTP Server");
|
||||||
|
} else {
|
||||||
|
console.debug("error", res);
|
||||||
|
}
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async() => {
|
||||||
|
load();
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<TableView title="NTP Servers" :columns="columns" :loading="loading" v-model:selection="selection" v-model:data="servers" :table-props="{sort:true, sortSelf: true}">
|
||||||
|
<button @click="load">Refresh</button>
|
||||||
|
<router-link class="button" to="/service/ntpservers/edit">Create</router-link>
|
||||||
|
<router-link class="button" :class="{ disabled: selection.length != 1 }" :to="'/service/ntpservers/edit/' + selection[0]">Edit</router-link>
|
||||||
|
<button @click="deleteRule" :disabled="selection.length != 1">Delete</button>
|
||||||
|
</TableView>
|
||||||
|
</div>
|
||||||
|
</template>
|
81
internal/api/service/ntp_server.go
Normal file
81
internal/api/service/ntp_server.go
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"nfsense.net/nfsense/internal/definitions/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetNTPServerParameters struct {
|
||||||
|
ID uint
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetNTPServerResult struct {
|
||||||
|
service.NTPServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Service) GetNTPServer(ctx context.Context, params GetNTPServerParameters) (GetNTPServerResult, error) {
|
||||||
|
if int(params.ID) >= len(f.ConfigManager.GetPendingConfig().Service.NTPServers) {
|
||||||
|
return GetNTPServerResult{}, fmt.Errorf("NTPServer does not Exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetNTPServerResult{
|
||||||
|
NTPServer: f.ConfigManager.GetPendingConfig().Service.NTPServers[params.ID],
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetNTPServersResult struct {
|
||||||
|
NTPServers []service.NTPServer `json:"ntp_servers"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Service) GetNTPServers(ctx context.Context, params struct{}) (GetNTPServersResult, error) {
|
||||||
|
return GetNTPServersResult{
|
||||||
|
NTPServers: f.ConfigManager.GetPendingConfig().Service.NTPServers,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateNTPServerParameters struct {
|
||||||
|
service.NTPServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Service) CreateNTPServer(ctx context.Context, params CreateNTPServerParameters) (struct{}, error) {
|
||||||
|
t, conf := f.ConfigManager.StartTransaction()
|
||||||
|
defer t.Discard()
|
||||||
|
|
||||||
|
conf.Service.NTPServers = append(conf.Service.NTPServers, params.NTPServer)
|
||||||
|
return struct{}{}, t.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateNTPServerParameters struct {
|
||||||
|
Index uint64 `json:"index"`
|
||||||
|
NTPServer service.NTPServer `json:"ntp_server"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Service) UpdateNTPServer(ctx context.Context, params UpdateNTPServerParameters) (struct{}, error) {
|
||||||
|
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Service.NTPServers) {
|
||||||
|
return struct{}{}, fmt.Errorf("NTPServer does not Exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
t, conf := f.ConfigManager.StartTransaction()
|
||||||
|
defer t.Discard()
|
||||||
|
|
||||||
|
conf.Service.NTPServers[params.Index] = params.NTPServer
|
||||||
|
return struct{}{}, t.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteNTPServerParameters struct {
|
||||||
|
Index uint64 `json:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Service) DeleteNTPServer(ctx context.Context, params DeleteNTPServerParameters) (struct{}, error) {
|
||||||
|
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Service.NTPServers) {
|
||||||
|
return struct{}{}, fmt.Errorf("NTPServer does not Exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
t, conf := f.ConfigManager.StartTransaction()
|
||||||
|
defer t.Discard()
|
||||||
|
|
||||||
|
conf.Service.NTPServers = append(conf.Service.NTPServers[:params.Index], conf.Service.NTPServers[params.Index+1:]...)
|
||||||
|
return struct{}{}, t.Commit()
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue