0.2.2: actions as plain POST forms (no fetch/JSON), job page auto-refresh
This commit is contained in:
1 parent
364ab42ffe
commit
18859ac3cc
7 files changed
+58
-12
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"appname": "VM Manager",
|
"appname": "VM Manager",
|
||||||
"version": "0.2.1",
|
"version": "0.2.2",
|
||||||
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
||||||
"vm_source": "auto",
|
"vm_source": "auto",
|
||||||
"bridges": ["ix0bridge"],
|
"bridges": ["ix0bridge"],
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ if (!function_exists('vmm_css')) {
|
|||||||
.vmm-ok{color:#2f9e63}
|
.vmm-ok{color:#2f9e63}
|
||||||
.vmm-err{color:#c25656}
|
.vmm-err{color:#c25656}
|
||||||
</style>
|
</style>
|
||||||
<script src="vmmngr.js"></script>
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-3
@@ -29,6 +29,10 @@ vmm_css();
|
|||||||
|
|
||||||
<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">
|
||||||
|
|
||||||
|
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
|
||||||
|
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (!$vmprov['available']): ?>
|
<?php if (!$vmprov['available']): ?>
|
||||||
<?php print_info_box(sprintf(gettext('vm-bhyve was not found. Neither %s nor the bundled copy exists.'), '/usr/local/sbin/vm')); ?>
|
<?php print_info_box(sprintf(gettext('vm-bhyve was not found. Neither %s nor the bundled copy exists.'), '/usr/local/sbin/vm')); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -106,10 +110,10 @@ vmm_css();
|
|||||||
<td class="lcebl">
|
<td class="lcebl">
|
||||||
<span class="vmm-actions">
|
<span class="vmm-actions">
|
||||||
<?php if ($isRunning): ?>
|
<?php if ($isRunning): ?>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Stop');?>" onclick='vmmConfirmRun("stop", <?=$jsName;?>, "Stop <?=vmm_h($n);?>?")'/>
|
<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>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Restart');?>" onclick='vmmConfirmRun("restart", <?=$jsName;?>, "Restart <?=vmm_h($n);?>?")'/>
|
<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>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Start');?>" onclick='vmmRun("start", <?=$jsName;?>)'/>
|
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" 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>
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* vmmngr_do.php - form handler for VM actions (0.2.2)
|
||||||
|
*
|
||||||
|
* Plain POST + redirect instead of fetch/JSON: works with the XigmaNAS session
|
||||||
|
* handling and redirects to login when the session has expired.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once 'vmmngr-boot.inc';
|
||||||
|
|
||||||
|
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) !== 'POST') {
|
||||||
|
header('Location: vmmngr.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$verb = (string)($_POST['verb'] ?? '');
|
||||||
|
$vm = (string)($_POST['vm'] ?? '');
|
||||||
|
$act = (string)($_POST['act'] ?? '');
|
||||||
|
if ($act !== '' && str_contains($act, ':')) {
|
||||||
|
[$verb, $vm] = explode(':', $act, 2);
|
||||||
|
}
|
||||||
|
$confirm = (string)($_POST['confirm'] ?? '');
|
||||||
|
$back = (string)($_POST['back'] ?? 'vmmngr.php');
|
||||||
|
|
||||||
|
if (!str_starts_with($back, 'vmmngr')) {
|
||||||
|
$back = 'vmmngr.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
$check = vmm_action_check($verb, $vm, $confirm);
|
||||||
|
if (!$check['ok']) {
|
||||||
|
$_SESSION['vmmngr_error'] = $check['error'];
|
||||||
|
header('Location: ' . $back);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$job = vmm_job_new($verb, $vm);
|
||||||
|
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||||
|
exit;
|
||||||
@@ -10,6 +10,10 @@ $id = (string)($_GET['id'] ?? '');
|
|||||||
$job = $id !== '' ? vmm_job_get($id) : null;
|
$job = $id !== '' ? vmm_job_get($id) : null;
|
||||||
$jobs = vmm_job_list(50);
|
$jobs = vmm_job_list(50);
|
||||||
|
|
||||||
|
if ($job !== null && in_array($job['state'], ['queued', 'running'], true)) {
|
||||||
|
header('Refresh: 2');
|
||||||
|
}
|
||||||
|
|
||||||
include 'fbegin.inc';
|
include 'fbegin.inc';
|
||||||
vmm_css();
|
vmm_css();
|
||||||
?>
|
?>
|
||||||
|
|||||||
+7
-6
@@ -53,13 +53,14 @@ vmm_css();
|
|||||||
<td class="celldata">
|
<td class="celldata">
|
||||||
<span class="vmm-actions">
|
<span class="vmm-actions">
|
||||||
<?php if ($isRunning): ?>
|
<?php if ($isRunning): ?>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Stop');?>" onclick='vmmConfirmRun("stop", <?=$jsName;?>, "Stop <?=vmm_h($name);?>?")'/>
|
<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>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Restart');?>" onclick='vmmConfirmRun("restart", <?=$jsName;?>, "Restart <?=vmm_h($name);?>?")'/>
|
<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>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Power off');?>" onclick='vmmConfirmRun("poweroff", <?=$jsName;?>, "Force power off <?=vmm_h($name);?>? Unsaved data in the guest may be lost.")'/>
|
<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>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Reset');?>" onclick='vmmConfirmRun("reset", <?=$jsName;?>, "Hard reset <?=vmm_h($name);?>?")'/>
|
<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>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Start');?>" onclick='vmmRun("start", <?=$jsName;?>)'/>
|
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="start:<?=vmm_h($name);?>"><?=gettext('Start');?></button>
|
||||||
<input type="button" class="formbtn" value="<?=gettext('Destroy');?>" onclick='vmmDestroy(<?=$jsName;?>)'/>
|
<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>
|
||||||
<?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.1
|
0.2.2
|
||||||
Reference in new issue
Block a user