🐛 Fixes captcha
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Text;
|
||||||
|
using dotnet_etcd.interfaces;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Yarp.ReverseProxy.Configuration;
|
using Yarp.ReverseProxy.Configuration;
|
||||||
|
|
||||||
@@ -5,7 +7,10 @@ namespace DysonNetwork.Gateway.Controllers;
|
|||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/.well-known")]
|
[Route("/.well-known")]
|
||||||
public class WellKnownController(IConfiguration configuration, IProxyConfigProvider proxyConfigProvider)
|
public class WellKnownController(
|
||||||
|
IConfiguration configuration,
|
||||||
|
IProxyConfigProvider proxyConfigProvider,
|
||||||
|
IEtcdClient etcdClient)
|
||||||
: ControllerBase
|
: ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("domains")]
|
[HttpGet("domains")]
|
||||||
@@ -16,6 +21,32 @@ public class WellKnownController(IConfiguration configuration, IProxyConfigProvi
|
|||||||
return Ok(domainMappings);
|
return Ok(domainMappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("services")]
|
||||||
|
public IActionResult GetServices()
|
||||||
|
{
|
||||||
|
var local = configuration.GetValue<bool>("LocalMode");
|
||||||
|
var response = etcdClient.GetRange("/services/");
|
||||||
|
var kvs = response.Kvs;
|
||||||
|
|
||||||
|
var serviceMap = kvs.ToDictionary(
|
||||||
|
kv => Encoding.UTF8.GetString(kv.Key.ToByteArray()).Replace("/services/", ""),
|
||||||
|
kv => Encoding.UTF8.GetString(kv.Value.ToByteArray())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (local) return Ok(serviceMap);
|
||||||
|
|
||||||
|
var domainMappings = configuration.GetSection("DomainMappings").GetChildren()
|
||||||
|
.ToDictionary(x => x.Key, x => x.Value);
|
||||||
|
foreach (var (key, _) in serviceMap.ToList())
|
||||||
|
{
|
||||||
|
if (!domainMappings.TryGetValue(key, out var domain)) continue;
|
||||||
|
if (domain is not null)
|
||||||
|
serviceMap[key] = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(serviceMap);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("routes")]
|
[HttpGet("routes")]
|
||||||
public IActionResult GetProxyRules()
|
public IActionResult GetProxyRules()
|
||||||
{
|
{
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"LocalMode": true,
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="h-full flex items-center justify-center">
|
<div class="h-full flex items-center justify-center">
|
||||||
<n-card class="max-w-lg text-center" title="Captcha">
|
<n-card class="max-w-lg text-center" title="Captcha">
|
||||||
<div class="flex justify-center my-4">
|
<div class="flex justify-center mb-4 mt-2">
|
||||||
<div v-if="provider === 'cloudflare'" class="cf-turnstile" :data-sitekey="apiKey" :data-callback="onSuccess"></div>
|
<div v-if="provider === 'cloudflare'" class="cf-turnstile" :data-sitekey="apiKey" data-callback="onTurnstileSuccess"></div>
|
||||||
<div v-else-if="provider === 'recaptcha'" class="g-recaptcha" :data-sitekey="apiKey" :data-callback="onSuccess"></div>
|
<div v-else-if="provider === 'recaptcha'" class="g-recaptcha" :data-sitekey="apiKey" data-callback="onRecaptchaSuccess"></div>
|
||||||
<div v-else-if="provider === 'hcaptcha'" class="h-captcha" :data-sitekey="apiKey" :data-callback="onSuccess"></div>
|
<div v-else-if="provider === 'hcaptcha'" class="h-captcha" :data-sitekey="apiKey" data-callback="onHcaptchaSuccess"></div>
|
||||||
<div v-else class="alert alert-warning">
|
<div v-else class="alert alert-warning">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||||
@@ -78,13 +78,33 @@ const loadCaptchaScript = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Handle successful CAPTCHA verification
|
// Handle successful CAPTCHA verification
|
||||||
const onSuccess = (token: string) => {
|
(window as any).onTurnstileSuccess = (token: string) => {
|
||||||
// Send token to parent window if in iframe
|
if (window.parent !== window) {
|
||||||
|
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
const redirectUri = route.query.redirect_uri as string;
|
||||||
|
if (redirectUri) {
|
||||||
|
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(window as any).onRecaptchaSuccess = (token: string) => {
|
||||||
|
if (window.parent !== window) {
|
||||||
|
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
const redirectUri = route.query.redirect_uri as string;
|
||||||
|
if (redirectUri) {
|
||||||
|
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(window as any).onHcaptchaSuccess = (token: string) => {
|
||||||
if (window.parent !== window) {
|
if (window.parent !== window) {
|
||||||
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
window.parent.postMessage(`captcha_tk=${token}`, '*');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle redirect if redirect_uri is present
|
|
||||||
const redirectUri = route.query.redirect_uri as string;
|
const redirectUri = route.query.redirect_uri as string;
|
||||||
if (redirectUri) {
|
if (redirectUri) {
|
||||||
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
window.location.href = `${redirectUri}?captcha_tk=${encodeURIComponent(token)}`;
|
||||||
|
Reference in New Issue
Block a user