From f91968a06844460b136f24af425b6b2294971a06 Mon Sep 17 00:00:00 2001 From: oreoezi Date: Sat, 13 Jan 2024 22:38:31 +0200 Subject: [PATCH] Changed UI to allow for default gateway change --- .../components/menus/pc/apps/IPConfig.svelte | 54 +++++++++++-------- assets/src/endpoints/pc/global.d.ts | 7 ++- src/topologie/workspace.cpp | 9 ++++ 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/assets/src/components/menus/pc/apps/IPConfig.svelte b/assets/src/components/menus/pc/apps/IPConfig.svelte index bf760d8..4a1577d 100644 --- a/assets/src/components/menus/pc/apps/IPConfig.svelte +++ b/assets/src/components/menus/pc/apps/IPConfig.svelte @@ -5,30 +5,26 @@ export let interfaces: EthernetInterface[]; let parsedInterfaces: {name: string, index: number}[] = []; - $: { - let maxIndex = 0; - - parsedInterfaces = interfaces.sort((a,b) => a.maxSpeed - b.maxSpeed).map((port, index) => { - let label = ""; - switch (port.maxSpeed) { - case 1000: label = "Gigabit"; break; - case 100: label = "Fast"; break; - } + let maxIndex = 0; - if (index != 0 && port.maxSpeed != interfaces[index-1].maxSpeed) - maxIndex = index; + parsedInterfaces = interfaces.sort((a,b) => a.maxSpeed - b.maxSpeed).map((port, index) => { + let label = ""; + switch (port.maxSpeed) { + case 1000: label = "Gigabit"; break; + case 100: label = "Fast"; break; + } - label += `Ethernet${index-maxIndex}/0`; - return { - name: label, - index: interfaces.indexOf(port) - } - }); + if (index != 0 && port.maxSpeed != interfaces[index-1].maxSpeed) + maxIndex = index; - activeIndex.prop = 0; - } + label += `Ethernet${index-maxIndex}/0`; + return { + name: label, + index: interfaces.indexOf(port) + } + }); - let ipAddr: string, subnetMask: string; + let ipAddr: string, subnetMask: string, defaultGateway: string; let activeIndex = { inProp: 0, @@ -44,6 +40,8 @@ } } + activeIndex.prop = 0; + function handleSubnetMaskChange(val: string) { window.wChangeDeviceSettings({ editMode: "interface", @@ -70,6 +68,19 @@ } }); } + + function handleDefaultGatewayChange(val: string) { + if (val.split(".").length != 4) + return; + + window.wChangeDeviceSettings({ + editMode: "interface", + interfaceIndex: activeIndex.prop, + ip: { + defaultGateway: val + } + }); + }
@@ -90,8 +101,7 @@
-
Default Gateway
- +
DNS Server
diff --git a/assets/src/endpoints/pc/global.d.ts b/assets/src/endpoints/pc/global.d.ts index 34ac18d..df2779d 100644 --- a/assets/src/endpoints/pc/global.d.ts +++ b/assets/src/endpoints/pc/global.d.ts @@ -12,7 +12,12 @@ type devSettingMode = { subnetMask?: { slashNotation?: number, dotNotation?: string - } + }, + defaultGateway?: string + }, + ipv6?: { + linkLocalAddress?: string + defaultGateway?: string }, isOn?: boolean, speed?: number, diff --git a/src/topologie/workspace.cpp b/src/topologie/workspace.cpp index 5e59f72..64d9699 100644 --- a/src/topologie/workspace.cpp +++ b/src/topologie/workspace.cpp @@ -120,6 +120,15 @@ bool handleIPSettings(EthernetInterface& intf, json data) { } } } + + if (!data["defaultGateway"].empty()) { + try { + IPv4Address dfGateway(data["defaultGateway"].get()); + intf.setDefaultGateway(dfGateway); + } catch (const std::invalid_argument&) { + throw UIParameterException("defaultGateway"); + } + } return true; }