mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
More work on #399
This commit is contained in:
parent
ba80dfe3aa
commit
8a288db2b0
9 changed files with 195 additions and 23 deletions
|
@ -28,10 +28,14 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Responses.Negotiation;
|
||||
using NLog;
|
||||
using Octokit;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
|
@ -45,24 +49,41 @@ namespace Ombi.UI.Modules.Admin
|
|||
{
|
||||
public AboutModule(ISettingsService<PlexRequestSettings> settingsService,
|
||||
ISettingsService<SystemSettings> systemService, ISecurityExtensions security,
|
||||
IStatusChecker statusChecker) : base("admin", settingsService, security)
|
||||
IStatusChecker statusChecker, IResourceLinker linker) : base("admin", settingsService, security)
|
||||
{
|
||||
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
|
||||
|
||||
SettingsService = systemService;
|
||||
StatusChecker = statusChecker;
|
||||
Linker = linker;
|
||||
|
||||
Get["/about", true] = async (x,ct) => await Index();
|
||||
Get["AboutPage","/about", true] = async (x,ct) => await Index();
|
||||
Post["/about", true] = async (x,ct) => await ReportIssue();
|
||||
|
||||
Get["/OAuth", true] = async (x, ct) => await OAuth();
|
||||
Get["/authorize", true] = async (x, ct) => await Authorize();
|
||||
}
|
||||
|
||||
private ISettingsService<SystemSettings> SettingsService { get; }
|
||||
private IStatusChecker StatusChecker { get; }
|
||||
private IResourceLinker Linker { get; }
|
||||
|
||||
|
||||
private async Task<Negotiator> Index()
|
||||
{
|
||||
var vm = await GetModel();
|
||||
return View["About", vm];
|
||||
}
|
||||
|
||||
private async Task<AboutAdminViewModel> GetModel()
|
||||
{
|
||||
var vm = new AboutAdminViewModel();
|
||||
var oAuth = Session[SessionKeys.OAuthToken]?.ToString() ?? string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(oAuth))
|
||||
{
|
||||
vm.OAuthEnabled = true;
|
||||
}
|
||||
|
||||
var systemSettings = await SettingsService.GetSettingsAsync();
|
||||
|
||||
|
@ -88,7 +109,7 @@ namespace Ombi.UI.Modules.Admin
|
|||
vm.Branch = EnumHelper<Branches>.GetDisplayValue(systemSettings.Branch);
|
||||
vm.LogLevel = LogManager.Configuration.LoggingRules.FirstOrDefault(x => x.NameMatches("database"))?.Levels?.FirstOrDefault()?.Name ?? "Unknown";
|
||||
|
||||
return View["About", vm];
|
||||
return vm;
|
||||
}
|
||||
|
||||
private async Task<Response> ReportIssue()
|
||||
|
@ -107,8 +128,90 @@ namespace Ombi.UI.Modules.Admin
|
|||
});
|
||||
}
|
||||
|
||||
var result = await StatusChecker.ReportBug(title,body);
|
||||
var model = await GetModel();
|
||||
body = CreateReportBody(model, body);
|
||||
var token = Session[SessionKeys.OAuthToken].ToString();
|
||||
var result = await StatusChecker.ReportBug(title, body, token);
|
||||
return Response.AsJson(new {result = true, url = result.HtmlUrl.ToString()});
|
||||
}
|
||||
|
||||
private async Task<Response> OAuth()
|
||||
{
|
||||
var path = Request.Url.Path;
|
||||
|
||||
Request.Url.Path = path.Replace("oauth", "authorize");
|
||||
var uri = await StatusChecker.OAuth(Request.Url.ToString(), Session);
|
||||
|
||||
return Response.AsJson(new { uri = uri.ToString()});
|
||||
}
|
||||
|
||||
public async Task<Response> Authorize()
|
||||
{
|
||||
var code = Request.Query["code"].ToString();
|
||||
var state = Request.Query["state"].ToString();
|
||||
|
||||
var expectedState = Session[SessionKeys.CSRF] as string;
|
||||
if (state != expectedState)
|
||||
{
|
||||
throw new InvalidOperationException("SECURITY FAIL!");
|
||||
}
|
||||
Session[SessionKeys.CSRF] = null;
|
||||
|
||||
var token = await StatusChecker.OAuthAccessToken(code);
|
||||
Session[SessionKeys.OAuthToken] = token.AccessToken;
|
||||
|
||||
return Context.GetRedirect(Linker.BuildRelativeUri(Context, "AboutPage").ToString());
|
||||
}
|
||||
|
||||
private string CreateReportBody(AboutAdminViewModel model, string body)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine("#### Ombi Version");
|
||||
sb.AppendLine($"V {model.ApplicationVersion}");
|
||||
sb.AppendLine("#### Update Branch:");
|
||||
sb.AppendLine(model.Branch);
|
||||
sb.AppendLine("#### Operating System:");
|
||||
sb.AppendLine(model.Os);
|
||||
sb.AppendLine(body);
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
// <!--- //!! Please use the Support / bug report template, otherwise we will close the Github issue !!
|
||||
//(Pleas submit a feature request over here: http://feathub.com/tidusjar/Ombi) //--->
|
||||
|
||||
//#### Ombi Version:
|
||||
|
||||
//V 1.XX.XX
|
||||
|
||||
//#### Update Branch:
|
||||
|
||||
//Stable/Early Access Preview/development
|
||||
|
||||
//#### Operating System:
|
||||
|
||||
//(Place text here)
|
||||
|
||||
//#### Mono Version (only if your not on windows)
|
||||
|
||||
//(Place text here)
|
||||
|
||||
//#### Applicable Logs (from `/logs/` directory or the Admin page):
|
||||
|
||||
//```
|
||||
|
||||
//(Logs go here. Don't remove the ``` tags for showing your logs correctly. Please make sure you remove any personal information from the logs)
|
||||
|
||||
//```
|
||||
|
||||
//#### Problem Description:
|
||||
|
||||
//(Place text here)
|
||||
|
||||
//#### Reproduction Steps:
|
||||
|
||||
//Please include any steps to reproduce the issue, this the request that is causing the problem etc.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue