summaryrefslogtreecommitdiff
path: root/pages/computers.inc
diff options
context:
space:
mode:
Diffstat (limited to 'pages/computers.inc')
-rw-r--r--pages/computers.inc133
1 files changed, 86 insertions, 47 deletions
diff --git a/pages/computers.inc b/pages/computers.inc
index 1541fa6..0d41a23 100644
--- a/pages/computers.inc
+++ b/pages/computers.inc
@@ -1,6 +1,6 @@
<?php
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; global $pagename;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; global $pagename; global $_USER;
$computer = [];
$parts = explode("/", $pagename);
@@ -38,6 +38,21 @@ if (count($parts) === 2 || count($parts) === 3) {
?>
+<script>
+ window.userName = "<?php
+
+ $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($_PROFILE["login"] === "raindrops" ? "gdapd" : "ynmuc") . "/fronters.json"), true);
+ $name = $_PROFILE["login"] === "raindrops" ? "Raindrops System" : "Cloudburst Sys";
+
+ if (count($fronters["members"]) > 0) {
+ $name = $fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"];
+ }
+
+ echo($name);
+
+ ?>";
+</script>
+
<br>
<div class="container">
<?php if (isset($parts[2]) && !isset($parts[3])): $id = $parts[2]; ?>
@@ -47,6 +62,13 @@ if (count($parts) === 2 || count($parts) === 3) {
<a href="/-/computers" class="small btn btn-outline-light" style="float:right;margin-top:5px;vertical-align:middle;opacity:1 !important; color:white;">Back</a>
</h2>
+ <?php if ($computer["luna_version"] === "1.0.0"): ?>
+ <div class="alert alert-danger">
+ <p><b>We are unable to give you access to this computer.</b></p>
+ <p>This computer is running Luna version 1.0.0. This version of Luna is considered malware because of inconspicuous behavior and is therefore not usable anymore and has been disabled. This means you cannot access this computer at the moment.</p>
+ Update this computer to run Luna 1.1.0 or newer and try again.
+ </div>
+ <?php else: ?>
<h4 style="margin-top: 20px;margin-bottom: 10px;">Overview</h4>
<style>
@media (max-width: 700px) {
@@ -275,33 +297,11 @@ if (count($parts) === 2 || count($parts) === 3) {
</tbody>
</table>
- <h4 style="margin-top: 20px;margin-bottom: 10px;" id="screens">Screens</h4>
+ <h4 style="margin-top: 20px;margin-bottom: 10px;" id="screens">Remote control</h4>
<p id="page-content">
- You can remotely control this computer. <a href="./<?= $id ?>/control">Open remote control.</a>
+ You can remotely control this computer. <a href="./<?= $id ?>/control">Open remote control.</a><br>
+ <small class="text-muted">Note: The user of this computer will need to approve your connection request before you can see and control their screen.</small>
</p>
- <div style="display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px;">
- <?php foreach ($computer["screens"] as $screen): ?>
- <div class="card">
- <div class="card-body">
- <img style="width: 100%;" src="https://ponies.equestria.horse/api/data?f=computers/screens/<?= $id . "-" . $screen["id"] ?>.jpg">
- </div>
- </div>
- <?php endforeach; ?>
- </div>
-
- <h4 style="margin-top: 20px;margin-bottom: 10px;" id="windows">Windows</h4>
- <div style="display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px;">
- <?php foreach ($computer["windows"] as $window): ?>
- <div class="card">
- <div class="card-body" style="display: flex; align-items: center;">
- <div style="width: 100%;">
- <img style="max-width: 100%; max-height: 100%;" src="https://ponies.equestria.horse/api/data?f=computers/windows/<?= $id . "-" . sha1($window["gid"]) ?>.jpg">
- <div style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden; width: 100%; text-align: center; margin-top: 7px; margin-bottom: -7px;"><?= $window["name"] ?></div>
- </div>
- </div>
- </div>
- <?php endforeach; ?>
- </div>
<h4 style="margin-top: 20px;margin-bottom: 10px;">Sessions</h4>
<table class="table">
@@ -534,42 +534,60 @@ if (count($parts) === 2 || count($parts) === 3) {
<?php endforeach; ?>
</tbody>
</table>
+ <?php endif; ?>
</div>
<?php elseif (isset($parts[3]) && $parts[3] === "control"): $id = $parts[2]; ?>
+ <?php if ($computer["luna_version"] !== "1.0.0"): ?>
<div>
<h2>
<span style="vertical-align: middle;">Remote controlling <?= $computer["host"] ?></span>
<a href="/-/computers/<?= $id ?>" class="small btn btn-outline-light" style="float:right;margin-top:5px;vertical-align:middle;opacity:1 !important; color:white;">Back</a>
</h2>
- <div style="display: flex; align-items: center;">
- <img id="display" style="max-width: 100%; max-height: 100%; height: 100%; width: 100%; opacity: .5" src="https://ponies.equestria.horse/api/data?f=computers/screens/<?= $id . "-" . $computer["screens"][0]["id"] ?>.jpg">
+ <div id="remote-control-load">
+ <img src="/assets/editor/load.svg" style="width: 36px; vertical-align: middle;" id="rc-loader-img" alt=""><span style="vertical-align: middle;" id="remote-control-load-msg">Initialising connection...</span></div>
+ </div>
+
+ <div class="alert alert-danger" id="remote-control-error" style="display:none;">
+ <b>Unable to connect:</b> <span id="remote-control-error-message">Error</span>
</div>
- <div id="commands" style="background: #151515; border: 1px solid #333; margin-top: 10px; border-radius: 10px; font-family: 'JetBrains Mono', monospace; font-size: 14px;">
- <div id="output" style="height: 200px; padding: 10px 20px; overflow: auto;">
- <pre id="output-text"></pre>
- <div id="loader" style="display: none;">
- <img src="/assets/editor/load.svg" style="width: 36px; vertical-align: middle; margin-left: -8px; margin-top: -8px;" id="loader-img" alt="">
- <span id="loader-time" style="vertical-align: middle; opacity: .5; display: inline-block; margin-top: -8px; margin-left: -8px;">
+ <div id="remote-control-app" style="display: none;">
+ <div style="display: flex; align-items: center;">
+ <img id="display" style="max-width: 100%; max-height: 100%; height: 100%; width: 100%; opacity: .5" src="https://ponies.equestria.horse/api/data?f=computers/screens/<?= $id . "-" . $computer["screens"][0]["id"] ?>.jpg">
+ </div>
+
+ <div id="commands" style="background: #151515; border: 1px solid #333; margin-top: 10px; border-radius: 10px; font-family: 'JetBrains Mono', monospace; font-size: 14px;">
+ <div id="output" style="height: 200px; padding: 10px 20px; overflow: auto;">
+ <pre id="output-text"></pre>
+ <div id="loader" style="display: none;">
+ <img src="/assets/editor/load.svg" style="width: 36px; vertical-align: middle; margin-left: -8px; margin-top: -8px;" id="loader-img" alt="">
+ <span id="loader-time" style="vertical-align: middle; opacity: .5; display: inline-block; margin-top: -8px; margin-left: -8px;">
<span id="loader-time-inner"></span>
<span id="loader-time-stopper">
| <a id="loader-time-stopper-link" style="cursor: pointer; text-decoration: underline;" onclick="stopCommand();">Stop</a>
</span>
</span>
+ </div>
+ </div>
+ <div id="entry" style="border-top: 1px solid #333;">
+ <input type="text" id="command-entry" placeholder="Enter a command" style="width: 100%; color: white; background: transparent; border: none; padding: 10px 20px; outline: none;">
</div>
- </div>
- <div id="entry" style="border-top: 1px solid #333;">
- <input type="text" id="command-entry" placeholder="Enter a command" style="width: 100%; color: white; background: transparent; border: none; padding: 10px 20px; outline: none;">
</div>
</div>
<script>
+ function setLoadMessage(msg) {
+ document.getElementById("remote-control-load-msg").innerText = msg;
+ }
+
function stopCommand() {
ws.send(JSON.stringify({
type: "halt"
}));
}
+
+ let rejected = false;
function scrollToBottom() {
document.getElementById("output").scrollTop = document.getElementById("output").scrollHeight;
@@ -601,22 +619,38 @@ if (count($parts) === 2 || count($parts) === 3) {
window.commandRunInterval = null;
function connect() {
+ setLoadMessage("Connecting to server...");
window.ws = new WebSocket("wss://ponies.equestria.horse/_Computers-RemoteControl-EntryPoint/socket");
window.baseLatency = null;
ws.addEventListener('open', (data) => {
+ setLoadMessage("Authenticating...");
console.log(data);
+
ws.send(JSON.stringify({
type: "client",
id: "<?= $id ?>",
+ name: window.userName,
token: "<?= $_COOKIE['PEH2_SESSION_TOKEN'] ?>"
- }))
+ }));
+
+ setLoadMessage("Waiting for the user to accept...");
});
ws.addEventListener('message', async (_data) => {
+ setLoadMessage("Loading...");
let data = JSON.parse(await (_data.data.text()));
+ if (data.rejected) {
+ document.getElementById("remote-control-load").style.display = "none";
+ document.getElementById("remote-control-error").style.display = "";
+ document.getElementById("remote-control-error-message").innerText = "The user has rejected the connection request.";
+ rejected = true;
+ }
+
if (data.type === "image") {
+ setLoadMessage("Loading initial image...");
+
document.getElementById("display").style.opacity = "1";
document.getElementById("display").src = data.url;
@@ -638,6 +672,9 @@ if (count($parts) === 2 || count($parts) === 3) {
} else {
window.baseLatency = Math.abs(new Date().getTime() - data.time);
}
+
+ document.getElementById("remote-control-load").style.display = "none";
+ document.getElementById("remote-control-app").style.display = "";
} else if (data.type === "command_stop") {
if (data.code !== 0) {
if (data.signal) {
@@ -655,6 +692,7 @@ if (count($parts) === 2 || count($parts) === 3) {
document.getElementById("command-entry").disabled = false;
document.getElementById("loader").style.display = "none";
scrollToBottom();
+ document.getElementById("command-entry").focus();
} else if (data.type === "command_start") {
document.getElementById("loader-time").style.display = "inline-block";
document.getElementById("loader-time-inner").innerText = "";
@@ -680,9 +718,14 @@ if (count($parts) === 2 || count($parts) === 3) {
document.getElementById("display").style.opacity = "0.5";
console.log(data);
- setTimeout(() => {
- connect();
- }, 1000);
+ if (!rejected) {
+ setLoadMessage("Connection error, retrying in 1 second.");
+
+ setTimeout(() => {
+ setLoadMessage("Retrying connection...");
+ connect();
+ }, 1000);
+ }
});
}
@@ -776,16 +819,12 @@ if (count($parts) === 2 || count($parts) === 3) {
window.controlling = false;
}
</script>
+ <?php endif; ?>
<?php else: ?>
<div>
<h2>Computers</h2>
<p>Click on a computer to view information about it (open windows, installed apps, ...).</p>
- <div class="alert alert-danger">
- <b>Luna is not for production.</b> The Luna program version 1.0.0 is considered malware and must not be used on any computer other than a development machine.
- </div>
-
- <!--
<ul class="list-group">
<?php foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata"), function ($i) {
return !str_starts_with($i, ".");
@@ -803,7 +842,7 @@ if (count($parts) === 2 || count($parts) === 3) {
</div>
</a>
<?php endforeach; ?>
- </ul>-->
+ </ul>
</div>
<?php endif; ?>
</div>