diff options
author | RaindropsSys <contact@minteck.org> | 2023-05-18 18:05:49 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-05-18 18:05:49 +0200 |
commit | 5e768d30a0c8ea53423cc4f077c8f37381b8cbb3 (patch) | |
tree | 6a880225d277907848e3cbd09b9ab28c6e47dacf /pages/computers.inc | |
parent | 59466d5019d69691fc17c607c456f77859017968 (diff) | |
download | pluralconnect-5e768d30a0c8ea53423cc4f077c8f37381b8cbb3.tar.gz pluralconnect-5e768d30a0c8ea53423cc4f077c8f37381b8cbb3.tar.bz2 pluralconnect-5e768d30a0c8ea53423cc4f077c8f37381b8cbb3.zip |
Updated 2 files (automated)
Diffstat (limited to 'pages/computers.inc')
-rw-r--r-- | pages/computers.inc | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/pages/computers.inc b/pages/computers.inc index 2e493fa..b711c32 100644 --- a/pages/computers.inc +++ b/pages/computers.inc @@ -4,6 +4,8 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; gl $computer = []; $parts = explode("/", $pagename); +$names = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/names.json"), true); + if (isset($parts[1])) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $parts[1] . ".json")) { $computer = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $parts[1] . ".json"), true); @@ -11,9 +13,9 @@ if (isset($parts[1])) { $owner = explode("-", $id)[0]; if (count($parts) > 2) { - $title = "Remote control · " . $computer["host"] . " · " . $title; + $title = "Remote control · " . ($names[$id] ?? $computer["host"]) . " · " . $title; } else { - $title = $computer["host"] . " · " . $title; + $title = ($names[$id] ?? $computer["host"]) . " · " . $title; } } else { header("Location: /-/computers"); @@ -26,9 +28,6 @@ if (isset($parts[2]) && $parts[2] !== "control") { die(); } -$names = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/names.json"), true); -require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; - $parts = array_values(array_filter($parts, function ($i) { return $i !== "-"; })); @@ -41,6 +40,12 @@ if (str_ends_with($computer["os"], "unknown")) { $computer["os"] = trim(substr($computer["os"], 0, -7)); } +if (str_ends_with($computer["os"], "rolling")) { + $computer["os"] = trim(substr($computer["os"], 0, -7)); +} + +require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; + ?> <script> @@ -146,6 +151,10 @@ if (str_ends_with($computer["os"], "unknown")) { echo("Android "); break; + case "wear": + echo("Wear OS "); + break; + case "server": echo("Server "); break; @@ -168,7 +177,7 @@ if (str_ends_with($computer["os"], "unknown")) { </tr> <tr> <td style="padding-right: 10px; text-align: right;"><b>Status:</b></td> - <?php if (timeAgo($computer["date"]) === "now"): ?> + <?php if (timeAgo($computer["date"]) === "now" || str_contains(timeAgo($computer["date"]), " sec ")): ?> <td>Online</td> <?php else: ?> <td>Last seen <?= timeAgo($computer["date"]) ?>: <?= date('j M, g:ia (T)', strtotime($computer["date"])) ?></td> @@ -271,13 +280,15 @@ if (str_ends_with($computer["os"], "unknown")) { <td style="padding-right: 10px; text-align: right;"><b>Charge level:</b></td> <td><?= $computer["battery"]["percent"] ?>%<?= $computer["battery"]["acConnected"] ? ", plugged in" : "" ?> (<?= round($computer["battery"]["voltage"], 2) ?> V)</td> </tr> + <?php if (isset($computer["battery"]["cycleCount"] ) && $computer["battery"]["cycleCount"] > 0): ?> <tr> <td style="padding-right: 10px; text-align: right;"><b>Cycles:</b></td> <td><?= $computer["battery"]["cycleCount"] ?></td> </tr> + <?php endif; ?> <tr> <td style="padding-right: 10px; text-align: right;"><b>Remaining capacity:</b></td> - <td><?= $computer["battery"]["currentCapacity"] ?>/<?= $computer["battery"]["maxCapacity"] ?> <?= $computer["battery"]["capacityUnit"] ?> (designed for <?= $computer["battery"]["designedCapacity"] ?> <?= $computer["battery"]["capacityUnit"] ?><?php if ($computer["battery"]["designedCapacity"] > 0): ?>, <?= round(($computer["battery"]["maxCapacity"] / $computer["battery"]["designedCapacity"]) * 100, 2) ?>% left<?php endif; ?>)</td> + <td><?= round($computer["battery"]["currentCapacity"], 2) ?>/<?= round($computer["battery"]["maxCapacity"], 2) ?> <?= $computer["battery"]["capacityUnit"] ?><?php if (isset($computer["battery"]["designedCapacity"]) && $computer["battery"]["designedCapacity"] > 0): ?> (designed for <?= $computer["battery"]["designedCapacity"] ?> <?= $computer["battery"]["capacityUnit"] ?><?php if ($computer["battery"]["designedCapacity"] > 0): ?>, <?= round(($computer["battery"]["maxCapacity"] / $computer["battery"]["designedCapacity"]) * 100, 2) ?>% left<?php endif; ?>)<?php endif; ?></td> </tr> <?php else: ?><tr><td colspan="2">This device does not contain a battery.</td></tr><?php endif; ?><?php else: ?><tr><td colspan="2">This operating system does not support reporting battery info.</td></tr><?php endif; ?> @@ -572,6 +583,7 @@ if (str_ends_with($computer["os"], "unknown")) { </table> <?php endif; ?> + <?php if (isset($computer["processes"]) && count($computer["processes"]) > 0): ?> <h4 style="margin-top: 20px;margin-bottom: 10px;">Processes</h4> <table class="table"> <thead> @@ -597,6 +609,7 @@ if (str_ends_with($computer["os"], "unknown")) { <?php endforeach; ?> </tbody> </table> + <?php endif; ?> <?php endif; ?> </div> <?php elseif (isset($parts[3]) && $parts[3] === "control"): $id = $parts[2]; ?> @@ -902,9 +915,9 @@ if (str_ends_with($computer["os"], "unknown")) { } ?> - <a href="/-/computers/<?= $id ?>" class="list-group-item list-group-item-action" style="display: grid; grid-template-columns: 100px 1fr; grid-column-gap: 10px; <?php if (timeAgo($computer["date"]) !== "now"): ?>opacity: .5;<?php endif; ?>"> + <a href="/-/computers/<?= $id ?>" class="list-group-item list-group-item-action" style="display: grid; grid-template-columns: 100px 1fr; grid-column-gap: 10px; <?php if (timeAgo($computer["date"]) !== "now" && !str_contains(timeAgo($computer["date"]), " sec ")): ?>opacity: .5;<?php endif; ?>"> <div style="display: flex; align-items: center;"> - <img style="width: 100px;" src="<?php + <div style="aspect-ratio: 16/10; width: 100px; background-image: url('<?php if (isset($computer["dsb"])) { switch ($computer["dsb"]["platform"]) { @@ -920,7 +933,7 @@ if (str_ends_with($computer["os"], "unknown")) { echo("https://ponies.equestria.horse/api/data?f=computers/screens/" . $id . "-" . $computer["screens"][0]["id"] . ".jpg"); } - ?>"> + ?>'); background-size: cover; background-position: center;"></div> </div> <div style="display: flex; align-items: center;"> <div> @@ -936,8 +949,37 @@ if (str_ends_with($computer["os"], "unknown")) { } ?><br> - Computer · Owned by <?= $owner === "raindrops" ? "Raindrops" : "Cloudburst"; ?><br> - <?php if (timeAgo($computer["date"]) === "now"): ?>Online<?php else: ?>Last seen <?= timeAgo($computer["date"]) ?><?php endif; ?> + <?php + + if (isset($computer["dsb"]) && isset($computer["dsb"]["platform"])) { + switch ($computer["dsb"]["platform"]) { + case "desktop": + case "chrome": + echo("Computer"); + break; + + case "android": + echo("Phone"); + break; + + case "wear": + echo("Watch"); + break; + + case "server": + echo("Server"); + break; + + default: + echo("Device"); + break; + } + } else { + echo("Legacy device"); + } + + ?> · Owned by <?= $owner === "raindrops" ? "Raindrops" : "Cloudburst"; ?><br> + <?php if (timeAgo($computer["date"]) === "now" || str_contains(timeAgo($computer["date"]), " sec ")): ?>Online<?php else: ?>Last seen <?= timeAgo($computer["date"]) ?><?php endif; ?> </div> </div> </a> |