Skip to content

Commit eafcc0e

Browse files
BornToBeRootCopilotCopilot
authored
Feature: Firewall app (#3383)
* Feature: Firewall app * Update Source/NETworkManager.Models/Firewall/FirewallRule.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix XML doc comments for Id/Name properties in FirewallRule.cs Agent-Logs-Url: https://github.com/BornToBeRoot/NETworkManager/sessions/5215e397-497d-4847-a3f7-a7454cafebb3 Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> * Feature: Add translation * Feature: Add translation and export * Feature: Add network profile to networkinterfaceview * Docs: #3383 * Chore: Hide firewall settings/profile * Chore: Refactor the UI * Feature: UI & Copy data * Chore: UI redesign * Docs: Discovery Protocol * Update package.json * Update yarn.lock * Feature: Enable/Disable/Delete Firewall rule * Feature: Open Hosts File Editor * Feature: Firewall add / edit firewall rule * Chore: Adjust strings * Feature: Firewall edit/del + docs * Fix: Copilot feedback * Fix: More firewall validations * dotnet format * Update firewall.md --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent b185208 commit eafcc0e

66 files changed

Lines changed: 4592 additions & 936 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Localization;
5+
using NETworkManager.Models.Firewall;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert <see cref="FirewallInterfaceType" /> to translated <see cref="string" /> or vice versa.
11+
/// </summary>
12+
public sealed class FirewallInterfaceTypeToStringConverter : IValueConverter
13+
{
14+
/// <summary>
15+
/// Convert <see cref="FirewallInterfaceType" /> to translated <see cref="string" />.
16+
/// </summary>
17+
/// <param name="value">Object from type <see cref="FirewallInterfaceType" />.</param>
18+
/// <param name="targetType"></param>
19+
/// <param name="parameter"></param>
20+
/// <param name="culture"></param>
21+
/// <returns>Translated <see cref="FirewallInterfaceType" />.</returns>
22+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
23+
{
24+
return value is not FirewallInterfaceType interfaceType
25+
? "-/-"
26+
: ResourceTranslator.Translate(ResourceIdentifier.FirewallInterfaceType, interfaceType);
27+
}
28+
29+
/// <summary>
30+
/// !!! Method not implemented !!!
31+
/// </summary>
32+
/// <param name="value"></param>
33+
/// <param name="targetType"></param>
34+
/// <param name="parameter"></param>
35+
/// <param name="culture"></param>
36+
/// <returns></returns>
37+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
38+
{
39+
throw new NotImplementedException();
40+
}
41+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
using NETworkManager.Localization.Resources;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert a <see cref="bool" /> array (Domain, Private, Public) representing firewall network
11+
/// profiles to a localized <see cref="string" />, or vice versa.
12+
/// </summary>
13+
public sealed class FirewallNetworkProfilesToStringConverter : IValueConverter
14+
{
15+
/// <summary>
16+
/// Convert a <see cref="bool" /> array (Domain, Private, Public) to a localized <see cref="string" />.
17+
/// Returns the localized "Any" label when all three profiles are active or none are active,
18+
/// since both cases are treated as "Any" by the Windows Firewall PowerShell layer.
19+
/// </summary>
20+
/// <param name="value">A <see cref="bool" /> array with exactly three elements.</param>
21+
/// <param name="targetType"></param>
22+
/// <param name="parameter"></param>
23+
/// <param name="culture"></param>
24+
/// <returns>Localized, comma-separated profile list (e.g. "Domain, Private, Public"), or "Any".</returns>
25+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
26+
{
27+
if (value is not bool[] { Length: 3 } profiles)
28+
return "-/-";
29+
30+
if ((profiles[0] && profiles[1] && profiles[2]) || (!profiles[0] && !profiles[1] && !profiles[2]))
31+
return Strings.Any;
32+
33+
var names = new List<string>(3);
34+
if (profiles[0]) names.Add(Strings.Domain);
35+
if (profiles[1]) names.Add(Strings.Private);
36+
if (profiles[2]) names.Add(Strings.Public);
37+
38+
return string.Join(", ", names);
39+
}
40+
41+
/// <summary>
42+
/// !!! Method not implemented !!!
43+
/// </summary>
44+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
45+
{
46+
throw new NotImplementedException();
47+
}
48+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Localization;
5+
using NETworkManager.Models.Firewall;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert <see cref="FirewallProtocol" /> to translated <see cref="string" /> or vice versa.
11+
/// </summary>
12+
public sealed class FirewallProtocolToStringConverter : IValueConverter
13+
{
14+
/// <summary>
15+
/// Convert <see cref="FirewallProtocol" /> to translated <see cref="string" />.
16+
/// </summary>
17+
/// <param name="value">Object from type <see cref="FirewallProtocol" />.</param>
18+
/// <param name="targetType"></param>
19+
/// <param name="parameter"></param>
20+
/// <param name="culture"></param>
21+
/// <returns>Translated <see cref="FirewallProtocol" />.</returns>
22+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
23+
{
24+
return value is not FirewallProtocol protocol
25+
? "-/-"
26+
: ResourceTranslator.Translate(ResourceIdentifier.FirewallProtocol, protocol);
27+
}
28+
29+
/// <summary>
30+
/// !!! Method not implemented !!!
31+
/// </summary>
32+
/// <param name="value"></param>
33+
/// <param name="targetType"></param>
34+
/// <param name="parameter"></param>
35+
/// <param name="culture"></param>
36+
/// <returns></returns>
37+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
38+
{
39+
throw new NotImplementedException();
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Localization;
5+
using NETworkManager.Models.Firewall;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert <see cref="FirewallRuleAction" /> to translated <see cref="string" /> or vice versa.
11+
/// </summary>
12+
public sealed class FirewallRuleActionToStringConverter : IValueConverter
13+
{
14+
/// <summary>
15+
/// Convert <see cref="FirewallRuleAction" /> to translated <see cref="string" />.
16+
/// </summary>
17+
/// <param name="value">Object from type <see cref="FirewallRuleAction" />.</param>
18+
/// <param name="targetType"></param>
19+
/// <param name="parameter"></param>
20+
/// <param name="culture"></param>
21+
/// <returns>Translated <see cref="FirewallRuleAction" />.</returns>
22+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
23+
{
24+
return value is not FirewallRuleAction action
25+
? "-/-"
26+
: ResourceTranslator.Translate(ResourceIdentifier.FirewallRuleAction, action);
27+
}
28+
29+
/// <summary>
30+
/// !!! Method not implemented !!!
31+
/// </summary>
32+
/// <param name="value"></param>
33+
/// <param name="targetType"></param>
34+
/// <param name="parameter"></param>
35+
/// <param name="culture"></param>
36+
/// <returns></returns>
37+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
38+
{
39+
throw new NotImplementedException();
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Localization;
5+
using NETworkManager.Models.Firewall;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert <see cref="FirewallRuleDirection" /> to translated <see cref="string" /> or vice versa.
11+
/// </summary>
12+
public sealed class FirewallRuleDirectionToStringConverter : IValueConverter
13+
{
14+
/// <summary>
15+
/// Convert <see cref="FirewallRuleDirection" /> to translated <see cref="string" />.
16+
/// </summary>
17+
/// <param name="value">Object from type <see cref="FirewallRuleDirection" />.</param>
18+
/// <param name="targetType"></param>
19+
/// <param name="parameter"></param>
20+
/// <param name="culture"></param>
21+
/// <returns>Translated <see cref="FirewallRuleDirection" />.</returns>
22+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
23+
{
24+
return value is not FirewallRuleDirection direction
25+
? "-/-"
26+
: ResourceTranslator.Translate(ResourceIdentifier.FirewallRuleDirection, direction);
27+
}
28+
29+
/// <summary>
30+
/// !!! Method not implemented !!!
31+
/// </summary>
32+
/// <param name="value"></param>
33+
/// <param name="targetType"></param>
34+
/// <param name="parameter"></param>
35+
/// <param name="culture"></param>
36+
/// <returns></returns>
37+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
38+
{
39+
throw new NotImplementedException();
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Localization.Resources;
5+
using NETworkManager.Models.Network;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert <see cref="NetworkProfile" /> to a localized <see cref="string" /> or vice versa.
11+
/// </summary>
12+
public sealed class NetworkProfileToStringConverter : IValueConverter
13+
{
14+
/// <summary>
15+
/// Convert <see cref="NetworkProfile" /> to a localized <see cref="string" />.
16+
/// </summary>
17+
/// <param name="value">Object from type <see cref="NetworkProfile" />.</param>
18+
/// <param name="targetType"></param>
19+
/// <param name="parameter"></param>
20+
/// <param name="culture"></param>
21+
/// <returns>Localized <see cref="string" /> representing the network profile.</returns>
22+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
23+
{
24+
return value is not NetworkProfile profile
25+
? "-/-"
26+
: profile switch
27+
{
28+
NetworkProfile.Domain => Strings.Domain,
29+
NetworkProfile.Private => Strings.Private,
30+
NetworkProfile.Public => Strings.Public,
31+
_ => "-/-"
32+
};
33+
}
34+
35+
/// <summary>
36+
/// !!! Method not implemented !!!
37+
/// </summary>
38+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
39+
{
40+
throw new NotImplementedException();
41+
}
42+
}

Source/NETworkManager.Documentation/DocumentationManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ public static DocumentationIdentifier GetIdentifierBySettingsName(SettingsName n
267267
SettingsName.WebConsole => GetIdentifierByApplicationName(ApplicationName.WebConsole),
268268
SettingsName.SNMP => GetIdentifierByApplicationName(ApplicationName.SNMP),
269269
SettingsName.SNTPLookup => GetIdentifierByApplicationName(ApplicationName.SNTPLookup),
270-
SettingsName.Firewall => GetIdentifierByApplicationName(ApplicationName.Firewall),
271270
SettingsName.WakeOnLAN => GetIdentifierByApplicationName(ApplicationName.WakeOnLAN),
272271
SettingsName.BitCalculator => GetIdentifierByApplicationName(ApplicationName.BitCalculator),
273272
_ => DocumentationIdentifier.Default

Source/NETworkManager.Localization/ResourceIdentifier.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ public enum ResourceIdentifier
2222
TcpState,
2323
Theme,
2424
TimeUnit,
25-
WiFiConnectionStatus
25+
WiFiConnectionStatus,
26+
FirewallProtocol,
27+
FirewallInterfaceType,
28+
FirewallRuleDirection,
29+
FirewallRuleAction
2630
}

Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/StaticStrings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,10 @@
342342
<data name="ExampleFqdnOrIPAddressPublic" xml:space="preserve">
343343
<value>borntoberoot.net or 1.1.1.1</value>
344344
</data>
345+
<data name="ExampleFirewallRuleName" xml:space="preserve">
346+
<value>MyApp - HTTP</value>
347+
</data>
348+
<data name="ExampleFirewallAddresses" xml:space="preserve">
349+
<value>10.0.0.0/8; LocalSubnet</value>
350+
</data>
345351
</root>

0 commit comments

Comments
 (0)