aboutsummaryrefslogtreecommitdiff
path: root/admin/private/permissions.php
blob: 8e6f456c247ce1f18d47b740c516e94849481bf1 (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
<?php

$perms = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/admin/private/permissions.json"), true);

if (isset($_OVERRIDEPERMISSION)) {
    $requested = $_OVERRIDEPERMISSION;
} else {
    $requested = substr(explode("/", $_SERVER["PHP_SELF"])[count(explode("/", $_SERVER["PHP_SELF"])) - 1], 0, -4);
}

$permsOkay = false;
foreach ($perms as $user => $uperms) {
    if ($user === $_DATA['id']) {
        if (in_array($requested, $uperms) || in_array("*", $uperms)) {
            $permsOkay = true;
        }
    }
}

if (!$permsOkay && $requested !== "denied") {
    if (isset($_PERMSFORAPI) && $_PERMSFORAPI) {
        $_GET['_'] = "api." . $requested;
        ob_end_clean();
        require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/panes/denied.php";
        die();
    } else if (isset($_PERMSFORSSO) && $_PERMSFORSSO) {
        $_GET['_'] = "sso." . $requested;
        ob_end_clean();
        require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/panes/denied.php";
        die();
    } else {
        $_GET['_'] = "dom." . $requested;
        ob_end_clean();
        require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/panes/denied.php";
        die();
    }
}