summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/api.inc.php
blob: 559161babe7281a0158e01706d08ddd6677f004b (plain) (blame)
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
<?php

/*
 * vvv - API to Panel - vvv
 */

HandleParameters();

/**
 * Handles the API parameters.
 */
function HandleParameters()
{

	$get = Request::get('get', 0, 'string');
	$uuid = Request::get('uuid', false, 'string');
	$output = null;
	if ($get === "timestamp") {
		$output = [
			'ts' => ApiPanelFrontend::getLastChangeTs($uuid),
			'now' => round(microtime(true) * 1000),
		];
	} elseif ($get === "machines") {
		$locationIds = LocationInfo::getLocationsOr404($uuid);
		$output = array();
		InfoPanel::appendMachineData($output, $locationIds, true);
		$output = array_values($output);
	} elseif ($get === "config") {
		$type = InfoPanel::getConfig($uuid, $output);
		if ($type === null) {
			http_response_code(404);
			die('Panel not found');
		}
	} elseif ($get === "pcstates") {
		$locationIds = LocationInfo::getLocationsOr404($uuid);
		$output = ApiPanelFrontend::getPcStates($locationIds, $uuid);
	} elseif ($get === "locationtree") {
		$locationIds = LocationInfo::getLocationsOr404($uuid);
		$output = Location::getTree(...$locationIds);
	} elseif ($get === "calendar") {
		$locationIds = LocationInfo::getLocationsOr404($uuid);
		$output = LocationInfo::getCalendar($locationIds, time() + 3);
	} elseif ($get === "manifest") {
		$output = ApiPanelFrontend::generateManifest($uuid);
	} elseif ($get === 'list') {
		$output = ApiExternalPanels::generatePublicPanelList();
	} elseif ($get === 'external-register') {
		$output = ApiExternalPanels::registerDevice();
	} elseif ($get === 'external-checkin') {
		$output = ApiExternalPanels::checkinCallback();
	}
	if ($output !== null) {
		Header('Content-Type: application/json; charset=utf-8');
		echo json_encode($output);
	} else {
		http_response_code(404);
		echo 'Unknown get option';
	}
}