mirror of
https://github.com/unraid/webgui.git
synced 2026-05-05 09:30:02 -05:00
PHP8 support
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2021, Lime Technology
|
||||
* Copyright 2015-2021, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
* Copyright 2012-2021, Bergware International.
|
||||
/* Copyright 2005-2023, Lime Technology
|
||||
* Copyright 2015-2023, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
* Copyright 2012-2023, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -13,14 +13,13 @@
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = 'vms';
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
|
||||
|
||||
|
||||
$user_prefs = '/boot/config/plugins/dynamix.vm.manager/userprefs.cfg';
|
||||
$vms = $lv->get_domains();
|
||||
if (empty($vms)) {
|
||||
@@ -28,17 +27,18 @@ if (empty($vms)) {
|
||||
return;
|
||||
}
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
foreach ($vms as $vm) $sort[] = array_search($vm,$prefs) ?? 999;
|
||||
$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);
|
||||
}
|
||||
$i = 0;
|
||||
$kvm = ['var kvm=[];'];
|
||||
$show = explode(',',unscript($_GET['show']??''));
|
||||
$path = $domain_cfg['MEDIADIR'] ;
|
||||
|
||||
$show = explode(',',unscript(_var($_GET,'show')));
|
||||
$path = _var($domain_cfg,'MEDIADIR');
|
||||
|
||||
foreach ($vms as $vm) {
|
||||
$res = $lv->get_domain_by_name($vm);
|
||||
$desc = $lv->domain_get_description($res);
|
||||
@@ -51,9 +51,9 @@ foreach ($vms as $vm) {
|
||||
$image = substr($icon,-4)=='.png' ? "<img src='$icon' class='img'>" : (substr($icon,0,5)=='icon-' ? "<i class='$icon img'></i>" : "<i class='fa fa-$icon img'></i>");
|
||||
$arrConfig = domain_to_config($uuid);
|
||||
if ($state == 'running') {
|
||||
$mem = $dom['memory'] / 1024;
|
||||
$mem = $dom['memory']/1024;
|
||||
} else {
|
||||
$mem = $lv->domain_get_memory($res) / 1024;
|
||||
$mem = $lv->domain_get_memory($res)/1024;
|
||||
}
|
||||
$mem = round($mem).'M';
|
||||
$vcpu = $dom['nrVirtCpu'];
|
||||
@@ -74,13 +74,13 @@ foreach ($vms as $vm) {
|
||||
$graphics = '';
|
||||
if ($vmrcport > 0) {
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
$vmrcprotocol = $lv->domain_get_vmrc_protocol($res) ;
|
||||
$vmrcurl = autov('/plugins/dynamix.vm.manager/'.$vmrcprotocol.'.html',true).'&autoconnect=true&host=' . $_SERVER['HTTP_HOST'] ;
|
||||
if ($vmrcprotocol == "spice") $vmrcurl .= '&vmname='. urlencode($vm) .'&port=/wsproxy/' . $vmrcport . '/' ; else $vmrcurl .= '&port=&path=/wsproxy/' . $wsport . '/';
|
||||
$vmrcprotocol = $lv->domain_get_vmrc_protocol($res);
|
||||
$vmrcurl = autov('/plugins/dynamix.vm.manager/'.$vmrcprotocol.'.html',true).'&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).":".$vmrcport;
|
||||
} elseif ($vmrcport == -1 || $autoport) {
|
||||
$vmrcprotocol = $lv->domain_get_vmrc_protocol($res) ;
|
||||
if ($autoport == "yes") $auto = "auto" ; else $auto="manual" ;
|
||||
$vmrcprotocol = $lv->domain_get_vmrc_protocol($res);
|
||||
if ($autoport == "yes") $auto = "auto"; else $auto="manual";
|
||||
$graphics = strtoupper($vmrcprotocol).':'._($auto);
|
||||
} elseif (!empty($arrConfig['gpu'])) {
|
||||
$arrValidGPUDevices = getValidGPUDevices();
|
||||
@@ -89,10 +89,10 @@ foreach ($vms as $vm) {
|
||||
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";
|
||||
$vmrcprotocol = "VGA" ;
|
||||
$vmrcprotocol = "VGA";
|
||||
} else {
|
||||
$graphics .= $arrDev['name']."\n";
|
||||
$vmrcprotocol = "VGA" ;
|
||||
$vmrcprotocol = "VGA";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,9 +145,9 @@ foreach ($vms as $vm) {
|
||||
$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" ;
|
||||
$boot= $arrDisk["boot order"];
|
||||
$serial = $arrDisk["serial"];
|
||||
if ($boot < 1) $boot="Not set";
|
||||
echo "<tr><td>$disk</td><td>$serial</td><td>$bus</td>";
|
||||
if ($state == 'shutoff') {
|
||||
echo "<td title='Click to increase Disk Size'>";
|
||||
@@ -173,17 +173,17 @@ foreach ($vms as $vm) {
|
||||
$disk = $arrCD['file'] ?? $arrCD['partition'];
|
||||
$dev = $arrCD['device'];
|
||||
$bus = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO';
|
||||
$boot= $arrCD["boot order"] ;
|
||||
if ($boot < 1) $boot="Not set" ;
|
||||
$boot= $arrCD["boot order"];
|
||||
if ($boot < 1) $boot="Not set";
|
||||
if ($disk != "" ) {
|
||||
$title = _("Eject CD Drive").".";
|
||||
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\", \"--eject\")" ;
|
||||
echo "<tr><td>$disk <a title='$title' href='#' onclick='$changemedia'> <i class='fa fa-eject' aria-hidden=true></i></a></td><td></td><td>$bus</td><td>$capacity</td><td>$allocation</td><td>$boot</td></tr>";
|
||||
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\", \"--eject\")";
|
||||
echo "<tr><td>$disk <a title='$title' href='#' onclick='$changemedia'> <i class='fa fa-eject' aria-hidden=true></i></a></td><td></td><td>$bus</td><td>$capacity</td><td>$allocation</td><td>$boot</td></tr>";
|
||||
} else {
|
||||
$title = _("Insert CD").".";
|
||||
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\",\"--select\")" ;
|
||||
$disk = _("No CD image inserted in to drive") ;
|
||||
echo "<tr><td>$disk<a title='$title' href='#' onclick='$changemedia'> <i class='fa fa-bullseye' aria-hidden=true></i></a> </td><td></td><td>$bus</td><td>$capacity</td><td>$allocation</td><td>$boot</td></tr>";
|
||||
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\",\"--select\")";
|
||||
$disk = _("No CD image inserted in to drive");
|
||||
echo "<tr><td>$disk<a title='$title' href='#' onclick='$changemedia'> <i class='fa fa-bullseye' aria-hidden=true></i></a> </td><td></td><td>$bus</td><td>$capacity</td><td>$allocation</td><td>$boot</td></tr>";
|
||||
|
||||
}
|
||||
|
||||
@@ -191,21 +191,21 @@ foreach ($vms as $vm) {
|
||||
|
||||
/* Display VM IP Addresses "execute":"guest-network-get-interfaces" --pretty */
|
||||
echo "<thead><tr><th><i class='fa fa-sitemap'></i> <b>"._('Interfaces')."</b></th><th></th><th></th><th>"._('Type')."</th><th>"._('IP Address')."</th><th>"._('Prefix')."</th></tr></thead>";
|
||||
$gastate = getgastate($res) ;
|
||||
$gastate = getgastate($res);
|
||||
if ($gastate == "connected") {
|
||||
$ip = $lv->domain_interface_addresses($res, 1) ;
|
||||
$ip = $lv->domain_interface_addresses($res, 1);
|
||||
if ($ip != false) {
|
||||
$duplicates = []; // hide duplicate interface names
|
||||
foreach ($ip as $arrIP) {
|
||||
$ipname = $arrIP["name"] ;
|
||||
$ipname = $arrIP["name"];
|
||||
if (preg_match('/^(lo|Loopback)/',$ipname)) continue; // omit loopback interface
|
||||
$iphdwadr = $arrIP["hwaddr"] == "" ? _("N/A") : $arrIP["hwaddr"] ;
|
||||
$iplist = $arrIP["addrs"] ;
|
||||
$iphdwadr = $arrIP["hwaddr"] == "" ? _("N/A") : $arrIP["hwaddr"];
|
||||
$iplist = $arrIP["addrs"];
|
||||
foreach ($iplist as $arraddr) {
|
||||
$ipaddrval = $arraddr["addr"] ;
|
||||
$ipaddrval = $arraddr["addr"];
|
||||
if (preg_match('/^f[c-f]/',$ipaddrval)) continue; // omit ipv6 private addresses
|
||||
$iptype = $arraddr["type"] ? "ipv6" : "ipv4" ;
|
||||
$ipprefix = $arraddr["prefix"] ;
|
||||
$iptype = $arraddr["type"] ? "ipv6" : "ipv4";
|
||||
$ipprefix = $arraddr["prefix"];
|
||||
$ipnamemac = "$ipname ($iphdwadr)";
|
||||
if (!in_array($ipnamemac,$duplicates)) $duplicates[] = $ipnamemac; else $ipnamemac = "";
|
||||
echo "<tr><td>$ipnamemac</td><td></td><td></td><td>$iptype</td><td>$ipaddrval</td><td>$ipprefix</td></tr>";
|
||||
@@ -214,7 +214,7 @@ foreach ($vms as $vm) {
|
||||
}
|
||||
} else {
|
||||
if ($gastate == "disconnected") echo "<tr><td>"._('Guest agent not installed')."</td><td></td><td></td><td></td></tr>";
|
||||
else echo "<tr><td>"._('Guest not running')."</td><td></td><td></td><td></td><td></td></tr>" ;
|
||||
else echo "<tr><td>"._('Guest not running')."</td><td></td><td></td><td></td><td></td></tr>";
|
||||
}
|
||||
echo "</tbody></table>";
|
||||
echo "</td></tr>";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
* Copyright 2015-2020, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
/* Copyright 2005-2023, Lime Technology
|
||||
* Copyright 2015-2023, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
* Copyright 2012-2023, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -13,10 +13,10 @@
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = 'vms';
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
|
||||
|
||||
@@ -62,8 +62,8 @@ function embed(&$syslinux, $key, $value) {
|
||||
}
|
||||
|
||||
$arrSizePrefix = [0 => '', 1 => 'K', 2 => 'M', 3 => 'G', 4 => 'T', 5 => 'P'];
|
||||
$action = unscript($_REQUEST['action']??'');
|
||||
$uuid = unscript($_REQUEST['uuid']??'');
|
||||
$action = unscript(_var($_REQUEST,'action'));
|
||||
$uuid = unscript(_var($_REQUEST,'uuid'));
|
||||
$arrResponse = [];
|
||||
|
||||
if ($uuid) {
|
||||
@@ -90,22 +90,22 @@ case 'domain-start':
|
||||
: ['error' => $lv->get_last_error()];
|
||||
break;
|
||||
|
||||
case 'domain-start-console':
|
||||
requireLibvirt();
|
||||
$arrResponse = $lv->domain_start($domName)
|
||||
? ['success' => true, 'state' => $lv->domain_get_state($domName)]
|
||||
: ['error' => $lv->get_last_error()];
|
||||
$dom = $lv->get_domain_by_name($domName) ;
|
||||
$vmrcport = $lv->domain_get_vnc_port($dom);
|
||||
$wsport = $lv->domain_get_ws_port($dom);
|
||||
$protocol = $lv->domain_get_vmrc_protocol($dom);
|
||||
if ($vmrcport > 0) {
|
||||
$vmrcurl = autov('/plugins/dynamix.vm.manager/'.$protocol.'.html',true).'&autoconnect=true&host=' . $_SERVER['HTTP_HOST'] ;
|
||||
if ($protocol == "spice") $vmrcurl .= '&vmname='. urlencode($domName) .'&port=/wsproxy/'.$vmrcport.'/'; else $vmrcurl .= '&port=&path=/wsproxy/' . $wsport . '/';
|
||||
}
|
||||
$arrResponse['vmrcurl'] = $vmrcurl ;
|
||||
break;
|
||||
|
||||
case 'domain-start-console':
|
||||
requireLibvirt();
|
||||
$arrResponse = $lv->domain_start($domName)
|
||||
? ['success' => true, 'state' => $lv->domain_get_state($domName)]
|
||||
: ['error' => $lv->get_last_error()];
|
||||
$dom = $lv->get_domain_by_name($domName);
|
||||
$vmrcport = $lv->domain_get_vnc_port($dom);
|
||||
$wsport = $lv->domain_get_ws_port($dom);
|
||||
$protocol = $lv->domain_get_vmrc_protocol($dom);
|
||||
if ($vmrcport > 0) {
|
||||
$vmrcurl = autov('/plugins/dynamix.vm.manager/'.$protocol.'.html',true).'&autoconnect=true&host='._var($_SERVER,'HTTP_HOST');
|
||||
if ($protocol == "spice") $vmrcurl .= '&vmname='. urlencode($domName) .'&port=/wsproxy/'.$vmrcport.'/'; else $vmrcurl .= '&port=&path=/wsproxy/'.$wsport.'/';
|
||||
}
|
||||
$arrResponse['vmrcurl'] = $vmrcurl;
|
||||
break;
|
||||
|
||||
case 'domain-pause':
|
||||
requireLibvirt();
|
||||
$arrResponse = $lv->domain_suspend($domName)
|
||||
@@ -216,13 +216,13 @@ case 'cdrom-change':
|
||||
|
||||
case 'change-media':
|
||||
requireLibvirt();
|
||||
$dev= $_REQUEST['dev'] ;
|
||||
$file= $_REQUEST['file'] ;
|
||||
$cmdstr = "virsh change-media '$domName' $dev $file" ;
|
||||
$dev= $_REQUEST['dev'];
|
||||
$file= $_REQUEST['file'];
|
||||
$cmdstr = "virsh change-media '$domName' $dev $file";
|
||||
$rtn=shell_exec($cmdstr)
|
||||
? ['success' => true]
|
||||
: ['error' => "Change Media Failed"];
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'memory-change':
|
||||
requireLibvirt();
|
||||
@@ -616,6 +616,7 @@ case 'virtio-win-iso-remove':
|
||||
$arrResponse = ['success' => true];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$arrResponse = ['error' => _('Unknown action')." '$action'"];
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user