0.6.1: ttyd console via random base path instead of basic auth (no browser prompt in the iframe)
This commit is contained in:
1 parent
21c259ec4f
commit
642a11f505
4 files changed
+18
-19
No files matched your search
+10
-9
@@ -1021,9 +1021,9 @@ function vmm_console_start(string $vm, string $bindHost = ''): array
|
|||||||
$bindHost = vmm_vnc_host_for_vm($vm);
|
$bindHost = vmm_vnc_host_for_vm($vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
$existing = vmm_console_status($vm);
|
// always start fresh (old instances may use the credential-based layout)
|
||||||
if ($existing !== null) {
|
if (vmm_console_status($vm) !== null) {
|
||||||
return ['ok' => true] + $existing;
|
vmm_console_stop($vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
$port = 0;
|
$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'];
|
return ['ok' => false, 'error' => 'no free port in 7681-7699'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = 'vmm';
|
// ttyd has no session integration, so the base path acts as a bearer token.
|
||||||
$pass = bin2hex(random_bytes(6));
|
// This avoids the browser's basic-auth dialog blocking the embedded frame.
|
||||||
|
$token = bin2hex(random_bytes(8));
|
||||||
$dir = VMM_ROOT . '/state/console';
|
$dir = VMM_ROOT . '/state/console';
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
@mkdir($dir, 0750, true);
|
@mkdir($dir, 0750, true);
|
||||||
}
|
}
|
||||||
$log = $dir . '/' . $vm . '.log';
|
$log = $dir . '/' . $vm . '.log';
|
||||||
$cmd = sprintf(
|
$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']),
|
escapeshellarg($ttyd['path']),
|
||||||
$port,
|
$port,
|
||||||
escapeshellarg($bindHost),
|
escapeshellarg($bindHost),
|
||||||
escapeshellarg($user . ':' . $pass),
|
escapeshellarg('/' . $token . '/'),
|
||||||
escapeshellarg($dev),
|
escapeshellarg($dev),
|
||||||
escapeshellarg($log)
|
escapeshellarg($log)
|
||||||
);
|
);
|
||||||
@@ -1076,10 +1077,10 @@ function vmm_console_start(string $vm, string $bindHost = ''): array
|
|||||||
'pid' => $pid,
|
'pid' => $pid,
|
||||||
'port' => $port,
|
'port' => $port,
|
||||||
'host' => $bindHost,
|
'host' => $bindHost,
|
||||||
'user' => $user,
|
'token' => $token,
|
||||||
'pass' => $pass,
|
|
||||||
'device' => $dev,
|
'device' => $dev,
|
||||||
'started' => time(),
|
'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));
|
file_put_contents(vmm_console_state_file($vm), json_encode($st, JSON_PRETTY_PRINT));
|
||||||
return ['ok' => true] + $st;
|
return ['ok' => true] + $st;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"appname": "VM Manager",
|
"appname": "VM Manager",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
||||||
"vm_source": "auto",
|
"vm_source": "auto",
|
||||||
"bridges": ["ix0bridge"],
|
"bridges": ["ix0bridge"],
|
||||||
|
|||||||
+6
-8
@@ -193,9 +193,10 @@ vmm_nav('dashboard');
|
|||||||
<td class="celltag"><?=gettext('Web terminal');?></td>
|
<td class="celltag"><?=gettext('Web terminal');?></td>
|
||||||
<td class="celldata">
|
<td class="celldata">
|
||||||
<?php if ($con !== null): ?>
|
<?php if ($con !== null): ?>
|
||||||
<a class="formbtn" href="http://<?=vmm_h((string)$con['host']);?>:<?=(int)$con['port'];?>/" target="_blank">console öffnen</a>
|
<?php $conUrl = $con['url'] ?? ('http://' . $con['host'] . ':' . (int)$con['port'] . '/'); ?>
|
||||||
<span class="vmm-mono" style="margin-left:8px;"><?=vmm_h((string)$con['user']);?> / <?=vmm_h((string)$con['pass']);?></span>
|
<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>
|
<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: ?>
|
<?php else: ?>
|
||||||
<button type="submit" class="formbtn" name="act" value="console_start:<?=vmm_h($name);?>"><?=gettext('Start web console');?></button>
|
<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>
|
<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>
|
</table>
|
||||||
|
|
||||||
<?php if ($con !== null): ?>
|
<?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;">
|
<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>
|
<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>
|
<thead><?php html_separator2(); html_titleline2(gettext('Web console'), 2); ?></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" class="celldata">
|
<td colspan="2" class="celldata">
|
||||||
<div style="margin-bottom:6px;opacity:.8;font-size:12px;">
|
<div style="margin-bottom:6px;opacity:.75;font-size:12px;">
|
||||||
<?=gettext('If the frame asks for a login: user');?>
|
<?=gettext('No login prompt - the URL itself carries the token.');?>
|
||||||
<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>
|
</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>
|
<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>
|
</td>
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
0.6.0
|
0.6.1
|
||||||
Reference in new issue
Block a user