get_domains(); if (empty($vms)) { echo ''._('No Virtual Machines installed').''; return; } if (file_exists($user_prefs)) { $prefs = (array)@parse_ini_file($user_prefs); $sort = []; foreach ($vms as $vm) $sort[] = array_search($vm,$prefs); array_multisort($sort,SORT_NUMERIC,$vms); unset($sort); } else { natcasesort($vms); } $i = 0; $kvm = ['var kvm=[];']; $show = explode(',',unscript(_var($_GET,'show'))); $path = _var($domain_cfg,'MEDIADIR'); $pci_device_changes = comparePCIData(); foreach ($vms as $vm) { $res = $lv->get_domain_by_name($vm); $desc = $lv->domain_get_description($res); $uuid = $lv->domain_get_uuid($res); $dom = $lv->domain_get_info($res); $id = $lv->domain_get_id($res) ?: '-'; $autostart = $lv->domain_get_autostart($res) ? 'checked' : ''; $state = $lv->domain_state_translate($dom['state']); $icon = $lv->domain_get_icon_url($res); $image = substr($icon,-4)=='.png' ? "" : (substr($icon,0,5)=='icon-' ? "" : ""); $arrConfig = domain_to_config($uuid); $snapshots = getvmsnapshots($vm) ; $vmpciids = $lv->domain_get_vm_pciids($vm); $pcierror = false; foreach($vmpciids as $pciid => $pcidetail) { if (isset($pci_device_changes["0000:".$pciid])) $pcierror = true; } $cdroms = $lv->get_cdrom_stats($res,true,true) ; if ($state == 'running') { $mem = $dom['memory']/1024; } else { $mem = $lv->domain_get_memory($res)/1024; } $mem = round($mem).'M'; $vcpu = $dom['nrVirtCpu']; $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" : ''); $disks = '-'; $diskdesc = ''; $fstype ="QEMU"; if (($diskcnt = $lv->get_disk_count($res)) > 0) { $disks = $diskcnt.' / '.$lv->get_disk_capacity($res); $fstype = $lv->get_disk_fstype($res); $diskdesc = 'Current physical size: '.$lv->get_disk_capacity($res, true)."\nDefault snapshot type: $fstype"; } $arrValidDiskBuses = getValidDiskBuses(); $WebUI = html_entity_decode($arrConfig['template']['webui']); $vmrcport = $lv->domain_get_vnc_port($res); $autoport = $lv->domain_get_vmrc_autoport($res); $vmrcurl = ''; $graphics = ''; $virtual = false ; if (isset($arrConfig['gpu'][0]['model'])) {$vrtdriver=" "._("Driver").strtoupper(":{$arrConfig['gpu'][0]['model']} "); $vrtmodel =$arrConfig['gpu'][0]['model'];} else $vrtdriver = ""; if (isset($arrConfig['gpu'][0]['render']) && $vrtmodel == "virtio3d") { if (isset($arrConfig['gpu'][0]['render']) && $arrConfig['gpu'][0]['render'] == "auto") $vrtdriver .= "
"._("RenderGPU").":"._("Auto"); else $vrtdriver .= "
"._("RenderGPU").":{$arrValidGPUDevices[$arrConfig['gpu'][0]['render']]['name']}"; } 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='._var($_SERVER,'HTTP_HOST'); if ($vmrcprotocol == "spice") $vmrcurl .= '&vmname='. urlencode($vm) .'&port=/wsproxy/'.$vmrcport.'/'; else $vmrcurl .= '&port=&path=/wsproxy/'.$wsport.'/'; $graphics = strtoupper($vmrcprotocol).':'._($auto)."$vrtdriver\n"; $virtual = true ; } elseif ($vmrcport == -1 || $autoport) { $vmrcprotocol = $lv->domain_get_vmrc_protocol($res); if ($autoport == "yes") $auto = "auto"; else $auto="manual"; $graphics = strtoupper($vmrcprotocol).':'._($auto)."$vrtdriver\n"; $virtual = true ; } if (!empty($arrConfig['gpu'])) { $arrValidGPUDevices = getValidGPUDevices(); foreach ($arrConfig['gpu'] as $arrGPU) { if ($arrGPU['id'] == "nogpu") {$graphics .= "No GPU"."\n";continue;} foreach ($arrValidGPUDevices as $arrDev) { if ($arrGPU['id'] == $arrDev['id']) { if (count(array_filter($arrValidGPUDevices, function($v) use ($arrDev) { return $v['name'] == $arrDev['name']; })) > 1) { $graphics .= $arrDev['name'].' ('.$arrDev['id'].')'."\n"; if (!$virtual) $vmrcprotocol = "VGA"; } else { $graphics .= $arrDev['name']."\n"; if (!$virtual) $vmrcprotocol = "VGA"; } } } } $graphics = str_replace("\n", "
", trim($graphics)); } unset($dom); if (!isset($domain_cfg["CONSOLE"])) $vmrcconsole = "web" ; else $vmrcconsole = $domain_cfg["CONSOLE"] ; if (!isset($domain_cfg["RDPOPT"])) $vmrcconsole .= ";no" ; else $vmrcconsole .= ";".$domain_cfg["RDPOPT"] ; $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); $kvm[] = "kvm.push({id:'$uuid',state:'$state'});"; switch ($state) { case 'running': $shape = 'play'; $status = 'started'; $color = 'green-text'; break; case 'paused': case 'pmsuspended': $shape = 'pause'; $status = 'paused'; $color = 'orange-text'; break; default: $shape = 'square'; $status = 'stopped'; $color = 'red-text'; break; } /* VM information */ if ($snapshots != null) $snapshotstr = '('._('Snapshots').': '.count($snapshots).")"; else $snapshotstr = '('._('Snapshots').': '._('None').")"; $cdbus = $cdbus2 = $cdfile = $cdfile2 = ""; $cdromcount = 0; foreach ($cdroms as $arrCD) { $disk = $arrCD['file'] ?? $arrCD['partition']; $dev = $arrCD['device']; $bus = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO'; if ($dev == "hda") { $cdbus = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO'; $cdfile = $arrCD['file'] ?? $arrCD['partition']; if ($cdfile != "") $cdromcount++; } if ($dev == "hdb") { $cdbus2 = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO'; $cdfile2 = $arrCD['file'] ?? $arrCD['partition']; if ($cdfile2 != "") $cdromcount++; } } $ipliststr = $iptablestr = "" ; $gastate = getgastate($res); if ($gastate == "connected") { $ip = $lv->domain_interface_addresses($res, 1); if ($ip != false) { $duplicates = []; // hide duplicate interface names foreach ($ip as $arrIP) { $ipname = $arrIP["name"]; if (preg_match('/^(lo|Loopback)/',$ipname)) continue; // omit loopback interface $iphdwadr = $arrIP["hwaddr"] == "" ? _("N/A") : $arrIP["hwaddr"]; $iplist = $arrIP["addrs"]; foreach ($iplist as $arraddr) { $ipaddrval = $arraddr["addr"]; if (preg_match('/^f[c-f]/',$ipaddrval)) continue; // omit ipv6 private addresses $iptype = $arraddr["type"] ? "ipv6" : "ipv4"; $ipprefix = $arraddr["prefix"]; $ipnamemac = "$ipname ($iphdwadr)"; if (!in_array($ipnamemac,$duplicates)) $duplicates[] = $ipnamemac; else $ipnamemac = ""; $ipliststr .= "$ipnamemac$iptype$ipaddrval$ipprefix"; $iptablestr .= "$ipaddrval/$ipprefix\n" ; } } } } else { if ($gastate == "disconnected") { $ipliststr .= ""._('Guest agent not installed').""; $iptablestr = _('Requires guest agent installed'); } else { $ipliststr = ""._('Guest not running').""; $iptablestr = _('Requires guest running'); } } $iptablestr = str_replace("\n", "
", trim($iptablestr)); $changemedia = "getisoimageboth(\"{$uuid}\",\"hda\",\"{$cdbus}\",\"{$cdfile}\",\"hdb\",\"{$cdbus2}\",\"{$cdfile2}\")"; $title = _('Select ISO image'); $cdstr = $cdromcount." / 2"; echo ""; echo "$image"; echo "$vm"; if ($pcierror) echo ""; echo "
"._($status)."
"; echo "$desc"; echo "$vcpu"; echo "$mem"; echo "$disks    $cdstr
$snapshotstr
"; echo "$graphics"; echo "$iptablestr"; echo ""; /* Disk device information */ echo "" : "' style='display:none'>"); echo ""; echo ""; echo ""; echo ""; /* Display VM disks */ foreach ($lv->get_disk_stats($res) as $arrDisk) { $capacity = $lv->format_size($arrDisk['capacity'], 0); $allocation = $lv->format_size($arrDisk['allocation'], 0); $disk = $arrDisk['file'] ?? $arrDisk['partition']; $dev = $arrDisk['device']; $bus = $arrValidDiskBuses[$arrDisk['bus']] ?? 'VirtIO'; $boot= $arrDisk["boot order"]; $serial = $arrDisk["serial"]; if ($boot < 1) $boot = _('Not set'); $reallocation = trim(get_realvolume($disk)); if (!empty($reallocation)) $reallocationstr = "($reallocation)"; else $reallocationstr = ""; echo ""; if ($state == 'shutoff') { echo ""; } else { echo ""; } echo ""; } /* Display VM cdroms */ foreach ($cdroms as $arrCD) { $tooltip = ""; $capacity = $lv->format_size($arrCD['capacity'], 0); $allocation = $lv->format_size($arrCD['allocation'], 0); if ($arrCD['spundown']) {$capacity = $allocation = "*"; $tooltip = "Drive spun down ISO volume is ".$arrCD['reallocation'];} else $tooltip = "ISO volume is ".$arrCD['reallocation']; $disk = $arrCD['file'] ?? $arrCD['partition'] ?? "" ; $dev = $arrCD['device']; $bus = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO'; $boot = $arrCD["boot order"] ?? "" ; if ($boot < 1) $boot = _('Not set'); if ($disk != "" ) { $title = _('Eject CD Drive'); $changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\", \"--eject\")"; echo ""; } else { $title = _('Insert CD'); $changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\",\"--select\")"; $disk = _("No CD image inserted into drive"); echo ""; } } echo ""; /* Display VM IP Addresses "execute":"guest-network-get-interfaces" --pretty */ echo ""; echo ""; echo $ipliststr ; echo ""; /* Display VM Snapshots */ if ($snapshots != null) { $j = 0; $steps = array(); foreach ($snapshots as $snap) { if ($snap['parent'] == "" || $snap['parent'] == "Base") $j++; $steps[$j] .= $snap['name'].';'; } echo ""; echo ""; foreach ($steps as $stepsline) { $snapshotlist = explode(";",$stepsline); $tab = "    "; foreach ($snapshotlist as $snapshotitem) { if ($snapshotitem == "") continue; $snapshot = $snapshots[$snapshotitem] ; $snapshotstate = _(ucfirst($snapshot["state"]))." ({$snapshot["method"]})"; $snapshotdesc = $snapshot["desc"]; $snapshotmemory = _(ucfirst($snapshot["memory"]["@attributes"]["snapshot"])); $snapshotparent = $snapshot["parent"] ? $snapshot["parent"] : "None"; $snapshotdatetime = my_time($snapshot["creationtime"],"Y-m-d" )."
".my_time($snapshot["creationtime"],"H:i:s"); $snapmenu = sprintf("onclick=\"addVMSnapContext('%s','%s','%s','%s','%s','%s')\"", addslashes($vm),addslashes($uuid),addslashes($template),$state,$snapshot["name"],$snapshot["method"]); echo ""; $tab .="    "; } echo ""; } } echo "
",_('Disk devices/Volume'),"",_('Serial'),"",_('Bus'),"",_('Capacity'),"",_('Allocation'),"Boot Order
$disk $reallocationstr$serial$bus"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "$capacity"; echo ""; echo "
$capacity$allocation$boot
$disk $bus$capacity$allocation$boot
$disk$bus$capacity$allocation$boot
",_('Interfaces')."",_('Type')."",_('IP Address'),"",_('Prefix'),"
",_('Snapshots'),"",_('Date/Time'),"",_('Type (Method)'),"",_('Parent'),"",_('Memory'),"
$tab|__   ",$snapshot["name"],"$snapshotdesc$snapshotdatetime$snapshotstate$snapshotparent$snapshotmemory
"; } echo "\0".implode($kvm); ?>