2012-01-19 05:01:47 +00:00
|
|
|
|
using System.Web.Mvc;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-08-26 17:45:59 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
2012-01-19 05:01:47 +00:00
|
|
|
|
using NzbDrone.Web.Filters;
|
2011-08-26 17:45:59 +00:00
|
|
|
|
using NzbDrone.Web.Models;
|
2012-02-07 08:12:37 +00:00
|
|
|
|
using System;
|
2011-08-06 02:04:35 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class CommandController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-08-26 17:45:59 +00:00
|
|
|
|
private readonly SabProvider _sabProvider;
|
2011-10-27 05:46:54 +00:00
|
|
|
|
private readonly SmtpProvider _smtpProvider;
|
2011-10-28 07:57:00 +00:00
|
|
|
|
private readonly TwitterProvider _twitterProvider;
|
2012-02-04 22:05:56 +00:00
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2012-02-07 08:12:37 +00:00
|
|
|
|
private readonly GrowlProvider _growlProvider;
|
2012-02-28 05:50:56 +00:00
|
|
|
|
private readonly SeasonProvider _seasonProvider;
|
2012-03-18 04:14:32 +00:00
|
|
|
|
private readonly ProwlProvider _prowlProvider;
|
2011-08-06 02:04:35 +00:00
|
|
|
|
|
2011-10-27 05:46:54 +00:00
|
|
|
|
public CommandController(JobProvider jobProvider, SabProvider sabProvider,
|
2012-02-04 22:05:56 +00:00
|
|
|
|
SmtpProvider smtpProvider, TwitterProvider twitterProvider,
|
2012-03-18 04:14:32 +00:00
|
|
|
|
EpisodeProvider episodeProvider, GrowlProvider growlProvider,
|
|
|
|
|
SeasonProvider seasonProvider, ProwlProvider prowlProvider)
|
2011-08-06 02:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
_jobProvider = jobProvider;
|
2011-08-26 17:45:59 +00:00
|
|
|
|
_sabProvider = sabProvider;
|
2011-10-27 05:46:54 +00:00
|
|
|
|
_smtpProvider = smtpProvider;
|
2011-10-28 07:57:00 +00:00
|
|
|
|
_twitterProvider = twitterProvider;
|
2012-02-04 22:05:56 +00:00
|
|
|
|
_episodeProvider = episodeProvider;
|
2012-02-07 08:12:37 +00:00
|
|
|
|
_growlProvider = growlProvider;
|
2012-02-28 05:50:56 +00:00
|
|
|
|
_seasonProvider = seasonProvider;
|
2012-03-18 04:14:32 +00:00
|
|
|
|
_prowlProvider = prowlProvider;
|
2011-08-06 02:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult RssSync()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(RssSyncJob));
|
2012-02-26 21:47:04 +00:00
|
|
|
|
return JsonNotificationResult.Queued("RSS sync");
|
2011-08-06 02:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-21 23:33:54 +00:00
|
|
|
|
public JsonResult BacklogSearch()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(BacklogSearchJob));
|
2012-02-26 21:47:04 +00:00
|
|
|
|
return JsonNotificationResult.Queued("Backlog search");
|
2011-10-21 23:33:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 01:21:20 +00:00
|
|
|
|
public JsonResult RecentBacklogSearch()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(RecentBacklogSearchJob));
|
2012-02-26 21:47:04 +00:00
|
|
|
|
return JsonNotificationResult.Queued("Recent backlog search");
|
2012-01-25 01:21:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 23:33:37 +00:00
|
|
|
|
public JsonResult PastWeekBacklogSearch()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(PastWeekBacklogSearchJob));
|
|
|
|
|
return JsonNotificationResult.Queued("Past Week backlog search");
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-25 16:35:27 +00:00
|
|
|
|
public JsonResult ForceRefresh(int seriesId)
|
2011-08-06 02:04:35 +00:00
|
|
|
|
{
|
2012-02-25 16:35:27 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId);
|
2011-08-06 02:04:35 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(DiskScanJob), seriesId);
|
2012-07-15 04:27:40 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(RefreshEpisodeMetadata), seriesId);
|
|
|
|
|
|
|
|
|
|
return JsonNotificationResult.Queued("Episode update/Disk scan");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult ForceRefreshAll()
|
|
|
|
|
{
|
|
|
|
|
_jobProvider.QueueJob(typeof(UpdateInfoJob));
|
|
|
|
|
_jobProvider.QueueJob(typeof(DiskScanJob));
|
|
|
|
|
_jobProvider.QueueJob(typeof(RefreshEpisodeMetadata));
|
2011-08-06 02:04:35 +00:00
|
|
|
|
|
2012-02-26 21:47:04 +00:00
|
|
|
|
return JsonNotificationResult.Queued("Episode update/Disk scan");
|
2011-08-06 02:04:35 +00:00
|
|
|
|
}
|
2011-08-26 17:45:59 +00:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-19 05:01:47 +00:00
|
|
|
|
[JsonErrorFilter]
|
2011-08-26 17:45:59 +00:00
|
|
|
|
public JsonResult GetSabnzbdCategories(string host, int port, string apiKey, string username, string password)
|
|
|
|
|
{
|
2012-01-19 05:01:47 +00:00
|
|
|
|
return new JsonResult { Data = _sabProvider.GetCategories(host, port, apiKey, username, password) };
|
2011-08-26 17:45:59 +00:00
|
|
|
|
}
|
2011-10-27 05:46:54 +00:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-04-04 22:29:55 +00:00
|
|
|
|
public JsonResult TestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses)
|
2011-10-27 05:46:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (_smtpProvider.SendTestEmail(server, port, ssl, username, password, fromAddress, toAddresses))
|
2012-04-04 22:29:55 +00:00
|
|
|
|
return JsonNotificationResult.Info("Successful", "Test email sent.");
|
2011-10-27 05:46:54 +00:00
|
|
|
|
|
2012-02-23 22:31:50 +00:00
|
|
|
|
return JsonNotificationResult.Oops("Couldn't send Email, please check your settings");
|
2011-10-27 05:46:54 +00:00
|
|
|
|
}
|
2011-10-28 07:57:00 +00:00
|
|
|
|
|
|
|
|
|
public JsonResult GetTwitterAuthorization()
|
|
|
|
|
{
|
|
|
|
|
var result = _twitterProvider.GetAuthorization();
|
|
|
|
|
|
|
|
|
|
if (result == null)
|
2012-02-23 22:31:50 +00:00
|
|
|
|
JsonNotificationResult.Oops("Couldn't get Twitter Authorization");
|
2011-10-28 07:57:00 +00:00
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult VerifyTwitterAuthorization(string token, string verifier)
|
|
|
|
|
{
|
|
|
|
|
var result = _twitterProvider.GetAndSaveAccessToken(token, verifier);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
2012-02-23 22:31:50 +00:00
|
|
|
|
JsonNotificationResult.Oops("Couldn't verify Twitter Authorization");
|
2012-01-19 05:01:47 +00:00
|
|
|
|
|
|
|
|
|
return JsonNotificationResult.Info("Good News!", "Successfully verified Twitter Authorization.");
|
2011-10-28 07:57:00 +00:00
|
|
|
|
|
|
|
|
|
}
|
2012-02-04 22:05:56 +00:00
|
|
|
|
|
2012-02-07 08:12:37 +00:00
|
|
|
|
public JsonResult RegisterGrowl(string host, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var split = host.Split(':');
|
|
|
|
|
var hostname = split[0];
|
|
|
|
|
var port = Convert.ToInt32(split[1]);
|
|
|
|
|
|
|
|
|
|
_growlProvider.Register(hostname, port, password);
|
|
|
|
|
_growlProvider.TestNotification(hostname, port, password);
|
|
|
|
|
|
|
|
|
|
return JsonNotificationResult.Info("Good News!", "Registered and tested growl successfully");
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2012-02-23 22:31:50 +00:00
|
|
|
|
return JsonNotificationResult.Oops("Couldn't register and test Growl");
|
2012-02-07 08:12:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-04 22:05:56 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public EmptyResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored)
|
|
|
|
|
{
|
2012-02-28 05:50:56 +00:00
|
|
|
|
_seasonProvider.SetIgnore(seriesId, seasonNumber, ignored);
|
2012-02-04 22:05:56 +00:00
|
|
|
|
return new EmptyResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public EmptyResult SaveEpisodeIgnore(int episodeId, bool ignored)
|
|
|
|
|
{
|
|
|
|
|
_episodeProvider.SetEpisodeIgnore(episodeId, ignored);
|
|
|
|
|
return new EmptyResult();
|
|
|
|
|
}
|
2012-03-18 04:14:32 +00:00
|
|
|
|
|
|
|
|
|
public JsonResult TestProwl(string apiKeys)
|
|
|
|
|
{
|
|
|
|
|
_prowlProvider.TestNotification(apiKeys);
|
|
|
|
|
return JsonNotificationResult.Info("Good News!", "Test message has been sent to Prowl");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult TestSabnzbd(string host, int port, string apiKey, string username, string password)
|
|
|
|
|
{
|
|
|
|
|
//_prowlProvider.TestNotification(apiKeys);
|
|
|
|
|
var version = _sabProvider.Test(host, port, apiKey, username, password);
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrWhiteSpace(version))
|
|
|
|
|
return JsonNotificationResult.Oops("Failed to connect to SABnzbd, please check your settings");
|
|
|
|
|
|
|
|
|
|
return JsonNotificationResult.Info("Success!", "SABnzbd settings have been verified successfully! Version: " + version);
|
|
|
|
|
}
|
2011-08-06 02:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|