Subversion Repositories php_clientchallenge

Rev

Rev 4 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 6
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * php_clientchallenge
4
 * php_clientchallenge
5
 * Copyright 2021 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2021-2022 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
9
 * You may obtain a copy of the License at
10
 *
10
 *
Line 27... Line 27...
27
 
27
 
28
if (isset($_REQUEST['action']) && ($_REQUEST['action'] === 'add_numbers')) {
28
if (isset($_REQUEST['action']) && ($_REQUEST['action'] === 'add_numbers')) {
29
 
29
 
30
        // Check request field "vts_validation_result" for valid response of the Challenge
30
        // Check request field "vts_validation_result" for valid response of the Challenge
31
        try {
31
        try {
-
 
32
                if (!isset($_REQUEST['vts_validation_result'])) throw new \Exception('No challenge response found');
-
 
33
                $client_response = @json_decode($_REQUEST['vts_validation_result'], true);
32
                \ViaThinkSoft\RateLimitingChallenge\ClientChallenge::checkValidation(MAX_TIME, VTS_CS_SERVER_SECRET);
34
                \ViaThinkSoft\RateLimitingChallenge\ClientChallenge::checkValidation($client_response, MAX_TIME, VTS_CS_SERVER_SECRET);
33
        } catch (\Exception $e) {
35
        } catch (\Exception $e) {
34
                $res = array("error" => $e->getMessage());
36
                $res = array("error" => $e->getMessage());
35
                header('Content-Type:application/json');
37
                header('Content-Type:application/json');
36
                die(json_encode($res));
38
                die(json_encode($res));
37
        }
39
        }