mirror of https://github.com/Jackett/Jackett
95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using Jackett.Common.Models.Config;
|
|
using Jackett.Common.Services.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MimeMapping;
|
|
using NLog;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Jackett.Server.Controllers
|
|
{
|
|
[Route("UI/[action]")]
|
|
//[JackettAuthorized]
|
|
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public class WebUIController : Controller
|
|
{
|
|
private IConfigurationService config;
|
|
private ServerConfig serverConfig;
|
|
private ISecuityService securityService;
|
|
private Logger logger;
|
|
|
|
public WebUIController(IConfigurationService config, ISecuityService ss, ServerConfig s, Logger l)
|
|
{
|
|
this.config = config;
|
|
serverConfig = s;
|
|
securityService = ss;
|
|
logger = l;
|
|
}
|
|
|
|
private HttpResponseMessage GetFile(string path)
|
|
{
|
|
var result = new HttpResponseMessage(HttpStatusCode.OK);
|
|
var mappedPath = Path.Combine(config.GetContentFolder(), path);
|
|
var stream = new FileStream(mappedPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
result.Content = new StreamContent(stream);
|
|
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeUtility.GetMimeMapping(mappedPath));
|
|
|
|
return result;
|
|
}
|
|
|
|
[HttpGet]
|
|
//[AllowAnonymous]
|
|
public IActionResult Logout()
|
|
{
|
|
var ctx = Request.HttpContext;
|
|
//TODO
|
|
//var authManager = ctx.Authentication;
|
|
//authManager.SignOut("ApplicationCookie");
|
|
return Redirect("Dashboard");
|
|
}
|
|
|
|
[HttpGet]
|
|
[HttpPost]
|
|
//[AllowAnonymous]
|
|
public IActionResult Dashboard()
|
|
{
|
|
var result = new PhysicalFileResult(config.GetContentFolder() + "/index.html", "text/html");
|
|
return result;
|
|
|
|
|
|
//if (Request.Path != null && Request.Path.ToString().Contains("logout"))
|
|
//{
|
|
// var file = GetFile("login.html");
|
|
// securityService.Logout(file);
|
|
// return file;
|
|
//}
|
|
|
|
//TODO
|
|
|
|
//if (securityService.CheckAuthorised(Request))
|
|
//{
|
|
//return GetFile("index.html");
|
|
|
|
//}
|
|
//else
|
|
//{
|
|
// var formData = await Request.ReadFormAsync();
|
|
|
|
// if (formData != null && securityService.HashPassword(formData["password"]) == serverConfig.AdminPassword)
|
|
// {
|
|
// var file = GetFile("index.html");
|
|
// securityService.Login(file);
|
|
// return file;
|
|
// }
|
|
// else
|
|
// {
|
|
// return GetFile("login.html");
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
}
|