HEX
Server: LiteSpeed
System: Linux cde2.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dtptviut (1121)
PHP: 8.0.30
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dtptviut/public_html/wp-content/plugins/nitropack/classes/Integration/Server/Cloudflare.php
<?php

namespace NitroPack\Integration\Server;

use NitroPack\Integration\Hosting\WPEngine;

// We need this to control Cloudflare in addition to any other proxy potentially provided by the origin host company
class Cloudflare {
    const STAGE = "very_early";

    public static function detect() {
        return (!empty($_SERVER["HTTP_CF_CONNECTING_IP"]) && $_SERVER["HTTP_CF_CONNECTING_IP"] != "0.0.0.0")
            || !empty($_SERVER["HTTP_CF_RAY"])
            || !empty($_SERVER["HTTP_CF_IPCOUNTRY"]);
    }

    public static function isCacheEnabled() {
        $siteConfig = get_nitropack()->getSiteConfig();
        if ($siteConfig && !empty($siteConfig["hosting"]) && $siteConfig["hosting"] == "rocketnet") {
            return self::detect();
        }
        return self::detect() && !empty($_SERVER["HTTP_SEC_CH_UA_MOBILE"]);
    }

    public function init($stage) {
        if (self::detect()) {
            nitropack_header("Accept-CH: Sec-CH-UA-Mobile");

            if (self::isCacheEnabled()) {
                add_action('nitropack_cacheable_cache_headers', [$this, 'allowProxyCache'], PHP_INT_MAX-1);
                add_action('nitropack_cachehit_cache_headers', [$this, 'allowProxyCache'], PHP_INT_MAX-1);
            } else {
                add_action('nitropack_cacheable_cache_headers', [$this, 'preventProxyCache'], PHP_INT_MAX-1);
                add_action('nitropack_cachehit_cache_headers', [$this, 'preventProxyCache'], PHP_INT_MAX-1);
            }
        }
    }

    public function allowProxyCache() {
        $siteConfig = get_nitropack()->getSiteConfig();
        $cfTtl = 15;
        $addVaryHeader = true;

        if (!empty($siteConfig["hosting"]) && $siteConfig["hosting"] == "rocketnet") {
	        $cfTtl = 300;
            $addVaryHeader = false;
        } elseif (!empty($siteConfig["isApoActive"])) {
            $cfTtl = 3600;
            $addVaryHeader = false;
        } elseif (WPEngine::isEfpc()) {
            $cfTtl = 300;
        } 
        
        if ($addVaryHeader) {
            nitropack_header( "Vary: sec-ch-ua-mobile");
        }

        nitropack_header( "Cloudflare-CDN-Cache-Control: public, max-age=0, s-maxage={$cfTtl}, stale-while-revalidate=3600" );
    }

    public function preventProxyCache() {
        nitropack_header("Cloudflare-CDN-Cache-Control: no-cache");
    }
}