This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# OPS-LOG Placeholder
|
||||
|
||||
[UNDER CONSTRUCTION]
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ using AyaNova.Models;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -109,25 +110,44 @@ namespace AyaNova.Api.Controllers
|
||||
//Iterate all log files and build return
|
||||
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();
|
||||
ret.Insert(0, "log-ayanova.txt");
|
||||
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}");
|
||||
}
|
||||
|
||||
//------------
|
||||
|
||||
|
||||
@@ -2309,5 +2309,6 @@
|
||||
"CompanyEmail": "Email",
|
||||
"CompanyPhone1": "Geschäftstelefon",
|
||||
"CompanyPhone2": "Telefon 2",
|
||||
"RenderingReport":"Berichterstellung im Gange"
|
||||
"RenderingReport":"Berichterstellung im Gange",
|
||||
"Download":"Herunterladen"
|
||||
}
|
||||
@@ -2309,5 +2309,6 @@
|
||||
"CompanyEmail": "Email",
|
||||
"CompanyPhone1": "Business phone number",
|
||||
"CompanyPhone2": "Phone 2",
|
||||
"RenderingReport":"Generating report"
|
||||
"RenderingReport":"Generating report",
|
||||
"Download":"Download"
|
||||
}
|
||||
@@ -2309,5 +2309,6 @@
|
||||
"CompanyEmail": "Email",
|
||||
"CompanyPhone1": "Teléfono",
|
||||
"CompanyPhone2": "Teléfono 2",
|
||||
"RenderingReport":"Generación de informes en curso"
|
||||
"RenderingReport":"Generación de informes en curso",
|
||||
"Download":"Descargar"
|
||||
}
|
||||
@@ -2309,5 +2309,6 @@
|
||||
"CompanyEmail": "Email",
|
||||
"CompanyPhone1": "Phone 1",
|
||||
"CompanyPhone2": "Phone 2",
|
||||
"RenderingReport":"Génération de rapport en cours"
|
||||
"RenderingReport":"Génération de rapport en cours",
|
||||
"Download":"Télécharger"
|
||||
}
|
||||
Reference in New Issue
Block a user