annotate web/index.py @ 29:048143905092

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