78 lines
3.0 KiB
PHP
78 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* vmmngr-boot.inc - bootstrap for all VM Manager pages.
|
|
*
|
|
* Works both in the extension tree and through the symlinks in /usr/local/www:
|
|
* realpath() resolves the link, so the shared library is found either way.
|
|
*/
|
|
|
|
require_once 'auth.inc';
|
|
require_once 'guiconfig.inc';
|
|
|
|
$vmm_self = realpath(__FILE__);
|
|
$vmm_root = dirname(dirname($vmm_self));
|
|
require_once $vmm_root . '/bin/vmm-lib.php';
|
|
|
|
if (!function_exists('vmm_badge')) {
|
|
function vmm_badge(string $state): string
|
|
{
|
|
$map = [
|
|
'running' => ['vmm-running', gettext('Running')],
|
|
'stopped' => ['vmm-stopped', gettext('Stopped')],
|
|
'suspended' => ['vmm-suspended', gettext('Suspended')],
|
|
'starting' => ['vmm-starting', gettext('Starting')],
|
|
'locked' => ['vmm-locked', gettext('Locked')],
|
|
];
|
|
[$cls, $label] = $map[$state] ?? ['vmm-unknown', ucfirst($state)];
|
|
return sprintf('<span class="vmm-badge %s">%s</span>', $cls, htmlspecialchars($label));
|
|
}
|
|
|
|
function vmm_h(string $s): string
|
|
{
|
|
return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
function vmm_source_label(array $p): string
|
|
{
|
|
$icon = match ($p['source']) {
|
|
'system' => '🖥',
|
|
'bundle' => '📦',
|
|
default => '⚠',
|
|
};
|
|
return sprintf('%s %s', $icon, $p['source']);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('vmm_css')) {
|
|
/**
|
|
* Theme-aware styles: no hardcoded dark panels — colours derive from the
|
|
* XigmaNAS theme variables, so light and dark themes both stay readable.
|
|
*/
|
|
function vmm_css(): void
|
|
{
|
|
?>
|
|
<style>
|
|
.vmm-badge{display:inline-block;padding:1px 8px;border-radius:10px;font-size:11px;font-weight:600;border:1px solid currentColor;background:transparent;white-space:nowrap}
|
|
.vmm-running{color:#2f9e63}
|
|
.vmm-stopped{color:#c25656}
|
|
.vmm-suspended,.vmm-starting{color:#b98a1f}
|
|
.vmm-unknown,.vmm-locked{color:#7d7dab}
|
|
.vmm-grid{display:flex;flex-wrap:wrap;gap:10px;margin:10px 0 14px}
|
|
.vmm-card{flex:1 1 160px;min-width:160px;padding:10px 12px;border:1px solid rgba(127,127,127,.35);border-radius:6px;background:var(--bgc-area-data,transparent);color:inherit}
|
|
.vmm-card .k{font-size:11px;text-transform:uppercase;letter-spacing:.05em;opacity:.7}
|
|
.vmm-card .v{font-size:20px;font-weight:600;margin-top:2px}
|
|
.vmm-card .s{font-size:11px;opacity:.75;margin-top:2px}
|
|
.vmm-mono{font-family:monospace;font-size:12px}
|
|
.vmm-raw{background:var(--bgc-input-ro,rgba(127,127,127,.08));color:inherit;border:1px solid rgba(127,127,127,.3);border-radius:4px;padding:10px;overflow:auto;max-height:340px;white-space:pre-wrap}
|
|
.vmm-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
.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-state{font-weight:600;margin-left:6px}
|
|
.vmm-ok{color:#2f9e63}
|
|
.vmm-err{color:#c25656}
|
|
</style>
|
|
<script src="vmmngr.js"></script>
|
|
<?php
|
|
}
|
|
}
|