This commit is contained in:
2022-01-03 19:25:10 +00:00
parent 80f0288fce
commit 3fc4cafc41
6 changed files with 42 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
# OPS-LOG Placeholder # OPS-LOG Placeholder
[UNDER CONSTRUCTION] [UNDER CONSTRUCTION]

View File

@@ -8,7 +8,8 @@ using AyaNova.Models;
using AyaNova.Util; using AyaNova.Util;
using AyaNova.Api.ControllerHelpers; using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz; using AyaNova.Biz;
using System.Threading.Tasks;
using System;
namespace AyaNova.Api.Controllers namespace AyaNova.Api.Controllers
{ {
@@ -109,25 +110,44 @@ namespace AyaNova.Api.Controllers
//Iterate all log files and build return //Iterate all log files and build return
var files = System.IO.Directory.GetFiles(ServerBootConfig.AYANOVA_LOG_PATH, "log-ayanova*.txt"); var files = System.IO.Directory.GetFiles(ServerBootConfig.AYANOVA_LOG_PATH, "log-ayanova*.txt");
// Newtonsoft.Json.Linq.JObject o = Newtonsoft.Json.Linq.JObject.FromObject(new
// {
// logs =
// from f in files
// orderby f
// select new
// {
// logName = System.IO.Path.GetFileName(f)
// }
// });
var ret = files.Where(z => !z.EndsWith("ayanova.txt")).OrderByDescending(z => z).Select(z => System.IO.Path.GetFileName(z)).ToList(); var ret = files.Where(z => !z.EndsWith("ayanova.txt")).OrderByDescending(z => z).Select(z => System.IO.Path.GetFileName(z)).ToList();
ret.Insert(0, "log-ayanova.txt"); ret.Insert(0, "log-ayanova.txt");
return Ok(ApiOkResponse.Response(ret)); return Ok(ApiOkResponse.Response(ret));
} }
/// <summary>
/// Download log
/// </summary>
/// <param name="logname"></param>
/// <param name="t">download token</param>
/// <returns>A single log file</returns>
[AllowAnonymous]
[HttpGet("download/{logname}")]
public async Task<IActionResult> DownloadLog([FromRoute] string logname, [FromQuery] string t)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var user = await UserBiz.ValidateDownloadTokenAndReturnUserAsync(t, ct);
if (user == null)
{
await Task.Delay(AyaNova.Util.ServerBootConfig.FAILED_AUTH_DELAY);//DOS protection
return StatusCode(401, new ApiErrorResponse(ApiErrorCode.AUTHENTICATION_FAILED));
}
if (!Authorized.HasReadFullRole(user.Roles, AyaType.LogFile))
return StatusCode(403, new ApiNotAuthorizedResponse());
var logFilePath = System.IO.Path.Combine(ServerBootConfig.AYANOVA_LOG_PATH, logname);
if (!System.IO.File.Exists(logFilePath))
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return PhysicalFile(logFilePath, "text/plain", $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}-{logname}");
}
//------------ //------------

View File

@@ -2309,5 +2309,6 @@
"CompanyEmail": "Email", "CompanyEmail": "Email",
"CompanyPhone1": "Geschäftstelefon", "CompanyPhone1": "Geschäftstelefon",
"CompanyPhone2": "Telefon 2", "CompanyPhone2": "Telefon 2",
"RenderingReport":"Berichterstellung im Gange" "RenderingReport":"Berichterstellung im Gange",
"Download":"Herunterladen"
} }

View File

@@ -2309,5 +2309,6 @@
"CompanyEmail": "Email", "CompanyEmail": "Email",
"CompanyPhone1": "Business phone number", "CompanyPhone1": "Business phone number",
"CompanyPhone2": "Phone 2", "CompanyPhone2": "Phone 2",
"RenderingReport":"Generating report" "RenderingReport":"Generating report",
"Download":"Download"
} }

View File

@@ -2309,5 +2309,6 @@
"CompanyEmail": "Email", "CompanyEmail": "Email",
"CompanyPhone1": "Teléfono", "CompanyPhone1": "Teléfono",
"CompanyPhone2": "Teléfono 2", "CompanyPhone2": "Teléfono 2",
"RenderingReport":"Generación de informes en curso" "RenderingReport":"Generación de informes en curso",
"Download":"Descargar"
} }

View File

@@ -2309,5 +2309,6 @@
"CompanyEmail": "Email", "CompanyEmail": "Email",
"CompanyPhone1": "Phone 1", "CompanyPhone1": "Phone 1",
"CompanyPhone2": "Phone 2", "CompanyPhone2": "Phone 2",
"RenderingReport":"Génération de rapport en cours" "RenderingReport":"Génération de rapport en cours",
"Download":"Télécharger"
} }