/
LogixNG_WebRequest_Test.php
133 lines (99 loc) · 3.41 KB
/
LogixNG_WebRequest_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// This php script is used to test and demonstrate the LogixNG action WebRequest.
error_reporting(E_ALL);
ini_set("display_errors", 1);
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
} else {
$action = "menu";
}
if ($action === "menu") {
echo <<<END_STARTPAGE
<html>
<head>
<title>Test of JMRI LogixNG action WebRequest</title>
</head>
<body>
<h1>Test of JMRI LogixNG action WebRequest</h1>
<p>
<h2>Throw turnout</h2>
Throw turnout <a href="?action=throw&turnout=Chicago32">Chicago32</a><br>
Throw turnout <a href="?action=throw&turnout=MiamiWest">MiamiWest</a><br>
Throw turnout <a href="?action=throw&turnout=TorontoFirst">TorontoFirst</a><br>
</p>
<h2>Test cookies</h2>
Set cookie <a href="?action=cookies&cookie=Blue">Blue</a><br>
Set cookie <a href="?action=cookies&cookie=Green">Green</a><br>
Set cookie <a href="?action=cookies&cookie=Yellow">Yellow</a><br>
<a href="?action=cookies&cookie=delete_all">Delete cookies</a><br>
</p>
<p>
<h2>Login</h2>
<form action="#" method="post">
<input type="hidden" name="action" value="login">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
</p>
</body>
</html>
END_STARTPAGE;
} else if ($action === "throw") {
$turnout = $_GET["turnout"];
switch ($turnout) {
case "Chicago32":
echo "Turnout Chicago32 is thrown\n";
exit(0);
case "MiamiWest":
echo "Turnout MiamiWest is thrown\n";
exit(0);
case "TorontoFirst":
echo "Turnout TorontoFirst is thrown\n";
exit(0);
default:
echo "Unknown turnout!\n";
exit(0);
}
} else if ($action === "cookies") {
$cookie = $_GET["cookie"];
$cookies = "";
foreach ($_COOKIE as $key => $value) {
if ($cookies !== "") $cookies .= ", ";
$cookies .= $key . "=" . $value;
}
$fifteenDaysFromNow = time() + 86400 * 15;
switch ($cookie) {
case "Blue":
setcookie("Blue", "BlueBlue!", $fifteenDaysFromNow);
echo "Cookie Blue is set. Cookies from client: $cookies\n";
exit(0);
case "Green":
setcookie("Green", "GreenGreen!", $fifteenDaysFromNow);
echo "Cookie Green is set. Cookies from client: $cookies\n";
exit(0);
case "Yellow":
setcookie("Yellow", "YellowYellow!", $fifteenDaysFromNow);
echo "Cookie Yellow is set. Cookies from client: $cookies\n";
exit(0);
case "delete_all":
foreach ($_COOKIE as $key => $value) {
$cookies .= $key . "=" . $value;
setcookie($key, $value, time()-3600);
}
echo "All cookies have been deleted!\n";
exit(0);
default:
echo "Unknown cookie!\n";
exit(0);
}
} else if ($action === "login") {
$fname = $_POST["fname"];
$lname = $_POST["lname"];
echo "Logged in. First name: $fname, last name: $lname\n";
exit(0);
}
// phpinfo();
?>