using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; using AyaNova.Models; using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; using System.Threading.Tasks; using AyaNova.Biz; using Newtonsoft.Json.Linq; using AyaNova.Util; using System.Linq; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //************************************************************************************************************** */ //JUNE 19th 2018 LARGE FILE UPLOAD POSSIBLY NEW INFO HERE: //http://www.talkingdotnet.com/how-to-increase-file-upload-size-asp-net-core/ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace AyaNova.Api.Controllers { /// /// Backup /// /// [ApiController] [ApiVersion("8.0")] [Route("api/v{version:apiVersion}/backup")] [Produces("application/json")] [Authorize] public class BackupController : ControllerBase { private readonly AyContext ct; private readonly ILogger log; private readonly ApiServerState serverState; /// /// /// /// /// /// public BackupController(AyContext dbcontext, ILogger logger, ApiServerState apiServerState) { ct = dbcontext; log = logger; serverState = apiServerState; } /// /// Trigger immediate system backup /// /// /// Job Id [HttpPost("backup-now")] [Authorize] public async Task PostServerState() { if (serverState.IsClosed) return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); if (!Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull | AuthorizationRoles.OpsAdminLimited)) return StatusCode(403, new ApiNotAuthorizedResponse()); var JobName = $"Backup (on demand)"; OpsJob j = new OpsJob(); j.Name = JobName; j.ObjectType = AyaType.NoType; j.JobType = JobType.Backup; j.SubType = JobSubType.NotSet; j.Exclusive = true; await JobsBiz.AddJobAsync(j, ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct); return Accepted(new { JobId = j.GId }); } /// /// Get list of backup files /// /// [HttpGet("list")] public ActionResult ListBackupFiles() { if (serverState.IsClosed) return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); if (!Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull | AuthorizationRoles.OpsAdminLimited)) return StatusCode(403, new ApiNotAuthorizedResponse()); return Ok(ApiOkResponse.Response(FileUtil.UtilityFileList())); } }//eoc }//eons