diff --git a/NzbDrone.App.Test/MonitoringProviderTest.cs b/NzbDrone.App.Test/MonitoringProviderTest.cs index 2d504b0724..f1e4b0a9b5 100644 --- a/NzbDrone.App.Test/MonitoringProviderTest.cs +++ b/NzbDrone.App.Test/MonitoringProviderTest.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Common.Model; +using NzbDrone.Common.Processes; using NzbDrone.Host; using NzbDrone.Test.Common; diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs index 4155ab4d09..099defbe9a 100644 --- a/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -6,6 +6,7 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.Model; +using NzbDrone.Common.Processes; using NzbDrone.Test.Common; using NzbDrone.Test.Dummy; diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 8fe4ab3af5..0d76e91a23 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -98,6 +98,7 @@ + @@ -122,7 +123,7 @@ - + diff --git a/NzbDrone.Common/Processes/ProcessOutput.cs b/NzbDrone.Common/Processes/ProcessOutput.cs new file mode 100644 index 0000000000..231b6097e4 --- /dev/null +++ b/NzbDrone.Common/Processes/ProcessOutput.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace NzbDrone.Common.Processes +{ + public class ProcessOutput + { + public List Standard { get; set; } + public List Error { get; set; } + + public ProcessOutput() + { + Standard = new List(); + Error = new List(); + } + } +} diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/Processes/ProcessProvider.cs similarity index 94% rename from NzbDrone.Common/ProcessProvider.cs rename to NzbDrone.Common/Processes/ProcessProvider.cs index e93edd781c..75bde50f87 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/Processes/ProcessProvider.cs @@ -9,7 +9,7 @@ using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Model; -namespace NzbDrone.Common +namespace NzbDrone.Common.Processes { public interface IProcessProvider { @@ -23,6 +23,7 @@ public interface IProcessProvider ProcessPriorityClass GetCurrentProcessPriority(); Process Start(string path, string args = null, Action onOutputDataReceived = null, Action onErrorDataReceived = null); Process SpawnNewProcess(string path, string args = null); + ProcessOutput StartAndCapture(string path, string args = null); } public class ProcessProvider : IProcessProvider @@ -88,11 +89,8 @@ public void OpenDefaultBrowser(string url) process.Start(); } - - public Process Start(string path, string args = null, Action onOutputDataReceived = null, Action onErrorDataReceived = null) { - if (OsInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) { args = path + " " + args; @@ -147,7 +145,6 @@ public Process Start(string path, string args = null, Action onOutputDat process.BeginErrorReadLine(); process.BeginOutputReadLine(); - return process; } @@ -172,6 +169,16 @@ public Process SpawnNewProcess(string path, string args = null) return process; } + public ProcessOutput StartAndCapture(string path, string args = null) + { + var output = new ProcessOutput(); + var process = Start(path, args, s => output.Standard.Add(s), error => output.Error.Add(error)); + + WaitForExit(process); + + return output; + } + public void WaitForExit(Process process) { Logger.Trace("Waiting for process {0} to exit.", process.ProcessName); @@ -225,7 +232,6 @@ private static ProcessInfo ConvertToProcessInfo(Process process) return null; } - private static string GetExeFileName(Process process) { if (process.MainModule.FileName != "mono.exe") diff --git a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index 31ebee3e5e..32b0c49ea0 100644 --- a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -6,6 +6,7 @@ using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Model; +using NzbDrone.Common.Processes; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Update; using NzbDrone.Core.Update.Commands; diff --git a/NzbDrone.Core/Update/InstallUpdateService.cs b/NzbDrone.Core/Update/InstallUpdateService.cs index 262806e05f..b0088ee87b 100644 --- a/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/NzbDrone.Core/Update/InstallUpdateService.cs @@ -3,6 +3,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Processes; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Update.Commands; using NzbDrone.Core.Instrumentation; diff --git a/NzbDrone.Host/AccessControl/UrlAclAdapter.cs b/NzbDrone.Host/AccessControl/UrlAclAdapter.cs index e536fffbd0..dff7d1f198 100644 --- a/NzbDrone.Host/AccessControl/UrlAclAdapter.cs +++ b/NzbDrone.Host/AccessControl/UrlAclAdapter.cs @@ -1,7 +1,9 @@ using System; +using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Processes; using NzbDrone.Core.Configuration; namespace NzbDrone.Host.AccessControl @@ -9,11 +11,15 @@ namespace NzbDrone.Host.AccessControl public interface IUrlAclAdapter { void RefreshRegistration(); + bool IsRegistered(); string UrlAcl { get; } + string LocalUrlAcl { get; } } public class UrlAclAdapter : IUrlAclAdapter { + private const string URL_ACL = "http://{0}:{1}/"; + private readonly IProcessProvider _processProvider; private readonly IConfigFileProvider _configFileProvider; private readonly Logger _logger; @@ -25,11 +31,29 @@ public UrlAclAdapter(IProcessProvider processProvider, IConfigFileProvider confi _logger = logger; } + public bool IsRegistered() + { + var arguments = String.Format("http show urlacl {0}", UrlAcl); + var output = RunNetsh(arguments); + + if (output == null || !output.Standard.Any()) return false; + + return output.Standard.Any(line => line.Contains(UrlAcl)); + } + public string UrlAcl { get { - return "http://*:" + _configFileProvider.Port + "/"; + return String.Format(URL_ACL, "*", _configFileProvider.Port); + } + } + + public string LocalUrlAcl + { + get + { + return String.Format(URL_ACL, "localhost", _configFileProvider.Port); } } @@ -47,17 +71,20 @@ private void RegisterUrl() RunNetsh(arguments); } - private void RunNetsh(string arguments) + private ProcessOutput RunNetsh(string arguments) { try { - var process = _processProvider.Start("netsh.exe", arguments); - process.WaitForExit(5000); + var output = _processProvider.StartAndCapture("netsh.exe", arguments); + + return output; } catch (Exception ex) { _logger.WarnException("Error executing netsh with arguments: " + arguments, ex); } + + return null; } } } \ No newline at end of file diff --git a/NzbDrone.Host/ApplicationServer.cs b/NzbDrone.Host/ApplicationServer.cs index d6e1e36259..ab0ee6f6ef 100644 --- a/NzbDrone.Host/ApplicationServer.cs +++ b/NzbDrone.Host/ApplicationServer.cs @@ -3,6 +3,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Processes; using NzbDrone.Core.Configuration; using NzbDrone.Host.Owin; diff --git a/NzbDrone.Host/Owin/OwinHostController.cs b/NzbDrone.Host/Owin/OwinHostController.cs index b4d8d24bac..14d5d331ca 100644 --- a/NzbDrone.Host/Owin/OwinHostController.cs +++ b/NzbDrone.Host/Owin/OwinHostController.cs @@ -38,19 +38,14 @@ public OwinHostController(IConfigFileProvider configFileProvider, IEnumerable