Plugin Directory

Changeset 2326883


Ignore:
Timestamp:
06/18/2020 04:38:20 PM (6 years ago)
Author:
wecantrack
Message:

1.1.0 release - bot detection - regex fixer

Location:
wecantrack
Files:
21 added
4 edited

Legend:

Unmodified
Added
Removed
  • wecantrack/trunk/WecantrackApp.php

    r2325087 r2326883  
    8282        }
    8383
    84         $domain_starts_at = strpos($url, '/', 2);
    85 
    86         if ($domain_starts_at !== false) {
    87             $url = substr($url, 0, $domain_starts_at);
    88         } else {
    89             return true;
    90         }
    91 
    92         if (isset($patterns['origins'][$url])) {
    93             return true;
    94         }
     84        // search if domain key matches to the origin keys
     85        if (isset($patterns['origins'][substr($url, 0, strpos($url, '/', 2))])) {
     86            return true;
     87        }
     88
     89        // check if the full url matches to any regex patterns
    9590        foreach($patterns['regexOrigins'] as $pattern) {
    9691            if (preg_match('~'.$pattern.'~i', $original_url)) {
     
    121116            }
    122117
    123             $api_url = "https://app.wecantrack.com/api/v1/clickout";
     118            // wecantrack will not process bots
     119            if (!isset($_SERVER['HTTP_USER_AGENT']) || self::useragent_is_bot($_SERVER['HTTP_USER_AGENT'])) {
     120                return $original_affiliate_url;
     121            }
    124122
    125123            $post_data = array(
     
    127125                'clickout_url' => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : self::get_site_url(),
    128126                '_ga' => !empty($_COOKIE['_ga']) ? sanitize_text_field($_COOKIE['_ga']) : null,
    129                 '_wctrck' => !empty($_COOKIE['_wctrck']) ? sanitize_text_field($_COOKIE['_wctrck']) : null
     127                '_wctrck' => !empty($_COOKIE['_wctrck']) ? sanitize_text_field($_COOKIE['_wctrck']) : null,
     128                'ua' => $_SERVER['HTTP_USER_AGENT'],
     129                'ip' => self::get_user_real_ip(),
    130130            );
    131131
    132             $response = wp_remote_post($api_url, array(
     132            $response = wp_remote_post('https://app.wecantrack.com/api/v1/clickout', array(
    133133                'timeout' => self::CURL_TIMEOUT_S,
    134134                'headers' => array(
     
    155155
    156156        return $original_affiliate_url;
     157    }
     158
     159    /**
     160     * Gets the real user IP
     161     *
     162     * @return string
     163     */
     164    private static function get_user_real_ip()
     165    {
     166        $ip_headers = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
     167        foreach ($ip_headers as $header) {
     168            if (array_key_exists($header, $_SERVER) === true) {
     169                foreach (array_map('trim', explode(',', $_SERVER[$header])) as $ip) {
     170                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
     171                        return $ip;
     172                    }
     173                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE) !== false) {
     174                        return $ip;
     175                    }
     176                }
     177            }
     178        }
     179        return null;
     180    }
     181
     182    /**
     183     * Detects if it's a bot depending on user agent
     184     *
     185     * @param $user_agent
     186     *
     187     * @return bool
     188     */
     189    private static function useragent_is_bot($user_agent)
     190    {
     191        $bots = ['bot/', 'crawler', 'semrush', 'bot.', ' bot ', '@bot', 'guzzle'];
     192
     193        foreach ($bots as $bot) {
     194            if (stripos($user_agent, $bot) !== false) {
     195                return true;
     196            };
     197        }
     198
     199        return false;
    157200    }
    158201
  • wecantrack/trunk/readme.txt

    r2325087 r2326883  
    55Tested up to: 5.4
    66Requires PHP: 5.6.20
    7 Stable tag: 1.0.9
     7Stable tag: 1.1.0
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
     
    6262== Changelog ==
    6363
     64= 1.1.0 - 18th June 2020 =
     65 * Affiliate link checker regex fix
     66 * Bot detection
     67
    6468= 1.0.9 - 16th June 2020 =
    6569 * Use rawurldecode
  • wecantrack/trunk/wecantrack.php

    r2325087 r2326883  
    77Plugin URI: https://wecantrack.com/wordpress
    88Description: Integrate all you affiliate sales in Google Analytics, Google Ads, Facebook, Data Studio and more!
    9 Version: 1.0.9
     9Version: 1.1.0
    1010Author: wecantrack.com
    1111Author URI: https://wecantrack.com
     
    1717if(!defined('ABSPATH')) { die('You are not allowed to call this page directly.'); }
    1818
    19 define('WECANTRACK_VERSION', '1.0.9');
     19define('WECANTRACK_VERSION', '1.1.0');
    2020define('WECANTRACK_PLUGIN_NAME', 'wecantrack');
    2121define('WECANTRACK_PATH', WP_PLUGIN_DIR.'/'.WECANTRACK_PLUGIN_NAME);
  • wecantrack/trunk/wecantrack.pot

    r2314056 r2326883  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: WeCanTrack 1.0.8\n"
     5"Project-Id-Version: WeCanTrack 1.1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wecantrack\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2020-05-28T22:12:23+00:00\n"
     12"POT-Creation-Date: 2020-06-18T16:09:52+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.4.0\n"
Note: See TracChangeset for help on using the changeset viewer.