/home/bdqbpbxa/demo-subdomains/ping-proxies.goodface.com.ua/public/update-sitemap.php
<?php

$sitemapPath = './sitemap.xml';
$correctPasswordHash = '$2y$10$dr0pSwjreEwoQ/pQeLeZquarg6YWXaWZHZJZCqL8u8retWq.Y0L6K';

function updateSitemap()
{
    $password = $_GET['password'] ?? '';
    global $correctPasswordHash;

    if (!password_verify($password, $correctPasswordHash)) {
        http_response_code(403);
        echo 'Incorrect password';
        exit;
    }

    $sitemapData = file_get_contents('https://ping-proxies-dev.onrender.com/api/sitemap/index.xml');
    if ($sitemapData === false) {
        throw new Exception('Failed to fetch new sitemap data from URL');
    }

    $updatedData = str_replace('<?xml-stylesheet type="text/xsl" href="xsl/sitemap.xsl"?>', '<?XML-stylesheet type="text/xsl" href="xsl/sitemap.xsl"?>', $sitemapData);

    if (file_put_contents($GLOBALS['sitemapPath'], $updatedData) === false) {
        throw new Exception('Failed to update the sitemap file');
    }

    return $updatedData;
}

if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['update']) && $_GET['update'] === 'true') {
    try {
        $sitemapData = updateSitemap();
        header('Location: sitemap.xml');
        exit;
    } catch (Exception $e) {
        echo 'Error updating the sitemap: ' . $e->getMessage();
    }
} else {
    echo 'Invalid request';
}