* Merge master in develop (#55)
* Fix reachable and IP leak test (#44)
* Fix reachable check
Fixes failing reachable checks when Basic Authentication is enabled in
Sonarr, Radarr, etc.
* Add option to disable IP leak test
* Revert "Fix reachable and IP leak test (#44)" (#46)
This reverts commit 3f5d7bbef3.
* Release 0.6.1 (#48)
* Fix typo
* Fix typos
* Fix typos
* Fix typo
* Clarify error message
* Fix reachable and ipleak test (#47)
* Fix reachable check
Fixes failing reachable checks when Basic Authentication is enabled in
Sonarr, Radarr, etc.
* Add option to disable IP leak test
---------
Co-authored-by: Jonas F <github@pcjones.de>
* Add IpLeakTest environment variable to docker compose
---------
Co-authored-by: akuntsch <github@akuntsch.de>
* Create Dockerfile.arm64
---------
Co-authored-by: akuntsch <github@akuntsch.de>
* Add configurable cache duration
* Make proxy port configurable
* Make proxy port configurable
* Add API Key auth
* Add default settings to appsettings
---------
Co-authored-by: akuntsch <github@akuntsch.de>
46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Text;
|
|
using System.Xml.Linq;
|
|
using UmlautAdaptarr.Options;
|
|
using UmlautAdaptarr.Services;
|
|
using UmlautAdaptarr.Utilities;
|
|
|
|
namespace UmlautAdaptarr.Controllers
|
|
{
|
|
public class CapsController(ProxyRequestService proxyRequestService, IOptions<GlobalOptions> options, ILogger<CapsController> logger) : ControllerBase
|
|
{
|
|
private readonly ProxyRequestService _proxyRequestService = proxyRequestService;
|
|
private readonly GlobalOptions _options = options.Value;
|
|
private readonly ILogger<CapsController> _logger = logger;
|
|
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> Caps([FromRoute] string apiKey, [FromRoute] string domain, [FromQuery] string? apikey)
|
|
{
|
|
if (_options.ApiKey != null && !apiKey.Equals(apiKey))
|
|
{
|
|
_logger.LogWarning("Invalid or missing API key for request.");
|
|
return Unauthorized("Unauthorized: Invalid or missing API key.");
|
|
}
|
|
|
|
if (!domain.StartsWith("localhost") && !UrlUtilities.IsValidDomain(domain))
|
|
{
|
|
return NotFound($"{domain} is not a valid URL.");
|
|
}
|
|
|
|
var requestUrl = UrlUtilities.BuildUrl(domain, "caps", apikey);
|
|
|
|
var responseMessage = await _proxyRequestService.ProxyRequestAsync(HttpContext, requestUrl);
|
|
|
|
var content = await responseMessage.Content.ReadAsStringAsync();
|
|
var encoding = responseMessage.Content.Headers.ContentType?.CharSet != null ?
|
|
Encoding.GetEncoding(responseMessage.Content.Headers.ContentType.CharSet) :
|
|
Encoding.UTF8;
|
|
var contentType = responseMessage.Content.Headers.ContentType?.MediaType ?? "application/xml";
|
|
|
|
return Content(content, contentType, encoding);
|
|
}
|
|
}
|
|
}
|