Skip to content

Commit 4af68ff

Browse files
committed
Show current configuration in config view, allow single dns server in config
1 parent 63bc690 commit 4af68ff

6 files changed

Lines changed: 81 additions & 50 deletions

File tree

‎Source/NETworkManager/Models/Network/NetworkInterface.cs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.Win32;
2+
using System;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.Diagnostics;
@@ -81,6 +82,10 @@ public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
8182
listDhcpServer.Add(dhcpServerIPAddress);
8283
}
8384

85+
// Check if autoconfiguration for dns is enabled (only via registry key)
86+
RegistryKey nameServerKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{0}", networkInterface.Id));
87+
bool dnsAutoconfigurationEnabled = string.IsNullOrEmpty(nameServerKey.GetValue("NameServer").ToString());
88+
8489
List<IPAddress> listDnsServer = new List<IPAddress>();
8590

8691
foreach (IPAddress dnsServerIPAddress in networkInterface.GetIPProperties().DnsAddresses)
@@ -101,13 +106,14 @@ public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
101106
IPv4Address = listIPv4Address.ToArray(),
102107
Subnetmask = listSubnetmask.ToArray(),
103108
IPv4Gateway = listIPv4Gateway.ToArray(),
104-
IsDhcpEnabled = networkInterface.GetIPProperties().GetIPv4Properties().IsDhcpEnabled,
109+
DhcpEnabled = networkInterface.GetIPProperties().GetIPv4Properties().IsDhcpEnabled,
105110
DhcpServer = listDhcpServer.ToArray(),
106111
DhcpLeaseObtained = dhcpLeaseObtained,
107112
DhcpLeaseExpires = dhcpLeaseExpires,
108113
IPv6AddressLinkLocal = listIPv6AddressLinkLocal.ToArray(),
109114
IPv6Address = listIPv6Address.ToArray(),
110115
IPv6Gateway = listIPv6Gateway.ToArray(),
116+
DnsAutoconfigurationEnabled = dnsAutoconfigurationEnabled,
111117
DnsSuffix = networkInterface.GetIPProperties().DnsSuffix,
112118
DnsServer = listDnsServer.ToArray()
113119
});
@@ -132,6 +138,8 @@ public void ConfigureNetworkInterface(NetworkInterfaceConfig config)
132138
command += config.EnableStaticDns ? string.Format("source=static address={0} register=primary validate=no", config.PrimaryDnsServer) : "source=dhcp";
133139
command += (config.EnableStaticDns && !string.IsNullOrEmpty(config.SecondaryDnsServer)) ? string.Format(";netsh interface ipv4 add dnsservers name=\"{0}\" address={1} index=2 validate=no", config.Name, config.SecondaryDnsServer) : "";
134140

141+
MessageBox.Show(command);
142+
135143
// Start process with elevated rights...
136144
ProcessStartInfo processStartInfo = new ProcessStartInfo();
137145
processStartInfo.Verb = "runas";

‎Source/NETworkManager/Models/Network/NetworkInterfaceInfo.cs‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,20 @@ public class NetworkInterfaceInfo
1717
public IPAddress[] IPv4Address { get; set; }
1818
public IPAddress[] Subnetmask { get; set; }
1919
public IPAddress[] IPv4Gateway { get; set; }
20-
public bool IsDhcpEnabled { get; set; }
20+
public bool DhcpEnabled { get; set; }
2121
public IPAddress[] DhcpServer { get; set; }
2222
public DateTime DhcpLeaseObtained { get; set; }
2323
public DateTime DhcpLeaseExpires { get; set; }
2424
public IPAddress[] IPv6Address { get; set; }
2525
public IPAddress[] IPv6AddressLinkLocal { get; set; }
2626
public IPAddress[] IPv6Gateway { get; set; }
27+
public bool DnsAutoconfigurationEnabled { get; set; }
2728
public string DnsSuffix { get; set; }
2829
public IPAddress[] DnsServer { get; set; }
2930

