2012-01-19 08:01:47 +03:00
|
|
|
using System.Web.Mvc;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2011-08-26 20:45:59 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 08:08:07 +03:00
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
2012-01-19 08:01:47 +03:00
|
|
|
using NzbDrone.Web.Filters;
|
2011-08-26 20:45:59 +03:00
|
|
|
using NzbDrone.Web.Models;
|
2012-02-07 11:12:37 +03:00
|
|
|
using System;
|
2011-08-06 05:04:35 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
|
|
|
public class CommandController : Controller
|
|
|
|
{
|
|
|
|
private readonly JobProvider _jobProvider;
|
2011-08-26 20:45:59 +03:00
|
|
|
private readonly SabProvider _sabProvider;
|
2011-10-27 08:46:54 +03:00
|
|
|
private readonly SmtpProvider _smtpProvider;
|
2011-10-28 10:57:00 +03:00
|
|
|
private readonly TwitterProvider _twitterProvider;
|
2012-02-05 01:05:56 +03:00
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2012-02-07 11:12:37 +03:00
|
|
|
private readonly GrowlProvider _growlProvider;
|
2012-02-28 08:50:56 +03:00
|
|
|
private readonly SeasonProvider _seasonProvider;
|
2012-03-18 07:14:32 +03:00
|
|
|
private readonly ProwlProvider _prowlProvider;
|
2011-08-06 05:04:35 +03:00
|
|
|
|
2011-10-27 08:46:54 +03:00
|
|
|
public CommandController(JobProvider jobProvider, SabProvider sabProvider,
|
2012-02-05 01:05:56 +03:00
|
|
|
SmtpProvider smtpProvider, TwitterProvider twitterProvider,
|
2012-03-18 07:14:32 +03:00
|
|
|
EpisodeProvider episodeProvider, GrowlProvider growlProvider,
|
|
|
|
SeasonProvider seasonProvider, ProwlProvider prowlProvider)
|
2011-08-06 05:04:35 +03:00
|
|
|
{
|
|
|
|
_jobProvider = jobProvider;
|
2011-08-26 20:45:59 +03:00
|
|
|
_sabProvider = sabProvider;
|
2011-10-27 08:46:54 +03:00
|
|
|
_smtpProvider = smtpProvider;
|
2011-10-28 10:57:00 +03:00
|
|
|
_twitterProvider = twitterProvider;
|
2012-02-05 01:05:56 +03:00
|
|
|
_episodeProvider = episodeProvider;
|
2012-02-07 11:12:37 +03:00
|
|
|
_growlProvider = growlProvider;
|
2012-02-28 08:50:56 +03:00
|
|
|
_seasonProvider = seasonProvider;
|
2012-03-18 07:14:32 +03:00
|
|
|
_prowlProvider = prowlProvider;
|
2011-08-06 05:04:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public JsonResult RssSync()
|
|
|
|
{
|
|
|
|
_jobProvider.QueueJob(typeof(RssSyncJob));
|
2012-02-27 00:47:04 +03:00
|
|
|
return JsonNotificationResult.Queued("RSS sync");
|
2011-08-06 05:04:35 +03:00
|
|
|
}
|
|
|
|
|
2011-10-22 02:33:54 +03:00
|
|
|
public JsonResult BacklogSearch()
|
|
|
|
{
|
|
|
|
_jobProvider.QueueJob(typeof(BacklogSearchJob));
|
2012-02-27 00:47:04 +03:00
|
|
|
return JsonNotificationResult.Queued("Backlog search");
|
2011-10-22 02:33:54 +03:00
|
|
|
}
|
|
|
|
|
2012-01-25 04:21:20 +03:00
|
|
|
public JsonResult RecentBacklogSearch()
|
|
|
|
{
|
|
|
|
_jobProvider.QueueJob(typeof(RecentBacklogSearchJob));
|
2012-02-27 00:47:04 +03:00
|
|
|
return JsonNotificationResult.Queued("Recent backlog search");
|
2012-01-25 04:21:20 +03:00
|
|
|
}
|
|
|
|
|
2012-02-25 19:35:27 +03:00
|
|
|
public JsonResult ForceRefresh(int seriesId)
|
2011-08-06 05:04:35 +03:00
|
|
|
{
|
2012-02-25 19:35:27 +03:00
|
|
|
_jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId);
|
2011-08-06 05:04:35 +03:00
|
|
|
_jobProvider.QueueJob(typeof(DiskScanJob), seriesId);
|
|
|
|
|
2012-02-27 00:47:04 +03:00
|
|
|
return JsonNotificationResult.Queued("Episode update/Disk scan");
|
2011-08-06 05:04:35 +03:00
|
|
|
}
|
2011-08-26 20:45:59 +03:00
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-19 08:01:47 +03:00
|
|
|
[JsonErrorFilter]
|
2011-08-26 20:45:59 +03:00
|
|
|
public JsonResult GetSabnzbdCategories(string host, int port, string apiKey, string username, string password)
|
|
|
|
{
|
2012-01-19 08:01:47 +03:00
|
|
|
return new JsonResult { Data = _sabProvider.GetCategories(host, port, apiKey, username, password) };
|
2011-08-26 20:45:59 +03:00
|
|
|
}
|
2011-10-27 08:46:54 +03:00
|
|
|
|
|
|
|
[HttpPost]
|
2012-04-05 01:29:55 +03:00
|
|
|
public JsonResult TestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses)
|
2011-10-27 08:46:54 +03:00
|
|
|
{
|
|
|
|
if (_smtpProvider.SendTestEmail(server, port, ssl, username, password, fromAddress, toAddresses))
|
2012-04-05 01:29:55 +03:00
|
|
|
return JsonNotificationResult.Info("Successful", "Test email sent.");
|
2011-10-27 08:46:54 +03:00
|
|
|
|
2012-02-24 01:31:50 +03:00
|
|
|
return JsonNotificationResult.Oops("Couldn't send Email, please check your settings");
|
2011-10-27 08:46:54 +03:00
|
|
|
}
|
2011-10-28 10:57:00 +03:00
|
|
|
|
|
|
|
public JsonResult GetTwitterAuthorization()
|
|
|
|
{
|
|
|
|
var result = _twitterProvider.GetAuthorization();
|
|
|
|
|
|
|
|
if (result == null)
|
2012-02-24 01:31:50 +03:00
|
|
|
JsonNotificationResult.Oops("Couldn't get Twitter Authorization");
|
2011-10-28 10:57:00 +03: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-24 01:31:50 +03:00
|
|
|
JsonNotificationResult.Oops("Couldn't verify Twitter Authorization");
|
2012-01-19 08:01:47 +03:00
|
|
|
|
|
|
|
return JsonNotificationResult.Info("Good News!", "Successfully verified Twitter Authorization.");
|
2011-10-28 10:57:00 +03:00
|
|
|
|
|
|
|
}
|
2012-02-05 01:05:56 +03:00
|
|
|
|
2012-02-07 11:12:37 +03: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-24 01:31:50 +03:00
|
|
|
return JsonNotificationResult.Oops("Couldn't register and test Growl");
|
2012-02-07 11:12:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-05 01:05:56 +03:00
|
|
|
[HttpPost]
|
|
|
|
public EmptyResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored)
|
|
|
|
{
|
2012-02-28 08:50:56 +03:00
|
|
|
_seasonProvider.SetIgnore(seriesId, seasonNumber, ignored);
|
2012-02-05 01:05:56 +03:00
|
|
|
return new EmptyResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public EmptyResult SaveEpisodeIgnore(int episodeId, bool ignored)
|
|
|
|
{
|
|
|
|
_episodeProvider.SetEpisodeIgnore(episodeId, ignored);
|
|
|
|
return new EmptyResult();
|
|
|
|
}
|
2012-03-18 07:14:32 +03: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 05:04:35 +03:00
|
|
|
}
|
|
|
|
}
|