comparison web/templog.py @ 485:d68af9e84485

working
author Matt Johnston <matt@ucc.asn.au>
date Thu, 06 Feb 2014 22:45:16 +0800
parents 9950ffa9a79b
children ae5efca89001
comparison
equal deleted inserted replaced
484:4a51e2bf689b 485:d68af9e84485
7 from datetime import datetime, timedelta 7 from datetime import datetime, timedelta
8 import time 8 import time
9 import urllib 9 import urllib
10 import sys 10 import sys
11 import os 11 import os
12 import traceback
13 import fcntl
12 14
13 import bottle 15 import bottle
14 from bottle import route, request, response 16 from bottle import route, request, response
15 17
16 import config 18 import config
17 import log 19 import log
20 import secure
18 21
19 DATE_FORMAT = '%Y%m%d-%H.%M' 22 DATE_FORMAT = '%Y%m%d-%H.%M'
20 ZOOM_SCALE = 2.0 23 ZOOM_SCALE = 2.0
21 24
22 @route('/update', method='post') 25 @route('/update', method='post')
45 start_epoch = time.mktime(start.timetuple()) 48 start_epoch = time.mktime(start.timetuple())
46 return log.graph_png(start_epoch, length_minutes * 60) 49 return log.graph_png(start_epoch, length_minutes * 60)
47 50
48 @route('/set') 51 @route('/set')
49 def set(): 52 def set():
50 return bottle.template('set', inline_data = log.get_params()) 53 return bottle.template('set',
54 inline_data = log.get_params(),
55 csrf_blob = secure.get_csrf_blob())
51 56
52 @route('/set_current.json') 57 @route('/set_current.json')
53 def set_fresh(): 58 def set_fresh():
54 response.set_header('Content-Type', 'application/javascript') 59 response.set_header('Content-Type', 'application/javascript')
55 return log.get_current() 60 return log.get_current()
98 return log.tail_debug_log() 103 return log.tail_debug_log()
99 104
100 @route('/env') 105 @route('/env')
101 def env(): 106 def env():
102 response.set_header('Content-Type', 'text/plain') 107 response.set_header('Content-Type', 'text/plain')
103 return '\n'.join(("%s %s" % k) for k in request.environ.items()) 108 return '\n'.join(traceback.format_stack())
109 #return '\n'.join(("%s %s" % k) for k in request.environ.items())
104 #return str(request.environ) 110 #return str(request.environ)
105 #yield "\n" 111 #yield "\n"
106 #var_lookup = environ['mod_ssl.var_lookup'] 112 #var_lookup = environ['mod_ssl.var_lookup']
107 #return var_lookup("SSL_SERVER_I_DN_O") 113 #return var_lookup("SSL_SERVER_I_DN_O")
108 114
109 @bottle.get('/<filename:re:.*\.js>') 115 @bottle.get('/<filename:re:.*\.js>')
110 def javascripts(filename): 116 def javascripts(filename):
117 response.set_header('Cache-Control', "public, max-age=1296000")
111 return bottle.static_file(filename, root='static') 118 return bottle.static_file(filename, root='static')
112 119
120 @route('/setparams', method='post')
121 def update():
122 post_json = json.loads(request.forms.data)
123
124 csrf_blob = post_json['csrf_blob']
125
126 return str(post_json['params'])
127
128 secure.setup_csrf()
113 129
114 def main(): 130 def main():
115 #bottle.debug(True) 131 #bottle.debug(True)
116 #bottle.run(reloader=True) 132 #bottle.run(reloader=True)
117 bottle.run(server='cgi', reloader=True) 133 bottle.run(server='cgi', reloader=True)