Skip to content

Commit

Permalink
Changed UI to allow for default gateway change
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreoezi committed Jan 13, 2024
1 parent b2a6b7a commit f91968a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
54 changes: 32 additions & 22 deletions assets/src/components/menus/pc/apps/IPConfig.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,6 +40,8 @@
}
}
activeIndex.prop = 0;
function handleSubnetMaskChange(val: string) {
window.wChangeDeviceSettings({
editMode: "interface",
Expand All @@ -70,6 +68,19 @@
}
});
}
function handleDefaultGatewayChange(val: string) {
if (val.split(".").length != 4)
return;
window.wChangeDeviceSettings({
editMode: "interface",
interfaceIndex: activeIndex.prop,
ip: {
defaultGateway: val
}
});
}
</script>

<div class="w-64">
Expand All @@ -90,8 +101,7 @@
<CallbackTextarea label={"Subnet Mask"} bind:text={subnetMask} callback={handleSubnetMaskChange}/>
</div>
<div>
<div class="inline-block w-32">Default Gateway</div>
<textarea class="inline-block resize-none w-32 h-6 text-xs"></textarea>
<CallbackTextarea label={"Default Gateway"} bind:text={defaultGateway} callback={handleDefaultGatewayChange}/>
</div>
<div>
<div class="inline-block w-32">DNS Server</div>
Expand Down
7 changes: 6 additions & 1 deletion assets/src/endpoints/pc/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ type devSettingMode = {
subnetMask?: {
slashNotation?: number,
dotNotation?: string
}
},
defaultGateway?: string
},
ipv6?: {
linkLocalAddress?: string
defaultGateway?: string
},
isOn?: boolean,
speed?: number,
Expand Down
9 changes: 9 additions & 0 deletions src/topologie/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ bool handleIPSettings(EthernetInterface& intf, json data) {
}
}
}

if (!data["defaultGateway"].empty()) {
try {
IPv4Address dfGateway(data["defaultGateway"].get<std::string>());
intf.setDefaultGateway(dfGateway);
} catch (const std::invalid_argument&) {
throw UIParameterException("defaultGateway");
}
}

return true;
}
Expand Down

0 comments on commit f91968a

Please sign in to comment.