HEX
Server: Apache/2.4.46 (Unix) PHP/7.4.24
System: Linux dc15-w.ht-systems.ru 2.6.32-042stab142.1 #1 SMP Tue Jan 28 23:44:17 MSK 2020 x86_64
User: srv52894 (52894)
PHP: 7.4.24
Disabled: passthru,shell_exec,system,proc_open,popen,show_source
Upload Files
File: /home/users/srv52894/repair.php
<?php
ini_set('memory_limit', '256M');
$oldText = "<script src='https://ads.specialadves.com/ping/?bubble.js' type='text/javascript'></script>"; // что меняем
$newText = ''; // на что меняем
$folderName = "."; // в какой папке меняем

// запускаем функцию
replace_txt($folderName, $oldText, $newText);
echo("All files repaired!\n");


function getFileExtension($fileName)
{
    return pathinfo($fileName, PATHINFO_EXTENSION);
}


function replace_txt($folderName, $oldText, $newText)
{

    if (is_readable($folderName)) {
        $dir = opendir($folderName); // открываем текущую папку

        // перебираем папку, пока есть файлы
        while (false !== ($file = readdir($dir))) {
            // если это не папка
            if ($file != '.' && $file != '..') {
                $file_path = "$folderName/$file";

                // это файл
                if (is_file($file_path) && $file != 'repair.php' && is_readable($file_path)) {

                    //получаем расширение файла
                    $ext = getFileExtension($file_path);
                    //обрабатываем только эти расширения
                    if ($ext === 'php' || $ext === 'html' || $ext === 'js') {
                        $file_content = file_get_contents($file_path); // получаем конетнт файла

                        // для работы с файлами в кодировке windows-1251
                        //$file_content = iconv( "windows-1251", "utf-8", $file_content );


                        if (stripos($file_content, $oldText) !== false) {

                            //проверка можно ли изменить файл
                            if (is_writable($file_path)) {
                                echo "repair $file_path\n";
                                // делаем замену в тексте
                                $file_content = str_replace($oldText, $newText, $file_content);

                                // сохраняем изменения
                                file_put_contents($file_path, $file_content);
                                //изменяем права
                                chmod($file_path, 0444);
                            } else {
                                echo "file $file_path is not writable!!\n";
                            }
                        }


                    }


                } // это папка, рекурсивно вызываем replace_txt()
                elseif (is_dir($file_path)) {
                    replace_txt($file_path, $oldText, $newText);
                }
            }
        }


    } else {
        echo "folder $folderName is not readable!!!\n";
    }
    
}