2013-05-23 08:12:01 +03:00
|
|
|
using System;
|
2013-05-20 05:35:48 +03:00
|
|
|
using System.Diagnostics;
|
|
|
|
using NLog;
|
2013-05-23 08:12:01 +03:00
|
|
|
using NzbDrone.Common;
|
2013-06-28 03:04:52 +03:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-23 08:12:01 +03:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-05-20 05:35:48 +03:00
|
|
|
|
2013-05-23 08:12:01 +03:00
|
|
|
namespace NzbDrone.Host
|
2013-05-20 05:35:48 +03:00
|
|
|
{
|
|
|
|
public interface IUrlAclAdapter
|
|
|
|
{
|
|
|
|
void RefreshRegistration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class UrlAclAdapter : IUrlAclAdapter
|
|
|
|
{
|
|
|
|
private readonly IProcessProvider _processProvider;
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-06-28 03:04:52 +03:00
|
|
|
public UrlAclAdapter(IProcessProvider processProvider, IConfigFileProvider configFileProvider, Logger logger)
|
2013-05-20 05:35:48 +03:00
|
|
|
{
|
|
|
|
_processProvider = processProvider;
|
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RefreshRegistration()
|
|
|
|
{
|
2013-06-28 03:04:52 +03:00
|
|
|
if (OsInfo.Version.Major < 6)
|
2013-05-20 05:35:48 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
RegisterUrl(_configFileProvider.Port);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RegisterUrl(int portNumber)
|
|
|
|
{
|
|
|
|
var arguments = String.Format("http add urlacl http://*:{0}/ user=EVERYONE", portNumber);
|
|
|
|
RunNetsh(arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
private string RunNetsh(string arguments)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var startInfo = new ProcessStartInfo()
|
|
|
|
{
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
UseShellExecute = false,
|
|
|
|
FileName = "netsh.exe",
|
|
|
|
Arguments = arguments
|
|
|
|
};
|
|
|
|
|
|
|
|
var process = _processProvider.Start(startInfo);
|
|
|
|
process.WaitForExit(5000);
|
|
|
|
return process.StandardOutput.ReadToEnd();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.WarnException("Error executing netsh with arguments: " + arguments, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|