Skip to content

Commit 9d7fd69

Browse files
committed
Feature: Firewall
1 parent 804e874 commit 9d7fd69

14 files changed

Lines changed: 410 additions & 1124 deletions
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
1-
using System.ComponentModel;
1+
using System.ComponentModel;
22
using System.Windows.Input;
33

44
namespace NETworkManager.Profiles;
55

6+
/// <summary>
7+
/// Interface for a full profile manager view model, extending <see cref="IProfileManagerMinimal"/>
8+
/// with profile collection access and profile/group management commands.
9+
/// </summary>
610
public interface IProfileManager : IProfileManagerMinimal
711
{
12+
/// <summary>
13+
/// Gets the filtered and sorted view of the profiles collection.
14+
/// </summary>
815
ICollectionView Profiles { get; }
16+
17+
/// <summary>
18+
/// Gets the command to add a new profile.
19+
/// </summary>
920
ICommand AddProfileCommand { get; }
21+
22+
/// <summary>
23+
/// Gets the command to edit the selected profile.
24+
/// </summary>
1025
ICommand EditProfileCommand { get; }
26+
27+
/// <summary>
28+
/// Gets the command to create a copy of the selected profile as a new profile.
29+
/// </summary>
1130
ICommand CopyAsProfileCommand { get; }
31+
32+
/// <summary>
33+
/// Gets the command to delete the selected profile.
34+
/// </summary>
1235
ICommand DeleteProfileCommand { get; }
36+
37+
/// <summary>
38+
/// Gets the command to edit the group of the selected profile.
39+
/// </summary>
1340
ICommand EditGroupCommand { get; }
1441
}

Source/NETworkManager.Profiles/IProfileManagerMinimal.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
namespace NETworkManager.Profiles;
22

