Fix dhcpv4

This commit is contained in:
Samuel Lorch 2023-10-28 21:04:13 +02:00
parent c75944f990
commit 2333a8ebf1
2 changed files with 30 additions and 30 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { authenticate, logout, checkAuthentication, setup } from "./api"; import { authenticate, logout, checkAuthentication, setup } from './api';
// Icons // Icons
import IDashboard from '~icons/ri/dashboard-2-line'; import IDashboard from '~icons/ri/dashboard-2-line';
@ -21,32 +21,32 @@ enum NavState { Open, Reduced, Collapsed };
const NavStateCount = 3; const NavStateCount = 3;
let navState = $ref(NavState.Open); let navState = $ref(NavState.Open);
const navRoutes = { const navRoutes = {
"/": { icon: IDashboard, caption: "Dashboard" }, '/': { icon: IDashboard, caption: 'Dashboard' },
"/firewall/forwardrules": { icon: IRule, caption: "Rules" }, '/firewall/forwardrules': { icon: IRule, caption: 'Rules' },
"/firewall/sourcenatrules": { icon: ISNAT, caption: "SNAT" }, '/firewall/sourcenatrules': { icon: ISNAT, caption: 'SNAT' },
"/firewall/destinationnatrules": { icon: IDNAT, caption: "DNAT" }, '/firewall/destinationnatrules': { icon: IDNAT, caption: 'DNAT' },
"/network/interfaces": { icon: IEthernet, caption: "Interfaces" }, '/network/interfaces': { icon: IEthernet, caption: 'Interfaces' },
"/network/staticroutes": { icon: IStaticRoutes, caption: "Static Routes" }, '/network/staticroutes': { icon: IStaticRoutes, caption: 'Static Routes' },
"/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: IDHCPServer, caption: "DHCP v4" }, '/service/dhcpservers': { icon: IDHCPServer, caption: 'DHCP Server' },
"/service/dnsservers": { icon: IDNSServer, caption: "DNS Server" }, '/service/dnsservers': { icon: IDNSServer, caption: 'DNS Server' },
"/service/ntpservers": { icon: ITimeServer, caption: "NTP Server" }, '/service/ntpservers': { icon: ITimeServer, caption: 'NTP Server' },
"/vpn/wireguardstatus": { icon: IWireguard, caption: "Wireguard Status" }, '/vpn/wireguardstatus': { icon: IWireguard, caption: 'Wireguard Status' },
"/vpn/wireguardinterfaces": { icon: IWireguard, caption: "Wireguard Interfaces" }, '/vpn/wireguardinterfaces': { icon: IWireguard, caption: 'Wireguard Interfaces' },
"/vpn/wireguardpeers": { icon: IWireguard, caption: "Wireguard Peers" }, '/vpn/wireguardpeers': { icon: IWireguard, caption: 'Wireguard Peers' },
"/system/users": { icon: IUser, caption: "Users" }, '/system/users': { icon: IUser, caption: 'Users' },
"/config/config": { icon: IConfig, caption: "Config" }, '/config/config': { icon: IConfig, caption: 'Config' },
}; };
enum AuthState { Unauthenticated, MfaRequired, Authenticated }; enum AuthState { Unauthenticated, MfaRequired, Authenticated };
let authState = $ref(AuthState.Unauthenticated); let authState = $ref(AuthState.Unauthenticated);
let loginDisabled = $ref(true); let loginDisabled = $ref(true);
let username = $ref(""); let username = $ref('');
let password = $ref(""); let password = $ref('');
const mobileMedia = window.matchMedia("only screen and (max-width: 768px)"); const mobileMedia = window.matchMedia('only screen and (max-width: 768px)');
if (mobileMedia.matches) { if (mobileMedia.matches) {
navState = NavState.Collapsed; navState = NavState.Collapsed;
} }
@ -67,10 +67,10 @@ function toggleNavState() {
async function tryLogin() { async function tryLogin() {
loginDisabled = true; loginDisabled = true;
const res = await authenticate(username, password); const res = await authenticate(username, password);
password = ""; password = '';
loginDisabled = false; loginDisabled = false;
if (res.error != null) { if (res.error != null) {
console.info("authentication error"); console.info('authentication error');
} }
else { else {
// TODO Check for MFA here // TODO Check for MFA here
@ -79,27 +79,27 @@ async function tryLogin() {
} }
async function tryLogout() { async function tryLogout() {
console.info("Logging out..."); console.info('Logging out...');
authState = AuthState.Unauthenticated; authState = AuthState.Unauthenticated;
logout(); logout();
} }
function UnauthorizedCallback() { function UnauthorizedCallback() {
console.info("Unauthenticated"); console.info('Unauthenticated');
authState = AuthState.Unauthenticated; authState = AuthState.Unauthenticated;
} }
async function checkAuth() { async function checkAuth() {
console.info("Checking Auth State..."); console.info('Checking Auth State...');
let res = await checkAuthentication(); let res = await checkAuthentication();
authState = res.auth; authState = res.auth;
loginDisabled = false; loginDisabled = false;
if (authState === AuthState.Authenticated) { if (authState === AuthState.Authenticated) {
console.info("Already Authenticated ", authState); console.info('Already Authenticated ', authState);
} else if (res.error == null) { } else if (res.error == null) {
console.info("Unauthorized"); console.info('Unauthorized');
} }
else console.info("Check Authentication error",res.error); else console.info('Check Authentication error',res.error);
} }
onMounted(async() => { onMounted(async() => {

View file

@ -43,8 +43,8 @@ onMounted(async() => {
<div> <div>
<TableView title="DHCP v4 Servers" :columns="columns" :loading="loading" v-model:selection="selection" v-model:data="servers" :table-props="{sort:true, sortSelf: true}"> <TableView title="DHCP v4 Servers" :columns="columns" :loading="loading" v-model:selection="selection" v-model:data="servers" :table-props="{sort:true, sortSelf: true}">
<button @click="load">Refresh</button> <button @click="load">Refresh</button>
<router-link class="button" to="/service/dhcpv4servers/edit">Create</router-link> <router-link class="button" to="/service/dhcpservers/edit">Create</router-link>
<router-link class="button" :class="{ disabled: selection.length != 1 }" :to="'/service/dhcpv4servers/edit/' + selection[0]">Edit</router-link> <router-link class="button" :class="{ disabled: selection.length != 1 }" :to="'/service/dhcpservers/edit/' + selection[0]">Edit</router-link>
<button @click="deleteRule" :disabled="selection.length != 1">Delete</button> <button @click="deleteRule" :disabled="selection.length != 1">Delete</button>
</TableView> </TableView>
</div> </div>