-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
43 lines (40 loc) · 1.11 KB
/
router.php
File metadata and controls
43 lines (40 loc) · 1.11 KB
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
<?php
declare(strict_types=1);
// Get the helix IP from the environment variables.
$helixIp = getenv('HELIXIP');
// This is a list of Helix API functions that will be proxied to the Helix.
$apiFunctions = [
'/getStatus',
'/getFiles',
'/playFile',
'/Event',
'/getTracks',
'/playTrack',
'/setVolume',
'/pickZone',
'/getGenericSettings',
];
if (isset($_SERVER["PATH_INFO"]) && in_array($_SERVER["PATH_INFO"], $apiFunctions)) {
// Proxy the API call to the Helix.
$url = 'http://' . $helixIp . $_SERVER['REQUEST_URI'];
$ch = curl_init();
$user_agent = "Mozilla/4.0";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$contents = curl_exec($ch);
curl_close($ch);
print $contents;
}
elseif ('/favicon.ico' === $_SERVER["REQUEST_URI"]) {
// Return favicon.
header("Content-type: image/x-icon");
readfile('favicon.ico');
}
else {
// Return the index.html page.
include 'index.html';
}