comparison web/index.py @ 28:e3e0ed7758f9

hmac
author Matt Johnston <matt@ucc.asn.au>
date Tue, 12 Jun 2012 00:35:23 +0800
parents dbbd503119ba
children 048143905092
comparison
equal deleted inserted replaced
27:dbbd503119ba 28:e3e0ed7758f9
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python2.7
2
3 import binascii
4 import hmac
2 5
3 import bottle 6 import bottle
4 from bottle import route, request 7 from bottle import route, request
5 8
9 import config
10 import log
11
6 @route('/update', method='post') 12 @route('/update', method='post')
7 def update(): 13 def update():
8 return "Done" 14 enc_lines = request.forms.lines
15 mac = request.forms.hmac
16
17 if hmac.new(config.HMAC_KEY, enc_lines).hexdigest() != mac:
18 raise HTTPError(code = 403, output = "Bad key")
19
20 lines = binascii.a2b_base64(enc_lines).split('\n')
21
22 log.parse(lines)
23
24 return "OK"
9 25
10 @route('/graph.png') 26 @route('/graph.png')
11 def graph(): 27 def graph():
12 pass 28 pass
13 29