forked from jrghnng/owrxantswitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy_backend.php
More file actions
57 lines (49 loc) · 1.43 KB
/
dummy_backend.php
File metadata and controls
57 lines (49 loc) · 1.43 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type");
$method = $_SERVER['REQUEST_METHOD'];
function getRandomAntennaNum() {
return rand(1, 4);
}
if ($method === 'OPTIONS') {
// Respond to preflight request
header("HTTP/1.1 204 No Content");
exit();
}
if ($method === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
if (isset($data['command'])) {
$command = $data['command'];
switch ($command) {
case 'n':
$response = [
'payload' => [
'response' => 'n:' . getRandomAntennaNum()
]
];
break;
case 's':
$response = [
'payload' => [
'response' => (string) getRandomAntennaNum()
]
];
break;
default:
$response = [
'payload' => [
'response' => 'Invalid command'
]
];
break;
}
echo json_encode($response);
} else {
echo json_encode(['error' => 'No command provided']);
}
} else {
echo json_encode(['error' => 'Invalid request method']);
}
?>