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;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"appname": "VM Manager",
"version": "0.6.0",
"version": "0.6.1",
"rootfolder": "/mnt/Daten/extensions/vmmngr",
"vm_source": "auto",
"bridges": ["ix0bridge"],
+6 -8
View File
@@ -193,9 +193,10 @@ vmm_nav('dashboard');
<td class="celltag"><?=gettext('Web terminal');?></td>
<td class="celldata">
<?php if ($con !== null): ?>
<a class="formbtn" href="http://<?=vmm_h((string)$con['host']);?>:<?=(int)$con['port'];?>/" target="_blank">console öffnen</a>
<span class="vmm-mono" style="margin-left:8px;"><?=vmm_h((string)$con['user']);?> / <?=vmm_h((string)$con['pass']);?></span>
<?php $conUrl = $con['url'] ?? ('http://' . $con['host'] . ':' . (int)$con['port'] . '/'); ?>
<a class="formbtn" href="<?=vmm_h($conUrl);?>" target="_blank"><?=gettext('open in a tab');?></a>
<button type="submit" class="formbtn" name="act" value="console_stop:<?=vmm_h($name);?>" style="margin-left:8px;"><?=gettext('Stop');?></button>
<div style="opacity:.75;margin-top:4px;"><?=gettext('The URL contains a random token - treat it like a password.');?></div>
<?php else: ?>
<button type="submit" class="formbtn" name="act" value="console_start:<?=vmm_h($name);?>"><?=gettext('Start web console');?></button>
<span style="opacity:.75;margin-left:8px;"><?=gettext('ttyd serves the serial console (text only) with basic auth.');?></span>
@@ -206,18 +207,15 @@ vmm_nav('dashboard');
</table>
<?php if ($con !== null): ?>
<?php $conUrl = 'http://' . $con['host'] . ':' . (int)$con['port'] . '/'; ?>
<?php $conUrl = $con['url'] ?? ('http://' . $con['host'] . ':' . (int)$con['port'] . '/'); ?>
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
<colgroup><col class="area_data_settings_col_tag"><col class="area_data_settings_col_data"></colgroup>
<thead><?php html_separator2(); html_titleline2(gettext('Web console'), 2); ?></thead>
<tbody>
<tr>
<td colspan="2" class="celldata">
<div style="margin-bottom:6px;opacity:.8;font-size:12px;">
<?=gettext('If the frame asks for a login: user');?>
<strong><?=vmm_h((string)$con['user']);?></strong>,
<?=gettext('password');?> <strong><?=vmm_h((string)$con['pass']);?></strong>
· <a href="<?=vmm_h($conUrl);?>" target="_blank"><?=gettext('open in a tab');?></a>
<div style="margin-bottom:6px;opacity:.75;font-size:12px;">
<?=gettext('No login prompt - the URL itself carries the token.');?>
</div>
<iframe src="<?=vmm_h($conUrl);?>" style="width:100%;height:440px;border:1px solid rgba(127,127,127,.4);border-radius:4px;background:#000;"></iframe>
</td>
+1 -1
View File
@@ -1 +1 @@
0.6.0
0.6.1