Radarr/NzbDrone.Host/AccessControl/UrlAclAdapter.cs

63 lines
1.6 KiB
C#
Raw Normal View History

using System;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
2013-08-10 20:30:27 +00:00
namespace NzbDrone.Host.AccessControl
{
public interface IUrlAclAdapter
{
void RefreshRegistration();
2013-08-30 22:55:01 +00:00
string UrlAcl { get; }
}
public class UrlAclAdapter : IUrlAclAdapter
{
private readonly IProcessProvider _processProvider;
private readonly IConfigFileProvider _configFileProvider;
private readonly Logger _logger;
public UrlAclAdapter(IProcessProvider processProvider, IConfigFileProvider configFileProvider, Logger logger)
{
_processProvider = processProvider;
_configFileProvider = configFileProvider;
_logger = logger;
}
2013-08-30 22:55:01 +00:00
public string UrlAcl
{
get
{
return "http://*:" + _configFileProvider.Port + "/";
}
}
public void RefreshRegistration()
{
if (OsInfo.Version.Major < 6)
return;
2013-08-30 22:55:01 +00:00
RegisterUrl();
}
2013-08-30 22:55:01 +00:00
private void RegisterUrl()
{
2013-08-30 22:55:01 +00:00
var arguments = String.Format("http add urlacl {0} sddl=D:(A;;GX;;;S-1-1-0)", UrlAcl);
RunNetsh(arguments);
}
private void RunNetsh(string arguments)
{
try
{
2013-08-14 05:20:24 +00:00
var process = _processProvider.Start("netsh.exe", arguments);
process.WaitForExit(5000);
}
catch (Exception ex)
{
_logger.WarnException("Error executing netsh with arguments: " + arguments, ex);
}
}
}
}