2011-06-08 08:15:35 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2011-09-04 05:05:44 +02:00
|
|
|
|
using System.Linq;
|
2011-06-08 08:15:35 +02:00
|
|
|
|
using System.Web.Mvc;
|
2012-02-10 06:26:30 +01:00
|
|
|
|
using System.Web.Script.Serialization;
|
2011-11-13 05:07:06 +01:00
|
|
|
|
using NzbDrone.Common;
|
2011-06-08 08:15:35 +02:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-04-22 08:23:29 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-22 19:09:06 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
2011-06-08 08:15:35 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
2011-04-22 08:23:29 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class SystemController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly JobProvider _jobProvider;
|
|
|
|
|
private readonly IndexerProvider _indexerProvider;
|
2011-04-22 19:09:06 +02:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-06-08 08:15:35 +02:00
|
|
|
|
private readonly DiskProvider _diskProvider;
|
2012-01-27 06:05:09 +01:00
|
|
|
|
private readonly BackupProvider _backupProvider;
|
2011-04-22 08:23:29 +02:00
|
|
|
|
|
2012-01-26 08:56:05 +01:00
|
|
|
|
public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider,
|
|
|
|
|
ConfigProvider configProvider, DiskProvider diskProvider,
|
2012-01-27 06:05:09 +01:00
|
|
|
|
BackupProvider backupProvider)
|
2011-04-22 08:23:29 +02:00
|
|
|
|
{
|
|
|
|
|
_jobProvider = jobProvider;
|
|
|
|
|
_indexerProvider = indexerProvider;
|
2011-04-22 19:09:06 +02:00
|
|
|
|
_configProvider = configProvider;
|
2011-06-08 08:15:35 +02:00
|
|
|
|
_diskProvider = diskProvider;
|
2012-01-27 06:05:09 +01:00
|
|
|
|
_backupProvider = backupProvider;
|
2011-04-22 08:23:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Jobs()
|
|
|
|
|
{
|
2012-02-10 07:17:53 +01:00
|
|
|
|
var queue = _jobProvider.Queue.Select(c => new JobQueueItemModel
|
2012-01-19 06:01:47 +01:00
|
|
|
|
{
|
|
|
|
|
Name = c.JobType.Name,
|
|
|
|
|
TargetId = c.TargetId,
|
|
|
|
|
SecondaryTargetId = c.SecondaryTargetId
|
|
|
|
|
});
|
2011-12-15 09:25:16 +01:00
|
|
|
|
|
2012-02-10 07:17:53 +01:00
|
|
|
|
var serializedQueue = new JavaScriptSerializer().Serialize(queue);
|
|
|
|
|
|
|
|
|
|
ViewData["Queue"] = serializedQueue;
|
|
|
|
|
|
|
|
|
|
var jobs = _jobProvider.All().Select(j => new JobModel
|
|
|
|
|
{
|
2012-02-12 01:01:52 +01:00
|
|
|
|
Id = j.Id,
|
|
|
|
|
Enable = j.Enable,
|
|
|
|
|
TypeName = j.TypeName,
|
|
|
|
|
Name = j.Name,
|
|
|
|
|
Interval = j.Interval,
|
|
|
|
|
LastExecution = j.LastExecution.ToString(),
|
|
|
|
|
Success = j.Success
|
2012-02-10 07:17:53 +01:00
|
|
|
|
}).OrderBy(j => j.Interval);
|
|
|
|
|
|
|
|
|
|
var serializedJobs = new JavaScriptSerializer().Serialize(jobs);
|
|
|
|
|
|
|
|
|
|
return View((object)serializedJobs);
|
2011-04-22 08:23:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Indexers()
|
|
|
|
|
{
|
2012-02-10 07:26:48 +01:00
|
|
|
|
var indexers = _indexerProvider.All();
|
|
|
|
|
var serialized = new JavaScriptSerializer().Serialize(indexers);
|
|
|
|
|
|
|
|
|
|
return View((object)serialized);
|
2011-04-22 08:23:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 19:09:06 +02:00
|
|
|
|
public ActionResult Config()
|
|
|
|
|
{
|
2012-02-10 06:26:30 +01:00
|
|
|
|
var config = _configProvider.All();
|
|
|
|
|
var serialized = new JavaScriptSerializer().Serialize(config);
|
|
|
|
|
|
|
|
|
|
return View((object)serialized);
|
2011-04-22 19:09:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 06:26:30 +01:00
|
|
|
|
public JsonResult SelectConfigAjax()
|
2011-05-09 06:23:57 +02:00
|
|
|
|
{
|
2012-02-10 06:26:30 +01:00
|
|
|
|
var config = _configProvider.All();
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
2012-02-12 01:01:52 +01:00
|
|
|
|
iTotalRecords = config.Count(),
|
|
|
|
|
iTotalDisplayRecords = config.Count(),
|
|
|
|
|
aaData = config
|
2012-02-10 06:26:30 +01:00
|
|
|
|
}, JsonRequestBehavior.AllowGet);
|
2011-05-09 06:23:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 06:26:30 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public string SaveConfigAjax(string id, string value)
|
2011-05-09 06:23:57 +02:00
|
|
|
|
{
|
2012-02-10 06:26:30 +01:00
|
|
|
|
_configProvider.SetValue(id, value);
|
|
|
|
|
return value;
|
2011-05-09 06:23:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 06:26:30 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public string InsertConfigAjax(string key, string value)
|
2011-05-09 06:23:57 +02:00
|
|
|
|
{
|
|
|
|
|
_configProvider.SetValue(key, value);
|
2012-02-10 06:26:30 +01:00
|
|
|
|
return key;
|
2011-05-09 06:23:57 +02:00
|
|
|
|
}
|
2011-06-08 08:15:35 +02:00
|
|
|
|
|
|
|
|
|
//PostDownloadView
|
|
|
|
|
public ActionResult PendingProcessing()
|
|
|
|
|
{
|
|
|
|
|
ViewData["DropDir"] = _configProvider.SabDropDirectory;
|
|
|
|
|
|
|
|
|
|
var dropDir = _configProvider.SabDropDirectory;
|
|
|
|
|
var subFolders = _diskProvider.GetDirectories(dropDir);
|
|
|
|
|
|
|
|
|
|
var models = new List<PendingProcessingModel>();
|
|
|
|
|
|
|
|
|
|
//Get the CreationTime and Files
|
|
|
|
|
foreach (var folder in subFolders)
|
|
|
|
|
{
|
|
|
|
|
var model = new PendingProcessingModel();
|
|
|
|
|
model.Name = new DirectoryInfo(folder).Name;
|
2012-02-10 08:11:56 +01:00
|
|
|
|
model.Created = _diskProvider.DirectoryDateCreated(folder).ToString();
|
2011-06-08 08:15:35 +02:00
|
|
|
|
model.Path = folder.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
|
|
|
|
|
|
|
|
|
|
var files = _diskProvider.GetFileInfos(folder, "*.*", SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
var fileResult = "<div><div style=\"width: 600px; display: inline-block;\"><b>Name</b></div><div style=\"display: inline-block;\"><b>Size</b></div></div>";
|
|
|
|
|
|
|
|
|
|
foreach (var fileInfo in files)
|
|
|
|
|
{
|
|
|
|
|
fileResult += String.Format("<div><div style=\"width: 600px; display: inline-block;\">{0}</div><div style=\"display: inline-block;\">{1}</div></div>", fileInfo.Name,
|
|
|
|
|
FileSizeFormatHelper.Format(fileInfo.Length, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.Files = fileResult;
|
|
|
|
|
|
|
|
|
|
models.Add(model);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 08:11:56 +01:00
|
|
|
|
var serialized = new JavaScriptSerializer().Serialize(models);
|
|
|
|
|
|
|
|
|
|
return View((object)serialized);
|
2011-06-08 08:15:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult RenamePendingProcessing(string path)
|
|
|
|
|
{
|
|
|
|
|
path = path.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\'');
|
|
|
|
|
|
|
|
|
|
var di = new DirectoryInfo(path);
|
|
|
|
|
var dropDir = di.Parent.FullName;
|
|
|
|
|
var folder = di.Name;
|
|
|
|
|
|
|
|
|
|
if (!folder.StartsWith("_UNPACK_") && !folder.StartsWith("_FAILED_"))
|
|
|
|
|
return new JsonResult { Data = "no change" };
|
|
|
|
|
|
|
|
|
|
folder = folder.Substring(8);
|
|
|
|
|
var newPath = dropDir + Path.DirectorySeparatorChar + folder;
|
|
|
|
|
_diskProvider.MoveDirectory(path, newPath);
|
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = "ok" };
|
|
|
|
|
}
|
2011-12-15 09:25:16 +01:00
|
|
|
|
|
|
|
|
|
public JsonResult RunJob(string typeName)
|
|
|
|
|
{
|
|
|
|
|
if (!_jobProvider.QueueJob(typeName))
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Opps("Invalid Job Name");
|
2011-12-15 09:25:16 +01:00
|
|
|
|
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Info("Job Queued");
|
2011-12-15 09:25:16 +01:00
|
|
|
|
}
|
2012-01-26 08:56:05 +01:00
|
|
|
|
|
|
|
|
|
public ActionResult Backup()
|
|
|
|
|
{
|
2012-01-27 06:05:09 +01:00
|
|
|
|
var file = _backupProvider.CreateBackupZip();
|
|
|
|
|
var fileInfo = new FileInfo(file);
|
|
|
|
|
|
|
|
|
|
return File(fileInfo.FullName, "application/binary", fileInfo.Name);
|
2012-01-26 08:56:05 +01:00
|
|
|
|
}
|
2011-04-22 08:23:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|