Skip to content

Commit

Permalink
Merge pull request from GHSA-28j3-84m7-gpjp
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed May 17, 2023
1 parent f94e8ab commit b8a8f02
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Ombi/Controllers/V2/SystemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,33 @@ public IActionResult GetLogFiles()
}

[HttpGet("logs/{logFileName}")]
public async Task<IActionResult> ReadLogFile(string logFileName, CancellationToken token)
public async Task<IActionResult> ReadLogFile(string logFileName)
{
var logFile = Path.Combine(string.IsNullOrEmpty(Ombi.Helpers.StartupSingleton.Instance.StoragePath) ? _hosting.ContentRootPath : Helpers.StartupSingleton.Instance.StoragePath, "Logs", logFileName);
using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(fs))
var logsFolder = Path.Combine(string.IsNullOrEmpty(Ombi.Helpers.StartupSingleton.Instance.StoragePath) ? _hosting.ContentRootPath : Helpers.StartupSingleton.Instance.StoragePath, "Logs");
var files = Directory.EnumerateFiles(logsFolder);
var matchingFile = files.FirstOrDefault(x => Path.GetFileName(x).Equals(logFileName));
if (matchingFile != null)
{
using var fs = new FileStream(matchingFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using StreamReader reader = new(fs);
return Ok(await reader.ReadToEndAsync());
}
return NotFound();
}

[HttpGet("logs/download/{logFileName}")]
public IActionResult Download(string logFileName, CancellationToken token)
public IActionResult Download(string logFileName)
{
var logFile = Path.Combine(string.IsNullOrEmpty(Ombi.Helpers.StartupSingleton.Instance.StoragePath) ? _hosting.ContentRootPath : Helpers.StartupSingleton.Instance.StoragePath, "Logs", logFileName);
using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(fs))
var logsFolder = Path.Combine(string.IsNullOrEmpty(Ombi.Helpers.StartupSingleton.Instance.StoragePath) ? _hosting.ContentRootPath : Helpers.StartupSingleton.Instance.StoragePath, "Logs");
var files = Directory.EnumerateFiles(logsFolder);
var matchingFile = files.FirstOrDefault(x => Path.GetFileName(x).Equals(logFileName));
if (matchingFile != null)
{
using var fs = new FileStream(matchingFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using StreamReader reader = new(fs);
return File(reader.BaseStream, "application/octet-stream", logFileName);
}
return NotFound();
}
}
}

0 comments on commit b8a8f02

Please sign in to comment.