-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
308 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Remotely.Server.Auth; | ||
using Remotely.Server.Services; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Remotely.Server.Services; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace Remotely.Server.API | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ServerLogsController : ControllerBase | ||
{ | ||
private readonly IDataService _dataService; | ||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() { WriteIndented = true }; | ||
private readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true }; | ||
private readonly ILogsManager _logsManager; | ||
private readonly ILogger<ServerLogsController> _logger; | ||
|
||
public ServerLogsController(IDataService dataService) | ||
public ServerLogsController( | ||
ILogsManager logsManager, | ||
ILogger<ServerLogsController> logger) | ||
{ | ||
_dataService = dataService; | ||
_logsManager = logsManager; | ||
_logger = logger; | ||
} | ||
|
||
[ServiceFilter(typeof(ApiAuthorizationFilter))] | ||
[HttpGet("Download")] | ||
public ActionResult Download() | ||
public async Task<IActionResult> Download() | ||
{ | ||
Request.Headers.TryGetValue("OrganizationID", out var orgId); | ||
_logger.LogInformation( | ||
"Downloading server logs. Remote IP: {ip}", | ||
HttpContext.Connection.RemoteIpAddress); | ||
|
||
var zipFile = await _logsManager.ZipAllLogs(); | ||
Response.OnCompleted(() => | ||
{ | ||
Directory.Delete(zipFile.DirectoryName, true); | ||
return Task.CompletedTask; | ||
}); | ||
|
||
var logs = _dataService.GetAllEventLogs(User.Identity?.Name, orgId); | ||
var fileBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(logs, _jsonOptions)); | ||
return File(fileBytes, "application/octet-stream", "ServerLogs.json"); | ||
return File(zipFile.OpenRead(), "application/octet-stream", zipFile.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.