mirror of
https://github.com/unraid/webgui.git
synced 2026-04-22 18:19:14 -05:00
Dashboard: boxed apps
This commit is contained in:
@@ -13,80 +13,109 @@
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
|
||||
|
||||
$display = $_POST['display'];
|
||||
$menu = [];
|
||||
|
||||
if (pgrep('dockerd')!==false && ($display=='icons' || $display=='docker')) {
|
||||
$user_prefs = $dockerManPaths['user-prefs'];
|
||||
$DockerClient = new DockerClient();
|
||||
$DockerTemplates = new DockerTemplates();
|
||||
$containers = $DockerClient->getDockerContainers();
|
||||
$allInfo = $DockerTemplates->getAllInfo();
|
||||
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
foreach ($containers as $ct) $sort[] = array_search($ct['Name'],$prefs) ?? 999;
|
||||
array_multisort($sort,SORT_NUMERIC,$containers);
|
||||
}
|
||||
|
||||
foreach ($containers as $ct) {
|
||||
$name = $ct['Name'];
|
||||
$id = $ct['Id'];
|
||||
$info = &$allInfo[$name];
|
||||
$running = $info['running'] ? 1:0;
|
||||
$paused = $info['paused'] ? 1:0;
|
||||
$is_autostart = $info['autostart'] ? 'true':'false';
|
||||
$updateStatus = $info['updated']=='true'||$info['updated']=='undef' ? 'true':'false';
|
||||
$template = $info['template'];
|
||||
$shell = $info['shell'];
|
||||
$webGui = html_entity_decode($info['url']);
|
||||
$support = html_entity_decode($info['Support']);
|
||||
$project = html_entity_decode($info['Project']);
|
||||
$menu[] = sprintf("addDockerContainerContext('%s','%s','%s',%s,%s,%s,%s,'%s','%s','%s','%s','%s');", addslashes($name), addslashes($ct['ImageId']), addslashes($template), $running, $paused, $updateStatus, $is_autostart, addslashes($webGui), $shell, $id, addslashes($support), addslashes($project));
|
||||
$shape = $running ? ($paused ? 'pause' : 'play') : 'square';
|
||||
$status = $running ? ($paused ? 'paused' : 'started') : 'stopped';
|
||||
$icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png';
|
||||
echo "<div id='$id' class='Panel $status' style='cursor:pointer'>";
|
||||
echo "<div style='display:block'><div style='position:relative;width:48px;height:48px;margin:0px auto;'>";
|
||||
echo "<img src='$icon' class='$status' style='position:absolute;top:0;bottom:0;left:0;right:0;width:48px;height:48px;'><i class='fa iconstatus fa-$shape $status' title='$status'></i></div></div>";
|
||||
echo "<div class='PanelText'><span class='PanelText ".($updateStatus=='false'?'update':$status)."'>$name</span></div></div>";
|
||||
}
|
||||
}
|
||||
|
||||
if (pgrep('libvirtd')!==false && ($display=='icons' || $display=='vms')) {
|
||||
$user_prefs = '/boot/config/plugins/dynamix.vm.manager/userprefs.cfg';
|
||||
$vms = $lv->get_domains();
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
foreach ($vms as $vm) $sort[] = array_search($vm,$prefs) ?? 999;
|
||||
array_multisort($sort,SORT_NUMERIC,$vms);
|
||||
} else {
|
||||
natcasesort($vms);
|
||||
}
|
||||
foreach ($vms as $vm) {
|
||||
$res = $lv->get_domain_by_name($vm);
|
||||
$uuid = libvirt_domain_get_uuid_string($res);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$id = $lv->domain_get_id($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
$vncport = $lv->domain_get_vnc_port($res);
|
||||
$vnc = '';
|
||||
if ($vncport > 0) {
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
$vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host='.$_SERVER['HTTP_HOST'].'&port=&path=/wsproxy/'.$wsport.'/';
|
||||
} else {
|
||||
$vncport = ($vncport < 0) ? "auto" : "";
|
||||
if ($display=='icons' || $display=='docker') {
|
||||
echo "<tr><td></td><td colspan='4'>";
|
||||
if ($_POST['docker']) {
|
||||
$user_prefs = $dockerManPaths['user-prefs'];
|
||||
$DockerClient = new DockerClient();
|
||||
$DockerTemplates = new DockerTemplates();
|
||||
$containers = $DockerClient->getDockerContainers();
|
||||
$allInfo = $DockerTemplates->getAllInfo();
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
foreach ($containers as $ct) $sort[] = array_search($ct['Name'],$prefs) ?? 999;
|
||||
array_multisort($sort,SORT_NUMERIC,$containers);
|
||||
}
|
||||
$template = $lv->_get_single_xpath_result($res, '//domain/metadata/*[local-name()=\'vmtemplate\']/@name');
|
||||
if (empty($template)) $template = 'Custom';
|
||||
$log = (is_file("/var/log/libvirt/qemu/$vm.log") ? "libvirt/qemu/$vm.log" : '');
|
||||
$menu[] = sprintf("addVMContext('%s','%s','%s','%s','%s','%s');", addslashes($vm), addslashes($uuid), addslashes($template), $state, addslashes($vnc), addslashes($log));
|
||||
$vmicon = $lv->domain_get_icon_url($res);
|
||||
echo renderVMContentIcon($uuid, $vm, $vmicon, $state, true);
|
||||
foreach ($containers as $ct) {
|
||||
$name = $ct['Name'];
|
||||
$id = $ct['Id'];
|
||||
$info = &$allInfo[$name];
|
||||
$running = $info['running'] ? 1:0;
|
||||
$paused = $info['paused'] ? 1:0;
|
||||
$is_autostart = $info['autostart'] ? 'true':'false';
|
||||
$updateStatus = $info['updated']=='true'||$info['updated']=='undef' ? 'true':'false';
|
||||
$template = $info['template'];
|
||||
$shell = $info['shell'];
|
||||
$webGui = html_entity_decode($info['url']);
|
||||
$support = html_entity_decode($info['Support']);
|
||||
$project = html_entity_decode($info['Project']);
|
||||
$menu[] = sprintf("addDockerContainerContext('%s','%s','%s',%s,%s,%s,%s,'%s','%s','%s','%s','%s');", addslashes($name), addslashes($ct['ImageId']), addslashes($template), $running, $paused, $updateStatus, $is_autostart, addslashes($webGui), $shell, $id, addslashes($support), addslashes($project));
|
||||
$shape = $running ? ($paused ? 'pause' : 'play') : 'square';
|
||||
$status = $running ? ($paused ? 'paused' : 'started') : 'stopped';
|
||||
$update = $updateStatus=='false' ? 'update' : '';
|
||||
$icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png';
|
||||
$image = substr($icon,-4)=='.png' ? "<img src='$icon'>" : (substr($icon,0,5)=='icon-' ? "<i class='$icon img'></i>" : "<i class='fa fa-$icon img'></i>");
|
||||
echo "<span id='$id' class='outer apps $status'>$image<span class='inner'><span class='$update'>$name</span><br><i class='fa fa-$shape $status'></i><span class='state'>$status</span></span></span>";
|
||||
}
|
||||
$none = count($containers) ? "No running docker containers" : "No docker containers defined";
|
||||
echo "<span id='no_apps' style='display:none'>$none<br><br></span>";
|
||||
} else {
|
||||
echo "Docker service not running<br><br>";
|
||||
}
|
||||
echo "</td><td></td></tr>";
|
||||
}
|
||||
echo "\0".implode($menu);
|
||||
echo "\0";
|
||||
if ($display=='icons' || $display=='vms') {
|
||||
echo "<tr><td></td><td colspan='4'>";
|
||||
if ($_POST['vm']) {
|
||||
$user_prefs = '/boot/config/plugins/dynamix.vm.manager/userprefs.cfg';
|
||||
$vms = $lv->get_domains();
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
foreach ($vms as $vm) $sort[] = array_search($vm,$prefs) ?? 999;
|
||||
array_multisort($sort,SORT_NUMERIC,$vms);
|
||||
} else {
|
||||
natcasesort($vms);
|
||||
}
|
||||
foreach ($vms as $vm) {
|
||||
$res = $lv->get_domain_by_name($vm);
|
||||
$uuid = libvirt_domain_get_uuid_string($res);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$id = $lv->domain_get_id($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
$vncport = $lv->domain_get_vnc_port($res);
|
||||
$vnc = '';
|
||||
if ($vncport > 0) {
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
$vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host='.$_SERVER['HTTP_HOST'].'&port=&path=/wsproxy/'.$wsport.'/';
|
||||
} else {
|
||||
$vncport = ($vncport < 0) ? "auto" : "";
|
||||
}
|
||||
$template = $lv->_get_single_xpath_result($res, '//domain/metadata/*[local-name()=\'vmtemplate\']/@name');
|
||||
if (empty($template)) $template = 'Custom';
|
||||
$log = (is_file("/var/log/libvirt/qemu/$vm.log") ? "libvirt/qemu/$vm.log" : '');
|
||||
$menu[] = sprintf("addVMContext('%s','%s','%s','%s','%s','%s');", addslashes($vm), addslashes($uuid), addslashes($template), $state, addslashes($vnc), addslashes($log));
|
||||
$icon = $lv->domain_get_icon_url($res);
|
||||
switch ($state) {
|
||||
case 'running':
|
||||
$shape = 'play';
|
||||
$status = 'started';
|
||||
break;
|
||||
case 'paused':
|
||||
case 'pmsuspended':
|
||||
$shape = 'pause';
|
||||
$status = 'paused';
|
||||
break;
|
||||
default:
|
||||
$shape = 'square';
|
||||
$status = 'stopped';
|
||||
break;
|
||||
}
|
||||
$image = substr($icon,-4)=='.png' ? "<img src='$icon'>" : (substr($icon,0,5)=='icon-' ? "<i class='$icon img'></i>" : "<i class='fa fa-$icon img'></i>");
|
||||
echo "<span id='vm-$uuid' class='outer vms $status'>$image<span class='inner'>$vm<br><i class='fa fa-$shape $status'></i><span class='state'>$status</span></span></span>";
|
||||
}
|
||||
$none = count($vms) ? "No running virtual machines" : "No virtual machines defined";
|
||||
echo "<span id='no_vms' style='display:none'>$none<br><br></span>";
|
||||
} else {
|
||||
echo "VM service not running<br><br>";
|
||||
}
|
||||
echo "</td><td></td></tr>";
|
||||
}
|
||||
echo "\0";
|
||||
echo implode($menu);
|
||||
|
||||
Reference in New Issue
Block a user