3031
public NetworkInterfaceInfo()
3132
{
3233

3334
}
34-
35-
public NetworkInterfaceInfo(string id, string name, string description, string type, PhysicalAddress physicalAddress, OperationalStatus status, bool isOperational, long speed, IPAddress[] ipv4Address, IPAddress[] subnetmask, IPAddress[] ipv4Gateway, bool isDhcpEnabled, IPAddress[] dhcpServer, DateTime dhcpLeaseObtained, DateTime dhcpLeaseExpires, IPAddress[] ipv6AddressLinkLocal, IPAddress[] ipv6Address, IPAddress[] ipv6Gateway, string dnsSuffix, IPAddress[] dnsServer)
36-
{
37-
Id = id;
38-
Name = name;
39-
Description = description;
40-
Type = type;
41-
PhysicalAddress = physicalAddress;
42-
Status = status;
43-
IsOperational = isOperational;
44-
Speed = Speed;
45-
IPv4Address = ipv4Address;
46-
Subnetmask = subnetmask;
47-
IPv4Gateway = ipv4Gateway;
48-
IsDhcpEnabled = isDhcpEnabled;
49-
DhcpServer = dhcpServer;
50-
DhcpLeaseObtained = dhcpLeaseObtained;
51-
DhcpLeaseExpires = dhcpLeaseExpires;
52-
IPv6AddressLinkLocal = ipv6AddressLinkLocal;
53-
IPv6Address = ipv6Address;
54-
IPv6Gateway = ipv6Gateway;
55-
DnsSuffix = dnsSuffix;
56-
DnsServer = dnsServer;
57-
}
5835
}
5936
}

‎Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
<system:String x:Key="String_Backup">Sicherung</system:String>
213213
<system:String x:Key="String_MultipleInstances">Mehrere Instanzen</system:String>
214214
<system:String x:Key="String_ConnectTheNetworkCardToConfigureIt">Verbinde die Netzwerkkarte mit einem Netzwerk, um diese zu konfigurieren!</system:String>
215+
<system:String x:Key="String_DNSAutoconfiguration">DNS Autkonfiguration</system:String>
215216

216217
<!-- Buttons -->
217218
<system:String x:Key="String_Button_Change">Wechseln</system:String>

‎Source/NETworkManager/Resources/Localization/Resources.en-US.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
<system:String x:Key="String_Backup">Backup</system:String>
213213
<system:String x:Key="String_MultipleInstances">Multiple instances</system:String>
214214
<system:String x:Key="String_ConnectTheNetworkCardToConfigureIt">Connect the network card to a network to configure it!</system:String>
215+
<system:String x:Key="String_DNSAutoconfiguration">DNS Autconfiguration</system:String>
215216

216217
<!-- Buttons -->
217218
<system:String x:Key="String_Button_Change">Change</system:String>

‎Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs‎

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface
112112
if (!_isLoading)
113113
SettingsManager.Current.NetworkInterface_SelectedInterfaceId = value.Id;
114114

115+
// Details
115116
DetailsName = value.Name;
116117
DetailsDescription = value.Description;
117118
DetailsType = value.Type;
@@ -121,16 +122,43 @@ public NetworkInterfaceInfo SelectedNetworkInterface
121122
DetailsIPv4Address = value.IPv4Address;
122123
DetailsSubnetmask = value.Subnetmask;
123124
DetailsIPv4Gateway = value.IPv4Gateway;
124-
DetailsIsIPv4DhcpEnabled = value.IsDhcpEnabled;
125-
DetailsIsIPv4DhcpServer = value.DhcpServer;
125+
DetailsIPv4DhcpEnabled = value.DhcpEnabled;
126+
DetailsIPv4DhcpServer = value.DhcpServer;
126127
DetailsDhcpLeaseObtained = value.DhcpLeaseObtained;
127128
DetailsDhcpLeaseExpires = value.DhcpLeaseExpires;
128129
DetailsIPv6AddressLinkLocal = value.IPv6AddressLinkLocal;
129130
DetailsIPv6Address = value.IPv6Address;
130131
DetailsIPv6Gateway = value.IPv6Gateway;
132+
DetailsDnsAutoconfigurationEnabled = value.DnsAutoconfigurationEnabled;
131133
DetailsDnsSuffix = value.DnsSuffix;
132134
DetailsDnsServer = value.DnsServer;
133135

