| @@ -24,14 +24,47 @@ | ||
| 24 | 24 | |
| 25 | 25 | return true; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | +function bwp_request_is_https() { | |
| 29 | + if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { | |
| 30 | + return true; | |
| 31 | + } | |
| 32 | + | |
| 33 | + // Reverse proxy / load balancer terminating TLS upstream | |
| 34 | + if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { | |
| 35 | + // may be a comma-separated chain: "https,http" — first hop is the client | |
| 36 | + $proto = strtolower(trim(explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'])[0])); | |
| 37 | + if ($proto === 'https') { | |
| 38 | + return true; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + | |
| 42 | + if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && strtolower($_SERVER['HTTP_X_FORWARDED_SSL']) === 'on') { | |
| 43 | + return true; | |
| 44 | + } | |
| 45 | + | |
| 46 | + if (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) === 'on') { | |
| 47 | + return true; | |
| 48 | + } | |
| 49 | + | |
| 50 | + if (!empty($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] === 443) { | |
| 51 | + return true; | |
| 52 | + } | |
| 53 | + | |
| 54 | + return false; | |
| 55 | +} | |
| 56 | + | |
| 28 | 57 | function bwp_get_request_url() { |
| 29 | - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') { | |
| 58 | + | |
| 59 | + $scheme = 'http://'; | |
| 60 | + | |
| 61 | + if (bwp_request_is_https()) { | |
| 30 | 62 | $scheme = 'https://'; |
| 31 | - } else { | |
| 63 | + } elseif (function_exists('wp_parse_url') && function_exists('get_option')) { | |
| 32 | 64 | $scheme = (wp_parse_url(get_option('home'), PHP_URL_SCHEME) === 'https') ? 'https://' : 'http://'; |
| 33 | 65 | } |
| 66 | + | |
| 34 | 67 | $host = isset($_SERVER['HTTP_HOST']) ? strip_tags(stripslashes($_SERVER['HTTP_HOST'])) : 'localhost'; |
| 35 | 68 | $uri = isset($_SERVER['REQUEST_URI']) ? strip_tags(stripslashes($_SERVER['REQUEST_URI'])) : '/'; |
| 36 | 69 | $url = $scheme . $host . $uri; |
| 37 | 70 | return strtolower($url); |
| @@ -101,9 +134,15 @@ | ||
| 101 | 134 | if (php_sapi_name() === 'cli' || (defined('WP_CLI') && WP_CLI)) { |
| 102 | 135 | return; |
| 103 | 136 | } |
| 104 | 137 | |
| 138 | + if ( strpos( $_SERVER["REQUEST_URI"], "berqwp-ping" ) !== false ) { | |
| 139 | + echo "PONG"; | |
| 140 | + exit(); | |
| 141 | + } | |
| 142 | + | |
| 105 | 143 | if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET' && !bwp_is_user_logged_in() && !bwp_is_ajax() && !berqDetectCrawler::is_crawler() && bwp_pass_cookie_requirement()) { |
| 144 | + | |
| 106 | 145 | $berqconfigs = berqConfigs::getInstance(); |
| 107 | 146 | $configs = $berqconfigs->get_configs(); |
| 108 | 147 | $url = bwp_get_request_url(); |
| 109 | 148 | $url = @dropin_remove_ignore_params($url); |
| @@ -126,8 +165,9 @@ | ||
| 126 | 165 | |
| 127 | 166 | if (berqwp_dropin_is_page_url_excluded($url)) { |
| 128 | 167 | return; |
| 129 | 168 | } |
| 169 | + | |
| 130 | 170 | |
| 131 | 171 | if (file_exists($cache_file) && $cache_max_life > time()) { |
| 132 | 172 | $file_content = @file_get_contents($cache_file); |
| 133 | 173 | |