0.2.0: job engine, VM actions, theme-aware styling

This commit is contained in:
Claw committed 2026-11-17 19:23:28 +01:00
1 parent c62de24cc0
commit 485a267ffe
14 files changed
+901 -71

No files matched your search

+44 -5
View File
@@ -1,9 +1,12 @@
<?php
/*
* vmmngr_api.php - read-only JSON endpoint.
* vmmngr_api.php - JSON endpoint for the VM Manager GUI.
*
* GET/POST ?action=list|info|selfcheck
* Every request requires an authenticated admin session (XigmaNAS auth.inc).
* GET ?action=list|info|selfcheck|job|jobs
* POST ?action=action (verb, vm, confirm) - mutations are POST only
* POST ?action=cancel (id)
*
* Requires an authenticated XigmaNAS session with admin rights.
*/
require_once 'vmmngr-boot.inc';
@@ -12,8 +15,11 @@ if (!session::is_admin()) {
vmm_json(['ok' => false, 'error' => 'forbidden'], 403);
}
$method = strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET'));
$action = (string)($_REQUEST['action'] ?? '');
$name = (string)($_REQUEST['name'] ?? '');
$name = (string)($_REQUEST['vm'] ?? $_REQUEST['name'] ?? '');
$confirm = (string)($_REQUEST['confirm'] ?? '');
$id = (string)($_REQUEST['id'] ?? '');
switch ($action) {
case 'list':
@@ -33,10 +39,43 @@ switch ($action) {
// no break
case 'selfcheck':
case '':
vmm_json(['ok' => true, 'selfcheck' => vmm_selfcheck()]);
// no break
case 'action':
if ($method !== 'POST') {
vmm_json(['ok' => false, 'error' => 'POST required'], 405);
}
$verb = (string)($_POST['verb'] ?? '');
$check = vmm_action_check($verb, $name, $confirm);
if (!$check['ok']) {
vmm_json(['ok' => false, 'error' => $check['error']], 409);
}
$job = vmm_job_new($verb, $name);
vmm_json(['ok' => true, 'job' => $job], 202);
// no break
case 'cancel':
if ($method !== 'POST') {
vmm_json(['ok' => false, 'error' => 'POST required'], 405);
}
$res = vmm_job_cancel($id);
vmm_json($res, $res['ok'] ? 200 : 409);
// no break
case 'job':
$job = vmm_job_get($id);
if ($job === null) {
vmm_json(['ok' => false, 'error' => 'job not found'], 404);
}
$job['log'] = vmm_job_log($id);
vmm_json(['ok' => true, 'job' => $job]);
// no break
case 'jobs':
vmm_json(['ok' => true, 'jobs' => vmm_job_list(30, $name)]);
// no break
default:
vmm_json(['ok' => false, 'error' => 'unknown action'], 400);
}