27
|
1 #!/usr/bin/env python2.7 |
|
2 |
28
|
3 import binascii |
|
4 import hmac |
29
|
5 import zlib |
28
|
6 |
27
|
7 import bottle |
|
8 from bottle import route, request |
|
9 |
28
|
10 import config |
|
11 import log |
|
12 |
27
|
13 @route('/update', method='post') |
|
14 def update(): |
28
|
15 enc_lines = request.forms.lines |
|
16 mac = request.forms.hmac |
|
17 |
|
18 if hmac.new(config.HMAC_KEY, enc_lines).hexdigest() != mac: |
|
19 raise HTTPError(code = 403, output = "Bad key") |
|
20 |
29
|
21 lines = zlib.decompress(binascii.a2b_base64(enc_lines)).split('\n') |
28
|
22 |
|
23 log.parse(lines) |
|
24 |
|
25 return "OK" |
27
|
26 |
|
27 @route('/graph.png') |
|
28 def graph(): |
|
29 pass |
|
30 |
|
31 @route('/') |
|
32 def top(): |
|
33 return bottle.template('top', urlparams=request.query_string) |
|
34 |
|
35 def main(): |
|
36 bottle.debug(True) |
|
37 bottle.run(port=9999, reloader=True) |
|
38 |
|
39 if __name__ == '__main__': |
|
40 main() |
|
41 |
|
42 |