0.3.0: clickable breadcrumb + tabs, images, templates (CRUD), create wizard
This commit is contained in:
1 parent
dea7668fd8
commit
3eb5e6d013
14 files changed
+729
-22
No files matched your search
@@ -1,13 +1,14 @@
|
|||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
## Erledigt
|
## Erledigt
|
||||||
- [x] **Kontrast/Farben** (19:18): Karten/Badges/`<pre>` nutzen jetzt Theme-Variablen
|
- [x] Kontrast/Farben: Theme-Variablen statt harter Hex-Werte.
|
||||||
(`--bgc-area-data`, `--bgc-input-ro`, currentColor) statt harter Hex-Werte.
|
- [x] M2: Start/Stop/Restart/Reset/Poweroff/Destroy + Job-Engine (flock, Logs, Recovery, RAM-Budget).
|
||||||
- [x] **M2**: Start/Stop/Restart/Reset/Poweroff/Destroy + Job-Engine
|
- [x] Destroy löst vorher ZFS-Holds (znapzend/zrepl), geloggt.
|
||||||
(flock pro VM, Logs, Recovery, RAM-Budget 85 %, Destroy mit eingetipptem Namen).
|
- [x] authtoken-Fix: `formend.inc` in jedem Formular (XigmaNAS 401 sonst).
|
||||||
|
- [x] Klickbare Breadcrumb + Tab-Navigation (Dashboard/Create/Images/Templates/Jobs/Configuration).
|
||||||
|
- [x] M3: Images (Download/Delete), Templates (CRUD/Duplizieren/Editor), Create-Wizard.
|
||||||
|
|
||||||
## Offen
|
## Offen
|
||||||
- [ ] M3: Create-Wizard, Images (ISO/IMG/Cloud-Init), Datastores
|
- [ ] M4: Switches-Seite, Snapshots/Clone/Rename, ISO-Install-Aktion, Autostart-Toggle
|
||||||
- [ ] M4: Templates-CRUD, Switches, Snapshots/Clone/Rename, Autostart
|
|
||||||
- [ ] M5: Konsole (ttyd), VNC, Passthru-Gate, OBI-Eintrag, Doku
|
- [ ] M5: Konsole (ttyd), VNC, Passthru-Gate, OBI-Eintrag, Doku
|
||||||
- [ ] Nice-to-have: Job-Liste filtern, Fortschritt bei Downloads
|
- [ ] Nice-to-have: Download-Fortschritt, Job-Cancel-Button in der GUI
|
||||||
+4
-2
@@ -59,7 +59,9 @@ $job['pid'] = getmypid();
|
|||||||
$job['started'] = time();
|
$job['started'] = time();
|
||||||
vmm_job_write($job);
|
vmm_job_write($job);
|
||||||
|
|
||||||
$argvVm = array_merge(VMM_ACTIONS[$verb]['argv'], [$name]);
|
$argvVm = isset($job['argv']) && is_array($job['argv']) && $job['argv'] !== []
|
||||||
|
? $job['argv']
|
||||||
|
: array_merge(VMM_ACTIONS[$verb]['argv'], [$name]);
|
||||||
joblog($log, 'start: vm ' . implode(' ', $argvVm));
|
joblog($log, 'start: vm ' . implode(' ', $argvVm));
|
||||||
|
|
||||||
$vm = vmm_resolve('vm');
|
$vm = vmm_resolve('vm');
|
||||||
@@ -118,7 +120,7 @@ fclose($pipes[0]);
|
|||||||
stream_set_blocking($pipes[1], false);
|
stream_set_blocking($pipes[1], false);
|
||||||
stream_set_blocking($pipes[2], false);
|
stream_set_blocking($pipes[2], false);
|
||||||
|
|
||||||
$timeout = (int)(VMM_ACTIONS[$verb]['timeout'] ?? 300);
|
$timeout = (int)($job['timeout'] ?? (VMM_ACTIONS[$verb]['timeout'] ?? 300));
|
||||||
$start = time();
|
$start = time();
|
||||||
$timedOut = false;
|
$timedOut = false;
|
||||||
$cancelFile = VMM_JOBDIR . '/' . $id . '.cancel';
|
$cancelFile = VMM_JOBDIR . '/' . $id . '.cancel';
|
||||||
|
|||||||
+101
-1
@@ -646,7 +646,7 @@ function vmm_job_log(string $id, int $maxBytes = 65536): string
|
|||||||
return "... (truncated)\n" . $data;
|
return "... (truncated)\n" . $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function vmm_job_new(string $verb, string $name): array
|
function vmm_job_new(string $verb, string $name, array $argv = [], int $timeout = 0): array
|
||||||
{
|
{
|
||||||
vmm_ensure_state_dirs();
|
vmm_ensure_state_dirs();
|
||||||
$id = date('Ymd-His') . '-' . bin2hex(random_bytes(4));
|
$id = date('Ymd-His') . '-' . bin2hex(random_bytes(4));
|
||||||
@@ -660,6 +660,8 @@ function vmm_job_new(string $verb, string $name): array
|
|||||||
'ended' => null,
|
'ended' => null,
|
||||||
'pid' => null,
|
'pid' => null,
|
||||||
'rc' => null,
|
'rc' => null,
|
||||||
|
'argv' => $argv,
|
||||||
|
'timeout' => $timeout,
|
||||||
'error' => '',
|
'error' => '',
|
||||||
'by' => (string)($_SERVER['REMOTE_ADDR'] ?? 'cli'),
|
'by' => (string)($_SERVER['REMOTE_ADDR'] ?? 'cli'),
|
||||||
];
|
];
|
||||||
@@ -757,6 +759,104 @@ function vmm_release_holds(string $dataset): array
|
|||||||
return $released;
|
return $released;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function vmm_data_dir(string $sub): string
|
||||||
|
{
|
||||||
|
$vmDir = vmm_vm_dir();
|
||||||
|
$base = preg_replace('/^zfs:/', '', $vmDir);
|
||||||
|
$base = rtrim($base, '/');
|
||||||
|
if ($base === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if ($base[0] !== '/') {
|
||||||
|
$base = '/mnt/' . $base;
|
||||||
|
}
|
||||||
|
return $base . '/' . $sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmm_file_list(string $dir, array $exts): array
|
||||||
|
{
|
||||||
|
if ($dir === '' || !is_dir($dir)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$out = [];
|
||||||
|
foreach (scandir($dir) ?: [] as $f) {
|
||||||
|
if ($f === '.' || $f === '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$path = $dir . '/' . $f;
|
||||||
|
if (!is_file($path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$ext = strtolower(pathinfo($f, PATHINFO_EXTENSION));
|
||||||
|
if ($exts !== [] && !in_array($ext, $exts, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$out[] = ['name' => $f, 'size' => filesize($path), 'mtime' => filemtime($path), 'ext' => $ext];
|
||||||
|
}
|
||||||
|
usort($out, static fn($a, $b) => strcmp($a['name'], $b['name']));
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmm_safe_basename(string $name): string
|
||||||
|
{
|
||||||
|
$name = basename($name);
|
||||||
|
if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9 ._()+-]{0,120}$/', $name)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmm_delete_data_file(string $dir, string $name): array
|
||||||
|
{
|
||||||
|
$safe = vmm_safe_basename($name);
|
||||||
|
if ($safe === '' || $dir === '') {
|
||||||
|
return ['ok' => false, 'error' => 'invalid file name'];
|
||||||
|
}
|
||||||
|
$path = $dir . '/' . $safe;
|
||||||
|
if (!is_file($path)) {
|
||||||
|
return ['ok' => false, 'error' => 'file not found'];
|
||||||
|
}
|
||||||
|
return @unlink($path)
|
||||||
|
? ['ok' => true, 'deleted' => $safe]
|
||||||
|
: ['ok' => false, 'error' => 'cannot delete'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmm_valid_template_name(string $name): bool
|
||||||
|
{
|
||||||
|
return (bool)preg_match('/^[A-Za-z0-9][A-Za-z0-9 ._()+\-]{0,120}\.conf$/', $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmm_template_get(string $name): array
|
||||||
|
{
|
||||||
|
$dir = vmm_data_dir('.templates');
|
||||||
|
$safe = vmm_safe_basename($name);
|
||||||
|
if ($safe === '' || !str_ends_with($safe, '.conf')) {
|
||||||
|
return ['ok' => false, 'error' => 'invalid template name'];
|
||||||
|
}
|
||||||
|
$path = $dir . '/' . $safe;
|
||||||
|
if (!is_file($path)) {
|
||||||
|
return ['ok' => false, 'error' => 'template not found'];
|
||||||
|
}
|
||||||
|
return ['ok' => true, 'name' => $safe, 'content' => (string)file_get_contents($path)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmm_template_save(string $name, string $content): array
|
||||||
|
{
|
||||||
|
$dir = vmm_data_dir('.templates');
|
||||||
|
$safe = vmm_safe_basename($name);
|
||||||
|
if ($safe === '' || !str_ends_with($safe, '.conf')) {
|
||||||
|
return ['ok' => false, 'error' => 'invalid template name'];
|
||||||
|
}
|
||||||
|
if (strlen($content) > 65536) {
|
||||||
|
return ['ok' => false, 'error' => 'template too large'];
|
||||||
|
}
|
||||||
|
if (!is_dir($dir)) {
|
||||||
|
@mkdir($dir, 0755, true);
|
||||||
|
}
|
||||||
|
$ok = @file_put_contents($dir . '/' . $safe, $content);
|
||||||
|
return $ok === false ? ['ok' => false, 'error' => 'cannot write template'] : ['ok' => true, 'name' => $safe];
|
||||||
|
}
|
||||||
|
|
||||||
function vmm_pid_alive(int $pid): bool
|
function vmm_pid_alive(int $pid): bool
|
||||||
{
|
{
|
||||||
if ($pid <= 0) {
|
if ($pid <= 0) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"appname": "VM Manager",
|
"appname": "VM Manager",
|
||||||
"version": "0.2.3",
|
"version": "0.3.0",
|
||||||
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
||||||
"vm_source": "auto",
|
"vm_source": "auto",
|
||||||
"bridges": ["ix0bridge"],
|
"bridges": ["ix0bridge"],
|
||||||
|
|||||||
@@ -43,6 +43,37 @@ if (!function_exists('vmm_badge')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('vmm_nav')) {
|
||||||
|
/**
|
||||||
|
* Clickable breadcrumb + section tabs (the XigmaNAS title itself is plain
|
||||||
|
* text, so navigation lives here).
|
||||||
|
*/
|
||||||
|
function vmm_nav(string $current): void
|
||||||
|
{
|
||||||
|
$items = [
|
||||||
|
'dashboard' => ['vmmngr.php', gettext('Dashboard')],
|
||||||
|
'create' => ['vmmngr_create.php', gettext('Create VM')],
|
||||||
|
'images' => ['vmmngr_images.php', gettext('Images')],
|
||||||
|
'templates' => ['vmmngr_templates.php', gettext('Templates')],
|
||||||
|
'jobs' => ['vmmngr_jobs.php', gettext('Jobs')],
|
||||||
|
'config' => ['vmmngr_config.php', gettext('Configuration')],
|
||||||
|
];
|
||||||
|
$label = $items[$current][1] ?? gettext('VM Manager');
|
||||||
|
?>
|
||||||
|
<div class="vmm-crumbs"><a href="vmmngr.php"><?=gettext('VM Manager');?></a><span class="vmm-sep">›</span><strong><?=vmm_h($label);?></strong></div>
|
||||||
|
<div class="vmm-tabs">
|
||||||
|
<?php foreach ($items as $key => [$href, $text]): ?>
|
||||||
|
<?php if ($key === $current): ?>
|
||||||
|
<span class="vmm-tab vmm-tab-cur"><?=vmm_h($text);?></span>
|
||||||
|
<?php else: ?>
|
||||||
|
<a class="vmm-tab" href="<?=vmm_h($href);?>"><?=vmm_h($text);?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('vmm_css')) {
|
if (!function_exists('vmm_css')) {
|
||||||
/**
|
/**
|
||||||
* Theme-aware styles: no hardcoded dark panels — colours derive from the
|
* Theme-aware styles: no hardcoded dark panels — colours derive from the
|
||||||
@@ -68,6 +99,13 @@ if (!function_exists('vmm_css')) {
|
|||||||
.vmm-job{display:none;margin:12px 0;border:1px solid rgba(127,127,127,.35);border-radius:6px;padding:10px;background:var(--bgc-area-data,transparent)}
|
.vmm-job{display:none;margin:12px 0;border:1px solid rgba(127,127,127,.35);border-radius:6px;padding:10px;background:var(--bgc-area-data,transparent)}
|
||||||
.vmm-job-head{font-size:12px;margin-bottom:6px;opacity:.9}
|
.vmm-job-head{font-size:12px;margin-bottom:6px;opacity:.9}
|
||||||
.vmm-job-state{font-weight:600;margin-left:6px}
|
.vmm-job-state{font-weight:600;margin-left:6px}
|
||||||
|
.vmm-crumbs{font-size:13px;margin:4px 0 8px}
|
||||||
|
.vmm-crumbs a{text-decoration:none}
|
||||||
|
.vmm-sep{margin:0 6px;opacity:.6}
|
||||||
|
.vmm-tabs{display:flex;flex-wrap:wrap;gap:4px;margin:0 0 12px;border-bottom:1px solid rgba(127,127,127,.35);padding-bottom:6px}
|
||||||
|
.vmm-tab{display:inline-block;padding:4px 10px;border:1px solid rgba(127,127,127,.35);border-radius:4px;text-decoration:none;font-size:12px}
|
||||||
|
.vmm-tab:hover{background:rgba(127,127,127,.12)}
|
||||||
|
.vmm-tab-cur{font-weight:600;background:rgba(127,127,127,.16);border-color:rgba(127,127,127,.55)}
|
||||||
.vmm-ok{color:#2f9e63}
|
.vmm-ok{color:#2f9e63}
|
||||||
.vmm-err{color:#c25656}
|
.vmm-err{color:#c25656}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+20
-3
@@ -6,6 +6,22 @@
|
|||||||
require_once 'vmmngr-boot.inc';
|
require_once 'vmmngr-boot.inc';
|
||||||
|
|
||||||
$pgtitle = [gettext('Extensions'), gettext('VM Manager')];
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager')];
|
||||||
|
|
||||||
|
// actions are posted to this page (XigmaNAS validates the authtoken here)
|
||||||
|
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && isset($_POST['act'])) {
|
||||||
|
$act = (string)$_POST['act'];
|
||||||
|
[$verb, $vmName] = array_pad(explode(':', $act, 2), 2, '');
|
||||||
|
$check = vmm_action_check($verb, $vmName, (string)($_POST['confirm'] ?? ''));
|
||||||
|
if (!$check['ok']) {
|
||||||
|
$_SESSION['vmmngr_error'] = $check['error'];
|
||||||
|
header('Location: vmmngr.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$job = vmm_job_new($verb, $vmName);
|
||||||
|
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$conf = vmm_config();
|
$conf = vmm_config();
|
||||||
$vmprov = vmm_resolve('vm');
|
$vmprov = vmm_resolve('vm');
|
||||||
$vms = $vmprov['available'] ? vmm_list() : [];
|
$vms = $vmprov['available'] ? vmm_list() : [];
|
||||||
@@ -25,6 +41,7 @@ $jobs = vmm_job_list(5);
|
|||||||
|
|
||||||
include 'fbegin.inc';
|
include 'fbegin.inc';
|
||||||
vmm_css();
|
vmm_css();
|
||||||
|
vmm_nav('dashboard');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form action="vmmngr.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
<form action="vmmngr.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
@@ -110,10 +127,10 @@ vmm_css();
|
|||||||
<td class="lcebl">
|
<td class="lcebl">
|
||||||
<span class="vmm-actions">
|
<span class="vmm-actions">
|
||||||
<?php if ($isRunning): ?>
|
<?php if ($isRunning): ?>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="stop:<?=vmm_h($n);?>" onclick="return confirm('Stop <?=vmm_h($n);?>?')"><?=gettext('Stop');?></button>
|
<button type="submit" class="formbtn" name="act" value="stop:<?=vmm_h($n);?>" onclick="return confirm('Stop <?=vmm_h($n);?>?')"><?=gettext('Stop');?></button>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="restart:<?=vmm_h($n);?>" onclick="return confirm('Restart <?=vmm_h($n);?>?')"><?=gettext('Restart');?></button>
|
<button type="submit" class="formbtn" name="act" value="restart:<?=vmm_h($n);?>" onclick="return confirm('Restart <?=vmm_h($n);?>?')"><?=gettext('Restart');?></button>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="start:<?=vmm_h($n);?>"><?=gettext('Start');?></button>
|
<button type="submit" class="formbtn" name="act" value="start:<?=vmm_h($n);?>"><?=gettext('Start');?></button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<a class="formbtn" href="vmmngr_vm.php?name=<?=urlencode($n);?>"><?=gettext('Details');?></a>
|
<a class="formbtn" href="vmmngr_vm.php?name=<?=urlencode($n);?>"><?=gettext('Details');?></a>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ $conf = vmm_config();
|
|||||||
|
|
||||||
include 'fbegin.inc';
|
include 'fbegin.inc';
|
||||||
?>
|
?>
|
||||||
<?php vmm_css(); ?>
|
<?php vmm_css();
|
||||||
|
vmm_nav('config'); ?>
|
||||||
|
|
||||||
<form action="vmmngr_config.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
<form action="vmmngr_config.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* vmmngr_create.php - VM creation wizard (0.3.0)
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once 'vmmngr-boot.inc';
|
||||||
|
|
||||||
|
$post = strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST';
|
||||||
|
$err = '';
|
||||||
|
|
||||||
|
$templates = vmm_file_list(vmm_data_dir('.templates'), ['conf']);
|
||||||
|
$datastores = vmm_datastores();
|
||||||
|
$switches = vmm_switches();
|
||||||
|
$images = vmm_file_list(vmm_data_dir('.img'), ['img']);
|
||||||
|
|
||||||
|
if ($post) {
|
||||||
|
$name = trim((string)($_POST['name'] ?? ''));
|
||||||
|
$tpl = (string)($_POST['template'] ?? '');
|
||||||
|
$ds = (string)($_POST['datastore'] ?? 'default');
|
||||||
|
$cpu = (string)($_POST['cpu'] ?? '2');
|
||||||
|
$mem = (string)($_POST['memory'] ?? '2G');
|
||||||
|
$size = (string)($_POST['size'] ?? '20G');
|
||||||
|
$cloud = isset($_POST['cloudinit']);
|
||||||
|
$img = (string)($_POST['image'] ?? '');
|
||||||
|
|
||||||
|
if (!vmm_valid_name($name)) {
|
||||||
|
$err = gettext('Invalid name: letters, digits, dot, dash, underscore (max 32).');
|
||||||
|
} elseif (vmm_vm_state($name) !== 'absent') {
|
||||||
|
$err = gettext('A VM with that name already exists.');
|
||||||
|
} elseif (!preg_match('/^[A-Za-z0-9._-]+\.conf$/', $tpl)) {
|
||||||
|
$err = gettext('Choose a template.');
|
||||||
|
} elseif (!preg_match('/^[0-9]{1,2}$/', $cpu) || (int)$cpu < 1 || (int)$cpu > 32) {
|
||||||
|
$err = gettext('vCPU must be between 1 and 32.');
|
||||||
|
} elseif (!preg_match('/^[0-9]{1,4}[MG]$/', strtoupper($mem))) {
|
||||||
|
$err = gettext('Memory must look like 2G or 512M.');
|
||||||
|
} elseif (!preg_match('/^[0-9]{1,4}[MG]$/', strtoupper($size))) {
|
||||||
|
$err = gettext('Disk size must look like 20G or 512M.');
|
||||||
|
} elseif ($cloud && ($img === '' || !preg_match('/^[A-Za-z0-9][A-Za-z0-9 ._()+-]*\.img$/', $img))) {
|
||||||
|
$err = gettext('Cloud-Init needs an image (.img) from the images page.');
|
||||||
|
} else {
|
||||||
|
$budget = vmm_ram_budget();
|
||||||
|
$need = vmm_size_to_bytes(strtoupper($mem));
|
||||||
|
if ($need > 0 && vmm_ram_used() + $need > $budget['limit']) {
|
||||||
|
$err = sprintf(
|
||||||
|
gettext('RAM budget exceeded: %s in use + %s requested, limit %s.'),
|
||||||
|
vmm_human_bytes(vmm_ram_used()),
|
||||||
|
vmm_human_bytes($need),
|
||||||
|
vmm_human_bytes($budget['limit'])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$argv = ['create', '-t', $tpl, '-d', $ds, '-s', strtoupper($size), '-m', strtoupper($mem), '-c', $cpu];
|
||||||
|
if ($cloud) {
|
||||||
|
$argv[] = '-C';
|
||||||
|
$argv[] = '-i';
|
||||||
|
$argv[] = $img;
|
||||||
|
}
|
||||||
|
$argv[] = $name;
|
||||||
|
$job = vmm_job_new('create', $name, $argv, 900);
|
||||||
|
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Create VM')];
|
||||||
|
include 'fbegin.inc';
|
||||||
|
vmm_css();
|
||||||
|
vmm_nav('create');
|
||||||
|
?>
|
||||||
|
<form action="vmmngr_create.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
|
|
||||||
|
<?php if ($err !== ''): ?>
|
||||||
|
<?php print_info_box(vmm_h($err)); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<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('New virtual machine'), 2); ?>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Name');?></td>
|
||||||
|
<td class="celldata"><input type="text" name="name" size="30" value="<?=vmm_h((string)($_POST['name'] ?? ''));?>"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Template');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<select name="template">
|
||||||
|
<?php foreach ($templates as $t): ?>
|
||||||
|
<option value="<?=vmm_h((string)$t['name']);?>"><?=vmm_h((string)$t['name']);?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<a href="vmmngr_templates.php" style="margin-left:8px;"><?=gettext('manage templates');?></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Datastore');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<select name="datastore">
|
||||||
|
<?php foreach ($datastores as $d): ?>
|
||||||
|
<option value="<?=vmm_h((string)($d['name'] ?? 'default'));?>"><?=vmm_h((string)($d['name'] ?? 'default'));?> (<?=vmm_h((string)($d['path'] ?? ''));?>)</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('vCPU');?></td>
|
||||||
|
<td class="celldata"><input type="text" name="cpu" size="6" value="<?=vmm_h((string)($_POST['cpu'] ?? '2'));?>"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Memory');?></td>
|
||||||
|
<td class="celldata"><input type="text" name="memory" size="8" value="<?=vmm_h((string)($_POST['memory'] ?? '2G'));?>"/> <span style="opacity:.7"><?=gettext('e.g. 2G');?></span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Disk size');?></td>
|
||||||
|
<td class="celldata"><input type="text" name="size" size="8" value="<?=vmm_h((string)($_POST['size'] ?? '20G'));?>"/> <span style="opacity:.7"><?=gettext('e.g. 20G');?></span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Network switch');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<select name="switch">
|
||||||
|
<?php foreach ($switches as $s): ?>
|
||||||
|
<option value="<?=vmm_h((string)($s['name'] ?? ''));?>"><?=vmm_h((string)($s['name'] ?? ''));?> (<?=vmm_h((string)($s['type'] ?? ''));?>)</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Cloud-Init');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<label><input type="checkbox" name="cloudinit" value="1"/> <?=gettext('provision with cloud-init seed');?></label>
|
||||||
|
<select name="image" style="margin-left:8px;">
|
||||||
|
<option value=""><?=gettext('choose image');?></option>
|
||||||
|
<?php foreach ($images as $i): ?>
|
||||||
|
<option value="<?=vmm_h((string)$i['name']);?>"><?=vmm_h((string)$i['name']);?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Summary');?></td>
|
||||||
|
<td class="celldata vmm-mono">
|
||||||
|
vm create -t <template> -d <datastore> -s <size> -m <memory> -c <cpu> <name>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"> </td>
|
||||||
|
<td class="celldata">
|
||||||
|
<button type="submit" class="formbtn" name="act" value="create"><?=gettext('Create');?></button>
|
||||||
|
<a class="formbtn" href="vmmngr.php"><?=gettext('Cancel');?></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<?php include 'formend.inc'; ?>
|
||||||
|
</td></tr></tbody></table></form>
|
||||||
|
<?php include 'fend.inc'; ?>
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* vmmngr_images.php - ISO/IMG inventory and downloads (0.3.0)
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once 'vmmngr-boot.inc';
|
||||||
|
|
||||||
|
$isoDir = vmm_data_dir('.iso');
|
||||||
|
$imgDir = vmm_data_dir('.img');
|
||||||
|
|
||||||
|
$post = strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST';
|
||||||
|
$act = $post ? (string)($_POST['act'] ?? '') : '';
|
||||||
|
$confirm = $post ? (string)($_POST['confirm'] ?? '') : '';
|
||||||
|
|
||||||
|
if ($post && $act !== '') {
|
||||||
|
if ($act === 'download') {
|
||||||
|
$kind = (string)($_POST['kind'] ?? 'iso');
|
||||||
|
$url = trim((string)($_POST['url'] ?? ''));
|
||||||
|
if (!preg_match('#^https?://[^\s"\'<>]+$#i', $url)) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Only http(s) URLs are allowed.');
|
||||||
|
} elseif (!in_array($kind, ['iso', 'img'], true)) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Unknown image type.');
|
||||||
|
} else {
|
||||||
|
$job = vmm_job_new(
|
||||||
|
$kind . '_download',
|
||||||
|
(string)(basename((string)parse_url($url, PHP_URL_PATH)) ?: $kind),
|
||||||
|
[$kind, $url],
|
||||||
|
21600
|
||||||
|
);
|
||||||
|
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} elseif (str_starts_with($act, 'delete:')) {
|
||||||
|
[, $kind, $file] = array_pad(explode(':', $act, 3), 3, '');
|
||||||
|
$dir = $kind === 'img' ? $imgDir : $isoDir;
|
||||||
|
if ($confirm !== $file) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Confirmation mismatch - file not deleted.');
|
||||||
|
} else {
|
||||||
|
$res = vmm_delete_data_file($dir, $file);
|
||||||
|
$_SESSION['vmmngr_error'] = $res['ok']
|
||||||
|
? sprintf(gettext('Deleted %s'), $res['deleted'])
|
||||||
|
: (string)$res['error'];
|
||||||
|
}
|
||||||
|
header('Location: vmmngr_images.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$isos = vmm_file_list($isoDir, ['iso']);
|
||||||
|
$imgs = vmm_file_list($imgDir, ['img']);
|
||||||
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Images')];
|
||||||
|
|
||||||
|
include 'fbegin.inc';
|
||||||
|
vmm_css();
|
||||||
|
vmm_nav('images');
|
||||||
|
?>
|
||||||
|
<script>
|
||||||
|
function vmmAskDelete(name) {
|
||||||
|
var typed = window.prompt('Type the file name to delete:\n' + name, '');
|
||||||
|
if (typed !== name) { return false; }
|
||||||
|
document.getElementById('vmm-confirm').value = typed;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form action="vmmngr_images.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
|
|
||||||
|
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
|
||||||
|
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<input type="hidden" name="confirm" id="vmm-confirm" value=""/>
|
||||||
|
|
||||||
|
<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('Download image'), 2); ?>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Type');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<select name="kind">
|
||||||
|
<option value="iso">ISO</option>
|
||||||
|
<option value="img">IMG (cloud/raw)</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag">URL</td>
|
||||||
|
<td class="celldata"><input type="text" name="url" size="80" placeholder="https://..."/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"> </td>
|
||||||
|
<td class="celldata">
|
||||||
|
<button type="submit" class="formbtn" name="act" value="download"><?=gettext('Download');?></button>
|
||||||
|
<span style="opacity:.75;margin-left:8px;"><?=gettext('Downloads run as a job in the background.');?></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$sections = [
|
||||||
|
['key' => 'iso', 'title' => 'ISO', 'dir' => $isoDir, 'files' => $isos],
|
||||||
|
['key' => 'img', 'title' => 'IMG', 'dir' => $imgDir, 'files' => $imgs],
|
||||||
|
];
|
||||||
|
foreach ($sections as $sec):
|
||||||
|
?>
|
||||||
|
<table class="area_data_selection" style="width:100%;border-collapse:collapse;">
|
||||||
|
<colgroup>
|
||||||
|
<col style="width:48%"><col style="width:12%"><col style="width:20%"><col style="width:20%">
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<?php html_separator2(); html_titleline2(sprintf('%s (%s)', $sec['title'], $sec['dir']), 4); ?>
|
||||||
|
<tr>
|
||||||
|
<th class="lhell"><?=gettext('File');?></th>
|
||||||
|
<th class="lhell"><?=gettext('Size');?></th>
|
||||||
|
<th class="lhell"><?=gettext('Modified');?></th>
|
||||||
|
<th class="lhebl"><?=gettext('Action');?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if ($sec['files'] === []): ?>
|
||||||
|
<tr><td class="lcell" colspan="4"><?=gettext('No images.');?></td></tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($sec['files'] as $f): ?>
|
||||||
|
<tr>
|
||||||
|
<td class="lcell vmm-mono"><?=vmm_h((string)$f['name']);?></td>
|
||||||
|
<td class="lcell"><?=vmm_h(vmm_human_bytes((int)$f['size']));?></td>
|
||||||
|
<td class="lcell vmm-mono"><?=date('Y-m-d H:i', (int)$f['mtime']);?></td>
|
||||||
|
<td class="lcebl">
|
||||||
|
<button type="submit" class="formbtn" name="act"
|
||||||
|
value="delete:<?=$sec['key'];?>:<?=vmm_h((string)$f['name']);?>"
|
||||||
|
onclick="return vmmAskDelete(<?=htmlspecialchars(json_encode((string)$f['name']), ENT_QUOTES);?>)"><?=gettext('Delete');?></button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br />
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<p><a class="formbtn" href="vmmngr_create.php"><?=gettext('Create VM');?></a> <a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a></p>
|
||||||
|
|
||||||
|
<?php include 'formend.inc'; ?>
|
||||||
|
</td></tr></tbody></table></form>
|
||||||
|
<?php include 'fend.inc'; ?>
|
||||||
@@ -16,6 +16,7 @@ if ($job !== null && in_array($job['state'], ['queued', 'running'], true)) {
|
|||||||
|
|
||||||
include 'fbegin.inc';
|
include 'fbegin.inc';
|
||||||
vmm_css();
|
vmm_css();
|
||||||
|
vmm_nav('jobs');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form action="vmmngr_jobs.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
<form action="vmmngr_jobs.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* vmmngr_template.php - template editor (0.3.0)
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once 'vmmngr-boot.inc';
|
||||||
|
|
||||||
|
$name = (string)($_GET['name'] ?? '');
|
||||||
|
$tpl = vmm_valid_template_name($name) ? vmm_template_get($name) : ['ok' => false, 'error' => 'invalid template name'];
|
||||||
|
|
||||||
|
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST') {
|
||||||
|
$content = (string)($_POST['content'] ?? '');
|
||||||
|
$res = vmm_template_save($name, $content);
|
||||||
|
$_SESSION['vmmngr_error'] = $res['ok']
|
||||||
|
? gettext('Template saved.')
|
||||||
|
: (string)$res['error'];
|
||||||
|
header('Location: vmmngr_template.php?name=' . urlencode($name));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Template'), $name];
|
||||||
|
include 'fbegin.inc';
|
||||||
|
vmm_css();
|
||||||
|
vmm_nav('templates');
|
||||||
|
?>
|
||||||
|
<form action="vmmngr_template.php?name=<?=urlencode($name);?>" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
|
|
||||||
|
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
|
||||||
|
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!$tpl['ok']): ?>
|
||||||
|
<?php print_info_box(vmm_h((string)$tpl['error'])); ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<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('Template'), $name), 2); ?>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Content');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<textarea name="content" rows="26" style="width:98%;font-family:monospace;font-size:12px;"><?=vmm_h((string)$tpl['content']);?></textarea>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Actions');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<button type="submit" class="formbtn"><?=gettext('Save');?></button>
|
||||||
|
<a class="formbtn" href="vmmngr_templates.php"><?=gettext('Back');?></a>
|
||||||
|
<span style="opacity:.75;margin-left:8px;"><?=gettext('Value format: key="value" per line, as vm-bhyve expects.');?></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php include 'formend.inc'; ?>
|
||||||
|
</td></tr></tbody></table></form>
|
||||||
|
<?php include 'fend.inc'; ?>
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* vmmngr_templates.php - template inventory and file operations (0.3.0)
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once 'vmmngr-boot.inc';
|
||||||
|
|
||||||
|
$tplDir = vmm_data_dir('.templates');
|
||||||
|
$post = strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST';
|
||||||
|
$act = $post ? (string)($_POST['act'] ?? '') : '';
|
||||||
|
$confirm = $post ? (string)($_POST['confirm'] ?? '') : '';
|
||||||
|
$newname = $post ? trim((string)($_POST['newname'] ?? '')) : '';
|
||||||
|
if ($post && $newname === '') {
|
||||||
|
$newname = trim((string)($_POST['new_name_input'] ?? ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($post && $act !== '') {
|
||||||
|
if (str_starts_with($act, 'duplicate:')) {
|
||||||
|
$src = substr($act, 10);
|
||||||
|
$dst = vmm_safe_basename($newname);
|
||||||
|
if ($dst === '' || !str_ends_with($dst, '.conf')) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('New name must end with .conf');
|
||||||
|
} elseif (is_file($tplDir . '/' . $dst)) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Template already exists.');
|
||||||
|
} else {
|
||||||
|
$t = vmm_template_get($src);
|
||||||
|
if (!$t['ok']) {
|
||||||
|
$_SESSION['vmmngr_error'] = (string)$t['error'];
|
||||||
|
} else {
|
||||||
|
$res = vmm_template_save($dst, (string)$t['content']);
|
||||||
|
$_SESSION['vmmngr_error'] = $res['ok']
|
||||||
|
? sprintf(gettext('Duplicated to %s'), $dst)
|
||||||
|
: (string)$res['error'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (str_starts_with($act, 'delete:')) {
|
||||||
|
$src = substr($act, 7);
|
||||||
|
if ($confirm !== $src) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Confirmation mismatch - template not deleted.');
|
||||||
|
} else {
|
||||||
|
$path = $tplDir . '/' . vmm_safe_basename($src);
|
||||||
|
$_SESSION['vmmngr_error'] = is_file($path) && @unlink($path)
|
||||||
|
? sprintf(gettext('Deleted %s'), $src)
|
||||||
|
: gettext('Cannot delete template.');
|
||||||
|
}
|
||||||
|
} elseif ($act === 'new') {
|
||||||
|
$dst = vmm_safe_basename($newname);
|
||||||
|
if ($dst === '' || !str_ends_with($dst, '.conf')) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Name must end with .conf');
|
||||||
|
} elseif (is_file($tplDir . '/' . $dst)) {
|
||||||
|
$_SESSION['vmmngr_error'] = gettext('Template already exists.');
|
||||||
|
} else {
|
||||||
|
$skeleton = "guest=\"linux\"\nloader=\"uefi\"\ncpu=2\nmemory=2G\n"
|
||||||
|
. "network0_type=\"virtio-net\"\nnetwork0_switch=\"public\"\n"
|
||||||
|
. "disk0_type=\"virtio-blk\"\ndisk0_name=\"disk0\"\ndisk0_dev=\"zvol\"\n";
|
||||||
|
$res = vmm_template_save($dst, $skeleton);
|
||||||
|
if ($res['ok']) {
|
||||||
|
header('Location: vmmngr_template.php?name=' . urlencode($dst));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$_SESSION['vmmngr_error'] = (string)$res['error'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header('Location: vmmngr_templates.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$templates = vmm_file_list($tplDir, ['conf']);
|
||||||
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Templates')];
|
||||||
|
|
||||||
|
include 'fbegin.inc';
|
||||||
|
vmm_css();
|
||||||
|
vmm_nav('templates');
|
||||||
|
?>
|
||||||
|
<script>
|
||||||
|
function vmmAskName(promptText) {
|
||||||
|
var typed = window.prompt(promptText, '');
|
||||||
|
if (typed === null || typed === '') { return false; }
|
||||||
|
document.getElementById('vmm-newname').value = typed;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
function vmmAskDelete(name) {
|
||||||
|
var typed = window.prompt('Type the template name to delete:\n' + name, '');
|
||||||
|
if (typed !== name) { return false; }
|
||||||
|
document.getElementById('vmm-confirm').value = typed;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form action="vmmngr_templates.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
|
|
||||||
|
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
|
||||||
|
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<input type="hidden" name="confirm" id="vmm-confirm" value=""/>
|
||||||
|
<input type="hidden" name="newname" id="vmm-newname" value=""/>
|
||||||
|
|
||||||
|
<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('New template'), 2); ?>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="celltag"><?=gettext('Name');?></td>
|
||||||
|
<td class="celldata">
|
||||||
|
<input type="text" name="new_name_input" size="30" placeholder="myvm.conf" oninput="document.getElementById('vmm-newname').value=this.value"/>
|
||||||
|
<button type="submit" class="formbtn" name="act" value="new"><?=gettext('Create');?></button>
|
||||||
|
<span style="opacity:.75;margin-left:8px;"><?=gettext('Starts from a minimal skeleton, then opens the editor.');?></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<table class="area_data_selection" style="width:100%;border-collapse:collapse;">
|
||||||
|
<colgroup>
|
||||||
|
<col style="width:38%"><col style="width:12%"><col style="width:20%"><col style="width:30%">
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<?php html_separator2(); html_titleline2(sprintf('%s (%s)', gettext('Templates'), $tplDir), 4); ?>
|
||||||
|
<tr>
|
||||||
|
<th class="lhell"><?=gettext('Template');?></th>
|
||||||
|
<th class="lhell"><?=gettext('Size');?></th>
|
||||||
|
<th class="lhell"><?=gettext('Modified');?></th>
|
||||||
|
<th class="lhebl"><?=gettext('Actions');?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if ($templates === []): ?>
|
||||||
|
<tr><td class="lcell" colspan="4"><?=gettext('No templates.');?></td></tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($templates as $t): ?>
|
||||||
|
<?php $tn = (string)$t['name']; ?>
|
||||||
|
<tr>
|
||||||
|
<td class="lcell vmm-mono"><a href="vmmngr_template.php?name=<?=urlencode($tn);?>"><?=vmm_h($tn);?></a></td>
|
||||||
|
<td class="lcell"><?=vmm_h(vmm_human_bytes((int)$t['size']));?></td>
|
||||||
|
<td class="lcell vmm-mono"><?=date('Y-m-d H:i', (int)$t['mtime']);?></td>
|
||||||
|
<td class="lcebl">
|
||||||
|
<a class="formbtn" href="vmmngr_template.php?name=<?=urlencode($tn);?>"><?=gettext('Edit');?></a>
|
||||||
|
<button type="submit" class="formbtn" name="act" value="duplicate:<?=vmm_h($tn);?>"
|
||||||
|
onclick="return vmmAskName('New name for the copy (must end with .conf):')"><?=gettext('Duplicate');?></button>
|
||||||
|
<button type="submit" class="formbtn" name="act" value="delete:<?=vmm_h($tn);?>"
|
||||||
|
onclick="return vmmAskDelete(<?=htmlspecialchars(json_encode($tn), ENT_QUOTES);?>)"><?=gettext('Delete');?></button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p><a class="formbtn" href="vmmngr_create.php"><?=gettext('Create VM');?></a> <a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a></p>
|
||||||
|
|
||||||
|
<?php include 'formend.inc'; ?>
|
||||||
|
</td></tr></tbody></table></form>
|
||||||
|
<?php include 'fend.inc'; ?>
|
||||||
+24
-6
@@ -11,12 +11,30 @@ if ($name === '' || !vmm_valid_name($name)) {
|
|||||||
exit;
|
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;
|
||||||
|
}
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
$info = vmm_info($name);
|
$info = vmm_info($name);
|
||||||
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), $name];
|
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), $name];
|
||||||
$jobs = vmm_job_list(10, $name);
|
$jobs = vmm_job_list(10, $name);
|
||||||
|
|
||||||
include 'fbegin.inc';
|
include 'fbegin.inc';
|
||||||
vmm_css();
|
vmm_css();
|
||||||
|
vmm_nav('dashboard');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form action="vmmngr_vm.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
<form action="vmmngr_vm.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||||
@@ -53,14 +71,14 @@ vmm_css();
|
|||||||
<td class="celldata">
|
<td class="celldata">
|
||||||
<span class="vmm-actions">
|
<span class="vmm-actions">
|
||||||
<?php if ($isRunning): ?>
|
<?php if ($isRunning): ?>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" 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="stop:<?=vmm_h($name);?>" onclick="return confirm('Stop <?=vmm_h($name);?>?')"><?=gettext('Stop');?></button>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" 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="restart:<?=vmm_h($name);?>" onclick="return confirm('Restart <?=vmm_h($name);?>?')"><?=gettext('Restart');?></button>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" 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="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" formaction="vmmngr_do.php" formmethod="post" name="act" value="reset:<?=vmm_h($name);?>" onclick="return confirm('Hard reset <?=vmm_h($name);?>?')"><?=gettext('Reset');?></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: ?>
|
<?php else: ?>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="start:<?=vmm_h($name);?>"><?=gettext('Start');?></button>
|
<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"/>
|
<input type="text" name="confirm" value="" placeholder="<?=gettext('type name to destroy');?>" style="width:150px"/>
|
||||||
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="destroy:<?=vmm_h($name);?>" onclick="return confirm('Destroy <?=vmm_h($name);?>? All disks and snapshots are deleted.')"><?=gettext('Destroy');?></button>
|
<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; ?>
|
<?php endif; ?>
|
||||||
<a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a>
|
<a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
0.2.3
|
0.3.0
|
||||||
Reference in new issue
Block a user