summaryrefslogtreecommitdiff
path: root/pages/api/session.php
blob: 25d833d5fa798964683aa2e57c4b18e0b740a649 (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
<?php

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

header("Content-Type: application/json");
global $token;

if (isset($_GET["raw"])) {
    die(json_encode(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token)), true), JSON_PRETTY_PRINT));
} else {
    if  (!$isLoggedIn || $isLowerLoggedIn) {
        die(json_encode([
            "name" => null,
            "created" => null,
            "last_seen" => null,
            "seen_at" => null
        ], JSON_PRETTY_PRINT));
    }

    $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token)), true);

    die(json_encode([
        "name" => $data["name"],
        "created" => date('c', $data["created"]),
        "last_seen" => date('c', $data["last"]),
        "seen_at" => array_keys($data["addresses"] ?? [])
    ], JSON_PRETTY_PRINT));
}