summaryrefslogtreecommitdiff
path: root/pages/api/chrome.php
blob: db325117299c4e701ba4ccad817984f793d59bee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn;


if (isset($_GET["e"])) {
    header("Access-Control-Allow-Origin: chrome-extension://foioekefbipjjonpgpbjahmplcealhhg");
} 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/equestria.dev/luna/raw/branch/mane/icons/logo.png" 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/equestria.dev/luna/raw/branch/mane/icons/logo.png" 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();
        case "unique":
            header("Content-Type: text/plain");
            die("Chromebook-" . strtoupper(substr(sha1($_COOKIE['PEH2_SESSION_TOKEN']), 0, 5)));
        default:
            header("Location: /");
            die();
    }
}