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); } echo ""; 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 = substr($ct['NetworkMode'],-4)==':???' ? 2 : ($info['updated']=='true' ? 0 : ($info['updated']=='false' ? 1 : 3)); $template = $info['template']; $shell = $info['shell']; $webGui = html_entity_decode($info['url']); $TSwebGui = html_entity_decode($info['TSurl']); $support = html_entity_decode($info['Support']); $project = html_entity_decode($info['Project']); $registry = html_entity_decode($info['registry']); $donateLink = html_entity_decode($info['DonateLink']); $readme = html_entity_decode($info['ReadMe']); $menu = sprintf("onclick=\"addDockerContainerContext('%s','%s','%s',%s,%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), addslashes($TSwebGui), $shell, $id, addslashes($support), addslashes($project), addslashes($registry), addslashes($donateLink), addslashes($readme)); $shape = $running ? ($paused ? 'pause' : 'play') : 'square'; $status = $running ? ($paused ? 'paused' : 'started') : 'stopped'; $color = $status=='started' ? 'green-text' : ($status=='paused' ? 'orange-text' : 'red-text'); $update = $updateStatus==1 ? 'blue-text' : ''; $icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png'; $image = substr($icon,-4)=='.png' ? "" : (substr($icon,0,5)=='icon-' ? "" : ""); echo "$image$name
"._($status)."
"; } $none = count($containers) ? _('No running docker containers') : _('No docker containers defined'); echo ""; echo ""; } echo "\0"; if ($_POST['vms']) { $vmusage = $_POST['vmusage']; $vmusagehtml = []; $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); } echo ""; $running = 0; $pci_device_changes = comparePCIData(); 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); $fstype ="QEMU"; if (($diskcnt = $lv->get_disk_count($res)) > 0) $fstype = $lv->get_disk_fstype($res); $state = $lv->domain_state_translate($dom['state']); $vmrcport = $lv->domain_get_vnc_port($res); $autoport = $lv->domain_get_vmrc_autoport($res); $vmrcurl = ''; $arrConfig = domain_to_config($uuid); if ($vmrcport > 0) { $wsport = $lv->domain_get_ws_port($res); $vmrcprotocol = $lv->domain_get_vmrc_protocol($res); if ($vmrcprotocol == "vnc") $vmrcscale = "&resize=scale"; else $vmrcscale = ""; $vmrcurl = autov('/plugins/dynamix.vm.manager/'.$vmrcprotocol.'.html',true).$vmrcscale.'&autoconnect=true&host=' . $_SERVER['HTTP_HOST']; if ($vmrcprotocol == "spice") $vmrcurl .= '&vmname='. urlencode($vm) . '&port=/wsproxy/'.$vmrcport.'/'; else $vmrcurl .= '&port=&path=/wsproxy/' . $wsport . '/'; } elseif ($vmrcport == -1 || $autoport) { $vmrcprotocol = $lv->domain_get_vmrc_protocol($res); $auto = ($autoport == "yes") ? "auto" : "manual"; } elseif (!empty($arrConfig['gpu'])) { $arrValidGPUDevices = getValidGPUDevices(); foreach ($arrConfig['gpu'] as $arrGPU) { foreach ($arrValidGPUDevices as $arrDev) { if ($arrGPU['id'] == $arrDev['id']) { if (count(array_filter($arrValidGPUDevices, function($v) use ($arrDev) { return $v['name'] == $arrDev['name']; })) > 1) { $vmrcprotocol = "VGA"; } else { $vmrcprotocol = "VGA"; } } } } } $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" : ''); if (!isset($domain_cfg["CONSOLE"])) $vmrcconsole = "web"; else $vmrcconsole = $domain_cfg["CONSOLE"]; if (!isset($domain_cfg["RDPOPT"])) $vmrcconsole .= ";no"; else $vmrcconsole .= ";".$domain_cfg["RDPOPT"]; $WebUI = html_entity_decode($arrConfig["template"]["webui"]??""); $vmpciids = $lv->domain_get_vm_pciids($vm); $pcierror = false; foreach($vmpciids as $pciid => $pcidetail) { if (isset($pci_device_changes["0000:".$pciid])) { $pcierror = true; } } $menu = sprintf("onclick=\"addVMContext('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')\"", addslashes($vm), addslashes($uuid), addslashes($template), $state, addslashes($vmrcurl), strtoupper($vmrcprotocol), addslashes($log),addslashes($fstype), $vmrcconsole,false,addslashes(str_replace('"',"'",$WebUI)),$pcierror); $icon = $lv->domain_get_icon_url($res); switch ($state) { case 'running': $shape = 'play'; $status = 'started'; $color = 'green-text'; $running++; break; case 'paused': case 'pmsuspended': $shape = 'pause'; $status = 'paused'; $color = 'orange-text'; break; default: $shape = 'square'; $status = 'stopped'; $color = 'red-text'; break; } $image = substr($icon,-4)=='.png' ? "" : (substr($icon,0,5)=='icon-' ? "" : ""); echo "$image$vm"; if ($pcierror) echo ""; echo "
"._($status)."
"; if ($state == "running") { #Build VM Usage array. $menuusage = sprintf("onclick=\"addVMContext('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')\"", addslashes($vm), addslashes($uuid), addslashes($template), $state, addslashes($vmrcurl), strtoupper($vmrcprotocol), addslashes($log),addslashes($fstype), $vmrcconsole,true,addslashes(str_replace('"',"'",$WebUI))); $vmusagehtml[] = "$image$vm
"._($status)."
"; $vmusagehtml[] = "

"._("Loading")."...."; $vmusagehtml[] = "
"._("Loading")."...."; $vmusagehtml[] = "
"._("Loading")."...."; $vmusagehtml[] = "
"._("Loading")."...."; $vmusagehtml[] = "
"._("Loading")."...."; $vmusagehtml[] = "
"; } } $none = count($vms) ? _('No running virtual machines') : _('No virtual machines defined'); echo ""; echo ""; echo "\0"; echo ""; if ($vmusage=='Y') { foreach ($vmusagehtml as $vmhtml) echo $vmhtml; if (!count($vmusagehtml)) echo "
"._('No running virtual machines')."
"; if ($running<1 && count($vmusagehtml)) echo "
". _('No running virtual machines')."
"; echo ""; } }