Configuring the AuthenticationType from the WebUI will now work, just restart and NzbDrone will change the AuthenticationType on start.

pull/4/head
Mark McDowall 13 years ago
parent 2c3eff2741
commit e941aef9f2

@ -694,4 +694,14 @@
</handlers>
</system.webServer>
</location>
<location path="NZBDrone">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
<windowsAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
</configuration>

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Model
{
public enum AuthenticationType
{
Anonymous = 0,
Windows = 1
}
}

@ -86,6 +86,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="ProcessInfo.cs" />
<Compile Include="Providers\ConsoleProvider.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
@ -132,6 +133,7 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>

@ -6,6 +6,7 @@ using System.Xml.Linq;
using System.Xml.XPath;
using NLog;
using NLog.Config;
using NzbDrone.Model;
namespace NzbDrone.Providers
{
@ -31,12 +32,12 @@ namespace NzbDrone.Providers
public virtual int Port
{
get { return GetValueInt("Port"); }
get { return GetValueInt("Port", 8989); }
}
public virtual bool LaunchBrowser
{
get { return GetValueBoolean("LaunchBrowser"); }
get { return GetValueBoolean("LaunchBrowser", true); }
}
public virtual string AppDataDirectory
@ -64,6 +65,12 @@ namespace NzbDrone.Providers
get { return Path.Combine(IISFolder, "AppServer", "applicationhost.config"); }
}
public virtual AuthenticationType AuthenticationType
{
get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); }
set { SetValue("AuthenticationType", (int)value); }
}
public virtual void ConfigureNlog()
{
LogManager.Configuration = new XmlLoggingConfiguration(
@ -93,6 +100,25 @@ namespace NzbDrone.Providers
new XAttribute("bindingInformation", String.Format("*:{0}:", Port))
));
//Update the authenticationTypes
var location = configXml.XPathSelectElement("configuration").Elements("location").Where(
d => d.Attribute("path").Value.ToLowerInvariant() == "nzbdrone").First();
var authenticationTypes = location.XPathSelectElements("system.webServer/security/authentication").First().Descendants();
//Set all authentication types enabled to false
foreach (var child in authenticationTypes)
{
child.Attribute("enabled").Value = "false";
}
var configuredAuthType = String.Format("{0}Authentication", AuthenticationType.ToString()).ToLowerInvariant();
//Set the users authenticationType to true
authenticationTypes.Where(t => t.Name.ToString().ToLowerInvariant() == configuredAuthType).Single().Attribute("enabled").Value = "true";
configXml.Save(configPath);
}
@ -107,42 +133,86 @@ namespace NzbDrone.Providers
}
}
public virtual void WriteDefaultConfig()
public virtual string GetValue(string key, object defaultValue, string parent = null)
{
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
xDoc.Add(new XElement("Config",
new XElement("Port", 8989),
new XElement("LaunchBrowser", true)
)
);
var parentContainer = config;
xDoc.Save(ConfigFile);
if (!String.IsNullOrEmpty(parent))
{
//Add the parent
if (config.Descendants(parent).Count() != 1)
{
SetValue(key, defaultValue, parent);
//Reload the configFile
xDoc = XDocument.Load(ConfigFile);
config = xDoc.Descendants("Config").Single();
}
parentContainer = config.Descendants(parent).Single();
}
var valueHolder = parentContainer.Descendants(key).ToList();
if (valueHolder.Count() == 1)
return valueHolder.First().Value;
//Save the value
SetValue(key, defaultValue, parent);
//return the default value
return defaultValue.ToString();
}
public virtual int GetValueInt(string key, int defaultValue, string parent = null)
{
return Convert.ToInt32(GetValue(key, defaultValue, parent));
}
public virtual bool GetValueBoolean(string key, bool defaultValue, string parent = null)
{
return Convert.ToBoolean(GetValue(key, defaultValue, parent));
}
private string GetValue(string key, string parent = null)
public virtual void SetValue(string key, object value, string parent = null)
{
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
var parentContainer = config;
if (parent != null)
if (!String.IsNullOrEmpty(parent))
{
//Add the parent container if it doesn't already exist
if (config.Descendants(parent).Count() != 1)
{
config.Add(new XElement(parent));
}
parentContainer = config.Descendants(parent).Single();
}
string value = parentContainer.Descendants(key).Single().Value;
var keyHolder = parentContainer.Descendants(key);
return value;
}
if (keyHolder.Count() != 1)
parentContainer.Add(new XElement(key, value));
private int GetValueInt(string key, string parent = null)
{
return Convert.ToInt32(GetValue(key, parent));
else
parentContainer.Descendants(key).Single().Value = value.ToString();
xDoc.Save(ConfigFile);
}
private bool GetValueBoolean(string key, string parent = null)
public virtual void WriteDefaultConfig()
{
return Convert.ToBoolean(GetValue(key, parent));
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xDoc.Add(new XElement("Config"));
xDoc.Save(ConfigFile);
}
}
}
Loading…
Cancel
Save