Plugin Directory

Changeset 2916773


Ignore:
Timestamp:
05/24/2023 11:00:16 AM (3 years ago)
Author:
verifiedvisitors
Message:

tagging version 1.1.0

Location:
verifiedvisitors
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • verifiedvisitors/tags/1.1.0/VerifiedVisitors.php

    r2890354 r2916773  
    55/**
    66 * @package VerifiedVisitors
    7  * @version 1.0.0
     7 * @version 1.1.0
    88 *
    99 * Plugin Name: VerifiedVisitors
     
    1212 * Author: VerifiedVisitors
    1313 * Author URI: https://www.verifiedvisitors.com/
    14  * Version: 1.0.0
    15  * Stable tag: 1.0.0
     14 * Version: 1.1.0
     15 * Stable tag: 1.1.0
    1616 * Requires at least: 4.9
    1717 * Requires PHP: 7.2
  • verifiedvisitors/tags/1.1.0/class.admin.php

    r2890354 r2916773  
    4343    function settings_section_callback()
    4444    {
    45         // echo '<p>Verified Visitors API Key</p>';
     45?>
     46        <p>API keys can be generated from your profile settings page in the VerifiedVisitors dashboard.</p>
     47        <p>Please see the install instructions for more information.</p>
     48    <?php
    4649    }
    4750
     
    4952    {
    5053        $setting = get_option(Config::VV_API_KEY_OPTION);
    51 ?>
     54    ?>
    5255        <input type="text" style="width: 500px" name="<?php echo Config::VV_API_KEY_OPTION ?>" value="<?php echo isset($setting) ? esc_attr($setting) : ''; ?>" />
    53         <p>API keys can be generated from your profile settings page in the VerifiedVisitors dashboard.</p>
    54         <p>Please see the install instructions for more information.</p>
    5556    <?php
    5657    }
     
    7071    function options_page_html()
    7172    {
    72         // Check user capabilities
    7373        if (!current_user_can('manage_options')) {
    7474            return;
    7575        }
    7676
    77         // Add error/update messages
     77        $option_key = Config::VV_API_KEY_OPTION;
    7878
    79         // Check if the user have submitted the settings
    80         // WordPress will add the "settings-updated" $_GET parameter to the url
    8179        if (isset($_GET['settings-updated'])) {
    82             // Add settings saved message with the class of "updated"
    83             add_settings_error(
    84                 'vv_messages',
    85                 'vv_message',
    86                 'Settings saved successfully',
    87                 'updated'
     80            $response = wp_remote_post(
     81                Config::API_URL,
     82                array(
     83                    'headers' => array(
     84                        'authorization' => 'bearer ' . get_option($option_key)
     85                    ),
     86                    'timeout' => 5
     87                )
    8888            );
     89
     90            $response_code = wp_remote_retrieve_response_code($response);
     91            error_log($response_code);
     92
     93            if ($response_code == 400) {
     94                add_settings_error(
     95                    $option_key,
     96                    "{$option_key}_success",
     97                    'Settings saved successfully',
     98                    'updated'
     99                );
     100            } else {
     101                add_settings_error(
     102                    $option_key,
     103                    "{$option_key}_failed_to_verify",
     104                    'Failed to verify API token',
     105                    'error'
     106                );
     107            }
    89108        }
    90109
    91         // Show error/update messages
    92         settings_errors('vv_messages');
     110        settings_errors($option_key);
    93111    ?>
    94112        <div class="wrap">
     
    96114            <form action="options.php" method="post">
    97115                <?php
    98                 // Output security fields for the registered setting "vv"
    99116                settings_fields('vv');
    100                 // Output setting sections and their fields (sections are registered for "vv", each field is registered to a specific section)
    101117                do_settings_sections('vv');
    102                 // Output save settings button
    103118                submit_button('Save');
    104119                ?>
  • verifiedvisitors/tags/1.1.0/class.config.php

    r2890354 r2916773  
    1010    public const COOKIE_NAME = 'vv_vid';
    1111    public const COOKIE_EXPIRATION = 30 * DAY_IN_SECONDS;
    12     public const VERSION = '1.0.0';
     12    public const VERSION = '1.1.0';
    1313    public const H_CAPTCHA_RESPONSE_KEY = "hCaptchaResponse";
    1414}
  • verifiedvisitors/tags/1.1.0/models/class.vac-request.php

    r2890354 r2916773  
    99    public $host;
    1010    public $uri;
     11    public $method;
     12    public $headers;
     13    public $connection;
     14    public $referer;
     15    public $origin;
     16    public $pragma;
     17    public $xForwardedFor;
     18    public $xForwardedProto;
     19    public $xRequestedWith;
     20    public $xRealIp;
     21    public $trueClientIp;
     22    public $via;
     23    public $accept;
     24    public $acceptEncoding;
     25    public $acceptLanguage;
     26    public $acceptCharset;
     27    public $contentType;
     28    public $contentLength;
     29    public $cacheControl;
    1130    public $hCaptchaToken;
    12     public $method;
    13     public $referer;
    14     public $xForwardedFor;
    1531    public $worker;
    1632
     
    2036        string $host,
    2137        string $uri,
     38        string $method,
     39        ?array $headers,
     40        ?string $connection,
     41        ?string $referer,
     42        ?string $origin,
     43        ?string $pragma,
     44        ?string $xForwardedFor,
     45        ?string $xForwardedProto,
     46        ?string $xRequestedWith,
     47        ?string $xRealIp,
     48        ?string $trueClientIp,
     49        ?string $via,
     50        ?string $accept,
     51        ?string $acceptEncoding,
     52        ?string $acceptLanguage,
     53        ?string $acceptCharset,
     54        ?string $contentType,
     55        ?string $contentLength,
     56        ?string $cacheControl,
    2257        ?string $hCaptchaToken,
    23         string $method,
    24         ?string $referer,
    25         ?string $xForwardedFor,
    2658        Worker $worker
    2759    ) {
     
    3062        $this->host = $host;
    3163        $this->uri = $uri;
     64        $this->method = $method;
     65        $this->headers = $headers;
     66        $this->connection = $connection;
     67        $this->referer = $referer;
     68        $this->origin = $origin;
     69        $this->pragma = $pragma;
     70        $this->xForwardedFor = $xForwardedFor;
     71        $this->xForwardedProto = $xForwardedProto;
     72        $this->xRequestedWith = $xRequestedWith;
     73        $this->xRealIp = $xRealIp;
     74        $this->trueClientIp =  $trueClientIp;
     75        $this->via =  $via;
     76        $this->accept =  $accept;
     77        $this->acceptEncoding =  $acceptEncoding;
     78        $this->acceptLanguage =  $acceptLanguage;
     79        $this->acceptCharset =  $acceptCharset;
     80        $this->contentType =  $contentType;
     81        $this->contentLength =  $contentLength;
     82        $this->cacheControl =  $cacheControl;
    3283        $this->hCaptchaToken = $hCaptchaToken;
    33         $this->method = $method;
    34         $this->referer = $referer;
    35         $this->xForwardedFor = $xForwardedFor;
    3684        $this->worker = $worker;
    3785    }
  • verifiedvisitors/tags/1.1.0/readme.txt

    r2890354 r2916773  
    44Requires at least: 4.9
    55Tested up to: 6.1
    6 Stable tag: 1.0.0
     6Stable tag: 1.1.0
    77Requires PHP: 7.2
    88License: GPLv3 or later
     
    110110== Changelog ==
    111111
     112= 1.1.0 =
     113* Collect additional request headers for improved visitor categorisation
     114* Validate API key in plugin settings page
     115* General improvements
     116
    112117= 1.0 =
    113118* Initial release.
  • verifiedvisitors/tags/1.1.0/utils/class.request-utils.php

    r2890354 r2916773  
    55class RequestUtils
    66{
     7    private static function get_raw_server_value(string $name)
     8    {
     9        if (array_key_exists($name, $_SERVER) && !empty($_SERVER[$name])) {
     10            $sanitised_value = sanitize_text_field($_SERVER[$name]);
     11            return $sanitised_value;
     12        }
     13        return null;
     14    }
     15
     16    private static function get_ip_address(string $name)
     17    {
     18        $sanitised_value = self::get_raw_server_value($name);
     19        $filtered_value = filter_var($sanitised_value, FILTER_VALIDATE_IP);
     20        if ($filtered_value == false) {
     21            error_log("{$name} was not a valid IP address");
     22            $filtered_value = null;
     23        }
     24        return $filtered_value;
     25    }
     26
     27    private static function get_request_method()
     28    {
     29        $sanitised_method = self::get_raw_server_value('REQUEST_METHOD');
     30        $method = ValidateUtils::validate_request_method($sanitised_method);
     31        if ($method == null) {
     32            error_log('REQUEST_METHOD was not a valid HTTP method');
     33        }
     34        return $method;
     35    }
     36
    737    public static function build_vac_request(?string $vv_vid)
    838    {
    939        $headers = getallheaders();
    10         $user_agent = $headers['User-Agent'] ?? null;
    11         $host = $headers['Host'] ?? null;
    12         $contextType = $headers['Content-Type'] ?? null;
    1340
    14         $client_ip = filter_var(sanitize_text_field($_SERVER['HTTP_CLIENT_IP']), FILTER_VALIDATE_IP);
    15         if ($client_ip == false) {
    16             error_log('HTTP_CLIENT_IP was not a valid IP address');
    17             $client_ip = null;
    18         }
     41        $request_time = self::get_raw_server_value('REQUEST_TIME_FLOAT') ?? microtime(true);
     42        $milliseconds = floor($request_time * 1000);
    1943
    20         $x_forwarded_for = filter_var(sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']), FILTER_VALIDATE_IP);
    21         if ($x_forwarded_for == false) {
    22             error_log('HTTP_X_FORWARDED_FOR was not a valid IP address');
    23             $x_forwarded_for = null;
    24         }
    25 
    26         $remote_addr = filter_var(sanitize_text_field($_SERVER['REMOTE_ADDR']), FILTER_VALIDATE_IP);
    27         if ($remote_addr == false) {
    28             error_log('REMOTE_ADDR was not a valid IP address');
    29             $remote_addr = null;
    30         }
    31 
    32         $ip = $client_ip;
    33         if ($ip == null) {
    34             $ip = $remote_addr;
    35         }
    36 
    37         $escaped_url = esc_url(sanitize_text_field($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
     44        $sanitised_host = self::get_raw_server_value('HTTP_HOST');
     45        $sanitised_uri = self::get_raw_server_value('REQUEST_URI');
     46        $sanitised_url = "{$sanitised_host}{$sanitised_uri}";
     47        $escaped_url = esc_url($sanitised_url);
    3848        $host = wp_parse_url($escaped_url, PHP_URL_HOST);
    3949        $path = wp_parse_url($escaped_url, PHP_URL_PATH);
    4050        $query_string = wp_parse_url($escaped_url, PHP_URL_QUERY);
     51        $query_string = empty($query_string) ? "" : "?{$query_string}";
     52        $uri = "{$host}{$path}{$query_string}";
     53        $method = self::get_request_method();
    4154
    42         $uri = $host . $path;
    43         if (!empty($query_string)) {
    44             $uri = "{$uri}?{$query_string}";
    45         }
     55        $connection = self::get_raw_server_value('HTTP_CONNECTION');
    4656
    47         $method = !empty($_SERVER['REQUEST_METHOD'])
    48             ? ValidateUtils::validate_request_method(sanitize_text_field($_SERVER['REQUEST_METHOD']))
    49             : null;
    50         if ($method == null) {
    51             error_log('REQUEST_METHOD was not a valid HTTP method');
    52         }
     57        $referer = esc_url(self::get_raw_server_value('HTTP_REFERER'));
     58        $origin = self::get_raw_server_value('HTTP_ORIGIN');
     59        $pragma = self::get_raw_server_value('HTTP_PRAGMA');
    5360
    54         $referer = esc_url(sanitize_text_field($_SERVER['HTTP_REFERER']));
     61        $user_agent = self::get_raw_server_value('HTTP_USER_AGENT');
     62        $host = self::get_raw_server_value('HTTP_HOST');
     63
     64        $client_ip = self::get_ip_address('HTTP_CLIENT_IP');
     65        $remote_addr = self::get_ip_address('REMOTE_ADDR');
     66        $ip = $client_ip ?? $remote_addr;
     67
     68        $x_forwarded_for = self::get_ip_address('HTTP_X_FORWARDED_FOR');
     69        $x_forwarded_proto = self::get_raw_server_value('HTTP_X_FORWARDED_PROTO');
     70        $x_requested_with = self::get_raw_server_value('HTTP_X_REQUESTED_WITH');
     71        $x_real_ip = self::get_ip_address('HTTP_X_REAL_IP');
     72        $true_client_ip = self::get_ip_address('HTTP_TRUE_CLIENT_IP');
     73        $via = self::get_raw_server_value('HTTP_VIA');
     74
     75        $accept_encoding = self::get_raw_server_value('HTTP_ACCEPT_ENCODING');
     76        $accept = self::get_raw_server_value('HTTP_ACCEPT');
     77        $accept_language = self::get_raw_server_value('HTTP_ACCEPT_LANGUAGE');
     78        $accept_charset = self::get_raw_server_value('HTTP_ACCEPT_CHARSET');
     79
     80        $content_type = $headers['Content-Type'];
     81        $content_length = $headers['Content-Length'];
     82
     83        $cache_control = self::get_raw_server_value('HTTP_CACHE_CONTROL');
    5584
    5685        $token = null;
    57         if ($method == 'POST' && StringUtils::str_starts_with($contextType, "application/json")) {
     86        if ($method == 'POST' && StringUtils::str_starts_with($content_type, "application/json")) {
    5887            $post = file_get_contents('php://input');
    5988            $data = json_decode($post);
    6089            $token = $data->hCaptchaResponse;
    6190        }
    62 
    63         $milliseconds = floor(microtime(true) * 1000);
    6491
    6592        $vac_request = new VacRequest(
     
    6895            $host,
    6996            $uri,
     97            $method,
     98            array_keys($headers),
     99            $connection,
     100            $referer,
     101            $origin,
     102            $pragma,
     103            $x_forwarded_for,
     104            $x_forwarded_proto,
     105            $x_requested_with,
     106            $x_real_ip,
     107            $true_client_ip,
     108            $via,
     109            $accept,
     110            $accept_encoding,
     111            $accept_language,
     112            $accept_charset,
     113            $content_type,
     114            $content_length,
     115            $cache_control,
    70116            $token,
    71             $method,
    72             $referer,
    73             $x_forwarded_for,
    74117            new Worker(Config::VERSION)
    75118        );
  • verifiedvisitors/trunk/VerifiedVisitors.php

    r2890354 r2916773  
    55/**
    66 * @package VerifiedVisitors
    7  * @version 1.0.0
     7 * @version 1.1.0
    88 *
    99 * Plugin Name: VerifiedVisitors
     
    1212 * Author: VerifiedVisitors
    1313 * Author URI: https://www.verifiedvisitors.com/
    14  * Version: 1.0.0
    15  * Stable tag: 1.0.0
     14 * Version: 1.1.0
     15 * Stable tag: 1.1.0
    1616 * Requires at least: 4.9
    1717 * Requires PHP: 7.2
  • verifiedvisitors/trunk/class.admin.php

    r2890354 r2916773  
    4343    function settings_section_callback()
    4444    {
    45         // echo '<p>Verified Visitors API Key</p>';
     45?>
     46        <p>API keys can be generated from your profile settings page in the VerifiedVisitors dashboard.</p>
     47        <p>Please see the install instructions for more information.</p>
     48    <?php
    4649    }
    4750
     
    4952    {
    5053        $setting = get_option(Config::VV_API_KEY_OPTION);
    51 ?>
     54    ?>
    5255        <input type="text" style="width: 500px" name="<?php echo Config::VV_API_KEY_OPTION ?>" value="<?php echo isset($setting) ? esc_attr($setting) : ''; ?>" />
    53         <p>API keys can be generated from your profile settings page in the VerifiedVisitors dashboard.</p>
    54         <p>Please see the install instructions for more information.</p>
    5556    <?php
    5657    }
     
    7071    function options_page_html()
    7172    {
    72         // Check user capabilities
    7373        if (!current_user_can('manage_options')) {
    7474            return;
    7575        }
    7676
    77         // Add error/update messages
     77        $option_key = Config::VV_API_KEY_OPTION;
    7878
    79         // Check if the user have submitted the settings
    80         // WordPress will add the "settings-updated" $_GET parameter to the url
    8179        if (isset($_GET['settings-updated'])) {
    82             // Add settings saved message with the class of "updated"
    83             add_settings_error(
    84                 'vv_messages',
    85                 'vv_message',
    86                 'Settings saved successfully',
    87                 'updated'
     80            $response = wp_remote_post(
     81                Config::API_URL,
     82                array(
     83                    'headers' => array(
     84                        'authorization' => 'bearer ' . get_option($option_key)
     85                    ),
     86                    'timeout' => 5
     87                )
    8888            );
     89
     90            $response_code = wp_remote_retrieve_response_code($response);
     91            error_log($response_code);
     92
     93            if ($response_code == 400) {
     94                add_settings_error(
     95                    $option_key,
     96                    "{$option_key}_success",
     97                    'Settings saved successfully',
     98                    'updated'
     99                );
     100            } else {
     101                add_settings_error(
     102                    $option_key,
     103                    "{$option_key}_failed_to_verify",
     104                    'Failed to verify API token',
     105                    'error'
     106                );
     107            }
    89108        }
    90109
    91         // Show error/update messages
    92         settings_errors('vv_messages');
     110        settings_errors($option_key);
    93111    ?>
    94112        <div class="wrap">
     
    96114            <form action="options.php" method="post">
    97115                <?php
    98                 // Output security fields for the registered setting "vv"
    99116                settings_fields('vv');
    100                 // Output setting sections and their fields (sections are registered for "vv", each field is registered to a specific section)
    101117                do_settings_sections('vv');
    102                 // Output save settings button
    103118                submit_button('Save');
    104119                ?>
  • verifiedvisitors/trunk/class.config.php

    r2890354 r2916773  
    1010    public const COOKIE_NAME = 'vv_vid';
    1111    public const COOKIE_EXPIRATION = 30 * DAY_IN_SECONDS;
    12     public const VERSION = '1.0.0';
     12    public const VERSION = '1.1.0';
    1313    public const H_CAPTCHA_RESPONSE_KEY = "hCaptchaResponse";
    1414}
  • verifiedvisitors/trunk/models/class.vac-request.php

    r2890354 r2916773  
    99    public $host;
    1010    public $uri;
     11    public $method;
     12    public $headers;
     13    public $connection;
     14    public $referer;
     15    public $origin;
     16    public $pragma;
     17    public $xForwardedFor;
     18    public $xForwardedProto;
     19    public $xRequestedWith;
     20    public $xRealIp;
     21    public $trueClientIp;
     22    public $via;
     23    public $accept;
     24    public $acceptEncoding;
     25    public $acceptLanguage;
     26    public $acceptCharset;
     27    public $contentType;
     28    public $contentLength;
     29    public $cacheControl;
    1130    public $hCaptchaToken;
    12     public $method;
    13     public $referer;
    14     public $xForwardedFor;
    1531    public $worker;
    1632
     
    2036        string $host,
    2137        string $uri,
     38        string $method,
     39        ?array $headers,
     40        ?string $connection,
     41        ?string $referer,
     42        ?string $origin,
     43        ?string $pragma,
     44        ?string $xForwardedFor,
     45        ?string $xForwardedProto,
     46        ?string $xRequestedWith,
     47        ?string $xRealIp,
     48        ?string $trueClientIp,
     49        ?string $via,
     50        ?string $accept,
     51        ?string $acceptEncoding,
     52        ?string $acceptLanguage,
     53        ?string $acceptCharset,
     54        ?string $contentType,
     55        ?string $contentLength,
     56        ?string $cacheControl,
    2257        ?string $hCaptchaToken,
    23         string $method,
    24         ?string $referer,
    25         ?string $xForwardedFor,
    2658        Worker $worker
    2759    ) {
     
    3062        $this->host = $host;
    3163        $this->uri = $uri;
     64        $this->method = $method;
     65        $this->headers = $headers;
     66        $this->connection = $connection;
     67        $this->referer = $referer;
     68        $this->origin = $origin;
     69        $this->pragma = $pragma;
     70        $this->xForwardedFor = $xForwardedFor;
     71        $this->xForwardedProto = $xForwardedProto;
     72        $this->xRequestedWith = $xRequestedWith;
     73        $this->xRealIp = $xRealIp;
     74        $this->trueClientIp =  $trueClientIp;
     75        $this->via =  $via;
     76        $this->accept =  $accept;
     77        $this->acceptEncoding =  $acceptEncoding;
     78        $this->acceptLanguage =  $acceptLanguage;
     79        $this->acceptCharset =  $acceptCharset;
     80        $this->contentType =  $contentType;
     81        $this->contentLength =  $contentLength;
     82        $this->cacheControl =  $cacheControl;
    3283        $this->hCaptchaToken = $hCaptchaToken;
    33         $this->method = $method;
    34         $this->referer = $referer;
    35         $this->xForwardedFor = $xForwardedFor;
    3684        $this->worker = $worker;
    3785    }
  • verifiedvisitors/trunk/readme.txt

    r2890354 r2916773  
    44Requires at least: 4.9
    55Tested up to: 6.1
    6 Stable tag: 1.0.0
     6Stable tag: 1.1.0
    77Requires PHP: 7.2
    88License: GPLv3 or later
     
    110110== Changelog ==
    111111
     112= 1.1.0 =
     113* Collect additional request headers for improved visitor categorisation
     114* Validate API key in plugin settings page
     115* General improvements
     116
    112117= 1.0 =
    113118* Initial release.
  • verifiedvisitors/trunk/utils/class.request-utils.php

    r2890354 r2916773  
    55class RequestUtils
    66{
     7    private static function get_raw_server_value(string $name)
     8    {
     9        if (array_key_exists($name, $_SERVER) && !empty($_SERVER[$name])) {
     10            $sanitised_value = sanitize_text_field($_SERVER[$name]);
     11            return $sanitised_value;
     12        }
     13        return null;
     14    }
     15
     16    private static function get_ip_address(string $name)
     17    {
     18        $sanitised_value = self::get_raw_server_value($name);
     19        $filtered_value = filter_var($sanitised_value, FILTER_VALIDATE_IP);
     20        if ($filtered_value == false) {
     21            error_log("{$name} was not a valid IP address");
     22            $filtered_value = null;
     23        }
     24        return $filtered_value;
     25    }
     26
     27    private static function get_request_method()
     28    {
     29        $sanitised_method = self::get_raw_server_value('REQUEST_METHOD');
     30        $method = ValidateUtils::validate_request_method($sanitised_method);
     31        if ($method == null) {
     32            error_log('REQUEST_METHOD was not a valid HTTP method');
     33        }
     34        return $method;
     35    }
     36
    737    public static function build_vac_request(?string $vv_vid)
    838    {
    939        $headers = getallheaders();
    10         $user_agent = $headers['User-Agent'] ?? null;
    11         $host = $headers['Host'] ?? null;
    12         $contextType = $headers['Content-Type'] ?? null;
    1340
    14         $client_ip = filter_var(sanitize_text_field($_SERVER['HTTP_CLIENT_IP']), FILTER_VALIDATE_IP);
    15         if ($client_ip == false) {
    16             error_log('HTTP_CLIENT_IP was not a valid IP address');
    17             $client_ip = null;
    18         }
     41        $request_time = self::get_raw_server_value('REQUEST_TIME_FLOAT') ?? microtime(true);
     42        $milliseconds = floor($request_time * 1000);
    1943
    20         $x_forwarded_for = filter_var(sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']), FILTER_VALIDATE_IP);
    21         if ($x_forwarded_for == false) {
    22             error_log('HTTP_X_FORWARDED_FOR was not a valid IP address');
    23             $x_forwarded_for = null;
    24         }
    25 
    26         $remote_addr = filter_var(sanitize_text_field($_SERVER['REMOTE_ADDR']), FILTER_VALIDATE_IP);
    27         if ($remote_addr == false) {
    28             error_log('REMOTE_ADDR was not a valid IP address');
    29             $remote_addr = null;
    30         }
    31 
    32         $ip = $client_ip;
    33         if ($ip == null) {
    34             $ip = $remote_addr;
    35         }
    36 
    37         $escaped_url = esc_url(sanitize_text_field($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
     44        $sanitised_host = self::get_raw_server_value('HTTP_HOST');
     45        $sanitised_uri = self::get_raw_server_value('REQUEST_URI');
     46        $sanitised_url = "{$sanitised_host}{$sanitised_uri}";
     47        $escaped_url = esc_url($sanitised_url);
    3848        $host = wp_parse_url($escaped_url, PHP_URL_HOST);
    3949        $path = wp_parse_url($escaped_url, PHP_URL_PATH);
    4050        $query_string = wp_parse_url($escaped_url, PHP_URL_QUERY);
     51        $query_string = empty($query_string) ? "" : "?{$query_string}";
     52        $uri = "{$host}{$path}{$query_string}";
     53        $method = self::get_request_method();
    4154
    42         $uri = $host . $path;
    43         if (!empty($query_string)) {
    44             $uri = "{$uri}?{$query_string}";
    45         }
     55        $connection = self::get_raw_server_value('HTTP_CONNECTION');
    4656
    47         $method = !empty($_SERVER['REQUEST_METHOD'])
    48             ? ValidateUtils::validate_request_method(sanitize_text_field($_SERVER['REQUEST_METHOD']))
    49             : null;
    50         if ($method == null) {
    51             error_log('REQUEST_METHOD was not a valid HTTP method');
    52         }
     57        $referer = esc_url(self::get_raw_server_value('HTTP_REFERER'));
     58        $origin = self::get_raw_server_value('HTTP_ORIGIN');
     59        $pragma = self::get_raw_server_value('HTTP_PRAGMA');
    5360
    54         $referer = esc_url(sanitize_text_field($_SERVER['HTTP_REFERER']));
     61        $user_agent = self::get_raw_server_value('HTTP_USER_AGENT');
     62        $host = self::get_raw_server_value('HTTP_HOST');
     63
     64        $client_ip = self::get_ip_address('HTTP_CLIENT_IP');
     65        $remote_addr = self::get_ip_address('REMOTE_ADDR');
     66        $ip = $client_ip ?? $remote_addr;
     67
     68        $x_forwarded_for = self::get_ip_address('HTTP_X_FORWARDED_FOR');
     69        $x_forwarded_proto = self::get_raw_server_value('HTTP_X_FORWARDED_PROTO');
     70        $x_requested_with = self::get_raw_server_value('HTTP_X_REQUESTED_WITH');
     71        $x_real_ip = self::get_ip_address('HTTP_X_REAL_IP');
     72        $true_client_ip = self::get_ip_address('HTTP_TRUE_CLIENT_IP');
     73        $via = self::get_raw_server_value('HTTP_VIA');
     74
     75        $accept_encoding = self::get_raw_server_value('HTTP_ACCEPT_ENCODING');
     76        $accept = self::get_raw_server_value('HTTP_ACCEPT');
     77        $accept_language = self::get_raw_server_value('HTTP_ACCEPT_LANGUAGE');
     78        $accept_charset = self::get_raw_server_value('HTTP_ACCEPT_CHARSET');
     79
     80        $content_type = $headers['Content-Type'];
     81        $content_length = $headers['Content-Length'];
     82
     83        $cache_control = self::get_raw_server_value('HTTP_CACHE_CONTROL');
    5584
    5685        $token = null;
    57         if ($method == 'POST' && StringUtils::str_starts_with($contextType, "application/json")) {
     86        if ($method == 'POST' && StringUtils::str_starts_with($content_type, "application/json")) {
    5887            $post = file_get_contents('php://input');
    5988            $data = json_decode($post);
    6089            $token = $data->hCaptchaResponse;
    6190        }
    62 
    63         $milliseconds = floor(microtime(true) * 1000);
    6491
    6592        $vac_request = new VacRequest(
     
    6895            $host,
    6996            $uri,
     97            $method,
     98            array_keys($headers),
     99            $connection,
     100            $referer,
     101            $origin,
     102            $pragma,
     103            $x_forwarded_for,
     104            $x_forwarded_proto,
     105            $x_requested_with,
     106            $x_real_ip,
     107            $true_client_ip,
     108            $via,
     109            $accept,
     110            $accept_encoding,
     111            $accept_language,
     112            $accept_charset,
     113            $content_type,
     114            $content_length,
     115            $cache_control,
    70116            $token,
    71             $method,
    72             $referer,
    73             $x_forwarded_for,
    74117            new Worker(Config::VERSION)
    75118        );
Note: See TracChangeset for help on using the changeset viewer.