136+
// Configuration
137+
if(value.DhcpEnabled)
138+
{
139+
ConfigEnableDynamicIPAddress = true;
140+
}
141+
else
142+
{
143+
ConfigEnableStaticIPAddress = true;
144+
ConfigIPAddress = value.IPv4Address.FirstOrDefault().ToString();
145+
ConfigSubnetmaskOrCidr = value.Subnetmask.FirstOrDefault().ToString();
146+
ConfigGateway = value.IPv4Gateway.FirstOrDefault().ToString();
147+
}
148+
149+
if(value.DnsAutoconfigurationEnabled)
150+
{
151+
ConfigEnableDynamicDns = true;
152+
}
153+
else
154+
{
155+
ConfigEnableStaticDns = true;
156+
157+
List<IPAddress> dnsServers = value.DnsServer.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToList();
158+
ConfigPrimaryDnsServer = dnsServers.Count > 0 ? dnsServers[0].ToString() : string.Empty ;
159+
ConfigSecondaryDnsServer = dnsServers.Count > 1 ? dnsServers[1].ToString() : string.Empty;
160+
}
161+
134162
CanConfigure = value.IsOperational;
135163
}
136164

@@ -267,30 +295,30 @@ public IPAddress[] DetailsIPv4Gateway
267295
}
268296
}
269297

270-
private bool _detailsIsIPv4DhcpEnabled;
271-
public bool DetailsIsIPv4DhcpEnabled
298+
private bool _detailsIPv4DhcpEnabled;
299+
public bool DetailsIPv4DhcpEnabled
272300
{
273-
get { return _detailsIsIPv4DhcpEnabled; }
301+
get { return _detailsIPv4DhcpEnabled; }
274302
set
275303
{
276-
if (value == _detailsIsIPv4DhcpEnabled)
304+
if (value == _detailsIPv4DhcpEnabled)
277305
return;
278306

279-
_detailsIsIPv4DhcpEnabled = value;
307+
_detailsIPv4DhcpEnabled = value;
280308
OnPropertyChanged();
281309
}
282310
}
283311

284-
private IPAddress[] _detailsIsIPv4DhcpServer;
285-
public IPAddress[] DetailsIsIPv4DhcpServer
312+
private IPAddress[] _detailsIPv4DhcpServer;
313+
public IPAddress[] DetailsIPv4DhcpServer
286314
{
287-
get { return _detailsIsIPv4DhcpServer; }
315+
get { return _detailsIPv4DhcpServer; }
288316
set
289317
{
290-
if (value == _detailsIsIPv4DhcpServer)
318+
if (value == _detailsIPv4DhcpServer)
291319
return;
292320

293-
_detailsIsIPv4DhcpServer = value;
321+
_detailsIPv4DhcpServer = value;
294322
OnPropertyChanged();
295323
}
296324
}
@@ -366,6 +394,20 @@ public IPAddress[] DetailsIPv6Gateway
366394
}
367395
}
368396

397+
private bool _detailsDnsAutoconfigurationEnabled;
398+
public bool DetailsDnsAutoconfigurationEnabled
399+
{
400+
get { return _detailsDnsAutoconfigurationEnabled; }
401+
set
402+
{
403+
if (value == _detailsDnsAutoconfigurationEnabled)
404+
return;
405+
406+
_detailsDnsAutoconfigurationEnabled = value;
407+
OnPropertyChanged();
408+
}
409+
}
410+
369411
private string _detailsDnsSuffix;
370412
public string DetailsDnsSuffix
371413
{
@@ -594,7 +636,7 @@ public NetworkInterfaceViewModel(IDialogCoordinator instance)
594636

595637
_isLoading = false;
596638
}
597-
639+
598640
private async void LoadNetworkInterfaces()
599641
{
600642
IsNetworkInterfaceLoading = true;
@@ -680,7 +722,7 @@ public async void ApplyNetworkInterfaceConfigAction()
680722
};
681723

