Merge pull request #1217 from SimonFair/Virtual-console-enable-copy-paste

Enable copy paste option for virtual consoles
This commit is contained in:
tom mortensen
2022-12-12 10:03:25 -08:00
committed by GitHub
3 changed files with 61 additions and 2 deletions

View File

@@ -723,6 +723,7 @@
$pcidevs='';
$gpudevs_used=[];
$vmrc='';
$channelscopypaste = '';
if (!empty($gpus)) {
foreach ($gpus as $i => $gpu) {
// Skip duplicate video devices
@@ -780,6 +781,22 @@
<model type='$strModelType'/>
</video>";
if ($gpu['copypaste'] == "yes") {
if ($strProtocol == "spice") {
$channelscopypaste = "<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
</channel>" ;
} else {
$channelscopypaste = "<channel type='qemu-vdagent'>
<source>
<clipboard copypaste='yes'/>
<mouse mode='client'/>
</source>
<target type='virtio' name='com.redhat.spice.0'/>
</channel>" ;
}
} else $channelcopypaste = "";
continue;
}
@@ -907,6 +924,7 @@
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
$channelscopypaste
$swtpm
$memballoon
</devices>

View File

@@ -965,6 +965,7 @@
$arrNICs = $lv->get_nic_info($res);
$arrHostDevs = $lv->domain_get_host_devices_pci($res);
$arrUSBDevs = $lv->domain_get_host_devices_usb($res);
$getcopypaste=getcopypaste($res) ;
// Metadata Parsing
// libvirt xpath parser sucks, use php's xpath parser instead
@@ -1002,6 +1003,7 @@
'port' => $vmrcport,
'wsport' => $lv->domain_get_ws_port($res),
'autoport' => $autoport,
'copypaste' => $getcopypaste,
];
}
@@ -1194,7 +1196,7 @@
unset($old['cputune']['vcpupin'],$old['devices']['video'],$old['devices']['disk'],$old['devices']['interface'],$old['devices']['filesystem'],$old['cpu']['@attributes'],$old['os']['boot'],$old['os']['loader'],$old['os']['nvram']);
// Remove old CPU cache and features
unset($old['cpu']['cache'], $old['cpu']['feature']) ;
unset($old['features']['hyperv']) ;
unset($old['features']['hyperv'],$old['devices']['channel']) ;
// set namespace
$new['metadata']['vmtemplate']['@attributes']['xmlns'] = 'unraid';
}
@@ -1271,4 +1273,27 @@
$data = $data[0]->state ;
return $data ;
}
function getchannels($res) {
global $lv ;
$xml = $lv->domain_get_xml($res) ;
$x = strpos($xml,"<channel", 0) ;
$y = strpos($xml,"</channel>", 0) ;
$z=$y ;
while ($y!=false) {
$y = strpos($xml,"</channel>", $z +10) ;
if ($y != false) $z =$y ;
}
$channels = substr($xml,$x, ($z + 10) -$x) ;
return $channels ;
}
function getcopypaste($res) {
$channels = getchannels($res) ;
$spicevmc = $qemuvdaagent = $copypaste = false ;
if (strpos($channels,"spicevmc",0)) $spicevmc = true ;
if (strpos($channels,"qemu-vdagent",0)) $qemuvdaagent = true ;
if ($spicevmc || $qemuvdaagent) $copypaste = true ; else $copypaste = false ;
return $copypaste ;
}
?>

View File

@@ -86,7 +86,8 @@
'model' => 'qxl',
'keymap' => 'en-us',
'port' => -1 ,
'wsport' => -1
'wsport' => -1,
'copypaste' => 'no'
]
],
'audio' => [
@@ -1000,6 +1001,16 @@
</select>
</td>
</tr>
<tr id="copypasteline" name="copypaste" class="<?if ($arrGPU['id'] != 'virtual') echo 'was';?>advanced ">
<td>_(VM Console enable Copy/paste)_:</td>
<td>
<select id="copypaste" name="gpu[<?=$i?>][copypaste]" class="narrow" >
<?
echo mk_option($arrGPU['copypaste'], 'no', _('No'));
echo mk_option($arrGPU['copypaste'], 'yes', _('Yes'));
?>
</select>
</tr>
<tr id="autoportline" name="autoportline" class="<?if ($arrGPU['id'] != 'virtual') echo 'was';?>advanced autoportline">
<td>_(VM Console AutoPort)_:</td>
<td>
@@ -1061,6 +1072,11 @@
If you wish to assign a protocol type, specify one here.
</p>
<p class="<?if ($arrGPU['id'] != 'virtual') echo 'was';?>advanced protocol">
<b>Virtual enable copy paste for VNC/SPICE</b><br>
If you enable copy paste you need to install additional software on the client in addition to the QEMU agent if that has been installed. <a href="https://www.spice-space.org/download.html" target="_blank">https://www.spice-space.org/download.html </a>is the location for spice-vdagent for both window and linux. Note copy paste function will not work with web spice viewer you need to use virt-viewer.
</p>
<p class="<?if ($arrGPU['id'] != 'virtual') echo 'was';?>advanced protocol">
<b>Virtual auto port</b><br>
Set it you want to specify a manual port for VNC or Spice. VNC needs two ports where Spice only requires one. Leave as auto yes for the system to set.