Linux heartbeat Agent als Download verfügbar
This commit is contained in:
36
Watcher/Controllers/DownloadController.cs
Normal file
36
Watcher/Controllers/DownloadController.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Watcher.Controllers;
|
||||
|
||||
[Authorize]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
[HttpGet("Download/File/{filename}")]
|
||||
public IActionResult FileDownload(string filename)
|
||||
{
|
||||
// Nur erlaubte Endungen zulassen (Sicherheit!)
|
||||
var allowedExtensions = new[] { ".exe", "" };
|
||||
var extension = Path.GetExtension(filename).ToLowerInvariant();
|
||||
|
||||
if (!allowedExtensions.Contains(extension))
|
||||
return BadRequest("Dateityp nicht erlaubt");
|
||||
|
||||
var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "downloads", filename);
|
||||
|
||||
if (!System.IO.File.Exists(path))
|
||||
return NotFound("Datei nicht gefunden");
|
||||
|
||||
// .exe MIME-Typ: application/octet-stream
|
||||
var mimeType = "application/octet-stream";
|
||||
|
||||
var fileBytes = System.IO.File.ReadAllBytes(path);
|
||||
|
||||
return File(fileBytes, mimeType, filename);
|
||||
//return File(fileBytes, filename);
|
||||
}
|
||||
}
|
@@ -45,6 +45,10 @@
|
||||
<i class="bi bi-trash me-1"></i>Löschen
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<a href="/Download/File/heartbeat" class="btn btn-success">
|
||||
🖥️ Tool herunterladen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
BIN
Watcher/wwwroot/downloads/heartbeat
Executable file
BIN
Watcher/wwwroot/downloads/heartbeat
Executable file
Binary file not shown.
Reference in New Issue
Block a user