-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacceptSurvey.py
More file actions
executable file
·40 lines (28 loc) · 1.04 KB
/
acceptSurvey.py
File metadata and controls
executable file
·40 lines (28 loc) · 1.04 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
#!/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
surveyForm = cgi.FieldStorage()
userName = decrypt(surveyForm.getvalue('userName'))
surveyID = int(decrypt(surveyForm.getvalue('surveyID')))
dateTimeStamp = decrypt(surveyForm.getvalue('dateTimeStamp'))
cursor.execute('''INSERT INTO SurveyIDData(userName, surveyID, dateTimeStamp)
VALUES(?,?,?)''', (userName, surveyID, dateTimeStamp))
db.commit() #changes are committed to database
db.close()
print "Content-type:text/json\r\n\r\n"
print "{",
keys = surveyForm.keys()
for key in keys:
print key, ":\"", surveyForm[key].value, "\"", ",",
print "}"