1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 01:57:21 +00:00

New: Added check to ensure FW is enabled before opening and closing ports.

This commit is contained in:
Mark McDowall 2012-01-25 18:00:17 -08:00
parent 340f05aef4
commit ab7d3ebcc5
2 changed files with 32 additions and 11 deletions

View file

@ -37,6 +37,10 @@ public virtual void MakeAccessible()
return;
}
int port = 0;
if (IsFirewallEnabled())
{
if(IsNzbDronePortOpen())
{
Logger.Trace("NzbDrone port is already open, skipping.");
@ -44,10 +48,11 @@ public virtual void MakeAccessible()
}
//Close any old ports
var port = CloseFirewallPort();
port = CloseFirewallPort();
//Open the new port
OpenFirewallPort(_configFileProvider.Port);
}
//Skip Url Register if not Vista or 7
if (_enviromentProvider.GetOsVersion().Major < 6)
@ -161,6 +166,22 @@ private int CloseFirewallPort()
return 0;
}
private bool IsFirewallEnabled()
{
try
{
var netFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
var mgr = (INetFwMgr)Activator.CreateInstance(netFwMgrType);
return mgr.LocalPolicy.CurrentProfile.FirewallEnabled;
}
catch(Exception ex)
{
Logger.WarnException("Failed to check if the firewall is enabled", ex);
return false;
}
}
private bool RegisterUrl(int portNumber)
{
try

View file

@ -45,7 +45,7 @@ public class SeriesModel
public bool Monitored { get; set; }
[DisplayName("Backlog Setting")]
[Description("Should NzbDrone download past missing episodes?")]
[Description("Should NzbDrone search for missing episodes every 30 days?")]
public int BacklogSetting { get; set; }
}
}