0.6.1: ttyd console via random base path instead of basic auth (no browser prompt in the iframe)

This commit is contained in:
Claw committed 2026-11-17 20:57:36 +01:00
1 parent 21c259ec4f
commit 642a11f505
4 files changed
+18 -19

No files matched your search

+10 -9
View File
@@ -1021,9 +1021,9 @@ function vmm_console_start(string $vm, string $bindHost = ''): array
$bindHost = vmm_vnc_host_for_vm($vm);
}
$existing = vmm_console_status($vm);
if ($existing !== null) {
return ['ok' => true] + $existing;
// always start fresh (old instances may use the credential-based layout)
if (vmm_console_status($vm) !== null) {
vmm_console_stop($vm);
}
$port = 0;
@@ -1039,19 +1039,20 @@ function vmm_console_start(string $vm, string $bindHost = ''): array
return ['ok' => false, 'error' => 'no free port in 7681-7699'];
}
$user = 'vmm';
$pass = bin2hex(random_bytes(6));
// ttyd has no session integration, so the base path acts as a bearer token.
// This avoids the browser's basic-auth dialog blocking the embedded frame.
$token = bin2hex(random_bytes(8));
$dir = VMM_ROOT . '/state/console';
if (!is_dir($dir)) {
@mkdir($dir, 0750, true);
}
$log = $dir . '/' . $vm . '.log';
$cmd = sprintf(
'/usr/bin/nohup %s -p %d -i %s -c %s -W /usr/bin/cu -l %s > %s 2>&1 &',
'/usr/bin/nohup %s -p %d -i %s -b %s -W /usr/bin/cu -l %s > %s 2>&1 &',
escapeshellarg($ttyd['path']),
$port,
escapeshellarg($bindHost),
escapeshellarg($user . ':' . $pass),
escapeshellarg('/' . $token . '/'),
escapeshellarg($dev),
escapeshellarg($log)
);
@@ -1076,10 +1077,10 @@ function vmm_console_start(string $vm, string $bindHost = ''): array
'pid' => $pid,
'port' => $port,
'host' => $bindHost,
'user' => $user,
'pass' => $pass,
'token' => $token,
'device' => $dev,
'started' => time(),
'url' => sprintf('http://%s:%d/%s/', $bindHost, $port, $token),
];
file_put_contents(vmm_console_state_file($vm), json_encode($st, JSON_PRETTY_PRINT));
return ['ok' => true] + $st;