Skip to content

Commit b77a7ad

Browse files
authored
Merge pull request #82 from K97i/v2-nic
Add NIC modal
2 parents fabf940 + 67c8970 commit b77a7ad

File tree

2 files changed

+76
-31
lines changed

2 files changed

+76
-31
lines changed

new/apps/web/src/lib/components/Widgets.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
/>
2828
<Ram ram={report.Hardware.Ram} pagefile={report.System.PageFile}/>
2929
<Gpu gpus={report.Hardware.Gpu} monitors={report.Hardware.Monitors} />
30-
30+
<Nic nic={report.Network.Adapters} />
3131
<!--
3232
<OS securityData={rawJSON.Security} basicinfoData={rawJSON.BasicInfo} />
33-
<NIC nicData={rawJSON.Network.Adapters} /> -->
33+
-->
3434
</div>
3535

3636
<div class="widgets">

new/apps/web/src/lib/components/widgets/Nic.svelte

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,81 @@
22
<script lang="ts">
33
import Widget from '../../common/ModalWidget.svelte';
44
5-
export let nicData: any;
5+
interface NicInfo {
6+
DefaultIPGateway: Array<string>;
7+
Description: string;
8+
DHCPEnabled: boolean;
9+
DHCPLeaseExpires: string;
10+
DHCPLeaseObtained: string;
11+
DHCPServer: string;
12+
DNSDomain: null,
13+
DNSDomainSuffixSearchOrder: Array<string>;
14+
DNSHostName: string;
15+
DNSServerSearchOrder: Array<string>;
16+
InterfaceIndex: number;
17+
IPAddress: Array<string>;
18+
IPEnabled: boolean;
19+
IPSubnet: Array<string>;
20+
MACAddress: string;
21+
LinkSpeed: number;
22+
PhysicalAdapter: boolean;
23+
FullDuplex: boolean;
24+
MediaConnectState: number;
25+
MediaDuplexState: number;
26+
MtuSize: number;
27+
Name: string;
28+
OperationalStatusDownMediaDisconnected: boolean;
29+
PermanentAddress: string;
30+
PromiscuousMode: boolean;
31+
State: number;
32+
DNSIPV6: string;
33+
DNSIsStatic: boolean;
34+
}
35+
36+
interface Props {
37+
nics: Array<NicInfo>;
38+
}
39+
40+
let {
41+
nics
42+
}: Props = $props();
43+
44+
function findPrimaryAdapter(nics: Array<NicInfo>): string {
45+
let physicalAdapters: Array<string> = [];
646
7-
function findNic() {
8-
let nicText = '';
9-
nicData.forEach((adapter: any, _: any) => {
47+
nics.forEach((adapter: NicInfo, _: any) => {
48+
// if adapter is *physical*, AND has a determined IP address
1049
if (adapter.PhysicalAdapter && adapter.IPAddress) {
11-
if (Object.values(adapter.IPAddress).length > 0) nicText = adapter.Description;
50+
if (adapter.IPAddress.length > 0) {
51+
return adapter.Description;
52+
};
1253
}
13-
});
1454
15-
nicData.forEach((_: string, adapter: Record<string, any>) => {
16-
if (adapter.PhysicalAdapter) nicText = adapter.Description;
55+
// identify and push physical adapters here, so we dont have to .forEach() the list later
56+
if (adapter.PhysicalAdapter) physicalAdapters.push(adapter.Description);
1757
});
1858
19-
if (nicText == '') {
20-
return 'Disconnected';
21-
} else {
22-
return nicText;
59+
// if there are none with an assigned IP address, but there are physical adapters,
60+
// return the first in the array
61+
if (physicalAdapters.length > 0){
62+
return physicalAdapters[0];
2363
}
64+
65+
return 'Disconnected';
2466
}
2567
</script>
2668

27-
<!-- NIC -->
69+
<!-- NICs -->
2870

29-
<Widget title="NIC" modalId="nic-modal">
30-
<div slot="values">
71+
<Widget title="NIC">
72+
{#snippet widgetContents()}
3173
<div class="widget-value">
32-
<div class="green">
33-
{findNic()}
34-
</div>
74+
<span>{findPrimaryAdapter(nics)}</span>
3575
</div>
36-
</div>
76+
{/snippet}
3777

38-
<div slot="modal-body">
39-
{#each nicData as adapter}
78+
{#snippet modalContents()}
79+
{#each nics as adapter}
4080
<table class="table nic">
4181
<tbody>
4282
<tr>
@@ -121,7 +161,7 @@
121161
</tr>
122162
<tr>
123163
<td>Physical Adapter?</td>
124-
<td>{adapter.PhysicalAdapter ?? 'unknown'}</td>
164+
<td>{adapter.PhysicalAdapter ?? 'Unknown'}</td>
125165
</tr>
126166
{#if adapter.LinkSpeed}
127167
<tr>
@@ -145,12 +185,6 @@
145185
<td>{adapter.DNSIsStatic}</td>
146186
</tr>
147187
{/if}
148-
{#if adapter.DNSIsStatic}
149-
<tr>
150-
<td>Is DNS Static?</td>
151-
<td>{adapter.DNSIsStatic}</td>
152-
</tr>
153-
{/if}
154188
{#if adapter.PhysicalAdapter}
155189
<tr>
156190
<td>Full Duplex?</td>
@@ -192,5 +226,16 @@
192226
</tbody>
193227
</table>
194228
{/each}
195-
</div>
229+
{/snippet}
196230
</Widget>
231+
232+
<style>
233+
span {
234+
color: var(--color-secondary-50);
235+
}
236+
237+
div {
238+
color: var(--color-surface-300);
239+
font-size: 13pt;
240+
}
241+
</style>

0 commit comments

Comments
 (0)