diff options
Diffstat (limited to 'pages/api')
-rw-r--r-- | pages/api/chrome.php | 87 | ||||
-rw-r--r-- | pages/api/close.php | 1 | ||||
-rw-r--r-- | pages/api/cloudburst-img.php | 2 | ||||
-rw-r--r-- | pages/api/computer.php | 8 | ||||
-rw-r--r-- | pages/api/data.php | 4 | ||||
-rw-r--r-- | pages/api/docs.php | 2 | ||||
-rw-r--r-- | pages/api/emergency-real.php | 2 | ||||
-rw-r--r-- | pages/api/emergency.php | 2 | ||||
-rw-r--r-- | pages/api/fronter.php | 2 | ||||
-rw-r--r-- | pages/api/me.php | 2 | ||||
-rw-r--r-- | pages/api/plex.php | 4 | ||||
-rw-r--r-- | pages/api/pluralkit-integration.php | 120 | ||||
-rw-r--r-- | pages/api/ponytown.php | 2 | ||||
-rw-r--r-- | pages/api/raindrops-img.php | 2 | ||||
-rw-r--r-- | pages/api/save-private.php | 2 | ||||
-rw-r--r-- | pages/api/save.php | 2 | ||||
-rw-r--r-- | pages/api/token.php | 2 | ||||
-rw-r--r-- | pages/api/wakeup-real.php | 2 | ||||
-rw-r--r-- | pages/api/wakeup.php | 2 |
19 files changed, 155 insertions, 95 deletions
diff --git a/pages/api/chrome.php b/pages/api/chrome.php new file mode 100644 index 0000000..0be8a94 --- /dev/null +++ b/pages/api/chrome.php @@ -0,0 +1,87 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; + + +if (isset($_GET["e"])) { + header("Access-Control-Allow-Origin: chrome-extension://klenhenmabddpffgdaijdkjmfkkafbno"); +} else { + header("Access-Control-Allow-Origin: *"); +} + +header("Access-Control-Allow-Credentials: true"); +header("Access-Control-Allow-Methods: *"); +header("Access-Control-Allow-Headers: *"); + +if (!isset($_GET["t"])) { + header("Content-Type: application/json"); + + if ($isLoggedIn) { + die("true"); + } else { + die("false"); + } +} else { + switch ($_GET["t"]) { + case "onboarding": + header("Content-Type: text/html"); + + ?> +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="icon" href="https://git.equestria.dev/repo-avatars/1c0dad449a8e21ad16fa0efb1426c1a3301b1f26a8cb3b3902eec88bb568e34c" type="image/png"> + <title>Luna for Chrome OS</title> + <style> + html, body { + background-color: #0d0b16; + color: white; + font-family: sans-serif; + overflow: hidden; + } + + button:hover { + opacity: .75; + } + + button:active { + opacity: .5; + } + </style> +</head> +<body> +<div style="max-width: 65vw; margin-left: auto; margin-right: auto; height: 100vh; display: flex; align-items: center; justify-content: center; text-align: center;"> + <div> + <img src="https://git.equestria.dev/repo-avatars/1c0dad449a8e21ad16fa0efb1426c1a3301b1f26a8cb3b3902eec88bb568e34c" width="128px"> + <h1>Please login to Cold Haze</h1> + <p>To proceed with activating Luna on this Chromebook, you need to login to Cold Haze. You also need to make sure you properly enroled this computer into Chrome Enterprise.</p> + <button onclick='window.open("https://ponies.equestria.horse/-/login/?return=/api/close&mini", "_blank", "popup,top=100,width=100,height:250")' style="cursor: pointer; background: #5958ad; color: white; border: none; padding: 5px 10px; border-radius: 5px;">Login</button> + </div> +</div> + +<script> + setTimeout(async () => { + if (JSON.parse(await (await fetch("https://ponies.equestria.horse/api/chrome")).text())) { + window.close(); + } + }); + + setInterval(async () => { + if (JSON.parse(await (await fetch("https://ponies.equestria.horse/api/chrome")).text())) { + window.close(); + } + }, 5000); +</script> +</body> +</html> +<?php + + die(); + default: + header("Location: /"); + die(); + } +}
\ No newline at end of file diff --git a/pages/api/close.php b/pages/api/close.php new file mode 100644 index 0000000..07d1cff --- /dev/null +++ b/pages/api/close.php @@ -0,0 +1 @@ +<script>window.close();</script>
\ No newline at end of file diff --git a/pages/api/cloudburst-img.php b/pages/api/cloudburst-img.php index 1967a90..7d22aad 100644 --- a/pages/api/cloudburst-img.php +++ b/pages/api/cloudburst-img.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/fronters.json"), true); $url = isset($fronters['members'][0]) ? ($fronters['members'][0]["avatar_url"] ? $_SERVER['DOCUMENT_ROOT'] . getAsset("ynmuc", $fronters['members'][0]["id"]) : $_SERVER['DOCUMENT_ROOT'] . "/uploads/raindrops.png") : $_SERVER['DOCUMENT_ROOT'] . "/uploads/raindrops.png"; diff --git a/pages/api/computer.php b/pages/api/computer.php index d3ec15a..8261fa8 100644 --- a/pages/api/computer.php +++ b/pages/api/computer.php @@ -1,12 +1,16 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $_PROFILE; +if (isset($_GET["chrome"])) { + header("Access-Control-Allow-Origin: chrome-extension://klenhenmabddpffgdaijdkjmfkkafbno"); +} + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; if (!$isLoggedIn) header("Location: /-/login") and die(); $request_raw = file_get_contents('php://input'); $json_object = json_decode($request_raw, true); -$host = md5($json_object['host']); +$host = md5($json_object['host'] ?? $_GET["host"]); switch ($_GET['type']) { case "heartbeat": diff --git a/pages/api/data.php b/pages/api/data.php index 0a1b01b..eb07824 100644 --- a/pages/api/data.php +++ b/pages/api/data.php @@ -1,7 +1,7 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.inc"; if (!$isLoggedIn) header("Location: /-/login") and die(); if (!isset($_GET['f']) || !file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $_GET['f'])) { diff --git a/pages/api/docs.php b/pages/api/docs.php index 89e9216..d279765 100644 --- a/pages/api/docs.php +++ b/pages/api/docs.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; if (!$isLoggedIn) header("Location: /-/login") and die(); $request_raw = file_get_contents('php://input'); diff --git a/pages/api/emergency-real.php b/pages/api/emergency-real.php index 2dd7172..05bbaf7 100644 --- a/pages/api/emergency-real.php +++ b/pages/api/emergency-real.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; if (!$isLoggedIn) header("Location: /-/login") and die(); global $_PROFILE; diff --git a/pages/api/emergency.php b/pages/api/emergency.php index e0726e7..ff79834 100644 --- a/pages/api/emergency.php +++ b/pages/api/emergency.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; if (!$isLoggedIn) header("Location: /-/login") and die(); global $_PROFILE; diff --git a/pages/api/fronter.php b/pages/api/fronter.php index b380a56..9ef5571 100644 --- a/pages/api/fronter.php +++ b/pages/api/fronter.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $isLowerLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $isLowerLoggedIn; if (!$isLoggedIn || $isLowerLoggedIn) { header("Location: /-/login"); die(); diff --git a/pages/api/me.php b/pages/api/me.php index 817b106..215e1cf 100644 --- a/pages/api/me.php +++ b/pages/api/me.php @@ -2,7 +2,7 @@ $app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $isLowerLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $isLowerLoggedIn; if (!$isLoggedIn && !$isLowerLoggedIn) header("Location: /-/login") and die(); global $_PROFILE; diff --git a/pages/api/plex.php b/pages/api/plex.php index 6d7ad8f..a2fa739 100644 --- a/pages/api/plex.php +++ b/pages/api/plex.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/random.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc"; $app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); function formatTitle($metadata) { @@ -48,8 +48,6 @@ if ($payload["Metadata"]["type"] === "track") { file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/cache/" . $id . ".jpg", file_get_contents("https://plex.equestria.dev" . $payload["Metadata"]["grandparentThumb"] . "?X-Plex-Token=" . $app["plex"])); } -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/.files.json", json_encode($_FILES)); - if ($payload["event"] === "playback.started" || $payload["event"] === "media.play") { $hookObject = json_encode([ "username" => "Plex", diff --git a/pages/api/pluralkit-integration.php b/pages/api/pluralkit-integration.php index 0793873..f5bb4dd 100644 --- a/pages/api/pluralkit-integration.php +++ b/pages/api/pluralkit-integration.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/agewarning.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/agewarning.inc"; $app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); $user = $_GET['user'] ?? null; @@ -86,86 +86,56 @@ if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || } } - if ($system !== $app["other"]["id"] || !isset($app["other"])) { - if (count($fronters["members"]) > 1) { - $context = stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: 🐴 Switch occurred in the $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 the $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 the $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 (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 ($system === "gdapd") { $topic = "public-switches-raindrops"; - - if (count($fronters["members"]) > 0) { - file_get_contents('https://' . $ntfy["server"] . '/public-switches-fr', false, stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: 🐴 $name vient de switch\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Voir sur Cold Haze, https://fr.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"]) . " est désormais au front" - ] - ])); - } else { - file_get_contents('https://' . $ntfy["server"] . '/public-switches-fr', false, stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: 🐴 $name vient de switch\r\n" . - "Priority: default\r\n" . - "Tags: switch\r\n" . - "Actions: view, Voir sur Cold Haze, https://fr.equestria.horse/, clear=true\r\n" . - "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => "Le poney de trait est désormais au front" - ] - ])); - } } else if ($system === "ynmuc") { $topic = "public-switches-cloudburst"; } else { diff --git a/pages/api/ponytown.php b/pages/api/ponytown.php index f41ac01..e75ea33 100644 --- a/pages/api/ponytown.php +++ b/pages/api/ponytown.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $_PROFILE; global $isLowerLoggedIn; global $app; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; global $isLowerLoggedIn; global $app; if (!$isLoggedIn && !$isLowerLoggedIn) header("Location: /-/login") and die(); $request_raw = file_get_contents('php://input'); diff --git a/pages/api/raindrops-img.php b/pages/api/raindrops-img.php index 4cbac6b..fcf1ae6 100644 --- a/pages/api/raindrops-img.php +++ b/pages/api/raindrops-img.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/fronters.json"), true); $url = isset($fronters['members'][0]) ? ($fronters['members'][0]["avatar_url"] ? $_SERVER['DOCUMENT_ROOT'] . getAsset("gdapd", $fronters['members'][0]["id"]) : $_SERVER['DOCUMENT_ROOT'] . "/uploads/raindrops.png") : $_SERVER['DOCUMENT_ROOT'] . "/uploads/raindrops.png"; diff --git a/pages/api/save-private.php b/pages/api/save-private.php index de7d505..6843e2a 100644 --- a/pages/api/save-private.php +++ b/pages/api/save-private.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; if (!$isLoggedIn) header("Location: /-/login") and die(); $request_raw = file_get_contents('php://input'); diff --git a/pages/api/save.php b/pages/api/save.php index 2ea3663..abb477d 100644 --- a/pages/api/save.php +++ b/pages/api/save.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $isLowerLoggedIn; global $app; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $isLowerLoggedIn; global $app; if (!$isLoggedIn && !$isLowerLoggedIn) header("Location: /-/login") and die(); $request_raw = file_get_contents('php://input'); diff --git a/pages/api/token.php b/pages/api/token.php index 99b9158..5c80ca3 100644 --- a/pages/api/token.php +++ b/pages/api/token.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; if (!$isLoggedIn) header("Location: /-/login") and die(); header("Content-Type: text/plain"); diff --git a/pages/api/wakeup-real.php b/pages/api/wakeup-real.php index 2267a4e..0467f27 100644 --- a/pages/api/wakeup-real.php +++ b/pages/api/wakeup-real.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; if (!$isLoggedIn) header("Location: /-/login") and die(); global $_PROFILE; diff --git a/pages/api/wakeup.php b/pages/api/wakeup.php index 69b0a68..c338b9a 100644 --- a/pages/api/wakeup.php +++ b/pages/api/wakeup.php @@ -1,6 +1,6 @@ <?php -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; if (!$isLoggedIn) header("Location: /-/login") and die(); global $_PROFILE; |