-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacceptCrashData.py
More file actions
executable file
·45 lines (33 loc) · 1.31 KB
/
acceptCrashData.py
File metadata and controls
executable file
·45 lines (33 loc) · 1.31 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
#!/usr/bin/python
import sqlite3, cgi, cgitb
from Crypto.PublicKey import RSA
from base64 import b64decode
fOpen = open('/srv/maze/private.pem', 'r')
privateKey = fOpen.read()
rsakey = RSA.importKey(privateKey)
def decrypt(decryptThis):
raw_cipher_data = b64decode(decryptThis)
return unicode(rsakey.decrypt(raw_cipher_data))
dbName = "gameData"
db = sqlite3.connect('/srv/sqlite/data/' + dbName)
cursor = db.cursor()
# Create instance of FieldStorage
crashForm = cgi.FieldStorage()
userName = decrypt(crashForm.getvalue('userName'))
currentLevel = int(decrypt(crashForm.getvalue('currentLevel')))
trackCount = int(decrypt(crashForm.getvalue('trackCount')))
crashNumber = decrypt(crashForm.getvalue('crashNumber'))
crashLocation = decrypt(crashForm.getvalue('crashLocation'))
dateTimeStamp = decrypt(crashForm.getvalue('dateTimeStamp'))
cursor.execute('''INSERT INTO CrashData(userName, currentLevel, trackCount, crashNumber,
crashLocation, dateTimeStamp)
VALUES(?,?,?,?,?,?)''', (userName, currentLevel, trackCount,
crashNumber, crashLocation, dateTimeStamp))
db.commit() #changes are committed to database
db.close()
print "Content-type:text/json\r\n\r\n"
print "{",
keys = crashForm.keys()
for key in keys:
print key, ":\"", crashForm[key].value, "\"", ",",
print "}"