vmmngr 0.1.0-preview: read-only VM Manager extension (installer, vmm-ctl, GUI)
This commit is contained in:
commit
5f664cc8c2
14 files changed
+1422
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* vmmngr_api.php - read-only JSON endpoint.
|
||||
*
|
||||
* GET/POST ?action=list|info|selfcheck
|
||||
* Every request requires an authenticated admin session (XigmaNAS auth.inc).
|
||||
*/
|
||||
|
||||
require_once 'vmmngr-boot.inc';
|
||||
|
||||
if (!session::is_admin()) {
|
||||
vmm_json(['ok' => false, 'error' => 'forbidden'], 403);
|
||||
}
|
||||
|
||||
$action = (string)($_REQUEST['action'] ?? '');
|
||||
$name = (string)($_REQUEST['name'] ?? '');
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$vms = vmm_list();
|
||||
vmm_json(['ok' => true, 'count' => count($vms), 'vms' => $vms]);
|
||||
// no break
|
||||
|
||||
case 'info':
|
||||
if (!vmm_valid_name($name)) {
|
||||
vmm_json(['ok' => false, 'error' => 'invalid name'], 400);
|
||||
}
|
||||
$info = vmm_info($name);
|
||||
if (isset($info['error'])) {
|
||||
vmm_json(['ok' => false, 'error' => $info['error']], 500);
|
||||
}
|
||||
vmm_json(['ok' => true, 'vm' => $name, 'info' => $info]);
|
||||
// no break
|
||||
|
||||
case 'selfcheck':
|
||||
case '':
|
||||
vmm_json(['ok' => true, 'selfcheck' => vmm_selfcheck()]);
|
||||
// no break
|
||||
|
||||
default:
|
||||
vmm_json(['ok' => false, 'error' => 'unknown action'], 400);
|
||||
}
|
||||
Reference in new issue
Block a user