-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookiegen.py
85 lines (72 loc) · 2.17 KB
/
cookiegen.py
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
#!/usr/bin/env python
"""one-time cookie generator to contain the credentials"""
import os
import sys
import cgi
import datetime
import Cookie
import shuttle
import json
import struct
print "Content-type: text/html\r\n"
form = cgi.FieldStorage()
if 'user' in form and 'pass' in form:
u = form.getvalue("user")
p = form.getvalue("pass")
if 'r' in form:
routes = form.getvalue('r')
alldata = json.load(open("all.json"))
if type(routes) == str:
rid = [alldata["true"][routes + " AM"][2]]
elif type(routes) == list:
rid = [alldata["true"][r + " AM"][2] for r in routes]
else:
rid = []
k = shuttle.generate_key(u, p, rid)
dt = datetime.datetime.now()
dt += datetime.timedelta(365)
# print "Status: 200 Success"
cookie = Cookie.SimpleCookie()
cookie["skey"] = k
if os.environ['SERVER_PORT'] == 8080:
cookie["skey"]["domain"] = "localhost"
cookie["skey"]["path"] = "/cgi-bin"
else:
cookie["skey"]["domain"] = '.' + os.environ['SERVER_NAME']
cookie["skey"]["path"] = "/shuttle"
cookie["skey"]["expires"] = dt.strftime("%a, %d-%b-%Y %H:%M:%S PST")
if os.environ['SERVER_NAME'].count('.') > 1:
cookie["skey"]["domain"] = os.environ['SERVER_NAME']
else:
cookie["skey"]["domain"] = '.' + os.environ['SERVER_NAME']
if "HTTP_ORIGIN" in os.environ:
origin = os.environ["HTTP_ORIGIN"]
else:
origin = ""
print cookie.output()
# print "Set-Cookie: key=%s; expires={}; path=/shuttle/; domain=cholz.de; version=1" % (
# k, dt.strftime("%a, %d-%b-%Y %H:%M:%S PST"))
# # dt.strftime("%a, %d %b %Y %H:%M:%S +0000"))
print '''<pre>
ready to bookmark:
<a href="%s%s/bookings.py">bookings</a>
</pre>''' % (origin, os.path.dirname(os.environ["SCRIPT_NAME"]))
else:
alldata = json.load(open("all.json"))
routes = [r[:-3] for r in alldata["true"].keys()]
routes.sort()
# print "Content-type: text/html\r\n"
print '''
<pre>
<form method="post">
user <input name="user" type="text" />
pass <input name="pass" type="password" />
<input type="submit" value="submit" />
optional:
'''
for r in routes:
print '<input type="checkbox" name="r" value="%s">%s<br/>' % (r, r)
print '''
</form>
</pre>
'''