diff options
Diffstat (limited to 'pages')
-rw-r--r-- | pages/api/docs.php | 4 | ||||
-rw-r--r-- | pages/api/pluralkit-integration.php | 127 | ||||
-rw-r--r-- | pages/api/ponytown.php | 4 | ||||
-rw-r--r-- | pages/computers.inc | 13 | ||||
-rw-r--r-- | pages/debug.inc | 117 | ||||
-rw-r--r-- | pages/jobs.inc | 123 |
6 files changed, 164 insertions, 224 deletions
diff --git a/pages/api/docs.php b/pages/api/docs.php index d279765..51b92f5 100644 --- a/pages/api/docs.php +++ b/pages/api/docs.php @@ -1,6 +1,7 @@ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; if (!$isLoggedIn) header("Location: /-/login") and die(); $request_raw = file_get_contents('php://input'); @@ -26,4 +27,5 @@ if ($json_object["category"]) $data["category"] = trim($json_object["category"]) $data["last"]["date"] = time(); $data["last"]["author"] = $_PROFILE['login']; -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $select . ".json", utf8_encode(json_encode($data)));
\ No newline at end of file +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $select . ".json", utf8_encode(json_encode($data))); +createJob("CleanupDocs", []);
\ No newline at end of file diff --git a/pages/api/pluralkit-integration.php b/pages/api/pluralkit-integration.php index b7abc6b..0efa8cb 100644 --- a/pages/api/pluralkit-integration.php +++ b/pages/api/pluralkit-integration.php @@ -41,106 +41,33 @@ if ($input['system_id'] === "7d9f543e-f742-40f6-9d07-86c3f2983124") { $lastFronter = json_decode(@file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/last.json"), true) ?? ""; -if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") { - if ($system === $app["other"]["id"]) { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/fronters", false, stream_context_create([ - 'http' => [ - 'method' => 'GET', - 'header' => - "Authorization: " . $app["other"]["token"] . "\r\n" - ] - ]))); - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/switches", false, stream_context_create([ - 'http' => [ - 'method' => 'GET', - 'header' => - "Authorization: " . $app["other"]["token"] . "\r\n" - ] - ]))); - } else { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/fronters")); - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/switches")); - } - - $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true); - $currentFronter = $fronters["members"][0]["id"]; - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/last.json", json_encode($currentFronter)); - - $ntfy = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["ntfy"]; - - if (count($fronters["members"]) > 0 && ($system !== $app["other"]["id"] || !isset($app["other"]))) { - foreach ($fronters["members"] as $member) { - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json")) { - $metadata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true); - - if (!isset($metadata["birth"])) { - showWarning($member["display_name"] ?? $member["name"], $member["name"], $system); - } else if (isset($metadata['birth']["age"]) && $metadata["birth"]["age"] === 0 && (!isset($metadata['birth']["year"]) || $metadata["birth"]["year"] < 1900)) { - showWarning($member["display_name"] ?? $member["name"], $member["name"], $system); - } else if (isset($metadata['birth']["year"]) && $metadata["birth"]["year"] < 1900) { - showWarning($member["display_name"] ?? $member["name"], $member["name"], $system); - } else if (!isset($metadata['birth']["year"]) && !isset($metadata['birth']["age"])) { - showWarning($member["display_name"] ?? $member["name"], $member["name"], $system); - } - } - } - } - - if (count($fronters["members"]) > 1) { - $context = stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: ๐ด Switch occurred in $name\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Open " . $fronters["members"][0]["display_name"] . " on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true;view, Open " . $fronters["members"][1]["display_name"] . " on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][1]["name"] . "/, clear=true\r\n" . - "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " and " . ($fronters["members"][1]["display_name"] ?? $fronters["members"][1]["name"]) . " switched in just now" - ] - ]); - } else if (count($fronters["members"]) > 0) { - $context = stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: ๐ด Switch occurred in $name\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true\r\n" . - "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " switched in just now" - ] - ]); - } else { - $context = stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: ๐ด Switch occurred in $name\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/, clear=true\r\n" . - "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => "The fallback pony switched in just now" - ] - ]); - } - - if ($system !== $app["other"]["id"] || !isset($app["other"])) { - file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, $context); - } +if ($input["type"] === "CREATE_MEMBER" || $input["type"] === "UPDATE_MEMBER" || $input["type"] === "DELETE_MEMBER") { + createJob("PKMembers", [ + "system" => $system + ]); + createJob("UpdateAssets", [ + "type" => "members" + ]); + createJob("UpdateLogo", []); +} - if ($system === "gdapd") { - $topic = "public-switches-raindrops"; - } else if ($system === "ynmuc") { - $topic = "public-switches-cloudburst"; - } else { - $topic = "main"; - } +if ($input["type"] === "UPDATE_SYSTEM") { + createJob("PKSystem", [ + "system" => $system + ]); + createJob("UpdateAssets", [ + "type" => "system" + ]); +} - file_get_contents('https://' . $ntfy["server"] . '/' . $topic, false, $context); +if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") { + createJob("PKFronters", [ + "system" => $system + ]); + createJob("PKSwitches", [ + "system" => $system + ]); + createJob("FrontersNotification", [ + "system" => $system + ]); }
\ No newline at end of file diff --git a/pages/api/ponytown.php b/pages/api/ponytown.php index 99d755c..6deec43 100644 --- a/pages/api/ponytown.php +++ b/pages/api/ponytown.php @@ -111,6 +111,10 @@ if (count($errors) === 0 && isset($_GET["real"])) { } } +createJob("UpdateAssets", [ + "type" => "ponytown" +]); + die(json_encode([ "success" => count($errors) === 0, "errors" => $errors diff --git a/pages/computers.inc b/pages/computers.inc index 67cb6ef..cc2c396 100644 --- a/pages/computers.inc +++ b/pages/computers.inc @@ -158,7 +158,7 @@ if (str_ends_with($computer["os"], "unknown")) { <?php if (timeAgo($computer["date"]) === "now"): ?> <td>Online</td> <?php else: ?> - <td>Offline since <?= timeAgo($computer["date"]) ?>: <?= date('j M, g:ia (T)', strtotime($computer["date"])) ?></td> + <td>Last seen <?= timeAgo($computer["date"]) ?>: <?= date('j M, g:ia (T)', strtotime($computer["date"])) ?></td> <?php endif; ?> </tr> </tbody> @@ -192,11 +192,11 @@ if (str_ends_with($computer["os"], "unknown")) { </tr> <tr> <td style="padding-right: 10px; text-align: right;"><b>Level 2 cache:</b></td> - <td><?= isset($computer["cpu"]["cache"]["l2"]) ? round($computer["cpu"]["cache"]["l2"] / 1024**2, 2) . " MiB" : "Not supported" ?></td> + <td><?= isset($computer["cpu"]["cache"]["l2"]) && is_numeric($computer["cpu"]["cache"]["l2"]) ? round($computer["cpu"]["cache"]["l2"] / 1024**2, 2) . " MiB" : "Not supported" ?></td> </tr> <tr> <td style="padding-right: 10px; text-align: right;"><b>Level 3 cache:</b></td> - <td><?= isset($computer["cpu"]["cache"]["l3"]) ? round($computer["cpu"]["cache"]["l3"] / 1024**2, 2) . " MiB" : "Not supported" ?></td> + <td><?= isset($computer["cpu"]["cache"]["l3"]) && is_numeric($computer["cpu"]["cache"]["l3"]) ? round($computer["cpu"]["cache"]["l3"] / 1024**2, 2) . " MiB" : "Not supported" ?></td> </tr> <?php endif; ?> <?php if (isset($computer["gpu"])): ?> @@ -214,7 +214,7 @@ if (str_ends_with($computer["os"], "unknown")) { <td> <?php $index = 0; foreach ($computer["gpu"]["displays"] as $display): ?> <?= $display["connection"] ?> <?= $display["vendor"] ?> <?= $display["model"] ?> (<?= $display["currentResX"] ?>x<?= $display["currentResY"] ?><?= $display["currentResX"] !== $display["resolutionX"] ? ", native " . $display["resolutionX"] . "x" . $display["resolutionY"] : "" ?>, <?= $display["currentRefreshRate"] ?> Hz) - <?= $index < count($computer["gpu"]["controllers"]) - 1 ? "<br>" : "" ?> + <?= $index < count($computer["gpu"]["displays"]) - 1 ? "<br>" : "" ?> <?php $index++; endforeach; ?> </td> </tr> @@ -902,9 +902,10 @@ if (str_ends_with($computer["os"], "unknown")) { </div> <div style="display: flex; align-items: center;"> <div> - <b><?= $computer["host"] ?></b> ยท <?= $computer["os"] ?><br> + <b><?= $computer["host"] ?></b><br> + <?= $computer["os"] ?><br> Computer ยท Owned by <?= $owner === "raindrops" ? "Raindrops System" : "Cloudburst System"; ?><br> - <?php if (timeAgo($computer["date"]) === "now"): ?>Online<?php else: ?>Offline since <?= timeAgo($computer["date"]) ?><?php endif; ?> + <?php if (timeAgo($computer["date"]) === "now"): ?>Online<?php else: ?>Last seen <?= timeAgo($computer["date"]) ?><?php endif; ?> </div> </div> </a> diff --git a/pages/debug.inc b/pages/debug.inc deleted file mode 100644 index 6d2b4c9..0000000 --- a/pages/debug.inc +++ /dev/null @@ -1,117 +0,0 @@ -<?php - -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; -require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; - -function itemToName(string $item): string { - global $lang; global $pages; - - if ($item === "docs_cleanup") return $lang["debug"]["docs_cleanup"]; - if ($item === "important_backup") return $lang["debug"]["important_backup"]; - if ($item === "restore") return $lang["debug"]["restore"]; - if ($item === "backups") return $lang["debug"]["backups"]; - if ($item === "calendar") return $lang["debug"]["calendar"]; - if ($item === "version") return $lang["debug"]["version"]; - if ($item === "logo") return $lang["debug"]["logo"]; - if ($item === "favicons") return $lang["debug"]["favicons"]; - if ($item === "assets") return $lang["debug"]["assets"]; - - if (str_starts_with($item, "system-")) { - $system = explode("-", $item)[2]; - $type = explode("-", $item)[1]; - $systemName = $system === "gdapd" ? "Raindrops System" : "Cloudburst System"; - - return match ($type) { - "general" => $lang["debug"]["general"] . " $systemName", - "members" => $lang["debug"]["members"] . " $systemName", - "fronters" => $lang["debug"]["fronters"] . " $systemName", - "switches" => $lang["debug"]["switches"] . " $systemName", - default => "$type " . $lang["debug"]["in"] . " $systemName", - }; - } - - if (str_starts_with($item, "images-")) { - $system = explode("-", $item)[1]; - $id = explode("-", $item)[2]; - $systemName = $system === "gdapd" ? "Raindrops" : "Cloudburst"; - $member = getSystemMember($system, $id) ?? [ "name" => $id, "display_name" => $id, "id" => $id ]; - - if ($member["name"] === "unknown") { - return str_replace("%1", $lang["debug"]["unknown"] . " (" . $systemName . ")", $lang["debug"]["images"]); - } else { - return str_replace("%1", getMiniName($member["display_name"] ?? $member["name"]), $lang["debug"]["images"]); - } - } - - return "<code>$item</code>"; -} - -?> - -<br> -<div class="container"> - <?php $data = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/includes/data/refresh.json"), true); ?> - - <div id="page-content"> - <h2><?= $pages["debug"]["name"][$lang["_name"]] ?></h2> - <p><?= $lang["debug"]["description"] ?></p> - - <?php if (time() - $data["timestamp"] > 360): ?> - <div class="alert alert-warning"> - <p> - <b><?= $lang["debug"]["warning"]["title"] ?></b> - </p> - <?= $lang["debug"]["warning"]["intro"] ?> - <ul> - <li><?= $lang["debug"]["warning"]["list"][0] ?></li> - <li><?= $lang["debug"]["warning"]["list"][1] ?></li> - <li><?= $lang["debug"]["warning"]["list"][2] ?></li> - </ul> - <?= $lang["debug"]["warning"]["admin"] ?> - </div> - <?php endif; ?> - - <h4><?= $lang["debug"]["general_title"] ?></h4> - <ul> - <li><b><?= $lang["debug"]["time"] ?></b> <?php $dt = DateTime::createFromFormat('U.u', $data["timestamp"]); echo($dt->format("l j F Y, G:i:s.u T")); ?></li> - <li><b><?= $lang["debug"]["duration"] ?></b> <?= round($data["duration"] * 1000) ?> ms</li> - <li><b><?= $lang["debug"]["long"] ?></b> <?= itemToName(array_search(max(array_values($data["times"])), $data["times"])) ?? "-" ?> (<?= round(max(array_values($data["times"])) * 1000) ?> ms, <?= round((max(array_values($data["times"])) / $data["duration"]) * 100, 2) ?>%)</li> - </ul> - - <h4 id="times"><?= $lang["debug"]["times"] ?></h4> - <div> - <?php foreach ($data["times"] as $item => $time): ?><span class="element tooltip-nohelp" title="<b><?= itemToName($item) ?></b><br>(<?= round($time * 1000) ?> ms)" data-bs-toggle="tooltip" data-bs-html="true" style="opacity:.75;display:inline-block;background:#<?= substr(md5($item), 0, 6) ?>;height:8px;margin:4px 0;width:<?= ($time / $data["duration"]) * 100 ?>%"></span><?php endforeach; ?> - </div> - <ul> - <?php foreach ($data["times"] as $item => $time): ?> - <li><b><?= itemToName($item) ?>:</b> <?= round($time * 1000) ?> ms</li> - <?php endforeach; ?> - </ul> - - <h4 id="failures"><?= $lang["debug"]["failures"] ?></h4> - <?php if (count($data["restored"]) < 1): ?> - <p><i><?= $lang["debug"]["no_failure"] ?></i></p> - <?php else: ?> - <p><?= $lang["debug"]["failure"] ?></p> - <ul> - <?php foreach ($data["restored"] as $item): ?> - <li><code><?= $item ?></code></li> - <?php endforeach; ?> - </ul> - <?php endif; ?> - </div> -</div> - -<style> - .element:hover { - margin: 0 !important; - height: 16px !important; - opacity: 1 !important; - } - - .element { - transition: margin 200ms, height 200ms, opacity 200ms; - } -</style> - -<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?> diff --git a/pages/jobs.inc b/pages/jobs.inc new file mode 100644 index 0000000..ae1405d --- /dev/null +++ b/pages/jobs.inc @@ -0,0 +1,123 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; +require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; + +$history = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/history.json"), true); + +?> + +<style> + .list-group-item { + color: #fff; + background-color: #222; + border: 1px solid rgba(255, 255, 255, .125); + } + + .list-group-item.disabled { + color: #fff; + background-color: #222; + border-color: rgba(255, 255, 255, .125); + opacity: .75; + } + + .list-group-item:hover { + background-color: #252525; + color: #ddd; + } + + .list-group-item:active, .list-group-item:focus { + background-color: #272727; + color: #bbb; + } + + details[open] summary { + font-weight: bold; + } + + pre { + background: #000000; + color: #ffffff; + padding: 10px 20px; + margin-top: 10px; + } + + pre.last { + margin-bottom: 0; + } + + .tracking li { + margin-bottom: 5px; + } + + .tracking li:nth-last-child(1), .tracking { + margin-bottom: 0 !important; + } +</style> + +<br> +<div class="container"> + <div id="page-content"> + <h2>Jobs history</h2> + + <div class="list-group"> + <?php foreach ($history as $item): ?> + <details class="list-group-item"> + <summary style="list-style: none; display: grid; grid-template-columns: 3fr repeat(2, 1fr);"> + <div><?= $item["name"] ?></div> + <div><?= timeAgo($item["tracking"]["queue"]) ?></div> + <div><?php if ($item["completed"]): ?><span class="text-success" style="filter: invert(1) hue-rotate(180deg);">Completed</span><?php else: ?><span class="text-danger" style="filter: invert(1) hue-rotate(180deg);">Failed</span><?php endif; ?></div> + </summary> + + <div class="list-group" style="margin-top: 10px;"> + <div class="list-group-item"> + <p> + <b>Duration:</b> <?= $item["time"] ?>ms + <b></b> + </p> + + <b>Console output:</b> + <pre>โ<?= $item["output"] ?></pre> + + <?php if (isset($item["error"])): ?> + <b>Server error message:</b> + <pre>โ<?= $item["error"] ?></pre> + <?php endif; ?> + + <b>Job lifetime:</b> + <ul class="tracking"> + <li><b>Queued by PHP</b><br><?php + $d = explode("|", substr(date('M jS Y, G:i|s.u', strtotime($item["tracking"]["queue"])), 0, -3)); + $d[1] = (string)((float)$d[1]); + echo($d[0] . ":" . $d[1]); + ?></li> + <?php if (isset($item["tracking"]["pickup"])): ?><li><b>Picked up by the runner</b><br><?php + $d = explode("|", substr(date('M jS Y, G:i|s.u', strtotime($item["tracking"]["pickup"])), 0, -3)); + $d[1] = (string)((float)$d[1]); + echo($d[0] . ":" . $d[1]); + ?></li><?php endif; ?> + <?php if (isset($item["tracking"]["start"])): ?><li><b>Started</b><br><?php + $d = explode("|", substr(date('M jS Y, G:i|s.u', strtotime($item["tracking"]["start"])), 0, -3)); + $d[1] = (string)((float)$d[1]); + echo($d[0] . ":" . $d[1]); + ?></li><?php endif; ?> + <?php if (isset($item["tracking"]["end"])): ?><li><b><?= $item["completed"] ? "Finished" : "Failed" ?></b><br><?php + $d = explode("|", substr(date('M jS Y, G:i|s.u', strtotime($item["tracking"]["end"])), 0, -3)); + $d[1] = (string)((float)$d[1]); + echo($d[0] . ":" . $d[1]); + ?></li><?php endif; ?> + <?php if (isset($item["tracking"]["logged"])): ?><li><b>Tracking logged</b><br><?php + $d = explode("|", substr(date('M jS Y, G:i|s.u', strtotime($item["tracking"]["logged"])), 0, -3)); + $d[1] = (string)((float)$d[1]); + echo($d[0] . ":" . $d[1]); + ?></li><?php endif; ?> + </ul> + </div> + </div> + </details> + <?php endforeach; ?> + </div> + </div> +</div> + +<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>
\ No newline at end of file |