mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
More work on #399
This commit is contained in:
parent
ba80dfe3aa
commit
8a288db2b0
9 changed files with 195 additions and 23 deletions
|
@ -1,4 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy.Session;
|
||||
using Octokit;
|
||||
using Ombi.Core.Models;
|
||||
|
||||
|
@ -7,6 +9,8 @@ namespace Ombi.Core
|
|||
public interface IStatusChecker
|
||||
{
|
||||
Task<StatusModel> GetStatus();
|
||||
Task<Issue> ReportBug(string title, string body);
|
||||
Task<Issue> ReportBug(string title, string body, string oauthToken);
|
||||
Task<Uri> OAuth(string url, ISession session);
|
||||
Task<OauthToken> OAuthAccessToken(string code);
|
||||
}
|
||||
}
|
|
@ -28,8 +28,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy.Session;
|
||||
using Octokit;
|
||||
using Octokit.Internal;
|
||||
using Ombi.Api;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Core.SettingModels;
|
||||
|
@ -43,7 +46,7 @@ namespace Ombi.Core.StatusChecker
|
|||
public StatusChecker(ISettingsService<SystemSettings> ss)
|
||||
{
|
||||
SystemSettings = ss;
|
||||
Git = new GitHubClient(new ProductHeaderValue("Ombi-StatusChecker"));
|
||||
Git = new GitHubClient(new ProductHeaderValue("Ombi"));
|
||||
}
|
||||
|
||||
private ISettingsService<SystemSettings> SystemSettings { get; }
|
||||
|
@ -180,15 +183,48 @@ namespace Ombi.Core.StatusChecker
|
|||
return model;
|
||||
}
|
||||
|
||||
public async Task<Issue> ReportBug(string title, string body)
|
||||
public async Task<Issue> ReportBug(string title, string body, string oauthToken)
|
||||
{
|
||||
Git.Connection.Credentials = new Credentials(oauthToken);
|
||||
var issue = new NewIssue(title)
|
||||
{
|
||||
Body = body
|
||||
};
|
||||
|
||||
var result = await Git.Issue.Create(Owner, RepoName, issue);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
string clientId = "f407108cdb1e660f68c5";
|
||||
string clientSecret = "84b56e22002da2929c34fc773d89f3402a19098a";
|
||||
|
||||
public async Task<Uri> OAuth(string url, ISession session)
|
||||
{
|
||||
|
||||
var csrf = StringCipher.Encrypt(Guid.NewGuid().ToString("N"), "CSRF");
|
||||
session[SessionKeys.CSRF] = csrf;
|
||||
|
||||
var request = new OauthLoginRequest(clientId)
|
||||
{
|
||||
Scopes = { "public_repo", "user" },
|
||||
State = csrf,
|
||||
RedirectUri = new Uri(url)
|
||||
};
|
||||
|
||||
// NOTE: user must be navigated to this URL
|
||||
var oauthLoginUrl = Git.Oauth.GetGitHubLoginUrl(request);
|
||||
|
||||
return oauthLoginUrl;
|
||||
}
|
||||
|
||||
public async Task<OauthToken> OAuthAccessToken(string code)
|
||||
{
|
||||
var request = new OauthTokenRequest(clientId, clientSecret, code);
|
||||
var token = await Git.Oauth.CreateAccessToken(request);
|
||||
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,5 +33,7 @@ namespace Ombi.Helpers
|
|||
public const string UserWizardPlexAuth = nameof(UserWizardPlexAuth);
|
||||
public const string UserWizardMachineId = nameof(UserWizardMachineId);
|
||||
public const string UserLoginName = nameof(UserLoginName);
|
||||
public const string OAuthToken = nameof(OAuthToken);
|
||||
public const string CSRF = "CSRF:State";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,5 +33,6 @@ namespace Ombi.UI.Models
|
|||
public string ApplicationVersion { get; set; } // File Version
|
||||
public string Branch { get; set; }
|
||||
public string LogLevel { get; set; }
|
||||
public bool OAuthEnabled { get; set; }
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -116,8 +116,6 @@ namespace Ombi.UI.Modules
|
|||
|
||||
private async Task<Response> GetMovies()
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
|
||||
var allRequests = await Service.GetAllAsync();
|
||||
allRequests = allRequests.Where(x => x.Type == RequestType.Movie);
|
||||
|
||||
|
|
|
@ -32,12 +32,23 @@
|
|||
<label class="control-label">@Model.LogLevel</label>
|
||||
</div>
|
||||
|
||||
@if (Model.OAuthEnabled)
|
||||
{
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="save" type="submit" class="btn btn-danger-outline">Report a bug</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="oAuth" type="submit" class="btn btn-primary-outline">Log in via Github</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
|
@ -52,6 +63,22 @@
|
|||
startBug();
|
||||
});
|
||||
|
||||
$('#oAuth').click(function () {
|
||||
var url = "/admin/oauth";
|
||||
url = createBaseUrl(baseUrl, url);
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: url,
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
window.location.href = response.uri;
|
||||
},
|
||||
error: function (e) {
|
||||
console.log(e);
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function startBug() {
|
||||
bootbox.prompt({
|
||||
|
@ -91,7 +118,7 @@
|
|||
$.ajax({
|
||||
type: "post",
|
||||
url: url,
|
||||
data: {title : issueTitle, body : additionalInfo},
|
||||
data: { title: issueTitle, body: additionalInfo },
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
if (response && response.result) {
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-user"></i> @UI.Layout_Admin <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="@url/admin"><i class="fa fa-cog"></i> @UI.Layout_Settings</a></li>
|
||||
<li><a href="@url/admin/about>"><i class="fa fa-cog"></i> @UI.Layout_Settings</a></li>
|
||||
<li><a href="@url/changepassword"><i class="fa fa-key"></i> @UI.Layout_ChangePassword</a></li>
|
||||
|
||||
<li class="divider"></li>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
@Html.LoadSettingsAssets()
|
||||
<div class="col-lg-3 col-md-3 col-sm-4">
|
||||
<div class="list-group table-of-contents">
|
||||
@Html.GetSidebarUrl(Context, "/admin/about", "About")
|
||||
@Html.GetSidebarUrl(Context, "/admin", "Plex Request")
|
||||
@Html.GetSidebarUrl(Context, "/admin/customization", "Customization")
|
||||
@Html.GetSidebarUrl(Context, "/admin/landingpage", "Landing Page")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue