45 lines
1.4 KiB
PHP
45 lines
1.4 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']);
|
|
}
|
|
}
|