2013-05-23 05:12:01 +00:00
|
|
|
using System;
|
2013-05-20 02:35:48 +00:00
|
|
|
using NLog;
|
2013-05-23 05:12:01 +00:00
|
|
|
using NzbDrone.Common;
|
2013-06-28 00:04:52 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-23 05:12:01 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-05-20 02:35:48 +00:00
|
|
|
|
2013-08-10 20:30:27 +00:00
|
|
|
namespace NzbDrone.Host.AccessControl
|
2013-05-20 02:35:48 +00: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 00:04:52 +00:00
|
|
|
public UrlAclAdapter(IProcessProvider processProvider, IConfigFileProvider configFileProvider, Logger logger)
|
2013-05-20 02:35:48 +00:00
|
|
|
{
|
|
|
|
_processProvider = processProvider;
|
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RefreshRegistration()
|
|
|
|
{
|
2013-06-28 00:04:52 +00:00
|
|
|
if (OsInfo.Version.Major < 6)
|
2013-05-20 02:35:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
RegisterUrl(_configFileProvider.Port);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RegisterUrl(int portNumber)
|
|
|
|
{
|
|
|
|
var arguments = String.Format("http add urlacl http://*:{0}/ user=EVERYONE", portNumber);
|
|
|
|
RunNetsh(arguments);
|
|
|
|
}
|
|
|
|
|
2013-08-07 05:32:22 +00:00
|
|
|
private void RunNetsh(string arguments)
|
2013-05-20 02:35:48 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-07 05:32:22 +00:00
|
|
|
var process = _processProvider.ShellExecute("netsh.exe", arguments);
|
2013-05-20 02:35:48 +00:00
|
|
|
process.WaitForExit(5000);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.WarnException("Error executing netsh with arguments: " + arguments, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|