2010-09-23 05:19:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2010-10-08 05:35:04 +02:00
|
|
|
|
using System.Threading;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using NLog;
|
2011-02-05 07:07:25 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-09-24 07:21:45 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
2010-10-08 05:35:04 +02:00
|
|
|
|
[HandleError]
|
2010-09-23 05:19:47 +02:00
|
|
|
|
public class SettingsController : Controller
|
|
|
|
|
{
|
2010-09-28 06:25:41 +02:00
|
|
|
|
private IConfigProvider _configProvider;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
private IIndexerProvider _indexerProvider;
|
2011-02-03 03:49:52 +01:00
|
|
|
|
private IQualityProvider _qualityProvider;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2010-09-24 07:21:45 +02:00
|
|
|
|
|
2011-02-03 03:49:52 +01:00
|
|
|
|
public SettingsController(IConfigProvider configProvider, IIndexerProvider indexerProvider, IQualityProvider qualityProvider)
|
2010-09-24 07:21:45 +02:00
|
|
|
|
{
|
2010-09-28 06:25:41 +02:00
|
|
|
|
_configProvider = configProvider;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
_indexerProvider = indexerProvider;
|
2011-02-03 03:49:52 +01:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2010-09-24 07:21:45 +02:00
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
public ActionResult Index(string viewName)
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2011-01-29 07:10:22 +01:00
|
|
|
|
if (viewName != null)
|
|
|
|
|
ViewData["viewName"] = viewName;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
ViewData["viewName"] = "General";
|
|
|
|
|
|
|
|
|
|
return View("Index", new SettingsModel
|
|
|
|
|
{
|
|
|
|
|
TvFolder = _configProvider.SeriesRoot
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult General()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "General";
|
|
|
|
|
return View("Index", new SettingsModel
|
|
|
|
|
{
|
2011-01-31 08:42:44 +01:00
|
|
|
|
TvFolder = _configProvider.SeriesRoot,
|
|
|
|
|
Quality = Convert.ToInt32(_configProvider.GetValue("Quality", "1", true)),
|
2011-01-29 07:10:22 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Indexers()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "Indexers";
|
|
|
|
|
return View("Index", new SettingsModel
|
|
|
|
|
{
|
|
|
|
|
NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, false),
|
|
|
|
|
NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false),
|
|
|
|
|
NzbsOrgUId = _configProvider.GetValue("NzbsOrgUId", String.Empty, false),
|
|
|
|
|
NzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, false),
|
|
|
|
|
NzbsrusUId = _configProvider.GetValue("NzbsrusUId", String.Empty, false),
|
|
|
|
|
NzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, false),
|
|
|
|
|
Indexers = _indexerProvider.AllIndexers()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Downloads()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "Downloads";
|
|
|
|
|
return View("Index", new SettingsModel
|
|
|
|
|
{
|
|
|
|
|
//Sync Frequency
|
|
|
|
|
//Download Propers?
|
|
|
|
|
//Retention
|
|
|
|
|
//SAB Host/IP
|
|
|
|
|
//SAB Port
|
|
|
|
|
//SAB APIKey
|
|
|
|
|
//SAB Username
|
|
|
|
|
//SAB Password
|
|
|
|
|
//SAB Category
|
|
|
|
|
//SAB Priority
|
|
|
|
|
|
|
|
|
|
SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)),
|
|
|
|
|
DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)),
|
2011-01-31 08:42:44 +01:00
|
|
|
|
Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)),
|
2011-01-29 07:10:22 +01:00
|
|
|
|
SabHost = _configProvider.GetValue("SabHost", "localhost", false),
|
|
|
|
|
SabPort = Convert.ToInt32(_configProvider.GetValue("SabPort", "8080", true)),
|
|
|
|
|
SabApiKey = _configProvider.GetValue("SabApiKey", String.Empty, false),
|
|
|
|
|
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false),
|
|
|
|
|
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false),
|
|
|
|
|
SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false),
|
|
|
|
|
//SabPriority = _configProvider.GetValue("SabPriority", String.Empty, false)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 03:49:52 +01:00
|
|
|
|
public ActionResult Quality()
|
|
|
|
|
{
|
2011-02-03 19:28:14 +01:00
|
|
|
|
ViewData["viewName"] = "Quality";
|
2011-02-03 03:49:52 +01:00
|
|
|
|
|
2011-02-05 07:07:25 +01:00
|
|
|
|
var qualityTypes = new List<QualityTypes>();
|
2011-02-03 03:49:52 +01:00
|
|
|
|
|
2011-02-05 07:07:25 +01:00
|
|
|
|
foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes)))
|
|
|
|
|
{
|
|
|
|
|
qualityTypes.Add(qual);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-06 03:52:49 +01:00
|
|
|
|
ViewData["Qualities"] = qualityTypes;
|
|
|
|
|
|
|
|
|
|
var userProfiles = _qualityProvider.GetAllProfiles().Where(q => q.UserProfile).ToList();
|
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles().ToList();
|
|
|
|
|
|
2011-02-05 07:07:25 +01:00
|
|
|
|
var defaultQualityProfileId = Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].ProfileId, true));
|
|
|
|
|
|
|
|
|
|
var selectList = new SelectList(profiles, "ProfileId", "Name");
|
|
|
|
|
|
|
|
|
|
var model = new QualityModel
|
|
|
|
|
{
|
|
|
|
|
Profiles = profiles,
|
|
|
|
|
UserProfiles = userProfiles,
|
|
|
|
|
DefaultProfileId = defaultQualityProfileId,
|
|
|
|
|
SelectList = selectList
|
|
|
|
|
};
|
2011-02-03 03:49:52 +01:00
|
|
|
|
|
|
|
|
|
return View("Index", model);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-05 19:27:14 +01:00
|
|
|
|
public ViewResult AddUserProfile()
|
|
|
|
|
{
|
2011-02-06 08:13:17 +01:00
|
|
|
|
var qualityTypes = new List<QualityTypes>();
|
|
|
|
|
|
|
|
|
|
foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes)))
|
|
|
|
|
{
|
|
|
|
|
qualityTypes.Add(qual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewData["Qualities"] = qualityTypes;
|
|
|
|
|
|
|
|
|
|
return View("UserProfileSection", new QualityProfile { Name = "New Profile", UserProfile = true });
|
2011-02-05 19:27:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
public ActionResult SubMenu()
|
|
|
|
|
{
|
|
|
|
|
return PartialView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Index(SettingsModel data)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_configProvider.SeriesRoot = data.TvFolder;
|
|
|
|
|
_configProvider.SetValue("NzbMatrixUsername", data.NzbMatrixUsername);
|
|
|
|
|
_configProvider.SetValue("NzbMatrixApiKey", data.NzbMatrixApiKey);
|
|
|
|
|
_configProvider.SetValue("NzbsOrgUId", data.NzbsOrgUId);
|
|
|
|
|
_configProvider.SetValue("NzbsOrgHash", data.NzbsOrgHash);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2011-02-04 03:58:02 +01:00
|
|
|
|
Logger.Error("Error saving settings.");
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
if (Request.IsAjaxRequest())
|
2011-02-04 03:58:02 +01:00
|
|
|
|
return Content("Error saving settings.");
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-02-04 03:58:02 +01:00
|
|
|
|
return Content("Error saving settings.");
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveGeneral(SettingsModel data)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-01-31 08:42:44 +01:00
|
|
|
|
if (data.TvFolder != null)
|
|
|
|
|
_configProvider.SeriesRoot = data.TvFolder;
|
|
|
|
|
|
|
|
|
|
//if (data.Quality != null)
|
|
|
|
|
// _configProvider.SetValue("Quality", data.Quality);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException(e.Message, e);
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
|
|
|
|
|
return Content("Settings Saved.");
|
2010-09-24 07:21:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2011-01-29 07:10:22 +01:00
|
|
|
|
public ActionResult SaveIndexers(SettingsModel data)
|
2010-09-24 07:21:45 +02:00
|
|
|
|
{
|
2011-01-29 07:10:22 +01:00
|
|
|
|
try
|
2010-09-24 07:21:45 +02:00
|
|
|
|
{
|
2011-01-31 02:30:59 +01:00
|
|
|
|
//Todo: Only allow indexers to be enabled if user information has been provided
|
2011-01-29 07:10:22 +01:00
|
|
|
|
foreach (var indexer in data.Indexers)
|
|
|
|
|
{
|
2011-01-31 02:30:59 +01:00
|
|
|
|
indexer.ApiUrl = String.Empty; //TODO: Remove this and use a Real API URL
|
2011-01-29 07:10:22 +01:00
|
|
|
|
_indexerProvider.Update(indexer);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 02:30:59 +01:00
|
|
|
|
if (data.NzbMatrixUsername != null)
|
|
|
|
|
_configProvider.SetValue("NzbMatrixUsername", data.NzbMatrixUsername);
|
|
|
|
|
|
|
|
|
|
if (data.NzbMatrixApiKey != null)
|
|
|
|
|
_configProvider.SetValue("NzbMatrixApiKey", data.NzbMatrixApiKey);
|
|
|
|
|
|
|
|
|
|
if (data.NzbsOrgUId != null)
|
|
|
|
|
_configProvider.SetValue("NzbsOrgUId", data.NzbsOrgUId);
|
|
|
|
|
|
|
|
|
|
if (data.NzbsOrgHash != null)
|
|
|
|
|
_configProvider.SetValue("NzbsOrgHash", data.NzbsOrgHash);
|
|
|
|
|
|
|
|
|
|
if (data.NzbsrusUId != null)
|
|
|
|
|
_configProvider.SetValue("NzbsrusUId", data.NzbsrusUId);
|
|
|
|
|
|
|
|
|
|
if (data.NzbsrusHash != null)
|
|
|
|
|
_configProvider.SetValue("NzbsrusHash", data.NzbsrusHash);
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException(e.Message, e);
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
2010-09-24 07:21:45 +02:00
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
|
|
|
|
|
return Content("Settings Saved.");
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveDownloads(SettingsModel data)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (data.SyncFrequency > 15)
|
|
|
|
|
_configProvider.SetValue("SyncFrequency", data.SyncFrequency.ToString());
|
|
|
|
|
|
|
|
|
|
_configProvider.SetValue("DownloadPropers", data.DownloadPropers.ToString());
|
|
|
|
|
|
2011-01-31 08:42:44 +01:00
|
|
|
|
if (data.Retention > 0)
|
|
|
|
|
_configProvider.SetValue("Retention", data.Retention.ToString());
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
if (data.SabHost != null)
|
|
|
|
|
_configProvider.SetValue("SabHost", data.SabHost);
|
|
|
|
|
|
|
|
|
|
if (data.SabPort > 0)
|
|
|
|
|
_configProvider.SetValue("SabPort", data.SabPort.ToString());
|
|
|
|
|
|
|
|
|
|
if (data.SabApiKey != null)
|
|
|
|
|
_configProvider.SetValue("SabApiKey", data.SabApiKey);
|
|
|
|
|
|
|
|
|
|
if (data.SabUsername != null)
|
|
|
|
|
_configProvider.SetValue("SabUsername", data.SabUsername);
|
|
|
|
|
|
|
|
|
|
if (data.SabPassword != null)
|
|
|
|
|
_configProvider.SetValue("SabPassword", data.SabPassword);
|
|
|
|
|
|
|
|
|
|
if (data.SabCategory != null)
|
|
|
|
|
_configProvider.SetValue("SabCategory", data.SabCategory);
|
|
|
|
|
|
|
|
|
|
//if (data.SabPriority != null)
|
|
|
|
|
// _configProvider.SetValue("SabPriority", data.SabPriority.ToString());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException(e.Message, e);
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 03:58:02 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveQuality(QualityModel data)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-02-05 07:07:25 +01:00
|
|
|
|
_configProvider.SetValue("DefaultQualityProfile", data.DefaultProfileId.ToString());
|
2011-02-06 08:13:17 +01:00
|
|
|
|
|
2011-02-07 22:22:45 +01:00
|
|
|
|
foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile))
|
|
|
|
|
{
|
|
|
|
|
if (!data.UserProfiles.Exists(p => p.ProfileId == dbProfile.ProfileId))
|
|
|
|
|
_qualityProvider.Delete(dbProfile.ProfileId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-02-06 08:13:17 +01:00
|
|
|
|
foreach (var profile in data.UserProfiles)
|
|
|
|
|
{
|
2011-02-07 22:22:45 +01:00
|
|
|
|
Logger.Debug(String.Format("Updating User Profile: {0}", profile));
|
|
|
|
|
|
2011-02-06 08:13:17 +01:00
|
|
|
|
profile.Allowed = new List<QualityTypes>();
|
|
|
|
|
foreach (var quality in profile.AllowedString.Split(','))
|
|
|
|
|
{
|
|
|
|
|
var qType = (QualityTypes)Enum.Parse(typeof (QualityTypes), quality);
|
|
|
|
|
profile.Allowed.Add(qType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit
|
|
|
|
|
if (!profile.Allowed.Contains(profile.Cutoff))
|
2011-02-07 22:22:45 +01:00
|
|
|
|
throw new InvalidOperationException("Invalid Cutoff Value");
|
|
|
|
|
//profile.Cutoff = profile.Allowed.Last();
|
2011-02-06 08:13:17 +01:00
|
|
|
|
|
|
|
|
|
if (profile.ProfileId > 0)
|
|
|
|
|
_qualityProvider.Update(profile);
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
_qualityProvider.Add(profile);
|
|
|
|
|
}
|
2011-02-04 03:58:02 +01:00
|
|
|
|
}
|
2011-02-05 07:07:25 +01:00
|
|
|
|
|
2011-02-04 03:58:02 +01:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException(e.Message, e);
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Request.IsAjaxRequest())
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SortedList(List<object > items)
|
|
|
|
|
{
|
|
|
|
|
return Content("Settings Saved.");
|
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|