270 lines
13 KiB
PHP
270 lines
13 KiB
PHP
<?php
|
|
/*
|
|
* vmmngr_vm.php - VM detail view with actions (0.2.0)
|
|
*/
|
|
|
|
require_once 'vmmngr-boot.inc';
|
|
|
|
$name = (string)($_GET['name'] ?? '');
|
|
// POSTs from this page carry the VM name in the act field; accept that too so
|
|
// a form without the query string can never bounce to the dashboard
|
|
if ($name === '' && isset($_POST['act'])) {
|
|
$parts = explode(':', (string)$_POST['act'], 2);
|
|
$name = $parts[1] ?? '';
|
|
}
|
|
if ($name === '' || !vmm_valid_name($name)) {
|
|
header('Location: vmmngr.php');
|
|
exit;
|
|
}
|
|
|
|
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && isset($_POST['act'])) {
|
|
$act = (string)$_POST['act'];
|
|
[$verb, $vmName] = array_pad(explode(':', $act, 2), 2, '');
|
|
if ($vmName !== $name) {
|
|
$vmName = $name;
|
|
}
|
|
|
|
// media: attach ISOs (install) or eject them
|
|
if ($verb === 'install' || $verb === 'eject') {
|
|
if ($verb === 'eject') {
|
|
$res = vmm_iso_detach($name);
|
|
$_SESSION['vmmngr_error'] = isset($res['error'])
|
|
? (string)$res['error']
|
|
: ($res['removed'] === [] ? gettext('No ISO attached.') : sprintf(gettext('Ejected: %s'), implode(', ', $res['removed'])));
|
|
header('Location: vmmngr_vm.php?name=' . urlencode($name));
|
|
exit;
|
|
}
|
|
$isoDir = vmm_data_dir('.iso');
|
|
$pick = [];
|
|
foreach (['iso', 'driver_iso'] as $field) {
|
|
$f = vmm_safe_basename((string)($_POST[$field] ?? ''));
|
|
if ($f !== '' && str_ends_with(strtolower($f), '.iso')) {
|
|
$pick[] = $isoDir . '/' . $f;
|
|
}
|
|
}
|
|
if ($pick === []) {
|
|
$_SESSION['vmmngr_error'] = gettext('Choose an ISO first.');
|
|
header('Location: vmmngr_vm.php?name=' . urlencode($name));
|
|
exit;
|
|
}
|
|
$res = vmm_iso_attach($name, $pick);
|
|
if (isset($res['error'])) {
|
|
$_SESSION['vmmngr_error'] = (string)$res['error'];
|
|
header('Location: vmmngr_vm.php?name=' . urlencode($name));
|
|
exit;
|
|
}
|
|
$job = vmm_job_new('start', $name);
|
|
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
|
exit;
|
|
}
|
|
$check = vmm_action_check($verb, $vmName, (string)($_POST['confirm'] ?? ''));
|
|
if (!$check['ok']) {
|
|
$_SESSION['vmmngr_error'] = $check['error'];
|
|
header('Location: vmmngr_vm.php?name=' . urlencode($name));
|
|
exit;
|
|
}
|
|
$job = vmm_job_new($verb, $vmName);
|
|
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
|
exit;
|
|
}
|
|
|
|
if (vmm_vm_state($name) === 'absent') {
|
|
$_SESSION['vmmngr_error'] = sprintf(gettext('Virtual machine %s does not exist (yet).'), $name);
|
|
header('Location: vmmngr.php');
|
|
exit;
|
|
}
|
|
|
|
$info = vmm_info($name);
|
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), $name];
|
|
$jobs = vmm_job_list(10, $name);
|
|
|
|
include 'fbegin.inc';
|
|
vmm_css();
|
|
vmm_nav('dashboard');
|
|
?>
|
|
|
|
<form action="vmmngr_vm.php?name=<?=urlencode($name);?>" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
|
|
|
<?php if (isset($info['error'])): ?>
|
|
<?php print_info_box(sprintf(gettext('Could not read VM details: %s'), vmm_h((string)$info['error']))); ?>
|
|
<?php else: ?>
|
|
<?php
|
|
$g = $info['general'] ?? [];
|
|
$state = vmm_state_from_string((string)($g['state'] ?? ''));
|
|
$isRunning = $state['state'] === 'running';
|
|
$jsName = htmlspecialchars(json_encode($name), ENT_QUOTES);
|
|
?>
|
|
|
|
<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(sprintf('%s: %s', gettext('Virtual Machine'), $name), 2);
|
|
?>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td class="celltag"><?=gettext('State');?></td><td class="celldata"><?=vmm_badge($state['state']);?> <?php if ($state['pid']): ?><span class="vmm-mono">PID <?=$state['pid'];?></span><?php endif; ?></td></tr>
|
|
<tr><td class="celltag"><?=gettext('Loader');?></td><td class="celldata"><?=vmm_h((string)($g['loader'] ?? ''));?></td></tr>
|
|
<tr><td class="celltag"><?=gettext('vCPU / Memory');?></td><td class="celldata"><?=vmm_h((string)($g['cpu'] ?? ''));?> vCPU · <?=vmm_h((string)($g['memory'] ?? ''));?><?php if (!empty($g['memory-resident'])): ?> <span class="vmm-mono">(<?=vmm_h((string)$g['memory-resident']);?>)</span><?php endif; ?></td></tr>
|
|
<tr><td class="celltag"><?=gettext('Datastore');?></td><td class="celldata"><?=vmm_h((string)($g['datastore'] ?? ''));?></td></tr>
|
|
<tr><td class="celltag">UUID</td><td class="celldata vmm-mono"><?=vmm_h((string)($g['uuid'] ?? ''));?></td></tr>
|
|
<tr>
|
|
<td class="celltag"><?=gettext('Actions');?></td>
|
|
<td class="celldata">
|
|
<span class="vmm-actions">
|
|
<?php if ($isRunning): ?>
|
|
<button type="submit" class="formbtn" name="act" value="stop:<?=vmm_h($name);?>" onclick="return confirm('Stop <?=vmm_h($name);?>?')"><?=gettext('Stop');?></button>
|
|
<button type="submit" class="formbtn" name="act" value="restart:<?=vmm_h($name);?>" onclick="return confirm('Restart <?=vmm_h($name);?>?')"><?=gettext('Restart');?></button>
|
|
<button type="submit" class="formbtn" name="act" value="poweroff:<?=vmm_h($name);?>" onclick="return confirm('Force power off <?=vmm_h($name);?>? Unsaved guest data may be lost.')"><?=gettext('Power off');?></button>
|
|
<button type="submit" class="formbtn" name="act" value="reset:<?=vmm_h($name);?>" onclick="return confirm('Hard reset <?=vmm_h($name);?>?')"><?=gettext('Reset');?></button>
|
|
<?php else: ?>
|
|
<button type="submit" class="formbtn" name="act" value="start:<?=vmm_h($name);?>"><?=gettext('Start');?></button>
|
|
<input type="text" name="confirm" value="" placeholder="<?=gettext('type name to destroy');?>" style="width:150px"/>
|
|
<button type="submit" class="formbtn" name="act" value="destroy:<?=vmm_h($name);?>" onclick="return confirm('Destroy <?=vmm_h($name);?>? All disks and snapshots are deleted.')"><?=gettext('Destroy');?></button>
|
|
<?php endif; ?>
|
|
<a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a>
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php
|
|
$attached = vmm_attached_isos($name);
|
|
$isos = vmm_file_list(vmm_data_dir('.iso'), ['iso']);
|
|
?>
|
|
<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('Install / media'), 2); ?>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="celltag"><?=gettext('Attached');?></td>
|
|
<td class="celldata vmm-mono">
|
|
<?php if ($attached === []): ?>
|
|
<?=gettext('none');?>
|
|
<?php else: ?>
|
|
<?php foreach ($attached as $a): ?>
|
|
<div>disk<?=(int)$a['slot'];?> → <?=vmm_h((string)$a['path']);?></div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php if (!$isRunning): ?>
|
|
<tr>
|
|
<td class="celltag"><?=gettext('Boot ISO');?></td>
|
|
<td class="celldata">
|
|
<select name="iso">
|
|
<option value=""><?=gettext('none');?></option>
|
|
<?php foreach ($isos as $i): ?>
|
|
<option value="<?=vmm_h((string)$i['name']);?>"><?=vmm_h((string)$i['name']);?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<span style="opacity:.75;margin-left:8px;"><?=gettext('Windows: boot from the installation ISO, drivers from virtio-win below.');?></span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="celltag"><?=gettext('Driver ISO');?></td>
|
|
<td class="celldata">
|
|
<select name="driver_iso">
|
|
<option value=""><?=gettext('none');?></option>
|
|
<?php foreach ($isos as $i): ?>
|
|
<?php if (stripos((string)$i['name'], 'virtio') === false) { continue; } ?>
|
|
<option value="<?=vmm_h((string)$i['name']);?>"><?=vmm_h((string)$i['name']);?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<span style="opacity:.75;margin-left:8px;"><?=gettext('Only virtio-* images are listed here.');?></span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="celltag"><?=gettext('Actions');?></td>
|
|
<td class="celldata">
|
|
<button type="submit" class="formbtn" name="act" value="install:<?=vmm_h($name);?>"><?=gettext('Attach and start');?></button>
|
|
<button type="submit" class="formbtn" name="act" value="eject:<?=vmm_h($name);?>" onclick="return confirm('Eject all attached ISOs?')"><?=gettext('Eject all');?></button>
|
|
<span style="opacity:.75;margin-left:8px;"><?=gettext('Attaching rewrites the VM config (backup as .vmmngr.bak).');?></span>
|
|
</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<div id="vmm-job" class="vmm-job"></div>
|
|
|
|
<?php foreach (($info['sections'] ?? []) as $type => $blocks): ?>
|
|
<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(vmm_h(ucwords(str_replace('-', ' ', $type))), 2); ?>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($blocks as $b): ?>
|
|
<?php foreach ($b['data'] as $k => $v): ?>
|
|
<tr>
|
|
<td class="celltag"><?=vmm_h((string)$k);?></td>
|
|
<td class="celldata vmm-mono"><?=vmm_h((string)$v);?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php foreach ($b['lines'] as $line): ?>
|
|
<tr>
|
|
<td class="celltag">—</td>
|
|
<td class="celldata vmm-mono"><?=vmm_h((string)$line);?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if ($b['data'] === [] && $b['lines'] === []): ?>
|
|
<tr><td class="celltag">—</td><td class="celldata"><?=gettext('none');?></td></tr>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<br />
|
|
<?php endforeach; ?>
|
|
|
|
<table class="area_data_selection" style="width:100%;border-collapse:collapse;">
|
|
<colgroup>
|
|
<col style="width:30%">
|
|
<col style="width:12%">
|
|
<col style="width:12%">
|
|
<col style="width:46%">
|
|
</colgroup>
|
|
<thead>
|
|
<?php html_separator2(); html_titleline2(gettext('Jobs for this VM'), 4); ?>
|
|
<tr>
|
|
<th class="lhell"><?=gettext('Job');?></th>
|
|
<th class="lhell"><?=gettext('Action');?></th>
|
|
<th class="lhell"><?=gettext('State');?></th>
|
|
<th class="lhebl"><?=gettext('Started');?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if ($jobs === []): ?>
|
|
<tr><td class="lcell" colspan="4"><?=gettext('No jobs yet.');?></td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($jobs as $j): ?>
|
|
<tr>
|
|
<td class="lcell vmm-mono"><a href="vmmngr_jobs.php?id=<?=urlencode((string)$j['id']);?>"><?=vmm_h((string)$j['id']);?></a></td>
|
|
<td class="lcell"><?=vmm_h((string)$j['verb']);?></td>
|
|
<td class="lcell"><span class="<?=($j['state'] ?? '') === 'failed' ? 'vmm-err' : 'vmm-ok';?>"><?=vmm_h((string)$j['state']);?></span></td>
|
|
<td class="lcebl vmm-mono"><?=!empty($j['started']) ? date('Y-m-d H:i:s', (int)$j['started']) : '—';?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<details style="margin-top:12px;">
|
|
<summary style="cursor:pointer;padding:6px 0;"><?=gettext('Raw vm-bhyve output');?></summary>
|
|
<pre class="vmm-raw vmm-mono"><?=vmm_h((string)($info['raw'] ?? ''));?></pre>
|
|
</details>
|
|
<?php endif; ?>
|
|
|
|
</td></tr></tbody></table><?php include 'formend.inc'; ?></form>
|
|
<?php include 'fend.inc'; ?>
|