diff --git a/Watcher/Controllers/DownloadController.cs b/Watcher/Controllers/DownloadController.cs new file mode 100644 index 0000000..45a0850 --- /dev/null +++ b/Watcher/Controllers/DownloadController.cs @@ -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); + } +} diff --git a/Watcher/Views/Server/_ServerCard.cshtml b/Watcher/Views/Server/_ServerCard.cshtml index 70976c1..e11be01 100644 --- a/Watcher/Views/Server/_ServerCard.cshtml +++ b/Watcher/Views/Server/_ServerCard.cshtml @@ -45,6 +45,10 @@ Löschen + + + 🖥️ Tool herunterladen + } diff --git a/Watcher/wwwroot/downloads/heartbeat b/Watcher/wwwroot/downloads/heartbeat new file mode 100755 index 0000000..ef10317 Binary files /dev/null and b/Watcher/wwwroot/downloads/heartbeat differ