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/comparisonfeed-wp/routers/feed.php
<?php
    /*
        Router iframe feeds
    */
    error_reporting(E_ERROR);

    include('../settings.php');

    // Allow CORS
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Headers: *');

    // Add header that prevents search engines from indexing the page.
    header('X-Robots-Tag: noindex, nofollow');

    function startsWith($haystack, $needle) {
        return (substr($haystack, 0, strlen($needle)) === $needle);
    }

    function endsWith($haystack, $needle) {
        return (substr($haystack, -strlen($needle)) === $needle);
    }    

    $url = '';        
    $location = $_GET['location'];
    $contentType = 'text/html';
    $cacheControl = 'max-age=600, private';
    $path = $_GET['path'];
    $image = $_GET['image'];

    // The path to where the needed resource is located on api.adservice.com is supplied as GET parameter.    
    // Construct URL.
    $pathStart = strpos($_SERVER['QUERY_STRING'], 'path=');
    $imageStart = strpos($_SERVER['QUERY_STRING'], 'image=');
    if ($pathStart !== false) {
        $url = $feedDomain . substr($_SERVER['QUERY_STRING'], $pathStart + 5);

        if (endsWith($path, '.css')) {
            $contentType = 'text/css';
            $cacheControl = 'max-age=3600, private';
        } else if (endsWith($path, '.js') || strpos($path, 'jquery.compareFeed.pl') !== false ||
            strpos($path, 'asjs.pl') !== false) {
            $contentType = 'application/javascript';
        } else if (strpos($path, 'comparisonFeed.pl') !== false) {
            $contentType = 'application/json';
        } else if (strpos($path, 'Translations.pl') !== false) {
            $contentType = 'application/json';
            $cacheControl = 'max-age=3600, private';
        } else if (endsWith($path, '.png') || endsWith($path, '.jpg') || endsWith($path, '.jpeg') ||
            endsWith($path, '.svg') || endsWith($path, '.gif')) {
            $path_parts = pathinfo($path);
            $extension = $path_parts['extension'];

            // Special case for SVG content type.
            if ($extension == 'svg') {
                $extension .= '+xml';
            }

            $contentType = 'image/'.$extension;
            $cacheControl = 'max-age=31536000';        
        }
    } else if ($imageStart !== false) {
        $url = $imageDomain . substr($_SERVER['QUERY_STRING'], $imageStart + 6);
    
        $path_parts = pathinfo($image);
        $extension = $path_parts['extension'];

        // Special case for SVG content type.
        if ($extension == 'svg') {
            $extension .= '+xml';
        }

        $contentType = 'image/'.$extension;
        $cacheControl = 'max-age=31536000';
    }    

    // Build curl request.
    $curl = curl_init();
    $options = array(
        CURLOPT_URL             => $url,
        CURLOPT_RETURNTRANSFER  => true,
        CURLOPT_ENCODING        => '',
        CURLOPT_IPRESOLVE       => CURL_IPRESOLVE_V4
    );
    curl_setopt_array($curl, $options);
    $result = curl_exec($curl);
    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close($curl);

    if ($httpCode == '200' || $httpCode == '302') {        
        // Set headers.
        header('Content-Type: ' . $contentType);
        header('Cache-Control: ' . $cacheControl);

        // Generate ETag to facilitate caching.
        $etag = md5($result);
        if ($etag) {
            header('ETag: ' . $etag);
        }

        if (strpos($path, 'jquery.compareFeed.pl') !== false || strpos($path, 'comparisonFeed.pl') !== false ||
            strpos($path, 'comparisoniFramePreview.pl') !== false) {            
            $result = str_replace('https://static.ascontentcloud.com', $location . 'routers/feed.php?path=' , $result);
            $result = str_replace('http://static.ascontentcloud.com', $location . 'routers/feed.php?path=' , $result);
            $result = str_replace('https://img.ascontentcloud.com', $location . 'routers/feed.php?image=' , $result);
            $result = str_replace('http://img.ascontentcloud.com', $location . 'routers/feed.php?image=' , $result);
            $result = preg_replace('/(http[s]?:\/\/img\.ascontentcloud\.com\/resources\/)([^.]+\.[a-z]+)/im', $location . 'routers/image.php?image=/resources/$2&i=1' , $result);
            $result = str_replace('https://feed.ascontentcloud.com', $location . 'routers/feed.php?location='.$location.'&path=' , $result);
            $result = str_replace('http://feed.ascontentcloud.com', $location . 'routers/feed.php?location='.$location.'&path=' , $result);        
        }        

        print $result;
    } else {
        header('Location: ' . $url);
    }
?>