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 ++++++++++++++++++++++++++ modules-available/remoteaccess/install.inc.php | 28 ++++++++++++++++ 2 files changed, 74 insertions(+) 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); diff --git a/modules-available/remoteaccess/install.inc.php b/modules-available/remoteaccess/install.inc.php index 2e248282..1eeaf7e8 100644 --- a/modules-available/remoteaccess/install.inc.php +++ b/modules-available/remoteaccess/install.inc.php @@ -67,4 +67,32 @@ if (!tableHasColumn('remoteaccess_machine', 'vncport')) { $dbret[] = UPDATE_DONE; } + +// 2021-08-21: Add Columns for reserving clients +if (!tablehasColumn('remoteaccess_machine', 'lectureid')) { + $ret = Database::exec("ALTER TABLE remoteaccess_machine ADD COLUMN `lectureid` char(36)"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, DATABASE::lastError()); + } + $dbret[] = UPDATE_DONE; +} + +// 2021-08-21: Timestamp to see when the client was reserved (timeout) +if (!tablehasColumn('remoteaccess_machine', 'timestamp')) { + $ret = Database::exec("ALTER TABLE remoteaccess_machine ADD COLUMN `timestamp` int unsigned"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, DATABASE::lastError()); + } + $dbret[] = UPDATE_DONE; +} + +// 2021-11-27: Add column for an edit session id +if (!tablehasColumn('remoteaccess_machine', 'editid')) { + $ret = Database::exec("ALTER TABLE remoteaccess_machine ADD COLUMN `editid` char(36)"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, DATABASE::lastError()); + } + $dbret[] = UPDATE_DONE; +} + responseFromArray($dbret); -- cgit v1.2.3-55-g7522