public static function _read_unbounce_domain_info($options_getter, $options_setter, $fetch_proxyable_url_set, $domain, $expire_now = false) { $proxyable_url_set = null; $cache_max_time_default = 10; $ps_domain = $options_getter(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY); $domains_info = $options_getter(UBConfig::UB_ROUTES_CACHE_KEY); $domain_info = UBUtil::array_fetch($domains_info, $domain, array()); $proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set'); $proxyable_url_set_fetched_at = UBUtil::array_fetch($domain_info, 'proxyable_url_set_fetched_at'); $proxyable_url_set_cache_timeout = UBUtil::array_fetch($domain_info, 'proxyable_url_set_cache_timeout'); $proxyable_url_set_etag = UBUtil::array_fetch($domain_info, 'proxyable_url_set_etag'); $cache_max_time = is_null($proxyable_url_set_cache_timeout) ? $cache_max_time_default : $proxyable_url_set_cache_timeout; $current_time = time(); if ($expire_now || is_null($proxyable_url_set) || $current_time - $proxyable_url_set_fetched_at > $cache_max_time) { try { $can_fetch = UBUtil::get_lock(); UBLogger::debug('Locking: ' . $can_fetch); if ($can_fetch) { $result_array = call_user_func($fetch_proxyable_url_set, $domain, $proxyable_url_set_etag, $ps_domain); list($routes_status, $etag, $max_age, $proxyable_url_set_new) = $result_array; if ($routes_status['status'] == 'NEW') { $domain_info['proxyable_url_set'] = $proxyable_url_set_new; $domain_info['proxyable_url_set_etag'] = $etag; $domain_info['proxyable_url_set_cache_timeout'] = $max_age; } elseif ($routes_status['status'] == 'SAME') { // Just extend the cache $domain_info['proxyable_url_set_cache_timeout'] = $max_age; } elseif ($routes_status['status'] == 'NONE') { $domain_info['proxyable_url_set'] = array(); $domain_info['proxyable_url_set_etag'] = null; } elseif ($routes_status['status'] == 'FAILURE') { UBLogger::warning('Route fetching failed'); } else { UBLogger::warning("Unknown response from route fetcher: '{$routes_status}'"); } // Creation of domain_info entry $domain_info['proxyable_url_set_fetched_at'] = $current_time; $domain_info['last_status'] = $routes_status['status']; if ($routes_status['status'] == 'FAILURE') { $domain_info['failure_message'] = $routes_status['failure_message']; } $domains_info[$domain] = $domain_info; // set autoload to false so that options are always loaded from DB $options_setter(UBConfig::UB_ROUTES_CACHE_KEY, $domains_info, false); } } catch (Exception $e) { UBLogger::warning('Could not update sitemap: ' . $e); } $release_result = UBUtil::release_lock(); UBLogger::debug('Unlocking: ' . $release_result); } return UBUtil::array_select_by_key($domain_info, array('proxyable_url_set', 'proxyable_url_set_fetched_at', 'failure_message', 'last_status')); }
public static function send_event_to_events_gateway($url, $data_string) { try { $stream_function = function ($curl, $str) { return strlen($str); }; $curl = curl_init(); $curl_options = array(CURLOPT_URL => $url, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_USERAGENT => UBConfig::UB_USER_AGENT, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)), CURLOPT_HEADERFUNCTION => $stream_function, CURLOPT_WRITEFUNCTION => $stream_function, CURLOPT_POSTFIELDS => $data_string, CURLOPT_TIMEOUT => 2); curl_setopt_array($curl, $curl_options); $success = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if (!$success) { $message = 'Unable to send log messages to ' . $url . ': "' . curl_error($curl) . '" - HTTP status: ' . curl_errno($curl); UBLogger::warning($message); } elseif ($http_code >= 200 && $http_code < 300) { $message = 'Successfully sent log messsages to ' . $url . ' - HTTP status: ' . $http_code; UBLogger::debug($message); } else { $message = 'Unable to send log messages to ' . $url . ' - HTTP status: ' . $http_code; UBLogger::warning($message); } curl_close($curl); } catch (Exception $e) { $message = 'Unable to send log messages to ' . $url . ' - Error: ' . $e; UBLogger::warning($message); } }
define('DONOTCACHEOBJECT', true); } UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url); $cookies_to_forward = UBUtil::array_select_by_key($_COOKIE, array('ubvs', 'ubpv', 'ubvt')); $cookie_string = UBHTTP::cookie_string_from_array($cookies_to_forward); $req_headers = $referer == null ? array('Host: ' . $domain) : array('Referer: ' . $referer, 'Host: ' . $domain); // Make sure we don't get cached by Wordpress hosts like WPEngine header('Cache-Control: max-age=0; private'); list($success, $message) = UBHTTP::stream_request($http_method, $raw_url, $cookie_string, $req_headers, $user_agent); if ($success === false) { update_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, $message); } $end = microtime(true); $time_taken = ($end - $start) * 1000; UBLogger::debug_var('time_taken', $time_taken); UBLogger::debug("proxying for {$current_url} done successfuly -- took {$time_taken} ms"); exit(0); } }, UBConfig::int_min()); add_action('admin_init', function () { UBUtil::clear_flash(); # Disable incompatible scripts # WPML wp_dequeue_script('installer-admin'); # Enqueue our own scripts # Main page wp_enqueue_script('ub-rx', plugins_url('js/rx.lite.compat.min.js', __FILE__)); wp_enqueue_script('set-unbounce-domains-js', plugins_url('js/set-unbounce-domains.js', __FILE__), array('jquery', 'ub-rx')); wp_enqueue_script('unbounce-page-js', plugins_url('js/unbounce-page.js', __FILE__), array('jquery')); # Diagnostics page wp_enqueue_script('ub-clipboard-js', plugins_url('js/clipboard.min.js', __FILE__));