annotate web/index.py @ 335:1e22eaf93620

work on web interface
author Matt Johnston <matt@ucc.asn.au>
date Tue, 12 Jun 2012 23:27:53 +0800
parents 3b821541657d
children 13fcf497f8b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
333
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #!/usr/bin/env python2.7
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
334
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
3 import binascii
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
4 import hmac
335
1e22eaf93620 work on web interface
Matt Johnston <matt@ucc.asn.au>
parents: 334
diff changeset
5 import zlib
334
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
6
333
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 import bottle
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 from bottle import route, request
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
334
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
10 import config
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
11 import log
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
12
333
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 @route('/update', method='post')
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 def update():
334
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
15 enc_lines = request.forms.lines
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
16 mac = request.forms.hmac
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
17
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
18 if hmac.new(config.HMAC_KEY, enc_lines).hexdigest() != mac:
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
19 raise HTTPError(code = 403, output = "Bad key")
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
20
335
1e22eaf93620 work on web interface
Matt Johnston <matt@ucc.asn.au>
parents: 334
diff changeset
21 lines = zlib.decompress(binascii.a2b_base64(enc_lines)).split('\n')
334
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
22
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
23 log.parse(lines)
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
24
Matt Johnston <matt@ucc.asn.au>
parents: 333
diff changeset
25 return "OK"
333
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 @route('/graph.png')
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 def graph():
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 pass
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 @route('/')
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 def top():
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 return bottle.template('top', urlparams=request.query_string)
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 def main():
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 bottle.debug(True)
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 bottle.run(port=9999, reloader=True)
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 if __name__ == '__main__':
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 main()
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41
298e502fdcd4 Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42