diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-20 16:20:07 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-20 16:20:07 +0200 |
commit | b4bcb0912c5fe1c7f00c7ac76e5b67620781d3cc (patch) | |
tree | 027238ccdf43719ae4bbb65eedeaf9823fff6471 /pages/computers.inc | |
parent | b484fc41a94e18f679f2494d598ac3d0ae72e3f8 (diff) | |
download | pluralconnect-b4bcb0912c5fe1c7f00c7ac76e5b67620781d3cc.tar.gz pluralconnect-b4bcb0912c5fe1c7f00c7ac76e5b67620781d3cc.tar.bz2 pluralconnect-b4bcb0912c5fe1c7f00c7ac76e5b67620781d3cc.zip |
Updated 12 files and added 3 files (automated)
Diffstat (limited to 'pages/computers.inc')
-rw-r--r-- | pages/computers.inc | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/pages/computers.inc b/pages/computers.inc index 7b25133..2e493fa 100644 --- a/pages/computers.inc +++ b/pages/computers.inc @@ -26,6 +26,7 @@ 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) { @@ -62,7 +63,19 @@ if (str_ends_with($computer["os"], "unknown")) { <?php if (isset($parts[2]) && !isset($parts[3])): $id = $parts[2]; ?> <div> <h2> - <span style="vertical-align: middle;"><?= $computer["host"] ?></span> + <script> + async function updateComputerName() { + let name = document.getElementById("computer_name").innerText.trim(); + + if (name === "") { + name = "<?= $computer["host"] ?>"; + document.getElementById("computer_name").innerText = name; + } else { + await fetch("/api/computername?id=<?= $id ?>&name=" + encodeURIComponent(name)); + } + } + </script> + <span id="computer_name" style="vertical-align: middle;" contenteditable="true" onkeyup="updateComputerName();"><?= $names[$id] ?? $computer["host"] ?></span> <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> @@ -273,7 +286,7 @@ if (str_ends_with($computer["os"], "unknown")) { </tr> <tr> <td style="padding-right: 10px; text-align: right;"><b>System:</b></td> - <td><?= $computer["os_info"]["distro"] ?> <?= $computer["os_info"]["release"] === "unknown" ? "" : $computer["os_info"]["release"] ?></td> + <td><?= $computer["os_info"]["distro"] ?> <?= $computer["os_info"]["release"] === "unknown" || $computer["os_info"]["release"] === "rolling" ? "" : $computer["os_info"]["release"] ?></td> </tr> <tr> <td style="padding-right: 10px; text-align: right;"><b>CPU architecture:</b></td> @@ -871,16 +884,25 @@ if (str_ends_with($computer["os"], "unknown")) { <p>Click on a device to view information about it</p> <ul class="list-group"> - <?php foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata"), function ($i) { + <?php + + $list = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata"), function ($i) { return !str_starts_with($i, "."); - }) as $file): $computer = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $file), true); $id = substr($file, 0, -5); $owner = explode("-", $id)[0]; + }); + uasort($list, function ($a, $b) { + $ca = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $a), true); + $cb = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $b), true); + return strtotime($cb["date"]) - strtotime($ca["date"]); + }); + + foreach ($list as $file): $computer = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $file), true); $id = substr($file, 0, -5); $owner = explode("-", $id)[0]; if (str_ends_with($computer["os"], "unknown")) { $computer["os"] = trim(substr($computer["os"], 0, -7)); } ?> - <a href="/-/computers/<?= $id ?>" class="list-group-item list-group-item-action" style="display: grid; grid-template-columns: 100px 1fr; grid-column-gap: 10px;"> + <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; ?>"> <div style="display: flex; align-items: center;"> <img style="width: 100px;" src="<?php @@ -902,7 +924,7 @@ if (str_ends_with($computer["os"], "unknown")) { </div> <div style="display: flex; align-items: center;"> <div> - <b><?= $computer["host"] ?></b><br> + <b><?= $names[$id] ?? $computer["host"] ?></b><br> <?php if (str_starts_with($computer["os"], "Google ")) { |