333
|
1 #!/usr/bin/env python2.7 |
|
2 |
334
|
3 import binascii |
|
4 import hmac |
335
|
5 import zlib |
334
|
6 |
333
|
7 import bottle |
|
8 from bottle import route, request |
|
9 |
334
|
10 import config |
|
11 import log |
|
12 |
333
|
13 @route('/update', method='post') |
|
14 def update(): |
334
|
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 |
335
|
21 lines = zlib.decompress(binascii.a2b_base64(enc_lines)).split('\n') |
334
|
22 |
|
23 log.parse(lines) |
|
24 |
|
25 return "OK" |
333
|
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 |