summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/qemu')
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc68
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include24
-rw-r--r--core/modules/qemu/data/opt/openslx/xsessions/README3
l---------core/modules/qemu/data/opt/openslx/xsessions/edit.desktop1
-rw-r--r--core/modules/qemu/data/root/.ssh/README3
-rw-r--r--core/modules/qemu/data/root/.ssh/authorized_keys2
6 files changed, 99 insertions, 2 deletions
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc
new file mode 100644
index 00000000..eb9030fa
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc
@@ -0,0 +1,68 @@
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2009..2021 bwLehrpool-Projektteam
+#
+# This program/file is free software distributed under the GPL version 2.
+# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
+#
+# If you have any feedback please consult https://bwlehrpool.de and
+# send your feedback to support@bwlehrpool.de.
+#
+# General information about bwLehrpool can be found at https://bwlehrpool.de
+#
+# -----------------------------------------------------------------------------
+# Utils and functions to parse Linux kernel command line options
+# -----------------------------------------------------------------------------
+
+#
+# Return :
+function create_rw_diskimage() {
+ # writelog "Creating rw image for qemu to safe and upload the snapshot later"
+
+ # Register upload function to trigger before the cleanup deletes the tmp image snapshot
+ add_cleanup upload_qemu_rw
+
+ # If the edit checkbox is checked the environment variable VMCHOOSER_ADMIN_MODE is TRUE
+ # ALLOW_EDIT=${VMCHOOSER_ADMIN_MODE}
+}
+
+# Helper to safe and upload the image before the cleanup deletes everything
+upload_qemu_rw() {
+
+ # writelog "Calling scp task trigger on SAT"
+ # SERVERIP=$SLX_PXE_SERVER_IP
+ # Call slx-admin api to trigger taskmanager ScpSnapshot task with all the info needed
+ # LECTUREID=$IMGUUID
+ # CLIENTIP=$SLX_PXE_CLIENT_IP
+ # curl "http://$SERVERIP/slx-admin/api.php?do=remoteaccess&action=scp&lectureid=$LECTUREID&clientip=$CLIENTIP"
+ # Image will be deleted by SAT via SSH after finished downloading
+
+
+ # LECTUREID=$IMGUUID
+ # CLIENTIP=$SLX_PXE_CLIENT_IP
+ SERVERIP=$SLX_PXE_SERVER_IP
+ SESSIONID=$(cat /var/lib/lightdm/editsession.id)
+
+ # Open firefox where the user can either safe or cancel
+ # Prepare firefox to not start the privacy "first launch" Page
+ firefox --CreateProfile progress
+ FFPROFILE=$(realpath ~/.mozilla/firefox/*.progress)
+ echo 'user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);' >> $FFPROFILE/user.js
+
+ # Start firefox and wait for the process
+ firefox --kiosk http://$SERVERIP:5000/progress/$SESSIONID -P progress &
+ FFPID="$!"
+ writelog "FF PID IS: $FFPID"
+ writelog "Waiting for firefox to exit"
+ wait $!
+ writelog "Firefox exited"
+
+ # At this point the snapshot was either downloaded by the sat or the edit session was cancelled and can be deleted
+ rm -rf /tmp/upload
+
+ # No permission to delete this file
+ # rm -f /var/lib/lightdm/editsession.id
+ # Remove the /var/lib/lightdm/edit.desktop that the slxgreeter created for autostart-editmode-login
+ # rm /var/lib/lightdm/edit.desktop
+}
+
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
index fd251f04..893835e7 100644
--- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
@@ -29,10 +29,30 @@ run_plugin() {
$(safesource "${QEMU_INCLUDE_DIR}/passthrough-pci.inc")
# include mediated device passthrough utils and functions
$(safesource "${QEMU_INCLUDE_DIR}/passthrough-mdev.inc")
+ # include function for creating the rw qcow2 image
+ $(safesource "${QEMU_INCLUDE_DIR}/create-rw-diskimage.inc")
- # setup RW image access for operation
local vm_diskfile
- if notempty VM_DISKFILE_RO; then
+ # If admin mode checkbox is set in the vmchooser, create the rw disk for the snapshot
+ if [ "${VMCHOOSER_ADMIN_MODE}" = TRUE ]; then
+ # Create tmp dir that survives cleanup
+ mkdir /tmp/upload
+
+ # Activate cleanup function for uploading
+ create_rw_diskimage
+
+ # Create snapshot file in upload dir that doesn't get deleted on cleanup
+ if [ -f /var/lib/lightdm/editsession.id ]; then
+ EDITID=$(cat /var/lib/lightdm/editsession.id)
+ vm_diskfile="/tmp/upload/$EDITID.qcow2"
+ else
+ writelog "No editid was found at /var/lib/lightdm/editsession.id, using IMGUUID as fallback"
+ vm_diskfile="/tmp/upload/$IMGUUID.qcow2"
+ fi
+ local vm_diskfile_type="$(qemu-img info --output=json ${VM_DISKFILE_RO} | jq -r '.format')"
+ qemu-img create -F "${vm_diskfile_type}" -b "${VM_DISKFILE_RO}" -f qcow2 "${vm_diskfile}"
+ # setup RW image access for operation
+ elif notempty VM_DISKFILE_RO; then
# create copy-on-write layer for readonly image
vm_diskfile="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).cow.qcow2"
local vm_diskfile_type="$(qemu-img info --output=json ${VM_DISKFILE_RO} | jq -r '.format')"
diff --git a/core/modules/qemu/data/opt/openslx/xsessions/README b/core/modules/qemu/data/opt/openslx/xsessions/README
new file mode 100644
index 00000000..87dacaa0
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/xsessions/README
@@ -0,0 +1,3 @@
+# This symlink was created, because slx can't write in this directory.
+# So here is a symlink, that's only valid (and therefore used) if the slxgreeter creates the file:
+# /var/lib/lightdm/edit.desktop
diff --git a/core/modules/qemu/data/opt/openslx/xsessions/edit.desktop b/core/modules/qemu/data/opt/openslx/xsessions/edit.desktop
new file mode 120000
index 00000000..5a789391
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/xsessions/edit.desktop
@@ -0,0 +1 @@
+/var/lib/lightdm/edit.desktop \ No newline at end of file
diff --git a/core/modules/qemu/data/root/.ssh/README b/core/modules/qemu/data/root/.ssh/README
new file mode 100644
index 00000000..8e73fe21
--- /dev/null
+++ b/core/modules/qemu/data/root/.ssh/README
@@ -0,0 +1,3 @@
+# The public key is used by the SAT to scp the snapshot after finishing a session
+# Currently this is a public key from the .51, but has to be replaced with a pub-key of the current used sat.
+# There might be better solutions but for the prototype it will do the job
diff --git a/core/modules/qemu/data/root/.ssh/authorized_keys b/core/modules/qemu/data/root/.ssh/authorized_keys
new file mode 100644
index 00000000..fb32e858
--- /dev/null
+++ b/core/modules/qemu/data/root/.ssh/authorized_keys
@@ -0,0 +1,2 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCjeHGg1UETeC3s7gAAu34kgpy6EQKrU0+fvP9gvaTU/A+DTTOE9PIhogU8sdKhA/RrHwuleEIQmNW8mFKW+BD3uoVlIt9kYN7wtxyZ130eJLEKpg7Qnt1Hkw4Dt1Vj6/kv0+j3RbzDuxDU9dODeSS/HzD//KwBiUNZ/9BtLglHXWKq7vhnEXOyU4OZm9J1LNQnLcxkCDyeMRlKZBsKIt1cPRZ+9tP82sWoqW6cwT8anAeqgJRib7JMKNeh5n6Ib8AeNX8u+YlhQiyIXHPI7vqIqwXfuyAjPEjdXF8Nqc7zz2+izOCpNtutHUvaZ2/1Yv/BJzC7TnGJ+qQVHY1fxqEHArqwcRoe3rtQnqXRQHL/JCcyc9O8vzR9BdBRIx5R24E7IyEfu3f8aBuguyJs/NhLUHWN2zB12MGn4Tjs8zERS69IG5ArVAZ3fYHR/f3LY4mNQIcB4LIXT4muboBvcx6/hv8vTVqBxVbIyf3BHQnKrXQlH8lX96P0bHG17hr3LMuYmm6H+Rk1OEiVUoebzlssK7mIGn458R2DkHnP0jsVeywB8aYb43/coQ0hLIUiljzr5H4Xmz0D6aFgAnDVNdhwiTveJ1JKlJENX81aa3iVwISPkPt14U5vEzCqmjLX2mzpEAK8f0E9GW477WEbE7AVFfcoO6VQWl+LT1Acq5H22w== root@lsfks-vm-01
+