mirror of https://github.com/hykilpikonna/AquaDX
[+] Automatic obtain request ip
parent
11eb7c058f
commit
322d90adfa
|
@ -7,6 +7,7 @@ import io.ktor.client.call.*
|
|||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.http.*
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
@ -18,17 +19,21 @@ class TurnstileProperties {
|
|||
var enable: Bool = false
|
||||
|
||||
lateinit var secret: Str
|
||||
|
||||
lateinit var ipHeader: Str
|
||||
}
|
||||
|
||||
@Service
|
||||
class CaptchaService(val props: TurnstileProperties) {
|
||||
class TurnstileService(val props: TurnstileProperties) {
|
||||
@Serializable
|
||||
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 (captcha == null) return false
|
||||
|
||||
val ip = request.getHeader(props.ipHeader) ?: request.remoteAddr
|
||||
|
||||
val outcome: Outcome = HTTP.post("https://challenges.cloudflare.com/turnstile/v0/siteverify") {
|
||||
setBody(
|
||||
FormDataContent(Parameters.build {
|
||||
|
|
Loading…
Reference in New Issue