33
/// <summary>
4-
/// Interface for the profile manager.
5-
/// Minimal implementation to get the view model.
4+
/// Minimal interface for the profile manager, providing lifecycle callbacks
5+
/// for when a <see cref="ProfileManager" /> dialog is opened or closed.
66
/// </summary>
77
public interface IProfileManagerMinimal
88
{
99
/// <summary>
10-
/// Event is fired when a dialog in the <see cref="ProfileManager" /> is opened.
10+
/// Called when a dialog in the <see cref="ProfileManager" /> is opened.
1111
/// </summary>
1212
public void OnProfileManagerDialogOpen()
1313
{
1414

1515
}
1616

1717
/// <summary>
18-
/// Event is fired when a dialog in the <see cref="ProfileManager" /> is closed.
18+
/// Called when a dialog in the <see cref="ProfileManager" /> is closed.
1919
/// </summary>
2020
public void OnProfileManagerDialogClose()
2121
{

Source/NETworkManager.Utilities/ExternalProcessStarter.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace NETworkManager.Utilities;
44

5+
/// <summary>
6+
/// Provides helper methods for starting external processes and opening URLs.
7+
/// </summary>
58
public static class ExternalProcessStarter
69
{
710
/// <summary>
8-
/// Open an url with the default browser.
11+
/// Open a url with the default browser.
912
/// </summary>
1013
/// <param name="url">Url like: https://github.com/BornToBeRoot</param>
1114
public static void OpenUrl(string url)
@@ -16,11 +19,22 @@ public static void OpenUrl(string url)
1619
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
1720
}
1821

22+
/// <summary>
23+
/// Starts an external process by filename.
24+
/// </summary>
25+
/// <param name="filename">The name or path of the executable to run (e.g. "WF.msc").</param>
26+
/// <param name="asAdmin">If <c>true</c>, the process is started with elevated privileges via UAC.</param>
1927
public static void RunProcess(string filename, bool asAdmin = false)
2028
{
2129
RunProcess(filename, null, asAdmin);
2230
}
2331

32+
/// <summary>
33+
/// Starts an external process by filename with optional arguments.
34+
/// </summary>
35+
/// <param name="filename">The name or path of the executable to run.</param>
36+
/// <param name="arguments">Optional command-line arguments to pass to the process.</param>
37+
/// <param name="asAdmin">If <c>true</c>, the process is started with elevated privileges via UAC.</param>
2438
public static void RunProcess(string filename, string arguments, bool asAdmin = false)
2539
{
2640
ProcessStartInfo info = new()

Source/NETworkManager/Controls/FirewallRuleGrid.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ private void DataGridRow_PreviewKeyDown(object sender, KeyEventArgs e)
207207
switch (e.Key)
208208
{
209209
case Key.A when Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl):
210-
dataContext.ApplyConfigurationCommand.Execute(null);
210+
//dataContext.ApplyConfigurationCommand.Execute(null);
211211
e.Handled = true;
212212
break;
213213
case Key.D when Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl):
214214
case Key.Delete:
215215
int index = RuleGrid.SelectedIndex;
216-
dataContext.DeleteRulesCommand.Execute(null);
216+
//dataContext.DeleteRulesCommand.Execute(null);
217217
if (grid.HasItems)
218218
{
219219
// Select the same index or the last item if we deleted the end
@@ -229,16 +229,16 @@ private void DataGridRow_PreviewKeyDown(object sender, KeyEventArgs e)
229229
case Key.C when (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
230230
&& (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
231231
&& (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)):
232-
FirewallViewModel.DeleteWindowsRulesCommand.Execute(null);
232+
// FirewallViewModel.DeleteWindowsRulesCommand.Execute(null);
233233
e.Handled = true;
234234
break;
235235
case Key.C when (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
236236
&& (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)):
237-
dataContext.DeleteAllRulesCommand.Execute(null);
237+
//dataContext.DeleteAllRulesCommand.Execute(null);
238238
e.Handled = true;
239239
break;
240240
case Key.N when Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl):
241-
dataContext.AddRuleCommand.Execute(null);
241+
//dataContext.AddRuleCommand.Execute(null);
242242
e.Handled = true;
243243
break;
244244
case Key.Right when row?.DetailsVisibility == Visibility.Collapsed:
@@ -271,7 +271,7 @@ private void DataGridRow_PreviewKeyDown(object sender, KeyEventArgs e)
271271
grid.UpdateLayout();
272272
row = grid.ItemContainerGenerator.ContainerFromIndex(grid.SelectedIndex) as DataGridRow;
273273
var viewModel = grid.DataContext as FirewallViewModel;
274-
viewModel?.SelectedRule = item;
274+
//viewModel?.SelectedRule = item;
275275
}
276276
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(grid), null);
277277
Keyboard.ClearFocus();
@@ -284,7 +284,7 @@ private void DataGridRow_PreviewKeyDown(object sender, KeyEventArgs e)
284284
e.Handled = true;
285285
break;
286286
case Key.W when Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl):
287-
dataContext.OpenWindowsFirewallCommand.Execute(null);
287+
//dataContext.OpenWindowsFirewallCommand.Execute(null);
288288
e.Handled = true;
289289
break;
290290
}

Source/NETworkManager/ProfileDialogManager.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ private static ProfileInfo ParseProfileInfo(ProfileViewModel instance)
254254
? instance.SNMP_Priv
255255
: new SecureString(),
256256

257+
// Firewall
258+
Firewall_Enabled = instance.Firewall_Enabled,
259+
257260
// Wake on LAN
258261
WakeOnLAN_Enabled = instance.WakeOnLAN_Enabled,
259262
WakeOnLAN_MACAddress = instance.WakeOnLAN_MACAddress?.Trim(),
@@ -270,10 +273,6 @@ private static ProfileInfo ParseProfileInfo(ProfileViewModel instance)
270273
IPGeolocation_Host = instance.IPGeolocation_InheritHost
271274
? instance.Host?.Trim()
272275
: instance.IPGeolocation_Host?.Trim(),
273-
274-
// Firewall
275-
Firewall_Enabled = instance.Firewall_Enabled,
276-
Firewall_Rules = instance.GetFirewallRules()
277276
};
278277
}
279278

0 commit comments

Comments
 (0)