-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.php
72 lines (61 loc) · 1.4 KB
/
test.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// test responses
$adminCode = "TESTY";
$validControllers = array(
'headTilt',
'headTurn',
'armElbowLeft',
'armHandOneLeft',
'armHandTwoLeft',
'armElbowRight',
'armHandOneRight',
'armHandTwoRight',
'backShoulderLeft',
'backShoulderRight',
'back',
'legKneeLeft',
'legKneeRight',
'legHeelLeft',
'legHeelRight'
);
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
header("HTTP/1.0 404 Not Found");
exit();
}
$token = $_GET[1];
$controller = $_GET[2];
$motion = $_GET[3];
// if token is not 5 digits
if (strlen($token) !==5) {
header("HTTP/1.0 404 Not Found");
exit();
}
// TODO: fetch current stored code here
session_start();
$storedCode = $_SESSION['storedCode'];
// used to check to ensure the user has the valid token (avoid input errors)
// token/validate/XXXXX
if ($token === 'token' && $controller == 'validate')
// in this case, token is actually stored in a different place
$token = $_GET[3];
if ($token === $adminCode) {
$guestCode = 'GUEST';
echo $guestCode;
header("HTTP/1.0 200 Ok");
exit();
} else if ($token == $storedCode) {
header("HTTP/1.0 200 Ok");
exit();
} // else falls out to next block
}
// ensure the token is valid
if ($token !== $storedCode) {
header("HTTP/1.0 401 Unauthorized");
exit();
}
// verify controller
if (!in_array($validControllers, $controller))
header("HTTP/1.0 404 Not found");
exit();
}
?>