blob: 2e634d39fce03421d32677e4e7f90c6a5f7b9872 (
plain)
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
|
#!/usr/bin/python3
import cgi
import cgitb
import os
import sys
import io
import json
cgitb.enable()
print("Content-Type: text/html")
print("")
cookies = {}
if "HTTP_COOKIE" in os.environ:
for cookie in map(str.strip, str.split(os.environ['HTTP_COOKIE'], ';')):
(key, value) = cookie.split('=')
cookies[key] = value
print("""
<html>
<head><title>Cookie test</title></head>
<body>
<h1>Reflected cookies</h1>
<ul>
""")
for k, v in cookies.items():
print(" <li>{}: {}</li>".format(cgi.escape(k), cgi.escape(v)))
print("""
</ul>
<hr />
<script>""")
print(" var uploaded_cookies = {};".format(json.dumps(cookies)))
print("""
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var counter = getCookie("counter");
if (counter === "") { counter = "0"; }
var uploaded_counter = uploaded_cookies["counter"] || "0";
document.write("<b>Cookie:</b> " + counter + "<br/><b>JSON:</b> " + uploaded_counter + "<br />");
document.cookie = "counter=" + ((parseInt(counter) + 1).toString());
</script>
</body>
</html>
""")
|