summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2021-11-29 01:22:54 +0100
committerJannik Schönartz2021-11-29 01:22:54 +0100
commita51f5cef0375973451807d2c4e0f17dc975fcd39 (patch)
treebb3acebddee09739011566465d6cceec3149c099
parent[statistics_reporting] Always send a minimal report (diff)
downloadslx-admin-remote-edit-vm.tar.gz
slx-admin-remote-edit-vm.tar.xz
slx-admin-remote-edit-vm.zip
[remoteaccess] Add support for remote edit (reservation and scp task trigger)remote-edit-vm
-rw-r--r--modules-available/remoteaccess/api.inc.php46
-rw-r--r--modules-available/remoteaccess/install.inc.php28
2 files changed, 74 insertions, 0 deletions
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 @@
<?php
+// Api call for reserving a client
+if (Request::any('action') === 'reserve') {
+ $lectureid = Request::any('lectureid', '', 'string');
+ $editid = Request::any('editid', '', 'string');
+ $now = time();
+
+ // For now only considere pcs, that are already in the remote db and pc in idle state
+ //$client = Database::queryFirst("SELECT m.machineuuid, m.clientip, r.password, r.vncport FROM machine m INNER JOIN remoteaccess_machine r ON r.machineuuid = m.machineuuid WHERE m.currentsession IS NULL AND m.state = 'IDLE'");
+ // Sometimes currentsession is not null while pc is in idle state ... bug?
+ $client = Database::queryFirst("SELECT m.machineuuid, m.clientip, r.password, r.vncport FROM machine m INNER JOIN remoteaccess_machine r ON r.machineuuid = m.machineuuid WHERE m.state = 'IDLE'");
+
+ // If there is a client reserve it
+ if ($client && $editid) {
+ Database::exec("UPDATE remoteaccess_machine SET timestamp=:now, lectureid=:lectureid, editid=:editid WHERE machineuuid=:machineuuid", ['now' => $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);