mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-10 21:07:27 +08:00
[+] Automatic obtain request ip
This commit is contained in:
@@ -7,6 +7,7 @@ import io.ktor.client.call.*
|
|||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.request.forms.*
|
import io.ktor.client.request.forms.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
@@ -18,17 +19,21 @@ class TurnstileProperties {
|
|||||||
var enable: Bool = false
|
var enable: Bool = false
|
||||||
|
|
||||||
lateinit var secret: Str
|
lateinit var secret: Str
|
||||||
|
|
||||||
|
lateinit var ipHeader: Str
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class CaptchaService(val props: TurnstileProperties) {
|
class TurnstileService(val props: TurnstileProperties) {
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Outcome(val success: Boolean)
|
data class Outcome(val success: Boolean)
|
||||||
|
|
||||||
suspend fun validate(captcha: Str?, ip: Str): Boolean {
|
suspend fun validate(captcha: Str?, request: HttpServletRequest): Boolean {
|
||||||
if (!props.enable) return true
|
if (!props.enable) return true
|
||||||
if (captcha == null) return false
|
if (captcha == null) return false
|
||||||
|
|
||||||
|
val ip = request.getHeader(props.ipHeader) ?: request.remoteAddr
|
||||||
|
|
||||||
val outcome: Outcome = HTTP.post("https://challenges.cloudflare.com/turnstile/v0/siteverify") {
|
val outcome: Outcome = HTTP.post("https://challenges.cloudflare.com/turnstile/v0/siteverify") {
|
||||||
setBody(
|
setBody(
|
||||||
FormDataContent(Parameters.build {
|
FormDataContent(Parameters.build {
|
||||||
|
|||||||
Reference in New Issue
Block a user