summaryrefslogtreecommitdiff
path: root/public/captcha.php
blob: c872672abd511f826d510e66311ef49cbdbf10f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include_once "../src/config.php";
include_once "../src/alert.php";

session_start();

if (!HCAPTCHA_ENABLE) {
    $_SESSION["captcha_solved"] = true;
    header("Location: /");
    exit;
}

if (isset($_SESSION["captcha_solved"]) && $_SESSION["captcha_solved"]) {
    header("Location: /");
    exit;
}

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["h-captcha-response"])) {
    // sending a request to captcha api
    $request = curl_init("https://hcaptcha.com/siteverify");
    curl_setopt($request, CURLOPT_POST, 1);
    curl_setopt($request, CURLOPT_HTTPHEADER, [sprintf("User-Agent: %s/1.0", INSTANCE_NAME)]);
    curl_setopt(
        $request,
        CURLOPT_POSTFIELDS,
        http_build_query(array("secret" => HCAPTCHA_SECRETKEY, "response" => $_POST["h-captcha-response"]))
    );
    curl_setopt($request, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($request);
    curl_close($request);

    $json = json_decode($response);

    if ($json->success) {
        $_SESSION["captcha_solved"] = true;
        header("Location: /");
        exit;
    }
}
?>

<html>

<head>
    <title>Resolving a hCaptcha - <?php echo INSTANCE_NAME ?></title>
    <link rel="stylesheet" href="/static/style.css">
    <script src='https://www.hCaptcha.com/1/api.js' async defer></script>
</head>

<body>
    <noscript>JavaScript is required to solve hCaptcha</noscript>
    <div class="container">
        <div class="wrapper">
            <section class="row" style="padding: 4px; justify-content: center;">
                <section class="box">
                    <div class="h-captcha" data-sitekey="<?php echo HCAPTCHA_SITEKEY ?>"></div>
                </section>
            </section>
        </div>
    </div>
</body>

</html>