682724
try
683-
{
725+
{
684726
Models.Network.NetworkInterface networkInterface = new Models.Network.NetworkInterface();
685727

686728
networkInterface.UserHasCanceled += NetworkInterface_UserHasCanceled;

‎Source/NETworkManager/Views/Applications/NetworkInterfaceView.xaml‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<RowDefinition Height="Auto" />
149149
<RowDefinition Height="Auto" />
150150
<RowDefinition Height="Auto" />
151+
<RowDefinition Height="Auto" />
151152
</Grid.RowDefinitions>
152153
<GridSplitter Grid.Column="1" Grid.RowSpan="18" Background="Transparent" HorizontalAlignment="Stretch" Focusable="False" />
153154
<TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_Name}" />
@@ -169,9 +170,9 @@
169170
<TextBlock Grid.Column="0" Grid.Row="8" Text="{DynamicResource String_IPv4DefaultGateway}" />
170171
<TextBox Grid.Column="2" Grid.Row="8" Text="{Binding DetailsIPv4Gateway, Converter={StaticResource IPAddressArrayToStringConverter}}" />
171172
<TextBlock Grid.Column="0" Grid.Row="9" Text="{DynamicResource String_DHCPEnabled}" />
172-
<TextBox Grid.Column="2" Grid.Row="9" Text="{Binding DetailsIsIPv4DhcpEnabled, Converter={StaticResource TrueFalseToStringConverter}}" />
173+
<TextBox Grid.Column="2" Grid.Row="9" Text="{Binding DetailsIPv4DhcpEnabled, Converter={StaticResource TrueFalseToStringConverter}}" />
173174
<TextBlock Grid.Column="0" Grid.Row="10" Text="{DynamicResource String_DHCPServer}" />
174-
<TextBox Grid.Column="2" Grid.Row="10" Text="{Binding DetailsIsIPv4DhcpServer, Converter={StaticResource IPAddressArrayToStringConverter}}" />
175+
<TextBox Grid.Column="2" Grid.Row="10" Text="{Binding DetailsIPv4DhcpServer, Converter={StaticResource IPAddressArrayToStringConverter}}" />
175176
<TextBlock Grid.Column="0" Grid.Row="11" Text="{DynamicResource String_DHCPLeaseObtained}" />
176177
<TextBox Grid.Column="2" Grid.Row="11" Text="{Binding DetailsDhcpLeaseObtained}" />
177178
<TextBlock Grid.Column="0" Grid.Row="12" Text="{DynamicResource String_DHCPLeaseExpires}" />
@@ -181,11 +182,13 @@
181182
<TextBlock Grid.Column="0" Grid.Row="14" Text="{DynamicResource String_IPv6Address}" />
182183
<TextBox Grid.Column="2" Grid.Row="14" Text="{Binding DetailsIPv6Address, Converter={StaticResource IPAddressArrayToStringConverter}}" />
183184
<TextBlock Grid.Column="0" Grid.Row="15" Text="{DynamicResource String_IPv6DefaultGateway}" />
184-
<TextBox Grid.Column="2" Grid.Row="15" Text="{Binding DetailsIPv6Gateway, Converter={StaticResource IPAddressArrayToStringConverter}}" />
185-
<TextBlock Grid.Column="0" Grid.Row="16" Text="{DynamicResource String_DNSSuffix}" />
186-
<TextBox Grid.Column="2" Grid.Row="16" Text="{Binding DetailsDnsSuffix}" />
187-
<TextBlock Grid.Column="0" Grid.Row="17" Text="{DynamicResource String_DNSServers}" Margin="0,0,10,0" />
188-
<TextBox Grid.Column="2" Grid.Row="17" Text="{Binding DetailsDnsServer, Converter={StaticResource IPAddressArrayToStringConverter}}" Margin="0,0,10,0" />
185+
<TextBox Grid.Column="2" Grid.Row="15" Text="{Binding DetailsIPv6Gateway , Converter={StaticResource IPAddressArrayToStringConverter}}" />
186+
<TextBlock Grid.Column="0" Grid.Row="16" Text="{DynamicResource String_DNSAutoconfiguration}" />
187+
<TextBox Grid.Column="2" Grid.Row="16" Text="{Binding DetailsDnsAutoconfigurationEnabled, Converter={StaticResource TrueFalseToStringConverter}}" />
188+
<TextBlock Grid.Column="0" Grid.Row="17" Text="{DynamicResource String_DNSSuffix}" />
189+
<TextBox Grid.Column="2" Grid.Row="17" Text="{Binding DetailsDnsSuffix}" />
190+
<TextBlock Grid.Column="0" Grid.Row="18" Text="{DynamicResource String_DNSServers}" Margin="0,0,10,0" />
191+
<TextBox Grid.Column="2" Grid.Row="18" Text="{Binding DetailsDnsServer, Converter={StaticResource IPAddressArrayToStringConverter}}" Margin="0,0,10,0" />
189192
</Grid>
190193
</ScrollViewer>
191194
</Grid>
@@ -385,8 +388,7 @@
385388
<TextBox.Text>
386389
<Binding Path="ConfigSecondaryDnsServer" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
387390
<Binding.ValidationRules>
388-
<Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
389-
<Validator:IPv4AddressValidator ValidatesOnTargetUpdated="True" />
391+
<Validator:EmptyOrIPv4AddressValidator ValidatesOnTargetUpdated="True" />
390392
</Binding.ValidationRules>
391393
</Binding>
392394
</TextBox.Text>

0 commit comments

Comments
 (0)