/// <summary> /// Creates a new general rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> // ReSharper disable once TooManyDependencies public FirewallWASRuleWin7( string name, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : base(name, action, direction, profiles) { }
/// <inheritdoc /> /// <summary> /// Creates a new port rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="port">Port number of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> // ReSharper disable once TooManyDependencies public FirewallWASRuleWin8( string name, ushort port, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : base(name, port, action, direction, profiles) { }
/// <summary> /// Creates a new application rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> public StandardRuleWin7(string name, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : base(name, action, direction, profiles) { if (UnderlyingObjectV2 == null) { throw new FirewallAPIv2NotSupportedException(); } }
/// <summary> /// Creates a new application rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> public StandardRule(string name, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) { UnderlyingObject = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID(@"HNetCfg.FWRule")); Name = name; Action = action; Direction = direction; IsEnable = true; Profiles = profiles; }
/// <summary> /// Creates a new general rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> // ReSharper disable once TooManyDependencies public FirewallWASRule( string name, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles ) : this(name, action, direction, profiles, new COMTypeResolver()) { }
/// <summary> /// Creates a new application rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="filename">Address of the executable file</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> // ReSharper disable once TooManyDependencies public FirewallWASRule( string name, string filename, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : this(name, action, direction, profiles) { ApplicationName = filename; }
public static void AddApplicationRule(string ruleName, string fileName, FirewallDirection direction, FirewallProtocol protocol) { if (Firewall.Instance.IsSupported) { if (StandardRuleWin8.IsSupported) { var rule = new StandardRuleWin8(ruleName, fileName, FirewallAction.Allow, direction, FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public) { Grouping = "Celeste Fan Project", Description = "Auto-generated rules by \"Celeste Fan Project Launcher\"", InterfaceTypes = FirewallInterfaceTypes.Lan | FirewallInterfaceTypes.RemoteAccess | FirewallInterfaceTypes.Wireless, Protocol = protocol }; //if (direction == FirewallDirection.Inbound && (protocol.Equals(FirewallProtocol.TCP) || protocol.Equals(FirewallProtocol.UDP))) // rule.EdgeTraversalOptions = EdgeTraversalAction.DefferToUser; Firewall.Instance.Rules.Add(rule); } else if (StandardRuleWin7.IsSupported) { var rule = new StandardRuleWin7(ruleName, fileName, FirewallAction.Allow, direction, FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public) { Grouping = "Celeste Fan Project", Description = "Auto-generated rules by \"Celeste Fan Project Launcher\"", InterfaceTypes = FirewallInterfaceTypes.Lan | FirewallInterfaceTypes.RemoteAccess | FirewallInterfaceTypes.Wireless, Protocol = protocol }; //if (direction == FirewallDirection.Inbound && (protocol.Equals(FirewallProtocol.TCP) || protocol.Equals(FirewallProtocol.UDP))) // rule.EdgeTraversalOptions = EdgeTraversalAction.DefferToUser; Firewall.Instance.Rules.Add(rule); } else { goto default_rule; } return; } default_rule: var defaultRule = FirewallManager.Instance.CreateApplicationRule( FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public, ruleName, FirewallAction.Allow, fileName, protocol); defaultRule.Direction = direction; FirewallManager.Instance.Rules.Add(defaultRule); }
/// <summary> /// Creates a new port rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="port">Port number of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> /// <param name="typeResolver">The COM+ object resolver</param> // ReSharper disable once TooManyDependencies public FirewallWASRuleWin8( string name, ushort port, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles, COMTypeResolver typeResolver ) : base(name, port, action, direction, profiles, typeResolver) { }
/// <summary> /// Creates a new application rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="filename">Address of the executable file</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> /// <param name="typeResolver">The COM+ object resolver</param> // ReSharper disable once TooManyDependencies public FirewallWASRuleWin7( string name, string filename, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles, COMTypeResolver typeResolver ) : base(name, filename, action, direction, profiles, typeResolver) { }
/// <summary> /// Creates a new port rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="port">Port number of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> public StandardRuleWin8(string name, ushort port, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : base(name, port, action, direction, profiles) { UnderlyingObjectV3 = UnderlyingObject as INetFwRule3; if (UnderlyingObjectV3 == null) { throw new FirewallAPIv2NotSupportedException(); } }
/// <summary> /// Creates a new port rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="port">Port number of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> // ReSharper disable once TooManyDependencies public FirewallWASRule( string name, ushort port, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : this(name, action, direction, profiles) { Protocol = FirewallProtocol.TCP; LocalPorts = new[] { port }; }
/// <summary> /// Creates a new application rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="filename">Address of the executable file</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> /// <param name="typeResolver">The COM+ object resolver</param> // ReSharper disable once TooManyDependencies public FirewallWASRule( string name, string filename, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles, COMTypeResolver typeResolver ) : this(name, action, direction, profiles, typeResolver) { ApplicationName = filename; }
private static void AddDefaultPortRule(string ruleName, ushort portNumber, FirewallDirection direction, FirewallProtocol protocol) { var defaultRule = FirewallManager.Instance.CreatePortRule( FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public, ruleName, FirewallAction.Allow, portNumber, protocol); defaultRule.Direction = direction; FirewallManager.Instance.Rules.Add(defaultRule); }
/// <summary> /// Creates a new general rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> // ReSharper disable once TooManyDependencies public FirewallWASRule( string name, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) : this(ComHelper.CreateInstance <INetFwRule>()) { Name = name; Action = action; Direction = direction; IsEnable = true; Profiles = profiles; }
private static IRule CreateFirewallRule(string action, FirewallDirection direction, string filename) { var file = new FileInfo(filename); var rule = FirewallManager.Instance.CreateApplicationRule( FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public, $"{action} {file.Name}", action == "Allow" ? FirewallAction.Allow : FirewallAction.Block, filename); rule.Direction = direction; return(rule); }
public static void AddPortRule(string ruleName, ushort portNumber, FirewallDirection direction, FirewallProtocol protocol) { if (Firewall.Instance.IsSupported) { if (StandardRuleWin8.IsSupported) { var rule = new StandardRuleWin8(ruleName, portNumber, FirewallAction.Allow, direction, FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public) { Grouping = "Celeste Fan Project", Description = "Auto-generated rules by \"Celeste Fan Project Launcher\"", InterfaceTypes = FirewallInterfaceTypes.Lan | FirewallInterfaceTypes.RemoteAccess | FirewallInterfaceTypes.Wireless, Protocol = protocol }; Firewall.Instance.Rules.Add(rule); } else if (StandardRuleWin7.IsSupported) { var rule = new StandardRuleWin7(ruleName, portNumber, FirewallAction.Allow, direction, FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public) { Grouping = "Celeste Fan Project", Description = "Auto-generated rules by \"Celeste Fan Project Launcher\"", InterfaceTypes = FirewallInterfaceTypes.Lan | FirewallInterfaceTypes.RemoteAccess | FirewallInterfaceTypes.Wireless, Protocol = protocol }; Firewall.Instance.Rules.Add(rule); } else { goto default_rule; } return; } default_rule: var defaultRule = FirewallManager.Instance.CreatePortRule( FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public, ruleName, FirewallAction.Allow, portNumber, protocol); defaultRule.Direction = direction; FirewallManager.Instance.Rules.Add(defaultRule); }
/// <summary> /// Creates a new general rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> /// <param name="typeResolver">The COM+ object resolver</param> // ReSharper disable once TooManyDependencies public FirewallWASRule( string name, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles, COMTypeResolver typeResolver ) : this(typeResolver.CreateInstance <INetFwRule>()) { Name = name; Action = action; Direction = direction; IsEnable = true; Profiles = profiles; }
/// <summary> /// Creates a new port rule for Windows Firewall with Advanced Security /// </summary> /// <param name="name">Name of the rule</param> /// <param name="port">Port number of the rule</param> /// <param name="action">Action that this rule defines</param> /// <param name="direction">Data direction in which this rule applies to</param> /// <param name="profiles">The profile that this rule belongs to</param> public StandardRule(string name, ushort port, FirewallAction action, FirewallDirection direction, FirewallProfiles profiles) { UnderlyingObject = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID(@"HNetCfg.FWRule")); Name = name; Action = action; Direction = direction; Protocol = FirewallProtocol.TCP; IsEnable = true; Profiles = profiles; if (direction == FirewallDirection.Inbound) { LocalPorts = new[] { port }; } else { RemotePorts = new[] { port }; } }
private static void AddDefaultApplicationRule(string ruleName, string fileName, FirewallDirection direction, FirewallProtocol protocol) { var defaultRule = FirewallManager.Instance.CreateApplicationRule( FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public, ruleName, FirewallAction.Allow, fileName, protocol); defaultRule.Direction = direction; FirewallManager.Instance.Rules.Add(defaultRule); }
public static void AddRule(String name, FirewallAction action, FirewallProtocol protocol, FirewallDirection direction , Int32[] localPorts, Int32[] remotePorts, String serviceName = null) { //Don't add if it already exists var policy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2")); if (policy.Rules.Cast <INetFwRule3>().Any(rule => rule.Name == name)) { return; } //Add new rule var newRule = (INetFwRule3)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule")); newRule.Enabled = true; newRule.Action = (NET_FW_ACTION_)action; newRule.Protocol = (Int32)protocol; if (localPorts != null) { newRule.LocalPorts = String.Join(",", localPorts); } if (remotePorts != null) { newRule.RemotePorts = String.Join(",", remotePorts); } newRule.Direction = (NET_FW_RULE_DIRECTION_)direction; if (serviceName != null) { newRule.serviceName = serviceName; } newRule.Name = name; //newRule.Grouping = group; newRule.Profiles = (Int32)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL; policy.Rules.Add(newRule); }
public static void AddApplicationRule(string nameOfApp, string localOfApp, string groupKey, string description, FirewallDirection direction, FirewallProtocol protocol, string firewallLogNote) { try { Log.Info("WINDOWS FIREWALL: Supported Firewall Found"); var rule = new FirewallWASRuleWin8(localOfApp, FirewallAction.Allow, direction, FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public) { ApplicationName = localOfApp, Name = nameOfApp, Grouping = groupKey, Description = description, NetworkInterfaceTypes = NetworkInterfaceTypes.Lan | NetworkInterfaceTypes.RemoteAccess | NetworkInterfaceTypes.Wireless, Protocol = protocol }; if (direction == FirewallDirection.Inbound) { rule.EdgeTraversalOptions = EdgeTraversalAction.Allow; } FirewallManager.Instance.Rules.Add(rule); Log.Info("WINDOWS FIREWALL: Finished Adding " + nameOfApp + " to Firewall! {" + firewallLogNote + "}"); } catch (FirewallWASNotSupportedException Error) { Log.Error("WINDOWS FIREWALL: " + Error.Message); AddDefaultApplicationRule(nameOfApp, localOfApp, direction, protocol, firewallLogNote); } }
public static void CheckIfRuleExists(bool removeFirewallRule, bool firstTimeRun, string nameOfApp, string localOfApp, string groupKey, string description, FirewallDirection direction, FirewallProtocol protocol, string firewallLogNote) { //Remove Firewall Rules if (removeFirewallRule == true && firstTimeRun == false) { RemoveRules(nameOfApp, firewallLogNote); } //Add Firewall Rules else if (removeFirewallRule == false && firstTimeRun == true) { AddApplicationRule(nameOfApp, localOfApp, groupKey, description, direction, protocol, firewallLogNote); } //Removes a Specific Rule from Firewall (When switching locations) else if (removeFirewallRule == true && firstTimeRun == true) { if (RuleExist(nameOfApp) == true) { RemoveRules(nameOfApp, firewallLogNote); Log.Info("WINDOWS FIREWALL: Found " + nameOfApp + " {" + firewallLogNote + "} In Firewall"); } else if (RuleExist(nameOfApp) == false) { AddApplicationRule(nameOfApp, localOfApp, groupKey, description, direction, protocol, firewallLogNote); } } else if (removeFirewallRule == false && firstTimeRun == false) { Log.Info("WINDOWS FIREWALL: Already Exlcuded " + nameOfApp + " {" + firewallLogNote + "}"); } else { Log.Error("WINDOWS FIREWALL: Firewall Error - Check With Visual Studio for Error Debuging"); } }
private static void AddDefaultApplicationRule(string nameOfApp, string localOfApp, FirewallDirection direction, FirewallProtocol protocol, string firewallLogNote) { try { Log.Warning("WINDOWS FIREWALL: Falling back to 'LegacyStandard'"); var defaultRule = FirewallManager.Instance.CreateApplicationRule( FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public, nameOfApp, FirewallAction.Allow, localOfApp, protocol); defaultRule.Direction = direction; FirewallManager.Instance.Rules.Add(defaultRule); Log.Warning("WINDOWS FIREWALL: Finished Adding " + nameOfApp + " to Firewall! {" + firewallLogNote + "}"); } catch (FirewallWASNotSupportedException Error) { Log.Error("WINDOWS FIREWALL: " + Error.Message); } }
private static void CheckServerFirewallRules(FirewallDirection direction) { string serverPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), ServerLogic.SERVER_EXECUTABLE); AddExclusiveFirewallRule(Path.GetFileName(serverPath), serverPath, direction); }
private static void CheckFirewallRules(FirewallDirection direction) { CheckClientFirewallRules(direction); CheckServerFirewallRules(direction); CheckHamachiFirewallRules(direction); }
private static void CheckHamachiFirewallRules(FirewallDirection direction) {
private static void CheckClientFirewallRules(FirewallDirection direction) { string clientPath = Path.Combine(LauncherLogic.Config.SubnauticaPath, GameInfo.Subnautica.ExeName); AddExclusiveFirewallRule(Path.GetFileName(clientPath), clientPath, direction); }
public static void AddApplicationRule(string nameOfApp, string localOfApp, string groupKey, string description, FirewallDirection direction, FirewallProtocol protocol, string firewallLogNote) { if (Firewall.Instance.IsSupported) { Log.Info("WINDOWS FIREWALL: Supported Firewall Found"); var rule = new StandardRuleWin7(localOfApp, FirewallAction.Allow, direction, FirewallProfiles.Domain | FirewallProfiles.Private | FirewallProfiles.Public) { ApplicationName = localOfApp, Name = nameOfApp, Grouping = groupKey, Description = description, InterfaceTypes = FirewallInterfaceTypes.Lan | FirewallInterfaceTypes.RemoteAccess | FirewallInterfaceTypes.Wireless, Protocol = protocol }; if (direction == FirewallDirection.Inbound) { rule.EdgeTraversalOptions = EdgeTraversalAction.Allow; } Firewall.Instance.Rules.Add(rule); Log.Info("WINDOWS FIREWALL: Finished Adding " + nameOfApp + " to Firewall! {" + firewallLogNote + "}"); } else { AddDefaultApplicationRule(nameOfApp, localOfApp, direction, protocol, firewallLogNote); } }