From a51f5cef0375973451807d2c4e0f17dc975fcd39 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 29 Nov 2021 01:22:54 +0100 Subject: [remoteaccess] Add support for remote edit (reservation and scp task trigger) --- modules-available/remoteaccess/api.inc.php | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'modules-available/remoteaccess/api.inc.php') diff --git a/modules-available/remoteaccess/api.inc.php b/modules-available/remoteaccess/api.inc.php index 859f5cfe..bebe0767 100644 --- a/modules-available/remoteaccess/api.inc.php +++ b/modules-available/remoteaccess/api.inc.php @@ -1,4 +1,50 @@ $now, 'lectureid' => $lectureid, 'editid' => $editid, 'machineuuid' => $client['machineuuid']]); + echo json_encode($client); + } else { + echo "Currently all machines are occupied, try again later!"; + } + + // Exit the call, so the rest doesn't get executed + exit(0); +} elseif (Request::any('action') === 'scp') { + // Start scp taskmanager task to download the qemu snapshot + $editid = Request::any('editid', '', 'string'); + $client = Database::queryFirst("SELECT m.machineuuid, m.clientip, r.editid, r.lectureid FROM machine m INNER JOIN remoteaccess_machine r ON r.machineuuid = m.machineuuid WHERE editid=:editid", ['editid' => $editid]); + + if (!$client) { + die("Invalid edit id"); + } + + // Check if client edit was allowed anyways. + // TODO does slx-admin even has the information if a user can edit a specific vm? + + // Start taskmanager task + $task = Taskmanager::submit('ScpSnapshot', array( + 'clientIp' => $client['clientip'], + 'editId' => $client['editid'], + 'lectureId' => $client['lectureid'], + )); + if (Taskmanager::isTask($task)) { + die(json_encode($task)); + } else { + die('Taskmanager could not start the task'); + } + exit(0); +} $ip = $_SERVER['REMOTE_ADDR']; if (substr($ip, 0, 7) === '::ffff:') $ip = substr($ip, 7); -- cgit v1.2.3-55-g7522