7 from datetime import datetime
10 def logWrite(request, action, message):
11 url = "http://localhost:5000/log"
13 "date" : datetime.today(),
14 "client_ip" : getClientIp(request),
15 "host" : request.get_host(),
16 "referrer" : request.META.get('HTTP_REFERER'),
21 result = urllib2.urlopen(url, urllib.urlencode(log))
22 content = result.read()
23 except urllib2.URLError as e:
24 print "Error: connection to " + url + " impossible, logging disabled"
26 def spawnThread(request, action, message):
28 # Create a new thread in Daemon mode to send the log entry
29 t = threading.Thread(target=logWrite, args=(request, action, message))
33 def userLogin(request):
34 spawnThread(request, 'userlogin', 'User logged in')
36 def userLogout(request):
37 spawnThread(request, 'userlogout', 'User logged out')
39 def userRegistration(request):
40 spawnThread(request, 'userregistration', 'User registered')
42 def userSliceRequest(request):
43 spawnThread(request, 'userslicerequest', 'User requested a slice')
45 def userContactSupport(request):
46 spawnThread(request, 'usercontactsupport', 'User contacted suppport')
48 def userAddResource(request):
49 spawnThread(request, 'useraddresource', 'User added resource to slice')
51 def userDelResource(request):
52 spawnThread(request, 'userdelresource', 'User removed resource from slice')
55 def getClientIp(request):
56 x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
58 ip = x_forwarded_for.split(',')[0]
60 ip = request.META.get('REMOTE_ADDR')