|
|
@ -6,6 +6,7 @@ using System.Xml.Linq;
|
|
|
|
using System.Xml.XPath;
|
|
|
|
using System.Xml.XPath;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NLog.Config;
|
|
|
|
using NLog.Config;
|
|
|
|
|
|
|
|
using NzbDrone.Model;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Providers
|
|
|
|
namespace NzbDrone.Providers
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -31,12 +32,12 @@ namespace NzbDrone.Providers
|
|
|
|
|
|
|
|
|
|
|
|
public virtual int Port
|
|
|
|
public virtual int Port
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get { return GetValueInt("Port"); }
|
|
|
|
get { return GetValueInt("Port", 8989); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool LaunchBrowser
|
|
|
|
public virtual bool LaunchBrowser
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("LaunchBrowser"); }
|
|
|
|
get { return GetValueBoolean("LaunchBrowser", true); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual string AppDataDirectory
|
|
|
|
public virtual string AppDataDirectory
|
|
|
@ -64,6 +65,12 @@ namespace NzbDrone.Providers
|
|
|
|
get { return Path.Combine(IISFolder, "AppServer", "applicationhost.config"); }
|
|
|
|
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()
|
|
|
|
public virtual void ConfigureNlog()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogManager.Configuration = new XmlLoggingConfiguration(
|
|
|
|
LogManager.Configuration = new XmlLoggingConfiguration(
|
|
|
@ -93,6 +100,25 @@ namespace NzbDrone.Providers
|
|
|
|
new XAttribute("bindingInformation", String.Format("*:{0}:", Port))
|
|
|
|
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);
|
|
|
|
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",
|
|
|
|
var parentContainer = config;
|
|
|
|
new XElement("Port", 8989),
|
|
|
|
|
|
|
|
new XElement("LaunchBrowser", true)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 xDoc = XDocument.Load(ConfigFile);
|
|
|
|
var config = xDoc.Descendants("Config").Single();
|
|
|
|
var config = xDoc.Descendants("Config").Single();
|
|
|
|
|
|
|
|
|
|
|
|
var parentContainer = config;
|
|
|
|
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();
|
|
|
|
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)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parentContainer.Descendants(key).Single().Value = value.ToString();
|
|
|
|
return Convert.ToInt32(GetValue(key, parent));
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|