Plugin Directory

Changeset 1985297


Ignore:
Timestamp:
12/04/2018 04:45:45 PM (6 years ago)
Author:
unbouncewordpress
Message:

Releasing version 1.0.40

Location:
unbounce
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • unbounce/tags/1.0.40/UBConfig.php

    r1984780 r1985297  
    66    const UB_PLUGIN_NAME           = 'ub-wordpress';
    77    const UB_CACHE_TIMEOUT_ENV_KEY = 'UB_WP_ROUTES_CACHE_EXP';
    8     const UB_USER_AGENT            = 'Unbounce WP Plugin 1.0.39';
    9     const UB_VERSION               = '1.0.39';
     8    const UB_USER_AGENT            = 'Unbounce WP Plugin 1.0.40';
     9    const UB_VERSION               = '1.0.40';
    1010
    1111  // Option keys
     
    2525    const UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR = 'ub-allow-public-address-x-forwarded-for';
    2626    const UB_PLUGIN_VERSION_KEY      = 'ub-plugin-version';
    27     const UB_USE_CURL_KEY            = 'ub-use-curl';
    2827
    2928    const UB_LOCK_NAME               = 'ub-sql-lock';
    3029
    31     public static function ub_option_defaults()
     30    public static function ub_option_keys()
    3231    {
    3332        // All options, used by UBDiagnostics and deactivation hook
    3433        // Arrays are not allowed in class constants, so use a function
    3534        return array(
    36         UBConfig::UB_ROUTES_CACHE_KEY => array(),
    37         UBConfig::UB_REMOTE_DEBUG_KEY => UBConfig::default_remote_debug_enabled(),
    38         UBConfig::UB_PAGE_SERVER_DOMAIN_KEY => UBConfig::default_page_server_domain(),
    39         UBConfig::UB_REMOTE_LOG_URL_KEY => UBConfig::default_remote_log_url(),
    40         UBConfig::UB_REMOTE_EVENTS_URL_KEY => UBConfig::default_remote_events_url(),
    41         UBConfig::UB_API_URL_KEY => UBConfig::default_api_url(),
    42         UBConfig::UB_API_CLIENT_ID_KEY => '',
    43         UBConfig::UB_AUTHORIZED_DOMAINS_KEY => UBConfig::default_authorized_domains(),
    44         UBConfig::UB_HAS_AUTHORIZED_KEY => '',
    45         UBConfig::UB_USER_ID_KEY => '',
    46         UBConfig::UB_DOMAIN_ID_KEY => '',
    47         UBConfig::UB_CLIENT_ID_KEY => '',
    48         UBConfig::UB_PROXY_ERROR_MESSAGE_KEY => '',
    49         UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR => 0,
    50         UBConfig::UB_USE_CURL_KEY => 1,
    51         UBConfig::UB_PLUGIN_VERSION_KEY => UBConfig::UB_VERSION
     35        UBConfig::UB_ROUTES_CACHE_KEY,
     36        UBConfig::UB_REMOTE_DEBUG_KEY,
     37        UBConfig::UB_PAGE_SERVER_DOMAIN_KEY,
     38        UBConfig::UB_REMOTE_LOG_URL_KEY,
     39        UBConfig::UB_REMOTE_EVENTS_URL_KEY,
     40        UBConfig::UB_API_URL_KEY,
     41        UBConfig::UB_API_CLIENT_ID_KEY,
     42        UBConfig::UB_AUTHORIZED_DOMAINS_KEY,
     43        UBConfig::UB_HAS_AUTHORIZED_KEY,
     44        UBConfig::UB_USER_ID_KEY,
     45        UBConfig::UB_DOMAIN_ID_KEY,
     46        UBConfig::UB_CLIENT_ID_KEY,
     47        UBConfig::UB_PROXY_ERROR_MESSAGE_KEY,
     48        UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR
    5249        );
    53     }
    54 
    55     public static function set_options_if_not_exist()
    56     {
    57         $ub_options = UBConfig::ub_option_defaults();
    58         foreach ($ub_options as $key => $default) {
    59             if (!get_option($key)) {
    60                 add_option($key, $default);
    61             }
    62         }
    6350    }
    6451
     
    7259    {
    7360        $url = getenv('UB_REMOTE_LOG_URL');
    74         return $url ? $url : 'https://events-gateway.unbounce.com/events/wordpress_logs';
     61        if ($url == null) {
     62            return 'https://events-gateway.unbounce.com/events/wordpress_logs';
     63        }
     64        return $url;
    7565    }
    7666
     
    7868    {
    7969        $url = getenv('UB_REMOTE_EVENTS_URL');
    80         return $url ? $url : 'https://events-gateway.unbounce.com/events/domains';
     70        if ($url == null) {
     71            return 'https://events-gateway.unbounce.com/events/domains';
     72        }
     73        return $url;
    8174    }
    8275
     
    9184        $client_id = getenv('UB_API_CLIENT_ID');
    9285        return $client_id ? $client_id : '660a311881321b9d4e777993e50875dec5da9cc4ef44369d121544b21da52b92';
    93     }
    94 
    95     public static function default_remote_debug_enabled()
    96     {
    97         $debug_enabled = getenv('UB_REMOTE_DEBUG_ENABLED');
    98         return $debug_enabled ? $debug_enabled : 0;
    9986    }
    10087
     
    175162                       'failure_message' => $failure_message),
    176163                 null, null, null);
    177     }
    178 
    179     public static function use_curl()
    180     {
    181         return get_option(UBConfig::UB_USE_CURL_KEY, 1) == 1;
    182164    }
    183165
  • unbounce/tags/1.0.40/UBDiagnostics.php

    r1984780 r1985297  
    101101        'PHP Version'             => phpversion(),
    102102        'WordPress Version'       => UBDiagnostics::wordpress_version(),
    103         'Unbounce Plugin Version' => '1.0.39',
     103        'Unbounce Plugin Version' => '1.0.40',
    104104        'Checks'                  => self::pp(UBDiagnostics::checks($domain, $domain_info)),
    105105        'Options'                 => self::pp(UBDiagnostics::ub_options()),
     
    125125    private static function ub_options()
    126126    {
    127         $ub_options = array();
    128         array_walk(UBConfig::ub_option_defaults(), function ($v, $k) use (&$ub_options) {
    129             $ub_options[$k] = get_option($k, $v);
    130         });
    131         return $ub_options;
     127        $option_values = array_map(function ($key) {
     128            return get_option($key);
     129        }, UBConfig::ub_option_keys());
     130
     131        // Return an array where the key is the option key and the value
     132        // the option value:
     133        // array('ub-option-key' => 'option value')
     134        return array_combine(UBConfig::ub_option_keys(), $option_values);
    132135    }
    133136
     
    179182            'php'                 => phpversion(),
    180183            'wordpress'           => UBDiagnostics::wordpress_version(),
    181             'plugin_version'      => '1.0.39',
     184            'plugin_version'      => '1.0.40',
    182185            'curl_installed'      => self::is_curl_installed(),
    183186            'xml_installed'       => self::is_xml_installed(),
  • unbounce/tags/1.0.40/UBHTTP.php

    r1984780 r1985297  
    1313    public static $response_header_whitelist = '/^(Content-Type:|Location:|Link:|Content-Location:|Set-Cookie:|X-Server-Instance:|X-Unbounce-PageId:|X-Unbounce-Variant:|X-Unbounce-VisitorID:)/i';
    1414    public static $request_header_blacklist = '/^(Accept-Encoding:)/i';
    15     public static $cookie_whitelist = array('ubvs', 'ubpv', 'ubvt', 'hubspotutk');
    1615
    1716    public static function is_private_ip_address($ip_address)
     
    7069
    7170    public static function get_proxied_for_header(
     71        $out_headers,
    7272        $forwarded_for,
    7373        $current_ip
     
    8080            $proxied_for = $current_ip;
    8181        }
    82         return array('X-Proxied-For' => $proxied_for);
     82
     83        $out_headers[] = 'X-Proxied-For: ' . $proxied_for;
     84        return $out_headers;
    8385    }
    8486
     
    155157
    156158  // taken from: http://stackoverflow.com/a/13036310/322727
    157     public static function convert_headers_to_curl($headers)
     159    private static function convert_headers_to_curl($headers)
    158160    {
    159161        // map to curl-friendly format
    160162        $req_headers = array();
    161163        array_walk($headers, function (&$v, $k) use (&$req_headers) {
    162             $req_headers[] = $k . ": " . $v;
     164            array_push($req_headers, $k . ": " . $v);
    163165        });
    164166
     
    169171        $method,
    170172        $target_url,
     173        $cookie_string,
    171174        $headers0,
    172175        $user_agent
    173176    ) {
     177
    174178        // Always add this header to responses to show it comes from our plugin.
    175179        header("X-Unbounce-Plugin: 1", false);
    176         if (UBConfig::use_curl()) {
    177             return UBHTTP::stream_request_curl(
    178                 $method,
    179                 $target_url,
    180                 $headers0,
    181                 $user_agent
    182             );
    183         } else {
    184             return UBHTTP::stream_request_wp_remote(
    185                 $method,
    186                 $target_url,
    187                 $headers0,
    188                 $user_agent
    189             );
    190         }
    191     }
    192 
    193     private static function stream_request_wp_remote(
    194         $method,
    195         $target_url,
    196         $headers0,
    197         $user_agent
    198     ) {
    199         $args = array(
    200             'method' => $method,
    201             'user-agent' => $user_agent,
    202             'redirection' => 0,
    203             'timeout' => 30,
    204             'headers' => UBHTTP::prepare_request_headers($headers0, true)
    205             );
    206         if ($method == 'POST') {
    207             $args['body'] = file_get_contents('php://input');
    208         }
    209 
    210         $resp = wp_remote_request($target_url, $args);
    211         if (is_wp_error($resp)) {
    212             $message = "Error proxying to '" . $target_url . "': " . $resp->get_error_message();
    213             UBLogger::warning($message);
    214             http_response_code(500);
    215             return array(false, $message);
    216         } else {
    217             http_response_code($resp['response']['code']);
    218             $response_headers = $resp['headers'];
    219             UBHTTP::set_response_headers($response_headers);
    220             echo $resp['body'];
    221             return array(true, null);
    222         }
    223     }
    224 
    225     public static function prepare_request_headers($base_h)
    226     {
     180
     181        $existing_headers = headers_list();
    227182        $forwarded_for = UBUtil::array_fetch($_SERVER, 'HTTP_X_FORWARDED_FOR');
    228183        $remote_ip = UBUtil::array_fetch($_SERVER, 'REMOTE_ADDR');
    229184
    230         $filtered_h = array_filter($base_h, function ($value, $key) {
    231             return !preg_match(UBHTTP::$request_header_blacklist, $key . ": " . $value);
    232         }, ARRAY_FILTER_USE_BOTH);
    233         $filtered_h = UBHTTP::sanitize_cookies($filtered_h);
    234 
    235         $filtered_h = array_merge($filtered_h, UBHTTP::get_proxied_for_header(
     185        $headers1 = UBHTTP::convert_headers_to_curl($headers0);
     186        $curl_headers = array_filter($headers1, function ($key) {
     187            return !preg_match(UBHTTP::$request_header_blacklist, $key);
     188        });
     189
     190        $headers = UBHTTP::get_proxied_for_header(
     191            $curl_headers,
    236192            $forwarded_for,
    237193            $remote_ip
    238         ));
    239         return $filtered_h;
    240     }
    241 
    242     public static function sanitize_cookies($headers)
    243     {
    244         $cookies_to_forward = UBUtil::array_select_by_key(
    245             UBHTTP::cookie_array_from_string($headers["Cookie"]),
    246             UBHTTP::$cookie_whitelist
    247         );
    248         $headers["Cookie"] = UBHTTP::cookie_string_from_array($cookies_to_forward);
    249         return $headers;
    250     }
    251 
    252     public static function cookie_array_from_string($cookie_string)
    253     {
    254         $cookie_kv_array = array();
    255         $cookie_flat_array = explode('; ', $cookie_string);
    256         foreach ($cookie_flat_array as $itm) {
    257             list($key, $val) = explode('=', $itm, 2);
    258             $cookie_kv_array[$key] = $val;
    259         }
    260         return $cookie_kv_array;
    261     }
    262 
    263     public static function set_response_headers($headers)
    264     {
    265         foreach ($headers as $h_key => $h_value) {
    266             if (preg_match(UBHTTP::$response_header_whitelist, $h_key . ":")) {
    267                 if (is_array($h_value)) {
    268                     foreach ($h_value as $header_item) {
    269                         header($h_key . ': ' . $header_item, false);
    270                     }
    271                 } else {
    272                     header($h_key . ': ' . $h_value, false);
    273                 }
    274             }
    275         }
    276     }
    277 
    278 
    279     private static function stream_request_curl(
    280         $method,
    281         $target_url,
    282         $headers0,
    283         $user_agent
    284     ) {
    285         $base_response_headers = headers_list();
    286 
    287         $headers1 = UBHTTP::prepare_request_headers($headers0);
    288         $headers = UBHTTP::convert_headers_to_curl($headers1);
    289 
     194        );
    290195        UBLogger::debug_var('target_url', $target_url);
    291196        UBLogger::debug_var('original_headers', print_r($headers0, true));
    292197        UBLogger::debug_var('sent_headers', print_r($headers, true));
    293198
    294         $stream_headers = UBHTTP::stream_headers_function($base_response_headers);
     199        $stream_headers = UBHTTP::stream_headers_function($existing_headers);
    295200        $stream_body = UBHTTP::stream_response_function();
    296201        $curl = curl_init();
     
    301206        CURLOPT_CUSTOMREQUEST => $method,
    302207        CURLOPT_USERAGENT => $user_agent,
     208        CURLOPT_COOKIE => $cookie_string,
    303209        CURLOPT_HTTPHEADER => $headers,
    304210        CURLOPT_HEADERFUNCTION => $stream_headers,
     
    419325    public static function send_event_to_events_gateway($url, $data_string)
    420326    {
    421         if (UBConfig::use_curl()) {
    422             UBHTTP::send_event_to_events_gateway_curl($url, $data_string);
    423         } else {
    424             UBHTTP::send_event_to_events_gateway_wp_remote($url, $data_string);
    425         }
    426     }
    427 
    428     private static function send_event_to_events_gateway_curl($url, $data_string)
    429     {
    430327        try {
    431328            $stream_function = function ($curl, $str) {
     
    473370        }
    474371    }
    475 
    476     private static function send_event_to_events_gateway_wp_remote($url, $data_string)
    477     {
    478         $args = array(
    479             'method' => 'POST',
    480             'user-agent' => UBConfig::UB_USER_AGENT,
    481             'redirection' => 0,
    482             'timeout' => 2,
    483             'headers' => array(
    484                 'Content-Type' => 'application/json',
    485                 'Content-Length' => strlen($data_string)
    486             ),
    487             'body' => $data_string
    488         );
    489 
    490         $resp = wp_remote_request($url, $args);
    491         if (is_wp_error($resp)) {
    492             $message = "Unable to send log messages to '" . $url . "': " . $resp->get_error_message();
    493             UBLogger::warning($message);
    494             return;
    495         }
    496 
    497         $http_code = $resp['response']['code'];
    498         if ($http_code >= 200 && $http_code < 300) {
    499             $message = 'Successfully sent log messsages to ' . $url
    500                 . ' - HTTP status: ' . $http_code;
    501             UBLogger::debug($message);
    502         } else {
    503             UBLogger::warning('$data_string=' . $data_string);
    504             $message = 'Unable to send log messages to ' . $url
    505                 . ' - HTTP status: ' . $http_code;
    506             UBLogger::warning($message);
    507         }
    508     }
    509372}
  • unbounce/tags/1.0.40/Unbounce-Page.php

    r1984780 r1985297  
    44Plugin URI: http://unbounce.com
    55Description: Unbounce is the most powerful standalone landing page builder available.
    6 Version: 1.0.39
     6Version: 1.0.40
    77Author: Unbounce
    88Author URI: http://unbounce.com
     
    2323
    2424register_activation_hook(__FILE__, function () {
    25     UBConfig::set_options_if_not_exist();
     25    add_option(UBConfig::UB_ROUTES_CACHE_KEY, array());
     26    add_option(UBConfig::UB_REMOTE_DEBUG_KEY, 0);
     27    add_option(
     28        UBConfig::UB_PAGE_SERVER_DOMAIN_KEY,
     29        UBConfig::default_page_server_domain()
     30    );
     31    add_option(
     32        UBConfig::UB_REMOTE_LOG_URL_KEY,
     33        UBConfig::default_remote_log_url()
     34    );
     35    add_option(
     36        UBConfig::UB_API_URL_KEY,
     37        UBConfig::default_api_url()
     38    );
     39    add_option(
     40        UBConfig::UB_API_CLIENT_ID_KEY,
     41        UBConfig::default_api_client_id()
     42    );
     43    add_option(
     44        UBConfig::UB_AUTHORIZED_DOMAINS_KEY,
     45        UBConfig::default_authorized_domains()
     46    );
     47    add_option(UBConfig::UB_HAS_AUTHORIZED_KEY, '');
     48    add_option(
     49        UBConfig::UB_REMOTE_EVENTS_URL_KEY,
     50        UBConfig::default_remote_events_url()
     51    );
     52    add_option(UBConfig::UB_USER_ID_KEY, '');
     53    add_option(UBConfig::UB_DOMAIN_ID_KEY, '');
     54    add_option(UBConfig::UB_CLIENT_ID_KEY, '');
     55    add_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, '');
     56    add_option(UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR, 0);
     57    add_option(UBConfig::UB_PLUGIN_VERSION_KEY, UBConfig::UB_VERSION);
    2658
    2759    // NOTE: This should be brought back when working on BEE-1136
     
    3062
    3163register_deactivation_hook(__FILE__, function () {
    32     foreach (UBConfig::ub_option_defaults() as $key => $value_not_needed) {
     64    foreach (UBConfig::ub_option_keys() as $key) {
    3365        delete_option($key);
    3466    }
     
    117149        UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url);
    118150
     151        $cookies_to_forward = UBUtil::array_select_by_key(
     152            $_COOKIE,
     153            array('ubvs', 'ubpv', 'ubvt', 'hubspotutk')
     154        );
     155
     156        $cookie_string = UBHTTP::cookie_string_from_array($cookies_to_forward);
     157
    119158        $all_headers = getallheaders();
    120159        $all_headers['Host'] = $domain;
     
    126165            $http_method,
    127166            $raw_url,
     167            $cookie_string,
    128168            $all_headers,
    129169            $user_agent
     
    150190    if (UBConfig::UB_VERSION != $pluginVersion) {
    151191        @UBDiagnostics::sendActivationEvent($pluginVersion);
    152         UBConfig::set_options_if_not_exist();
    153192        update_option(UBConfig::UB_PLUGIN_VERSION_KEY, UBConfig::UB_VERSION);
    154193    }
  • unbounce/tags/1.0.40/readme.txt

    r1984780 r1985297  
    44Requires at least: 4.1.5
    55Tested up to: 5.0
    6 Stable tag: 1.0.39
     6Stable tag: 1.0.40
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    100100
    101101== Changelog ==
    102 
    103 = 1.0.39 =
    104 * Fixes an issue preventing new options from being created when upgrading the plugin
    105 
    106 = 1.0.38 =
    107 * Adds an option (ub-use-curl) to opt-out of using cURL as a proxying client, the alternative being wp_remore_request
     102= 1.0.40 =
     103* Effective reversal to 1.0.37 to address blocking issue to some customers
    108104
    109105= 1.0.37 =
  • unbounce/tags/1.0.40/templates/diagnostics.php

    r1984780 r1985297  
    9999            <p>Check that you don’t have any caching plugins installed, or any plugins that affect the order in which Javascript is loaded. These types of plugins will affect how Unbounce pages behave on WordPress.</p>
    100100            <ul class="causes">
    101              <li>wp-rocket - This plugin re-orders script tags, which breaks how Javascript loads for Unbounce pages.</li>
     101             <li>wp-rocket - This plugin re-orders script tags in the <head> which break how Javascript Loads.</li>
    102102             <li>wp-super-cache - caching plugins often cause Unbounce pages to 404</li>
    103103             <li>wp-total-cache - caching plugins often cause Unbounce pages to 404</li>
  • unbounce/tags/1.0.40/templates/main_authorized_footer.php

    r1984780 r1985297  
    2222  Click here for troubleshooting and plugin diagnostics
    2323</a>
    24 <p class="ub-version">Unbounce Version 1.0.39</p>
     24<p class="ub-version">Unbounce Version 1.0.40</p>
  • unbounce/tags/1.0.40/templates/main_unauthorized_footer.php

    r1984780 r1985297  
    55  Click here for troubleshooting and plugin diagnostics
    66</a>
    7 <p class="ub-version">Unbounce Version 1.0.39</p>
     7<p class="ub-version">Unbounce Version 1.0.40</p>
  • unbounce/trunk/UBConfig.php

    r1984780 r1985297  
    66    const UB_PLUGIN_NAME           = 'ub-wordpress';
    77    const UB_CACHE_TIMEOUT_ENV_KEY = 'UB_WP_ROUTES_CACHE_EXP';
    8     const UB_USER_AGENT            = 'Unbounce WP Plugin 1.0.39';
    9     const UB_VERSION               = '1.0.39';
     8    const UB_USER_AGENT            = 'Unbounce WP Plugin 1.0.40';
     9    const UB_VERSION               = '1.0.40';
    1010
    1111  // Option keys
     
    2525    const UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR = 'ub-allow-public-address-x-forwarded-for';
    2626    const UB_PLUGIN_VERSION_KEY      = 'ub-plugin-version';
    27     const UB_USE_CURL_KEY            = 'ub-use-curl';
    2827
    2928    const UB_LOCK_NAME               = 'ub-sql-lock';
    3029
    31     public static function ub_option_defaults()
     30    public static function ub_option_keys()
    3231    {
    3332        // All options, used by UBDiagnostics and deactivation hook
    3433        // Arrays are not allowed in class constants, so use a function
    3534        return array(
    36         UBConfig::UB_ROUTES_CACHE_KEY => array(),
    37         UBConfig::UB_REMOTE_DEBUG_KEY => UBConfig::default_remote_debug_enabled(),
    38         UBConfig::UB_PAGE_SERVER_DOMAIN_KEY => UBConfig::default_page_server_domain(),
    39         UBConfig::UB_REMOTE_LOG_URL_KEY => UBConfig::default_remote_log_url(),
    40         UBConfig::UB_REMOTE_EVENTS_URL_KEY => UBConfig::default_remote_events_url(),
    41         UBConfig::UB_API_URL_KEY => UBConfig::default_api_url(),
    42         UBConfig::UB_API_CLIENT_ID_KEY => '',
    43         UBConfig::UB_AUTHORIZED_DOMAINS_KEY => UBConfig::default_authorized_domains(),
    44         UBConfig::UB_HAS_AUTHORIZED_KEY => '',
    45         UBConfig::UB_USER_ID_KEY => '',
    46         UBConfig::UB_DOMAIN_ID_KEY => '',
    47         UBConfig::UB_CLIENT_ID_KEY => '',
    48         UBConfig::UB_PROXY_ERROR_MESSAGE_KEY => '',
    49         UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR => 0,
    50         UBConfig::UB_USE_CURL_KEY => 1,
    51         UBConfig::UB_PLUGIN_VERSION_KEY => UBConfig::UB_VERSION
     35        UBConfig::UB_ROUTES_CACHE_KEY,
     36        UBConfig::UB_REMOTE_DEBUG_KEY,
     37        UBConfig::UB_PAGE_SERVER_DOMAIN_KEY,
     38        UBConfig::UB_REMOTE_LOG_URL_KEY,
     39        UBConfig::UB_REMOTE_EVENTS_URL_KEY,
     40        UBConfig::UB_API_URL_KEY,
     41        UBConfig::UB_API_CLIENT_ID_KEY,
     42        UBConfig::UB_AUTHORIZED_DOMAINS_KEY,
     43        UBConfig::UB_HAS_AUTHORIZED_KEY,
     44        UBConfig::UB_USER_ID_KEY,
     45        UBConfig::UB_DOMAIN_ID_KEY,
     46        UBConfig::UB_CLIENT_ID_KEY,
     47        UBConfig::UB_PROXY_ERROR_MESSAGE_KEY,
     48        UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR
    5249        );
    53     }
    54 
    55     public static function set_options_if_not_exist()
    56     {
    57         $ub_options = UBConfig::ub_option_defaults();
    58         foreach ($ub_options as $key => $default) {
    59             if (!get_option($key)) {
    60                 add_option($key, $default);
    61             }
    62         }
    6350    }
    6451
     
    7259    {
    7360        $url = getenv('UB_REMOTE_LOG_URL');
    74         return $url ? $url : 'https://events-gateway.unbounce.com/events/wordpress_logs';
     61        if ($url == null) {
     62            return 'https://events-gateway.unbounce.com/events/wordpress_logs';
     63        }
     64        return $url;
    7565    }
    7666
     
    7868    {
    7969        $url = getenv('UB_REMOTE_EVENTS_URL');
    80         return $url ? $url : 'https://events-gateway.unbounce.com/events/domains';
     70        if ($url == null) {
     71            return 'https://events-gateway.unbounce.com/events/domains';
     72        }
     73        return $url;
    8174    }
    8275
     
    9184        $client_id = getenv('UB_API_CLIENT_ID');
    9285        return $client_id ? $client_id : '660a311881321b9d4e777993e50875dec5da9cc4ef44369d121544b21da52b92';
    93     }
    94 
    95     public static function default_remote_debug_enabled()
    96     {
    97         $debug_enabled = getenv('UB_REMOTE_DEBUG_ENABLED');
    98         return $debug_enabled ? $debug_enabled : 0;
    9986    }
    10087
     
    175162                       'failure_message' => $failure_message),
    176163                 null, null, null);
    177     }
    178 
    179     public static function use_curl()
    180     {
    181         return get_option(UBConfig::UB_USE_CURL_KEY, 1) == 1;
    182164    }
    183165
  • unbounce/trunk/UBDiagnostics.php

    r1984780 r1985297  
    101101        'PHP Version'             => phpversion(),
    102102        'WordPress Version'       => UBDiagnostics::wordpress_version(),
    103         'Unbounce Plugin Version' => '1.0.39',
     103        'Unbounce Plugin Version' => '1.0.40',
    104104        'Checks'                  => self::pp(UBDiagnostics::checks($domain, $domain_info)),
    105105        'Options'                 => self::pp(UBDiagnostics::ub_options()),
     
    125125    private static function ub_options()
    126126    {
    127         $ub_options = array();
    128         array_walk(UBConfig::ub_option_defaults(), function ($v, $k) use (&$ub_options) {
    129             $ub_options[$k] = get_option($k, $v);
    130         });
    131         return $ub_options;
     127        $option_values = array_map(function ($key) {
     128            return get_option($key);
     129        }, UBConfig::ub_option_keys());
     130
     131        // Return an array where the key is the option key and the value
     132        // the option value:
     133        // array('ub-option-key' => 'option value')
     134        return array_combine(UBConfig::ub_option_keys(), $option_values);
    132135    }
    133136
     
    179182            'php'                 => phpversion(),
    180183            'wordpress'           => UBDiagnostics::wordpress_version(),
    181             'plugin_version'      => '1.0.39',
     184            'plugin_version'      => '1.0.40',
    182185            'curl_installed'      => self::is_curl_installed(),
    183186            'xml_installed'       => self::is_xml_installed(),
  • unbounce/trunk/UBHTTP.php

    r1984780 r1985297  
    1313    public static $response_header_whitelist = '/^(Content-Type:|Location:|Link:|Content-Location:|Set-Cookie:|X-Server-Instance:|X-Unbounce-PageId:|X-Unbounce-Variant:|X-Unbounce-VisitorID:)/i';
    1414    public static $request_header_blacklist = '/^(Accept-Encoding:)/i';
    15     public static $cookie_whitelist = array('ubvs', 'ubpv', 'ubvt', 'hubspotutk');
    1615
    1716    public static function is_private_ip_address($ip_address)
     
    7069
    7170    public static function get_proxied_for_header(
     71        $out_headers,
    7272        $forwarded_for,
    7373        $current_ip
     
    8080            $proxied_for = $current_ip;
    8181        }
    82         return array('X-Proxied-For' => $proxied_for);
     82
     83        $out_headers[] = 'X-Proxied-For: ' . $proxied_for;
     84        return $out_headers;
    8385    }
    8486
     
    155157
    156158  // taken from: http://stackoverflow.com/a/13036310/322727
    157     public static function convert_headers_to_curl($headers)
     159    private static function convert_headers_to_curl($headers)
    158160    {
    159161        // map to curl-friendly format
    160162        $req_headers = array();
    161163        array_walk($headers, function (&$v, $k) use (&$req_headers) {
    162             $req_headers[] = $k . ": " . $v;
     164            array_push($req_headers, $k . ": " . $v);
    163165        });
    164166
     
    169171        $method,
    170172        $target_url,
     173        $cookie_string,
    171174        $headers0,
    172175        $user_agent
    173176    ) {
     177
    174178        // Always add this header to responses to show it comes from our plugin.
    175179        header("X-Unbounce-Plugin: 1", false);
    176         if (UBConfig::use_curl()) {
    177             return UBHTTP::stream_request_curl(
    178                 $method,
    179                 $target_url,
    180                 $headers0,
    181                 $user_agent
    182             );
    183         } else {
    184             return UBHTTP::stream_request_wp_remote(
    185                 $method,
    186                 $target_url,
    187                 $headers0,
    188                 $user_agent
    189             );
    190         }
    191     }
    192 
    193     private static function stream_request_wp_remote(
    194         $method,
    195         $target_url,
    196         $headers0,
    197         $user_agent
    198     ) {
    199         $args = array(
    200             'method' => $method,
    201             'user-agent' => $user_agent,
    202             'redirection' => 0,
    203             'timeout' => 30,
    204             'headers' => UBHTTP::prepare_request_headers($headers0, true)
    205             );
    206         if ($method == 'POST') {
    207             $args['body'] = file_get_contents('php://input');
    208         }
    209 
    210         $resp = wp_remote_request($target_url, $args);
    211         if (is_wp_error($resp)) {
    212             $message = "Error proxying to '" . $target_url . "': " . $resp->get_error_message();
    213             UBLogger::warning($message);
    214             http_response_code(500);
    215             return array(false, $message);
    216         } else {
    217             http_response_code($resp['response']['code']);
    218             $response_headers = $resp['headers'];
    219             UBHTTP::set_response_headers($response_headers);
    220             echo $resp['body'];
    221             return array(true, null);
    222         }
    223     }
    224 
    225     public static function prepare_request_headers($base_h)
    226     {
     180
     181        $existing_headers = headers_list();
    227182        $forwarded_for = UBUtil::array_fetch($_SERVER, 'HTTP_X_FORWARDED_FOR');
    228183        $remote_ip = UBUtil::array_fetch($_SERVER, 'REMOTE_ADDR');
    229184
    230         $filtered_h = array_filter($base_h, function ($value, $key) {
    231             return !preg_match(UBHTTP::$request_header_blacklist, $key . ": " . $value);
    232         }, ARRAY_FILTER_USE_BOTH);
    233         $filtered_h = UBHTTP::sanitize_cookies($filtered_h);
    234 
    235         $filtered_h = array_merge($filtered_h, UBHTTP::get_proxied_for_header(
     185        $headers1 = UBHTTP::convert_headers_to_curl($headers0);
     186        $curl_headers = array_filter($headers1, function ($key) {
     187            return !preg_match(UBHTTP::$request_header_blacklist, $key);
     188        });
     189
     190        $headers = UBHTTP::get_proxied_for_header(
     191            $curl_headers,
    236192            $forwarded_for,
    237193            $remote_ip
    238         ));
    239         return $filtered_h;
    240     }
    241 
    242     public static function sanitize_cookies($headers)
    243     {
    244         $cookies_to_forward = UBUtil::array_select_by_key(
    245             UBHTTP::cookie_array_from_string($headers["Cookie"]),
    246             UBHTTP::$cookie_whitelist
    247         );
    248         $headers["Cookie"] = UBHTTP::cookie_string_from_array($cookies_to_forward);
    249         return $headers;
    250     }
    251 
    252     public static function cookie_array_from_string($cookie_string)
    253     {
    254         $cookie_kv_array = array();
    255         $cookie_flat_array = explode('; ', $cookie_string);
    256         foreach ($cookie_flat_array as $itm) {
    257             list($key, $val) = explode('=', $itm, 2);
    258             $cookie_kv_array[$key] = $val;
    259         }
    260         return $cookie_kv_array;
    261     }
    262 
    263     public static function set_response_headers($headers)
    264     {
    265         foreach ($headers as $h_key => $h_value) {
    266             if (preg_match(UBHTTP::$response_header_whitelist, $h_key . ":")) {
    267                 if (is_array($h_value)) {
    268                     foreach ($h_value as $header_item) {
    269                         header($h_key . ': ' . $header_item, false);
    270                     }
    271                 } else {
    272                     header($h_key . ': ' . $h_value, false);
    273                 }
    274             }
    275         }
    276     }
    277 
    278 
    279     private static function stream_request_curl(
    280         $method,
    281         $target_url,
    282         $headers0,
    283         $user_agent
    284     ) {
    285         $base_response_headers = headers_list();
    286 
    287         $headers1 = UBHTTP::prepare_request_headers($headers0);
    288         $headers = UBHTTP::convert_headers_to_curl($headers1);
    289 
     194        );
    290195        UBLogger::debug_var('target_url', $target_url);
    291196        UBLogger::debug_var('original_headers', print_r($headers0, true));
    292197        UBLogger::debug_var('sent_headers', print_r($headers, true));
    293198
    294         $stream_headers = UBHTTP::stream_headers_function($base_response_headers);
     199        $stream_headers = UBHTTP::stream_headers_function($existing_headers);
    295200        $stream_body = UBHTTP::stream_response_function();
    296201        $curl = curl_init();
     
    301206        CURLOPT_CUSTOMREQUEST => $method,
    302207        CURLOPT_USERAGENT => $user_agent,
     208        CURLOPT_COOKIE => $cookie_string,
    303209        CURLOPT_HTTPHEADER => $headers,
    304210        CURLOPT_HEADERFUNCTION => $stream_headers,
     
    419325    public static function send_event_to_events_gateway($url, $data_string)
    420326    {
    421         if (UBConfig::use_curl()) {
    422             UBHTTP::send_event_to_events_gateway_curl($url, $data_string);
    423         } else {
    424             UBHTTP::send_event_to_events_gateway_wp_remote($url, $data_string);
    425         }
    426     }
    427 
    428     private static function send_event_to_events_gateway_curl($url, $data_string)
    429     {
    430327        try {
    431328            $stream_function = function ($curl, $str) {
     
    473370        }
    474371    }
    475 
    476     private static function send_event_to_events_gateway_wp_remote($url, $data_string)
    477     {
    478         $args = array(
    479             'method' => 'POST',
    480             'user-agent' => UBConfig::UB_USER_AGENT,
    481             'redirection' => 0,
    482             'timeout' => 2,
    483             'headers' => array(
    484                 'Content-Type' => 'application/json',
    485                 'Content-Length' => strlen($data_string)
    486             ),
    487             'body' => $data_string
    488         );
    489 
    490         $resp = wp_remote_request($url, $args);
    491         if (is_wp_error($resp)) {
    492             $message = "Unable to send log messages to '" . $url . "': " . $resp->get_error_message();
    493             UBLogger::warning($message);
    494             return;
    495         }
    496 
    497         $http_code = $resp['response']['code'];
    498         if ($http_code >= 200 && $http_code < 300) {
    499             $message = 'Successfully sent log messsages to ' . $url
    500                 . ' - HTTP status: ' . $http_code;
    501             UBLogger::debug($message);
    502         } else {
    503             UBLogger::warning('$data_string=' . $data_string);
    504             $message = 'Unable to send log messages to ' . $url
    505                 . ' - HTTP status: ' . $http_code;
    506             UBLogger::warning($message);
    507         }
    508     }
    509372}
  • unbounce/trunk/Unbounce-Page.php

    r1984780 r1985297  
    44Plugin URI: http://unbounce.com
    55Description: Unbounce is the most powerful standalone landing page builder available.
    6 Version: 1.0.39
     6Version: 1.0.40
    77Author: Unbounce
    88Author URI: http://unbounce.com
     
    2323
    2424register_activation_hook(__FILE__, function () {
    25     UBConfig::set_options_if_not_exist();
     25    add_option(UBConfig::UB_ROUTES_CACHE_KEY, array());
     26    add_option(UBConfig::UB_REMOTE_DEBUG_KEY, 0);
     27    add_option(
     28        UBConfig::UB_PAGE_SERVER_DOMAIN_KEY,
     29        UBConfig::default_page_server_domain()
     30    );
     31    add_option(
     32        UBConfig::UB_REMOTE_LOG_URL_KEY,
     33        UBConfig::default_remote_log_url()
     34    );
     35    add_option(
     36        UBConfig::UB_API_URL_KEY,
     37        UBConfig::default_api_url()
     38    );
     39    add_option(
     40        UBConfig::UB_API_CLIENT_ID_KEY,
     41        UBConfig::default_api_client_id()
     42    );
     43    add_option(
     44        UBConfig::UB_AUTHORIZED_DOMAINS_KEY,
     45        UBConfig::default_authorized_domains()
     46    );
     47    add_option(UBConfig::UB_HAS_AUTHORIZED_KEY, '');
     48    add_option(
     49        UBConfig::UB_REMOTE_EVENTS_URL_KEY,
     50        UBConfig::default_remote_events_url()
     51    );
     52    add_option(UBConfig::UB_USER_ID_KEY, '');
     53    add_option(UBConfig::UB_DOMAIN_ID_KEY, '');
     54    add_option(UBConfig::UB_CLIENT_ID_KEY, '');
     55    add_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, '');
     56    add_option(UBConfig::UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR, 0);
     57    add_option(UBConfig::UB_PLUGIN_VERSION_KEY, UBConfig::UB_VERSION);
    2658
    2759    // NOTE: This should be brought back when working on BEE-1136
     
    3062
    3163register_deactivation_hook(__FILE__, function () {
    32     foreach (UBConfig::ub_option_defaults() as $key => $value_not_needed) {
     64    foreach (UBConfig::ub_option_keys() as $key) {
    3365        delete_option($key);
    3466    }
     
    117149        UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url);
    118150
     151        $cookies_to_forward = UBUtil::array_select_by_key(
     152            $_COOKIE,
     153            array('ubvs', 'ubpv', 'ubvt', 'hubspotutk')
     154        );
     155
     156        $cookie_string = UBHTTP::cookie_string_from_array($cookies_to_forward);
     157
    119158        $all_headers = getallheaders();
    120159        $all_headers['Host'] = $domain;
     
    126165            $http_method,
    127166            $raw_url,
     167            $cookie_string,
    128168            $all_headers,
    129169            $user_agent
     
    150190    if (UBConfig::UB_VERSION != $pluginVersion) {
    151191        @UBDiagnostics::sendActivationEvent($pluginVersion);
    152         UBConfig::set_options_if_not_exist();
    153192        update_option(UBConfig::UB_PLUGIN_VERSION_KEY, UBConfig::UB_VERSION);
    154193    }
  • unbounce/trunk/readme.txt

    r1984780 r1985297  
    44Requires at least: 4.1.5
    55Tested up to: 5.0
    6 Stable tag: 1.0.39
     6Stable tag: 1.0.40
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    100100
    101101== Changelog ==
    102 
    103 = 1.0.39 =
    104 * Fixes an issue preventing new options from being created when upgrading the plugin
    105 
    106 = 1.0.38 =
    107 * Adds an option (ub-use-curl) to opt-out of using cURL as a proxying client, the alternative being wp_remore_request
     102= 1.0.40 =
     103* Effective reversal to 1.0.37 to address blocking issue to some customers
    108104
    109105= 1.0.37 =
  • unbounce/trunk/templates/diagnostics.php

    r1984780 r1985297  
    9999            <p>Check that you don’t have any caching plugins installed, or any plugins that affect the order in which Javascript is loaded. These types of plugins will affect how Unbounce pages behave on WordPress.</p>
    100100            <ul class="causes">
    101              <li>wp-rocket - This plugin re-orders script tags, which breaks how Javascript loads for Unbounce pages.</li>
     101             <li>wp-rocket - This plugin re-orders script tags in the <head> which break how Javascript Loads.</li>
    102102             <li>wp-super-cache - caching plugins often cause Unbounce pages to 404</li>
    103103             <li>wp-total-cache - caching plugins often cause Unbounce pages to 404</li>
  • unbounce/trunk/templates/main_authorized_footer.php

    r1984780 r1985297  
    2222  Click here for troubleshooting and plugin diagnostics
    2323</a>
    24 <p class="ub-version">Unbounce Version 1.0.39</p>
     24<p class="ub-version">Unbounce Version 1.0.40</p>
  • unbounce/trunk/templates/main_unauthorized_footer.php

    r1984780 r1985297  
    55  Click here for troubleshooting and plugin diagnostics
    66</a>
    7 <p class="ub-version">Unbounce Version 1.0.39</p>
     7<p class="ub-version">Unbounce Version 1.0.40</p>
Note: See TracChangeset for help on using the changeset viewer.