Changeset 1985297
- Timestamp:
- 12/04/2018 04:45:45 PM (6 years ago)
- Location:
- unbounce
- Files:
-
- 16 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
unbounce/tags/1.0.40/UBConfig.php
r1984780 r1985297 6 6 const UB_PLUGIN_NAME = 'ub-wordpress'; 7 7 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'; 10 10 11 11 // Option keys … … 25 25 const UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR = 'ub-allow-public-address-x-forwarded-for'; 26 26 const UB_PLUGIN_VERSION_KEY = 'ub-plugin-version'; 27 const UB_USE_CURL_KEY = 'ub-use-curl';28 27 29 28 const UB_LOCK_NAME = 'ub-sql-lock'; 30 29 31 public static function ub_option_ defaults()30 public static function ub_option_keys() 32 31 { 33 32 // All options, used by UBDiagnostics and deactivation hook 34 33 // Arrays are not allowed in class constants, so use a function 35 34 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 52 49 ); 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 }63 50 } 64 51 … … 72 59 { 73 60 $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; 75 65 } 76 66 … … 78 68 { 79 69 $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; 81 74 } 82 75 … … 91 84 $client_id = getenv('UB_API_CLIENT_ID'); 92 85 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;99 86 } 100 87 … … 175 162 'failure_message' => $failure_message), 176 163 null, null, null); 177 }178 179 public static function use_curl()180 {181 return get_option(UBConfig::UB_USE_CURL_KEY, 1) == 1;182 164 } 183 165 -
unbounce/tags/1.0.40/UBDiagnostics.php
r1984780 r1985297 101 101 'PHP Version' => phpversion(), 102 102 'WordPress Version' => UBDiagnostics::wordpress_version(), 103 'Unbounce Plugin Version' => '1.0. 39',103 'Unbounce Plugin Version' => '1.0.40', 104 104 'Checks' => self::pp(UBDiagnostics::checks($domain, $domain_info)), 105 105 'Options' => self::pp(UBDiagnostics::ub_options()), … … 125 125 private static function ub_options() 126 126 { 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); 132 135 } 133 136 … … 179 182 'php' => phpversion(), 180 183 'wordpress' => UBDiagnostics::wordpress_version(), 181 'plugin_version' => '1.0. 39',184 'plugin_version' => '1.0.40', 182 185 'curl_installed' => self::is_curl_installed(), 183 186 'xml_installed' => self::is_xml_installed(), -
unbounce/tags/1.0.40/UBHTTP.php
r1984780 r1985297 13 13 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'; 14 14 public static $request_header_blacklist = '/^(Accept-Encoding:)/i'; 15 public static $cookie_whitelist = array('ubvs', 'ubpv', 'ubvt', 'hubspotutk');16 15 17 16 public static function is_private_ip_address($ip_address) … … 70 69 71 70 public static function get_proxied_for_header( 71 $out_headers, 72 72 $forwarded_for, 73 73 $current_ip … … 80 80 $proxied_for = $current_ip; 81 81 } 82 return array('X-Proxied-For' => $proxied_for); 82 83 $out_headers[] = 'X-Proxied-For: ' . $proxied_for; 84 return $out_headers; 83 85 } 84 86 … … 155 157 156 158 // taken from: http://stackoverflow.com/a/13036310/322727 157 p ublicstatic function convert_headers_to_curl($headers)159 private static function convert_headers_to_curl($headers) 158 160 { 159 161 // map to curl-friendly format 160 162 $req_headers = array(); 161 163 array_walk($headers, function (&$v, $k) use (&$req_headers) { 162 $req_headers[] = $k . ": " . $v;164 array_push($req_headers, $k . ": " . $v); 163 165 }); 164 166 … … 169 171 $method, 170 172 $target_url, 173 $cookie_string, 171 174 $headers0, 172 175 $user_agent 173 176 ) { 177 174 178 // Always add this header to responses to show it comes from our plugin. 175 179 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(); 227 182 $forwarded_for = UBUtil::array_fetch($_SERVER, 'HTTP_X_FORWARDED_FOR'); 228 183 $remote_ip = UBUtil::array_fetch($_SERVER, 'REMOTE_ADDR'); 229 184 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, 236 192 $forwarded_for, 237 193 $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 ); 290 195 UBLogger::debug_var('target_url', $target_url); 291 196 UBLogger::debug_var('original_headers', print_r($headers0, true)); 292 197 UBLogger::debug_var('sent_headers', print_r($headers, true)); 293 198 294 $stream_headers = UBHTTP::stream_headers_function($ base_response_headers);199 $stream_headers = UBHTTP::stream_headers_function($existing_headers); 295 200 $stream_body = UBHTTP::stream_response_function(); 296 201 $curl = curl_init(); … … 301 206 CURLOPT_CUSTOMREQUEST => $method, 302 207 CURLOPT_USERAGENT => $user_agent, 208 CURLOPT_COOKIE => $cookie_string, 303 209 CURLOPT_HTTPHEADER => $headers, 304 210 CURLOPT_HEADERFUNCTION => $stream_headers, … … 419 325 public static function send_event_to_events_gateway($url, $data_string) 420 326 { 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 {430 327 try { 431 328 $stream_function = function ($curl, $str) { … … 473 370 } 474 371 } 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_string488 );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 ' . $url500 . ' - 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 ' . $url505 . ' - HTTP status: ' . $http_code;506 UBLogger::warning($message);507 }508 }509 372 } -
unbounce/tags/1.0.40/Unbounce-Page.php
r1984780 r1985297 4 4 Plugin URI: http://unbounce.com 5 5 Description: Unbounce is the most powerful standalone landing page builder available. 6 Version: 1.0. 396 Version: 1.0.40 7 7 Author: Unbounce 8 8 Author URI: http://unbounce.com … … 23 23 24 24 register_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); 26 58 27 59 // NOTE: This should be brought back when working on BEE-1136 … … 30 62 31 63 register_deactivation_hook(__FILE__, function () { 32 foreach (UBConfig::ub_option_ defaults() as $key => $value_not_needed) {64 foreach (UBConfig::ub_option_keys() as $key) { 33 65 delete_option($key); 34 66 } … … 117 149 UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url); 118 150 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 119 158 $all_headers = getallheaders(); 120 159 $all_headers['Host'] = $domain; … … 126 165 $http_method, 127 166 $raw_url, 167 $cookie_string, 128 168 $all_headers, 129 169 $user_agent … … 150 190 if (UBConfig::UB_VERSION != $pluginVersion) { 151 191 @UBDiagnostics::sendActivationEvent($pluginVersion); 152 UBConfig::set_options_if_not_exist();153 192 update_option(UBConfig::UB_PLUGIN_VERSION_KEY, UBConfig::UB_VERSION); 154 193 } -
unbounce/tags/1.0.40/readme.txt
r1984780 r1985297 4 4 Requires at least: 4.1.5 5 5 Tested up to: 5.0 6 Stable tag: 1.0. 396 Stable tag: 1.0.40 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 100 100 101 101 == 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 108 104 109 105 = 1.0.37 = -
unbounce/tags/1.0.40/templates/diagnostics.php
r1984780 r1985297 99 99 <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> 100 100 <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> 102 102 <li>wp-super-cache - caching plugins often cause Unbounce pages to 404</li> 103 103 <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 22 22 Click here for troubleshooting and plugin diagnostics 23 23 </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 5 5 Click here for troubleshooting and plugin diagnostics 6 6 </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 6 6 const UB_PLUGIN_NAME = 'ub-wordpress'; 7 7 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'; 10 10 11 11 // Option keys … … 25 25 const UB_ALLOW_PUBLIC_ADDRESS_X_FORWARDED_FOR = 'ub-allow-public-address-x-forwarded-for'; 26 26 const UB_PLUGIN_VERSION_KEY = 'ub-plugin-version'; 27 const UB_USE_CURL_KEY = 'ub-use-curl';28 27 29 28 const UB_LOCK_NAME = 'ub-sql-lock'; 30 29 31 public static function ub_option_ defaults()30 public static function ub_option_keys() 32 31 { 33 32 // All options, used by UBDiagnostics and deactivation hook 34 33 // Arrays are not allowed in class constants, so use a function 35 34 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 52 49 ); 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 }63 50 } 64 51 … … 72 59 { 73 60 $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; 75 65 } 76 66 … … 78 68 { 79 69 $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; 81 74 } 82 75 … … 91 84 $client_id = getenv('UB_API_CLIENT_ID'); 92 85 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;99 86 } 100 87 … … 175 162 'failure_message' => $failure_message), 176 163 null, null, null); 177 }178 179 public static function use_curl()180 {181 return get_option(UBConfig::UB_USE_CURL_KEY, 1) == 1;182 164 } 183 165 -
unbounce/trunk/UBDiagnostics.php
r1984780 r1985297 101 101 'PHP Version' => phpversion(), 102 102 'WordPress Version' => UBDiagnostics::wordpress_version(), 103 'Unbounce Plugin Version' => '1.0. 39',103 'Unbounce Plugin Version' => '1.0.40', 104 104 'Checks' => self::pp(UBDiagnostics::checks($domain, $domain_info)), 105 105 'Options' => self::pp(UBDiagnostics::ub_options()), … … 125 125 private static function ub_options() 126 126 { 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); 132 135 } 133 136 … … 179 182 'php' => phpversion(), 180 183 'wordpress' => UBDiagnostics::wordpress_version(), 181 'plugin_version' => '1.0. 39',184 'plugin_version' => '1.0.40', 182 185 'curl_installed' => self::is_curl_installed(), 183 186 'xml_installed' => self::is_xml_installed(), -
unbounce/trunk/UBHTTP.php
r1984780 r1985297 13 13 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'; 14 14 public static $request_header_blacklist = '/^(Accept-Encoding:)/i'; 15 public static $cookie_whitelist = array('ubvs', 'ubpv', 'ubvt', 'hubspotutk');16 15 17 16 public static function is_private_ip_address($ip_address) … … 70 69 71 70 public static function get_proxied_for_header( 71 $out_headers, 72 72 $forwarded_for, 73 73 $current_ip … … 80 80 $proxied_for = $current_ip; 81 81 } 82 return array('X-Proxied-For' => $proxied_for); 82 83 $out_headers[] = 'X-Proxied-For: ' . $proxied_for; 84 return $out_headers; 83 85 } 84 86 … … 155 157 156 158 // taken from: http://stackoverflow.com/a/13036310/322727 157 p ublicstatic function convert_headers_to_curl($headers)159 private static function convert_headers_to_curl($headers) 158 160 { 159 161 // map to curl-friendly format 160 162 $req_headers = array(); 161 163 array_walk($headers, function (&$v, $k) use (&$req_headers) { 162 $req_headers[] = $k . ": " . $v;164 array_push($req_headers, $k . ": " . $v); 163 165 }); 164 166 … … 169 171 $method, 170 172 $target_url, 173 $cookie_string, 171 174 $headers0, 172 175 $user_agent 173 176 ) { 177 174 178 // Always add this header to responses to show it comes from our plugin. 175 179 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(); 227 182 $forwarded_for = UBUtil::array_fetch($_SERVER, 'HTTP_X_FORWARDED_FOR'); 228 183 $remote_ip = UBUtil::array_fetch($_SERVER, 'REMOTE_ADDR'); 229 184 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, 236 192 $forwarded_for, 237 193 $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 ); 290 195 UBLogger::debug_var('target_url', $target_url); 291 196 UBLogger::debug_var('original_headers', print_r($headers0, true)); 292 197 UBLogger::debug_var('sent_headers', print_r($headers, true)); 293 198 294 $stream_headers = UBHTTP::stream_headers_function($ base_response_headers);199 $stream_headers = UBHTTP::stream_headers_function($existing_headers); 295 200 $stream_body = UBHTTP::stream_response_function(); 296 201 $curl = curl_init(); … … 301 206 CURLOPT_CUSTOMREQUEST => $method, 302 207 CURLOPT_USERAGENT => $user_agent, 208 CURLOPT_COOKIE => $cookie_string, 303 209 CURLOPT_HTTPHEADER => $headers, 304 210 CURLOPT_HEADERFUNCTION => $stream_headers, … … 419 325 public static function send_event_to_events_gateway($url, $data_string) 420 326 { 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 {430 327 try { 431 328 $stream_function = function ($curl, $str) { … … 473 370 } 474 371 } 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_string488 );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 ' . $url500 . ' - 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 ' . $url505 . ' - HTTP status: ' . $http_code;506 UBLogger::warning($message);507 }508 }509 372 } -
unbounce/trunk/Unbounce-Page.php
r1984780 r1985297 4 4 Plugin URI: http://unbounce.com 5 5 Description: Unbounce is the most powerful standalone landing page builder available. 6 Version: 1.0. 396 Version: 1.0.40 7 7 Author: Unbounce 8 8 Author URI: http://unbounce.com … … 23 23 24 24 register_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); 26 58 27 59 // NOTE: This should be brought back when working on BEE-1136 … … 30 62 31 63 register_deactivation_hook(__FILE__, function () { 32 foreach (UBConfig::ub_option_ defaults() as $key => $value_not_needed) {64 foreach (UBConfig::ub_option_keys() as $key) { 33 65 delete_option($key); 34 66 } … … 117 149 UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url); 118 150 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 119 158 $all_headers = getallheaders(); 120 159 $all_headers['Host'] = $domain; … … 126 165 $http_method, 127 166 $raw_url, 167 $cookie_string, 128 168 $all_headers, 129 169 $user_agent … … 150 190 if (UBConfig::UB_VERSION != $pluginVersion) { 151 191 @UBDiagnostics::sendActivationEvent($pluginVersion); 152 UBConfig::set_options_if_not_exist();153 192 update_option(UBConfig::UB_PLUGIN_VERSION_KEY, UBConfig::UB_VERSION); 154 193 } -
unbounce/trunk/readme.txt
r1984780 r1985297 4 4 Requires at least: 4.1.5 5 5 Tested up to: 5.0 6 Stable tag: 1.0. 396 Stable tag: 1.0.40 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 100 100 101 101 == 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 108 104 109 105 = 1.0.37 = -
unbounce/trunk/templates/diagnostics.php
r1984780 r1985297 99 99 <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> 100 100 <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> 102 102 <li>wp-super-cache - caching plugins often cause Unbounce pages to 404</li> 103 103 <li>wp-total-cache - caching plugins often cause Unbounce pages to 404</li> -
unbounce/trunk/templates/main_authorized_footer.php
r1984780 r1985297 22 22 Click here for troubleshooting and plugin diagnostics 23 23 </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 5 5 Click here for troubleshooting and plugin diagnostics 6 6 </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.