CodeLiturgy.Dashboard/CodeLiturgy.Views/Controllers/ApacheController.cs

77 lines
2.2 KiB
C#

using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Domain;
using CodeLiturgy.Views.Augeas;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Sharp.Augeas;
using System.Text.Json;
namespace CodeLiturgy.Views.Controllers
{
[ApiController]
[Authorize]
public class ApacheController : ControllerBase
{
private ILogger<SitesController> _logger;
private readonly SiteDbContext _siteDbContext;
private readonly AugeasManager _augeasManager;
public ApacheController(
ApplicationUserManager userManager,
ILogger<SitesController> logger,
SiteDbContext siteDbContext,
AugeasManager augeasManager)
{
_logger = logger;
_siteDbContext = siteDbContext;
_augeasManager = augeasManager;
}
[HttpGet("/api/apache")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public ActionResult GetSites(
int skip = 0, int take = 50, int orderDir = 1)
{
var sites = _augeasManager
.GetApacheAvailableConfigurations(skip, take);
return Ok(sites);
}
[HttpGet("/api/apache/preview/{site}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public ActionResult GetSitePreview(
string site)
{
var preview = _augeasManager
.GetPreview(site);
return Ok(preview);
}
[HttpGet("/api/apache/tree/{site}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public ActionResult<SuperNode> GetSiteTree(
string site)
{
var tree = _augeasManager
.GetVirtualHostTree(site);
return Ok(tree);
}
}
}