-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.py
More file actions
48 lines (36 loc) · 1.51 KB
/
echo.py
File metadata and controls
48 lines (36 loc) · 1.51 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
46
47
48
#!/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
echoForm = cgi.FieldStorage()
userName = decrypt(echoForm.getvalue('userName'))
currentLevel = int(decrypt(echoForm.getvalue('currentLevel')))
trackCount = int(decrypt(echoForm.getvalue('trackCount')))
echoLocation = decrypt(echoForm.getvalue('echoLocation'))
locationType = decrypt(echoForm.getvalue('locationType'))
postEchoAction = decrypt(echoForm.getvalue('postEchoAction'))
correctAction = decrypt(echoForm.getvalue('correctAction'))
echoFile = decrypt(echoForm.getvalue('echoFile'))
dateTimeStamp = decrypt(echoForm.getvalue('dateTimeStamp'))
cursor.execute('''INSERT INTO EchoData(userName, currentLevel, trackCount,
echoLocation, locationType, postEchoAction, correctAction, echoFile, dateTimeStamp)
VALUES(?,?,?,?,?,?,?,?,?)''', (userName, currentLevel, trackCount,
echoLocation, locationType, postEchoAction, correctAction, echoFile, dateTimeStamp))
db.commit() #changes are committed to database
db.close()
print "Content-type:text/json\r\n\r\n"
print "{",
keys = echoForm.keys()
for key in keys:
print key, ":\"", echoForm[key].value, "\"", ",",
print "}"