Mercurial > farol > farol
comparison farol/main.py @ 3:3478e20885fd 0.1
Add a ReverseProxy and fix the cache path everywhere
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Wed, 24 Sep 2014 17:46:44 +0200 |
parents | 63b00c10ada8 |
children | 8f41bb7f4681 |
comparison
equal
deleted
inserted
replaced
2:fe1918b6e3e0 | 3:3478e20885fd |
---|---|
36 from werkzeug import secure_filename | 36 from werkzeug import secure_filename |
37 | 37 |
38 from .session import get_current, set_current, has_current, del_current, document_required | 38 from .session import get_current, set_current, has_current, del_current, document_required |
39 from .vulnerability import vulnerability | 39 from .vulnerability import vulnerability |
40 from .producttree import producttree | 40 from .producttree import producttree |
41 from .proxy import ReverseProxied | |
41 | 42 |
42 app = Flask(__name__, instance_relative_config=True) | 43 app = Flask(__name__, instance_relative_config=True) |
43 app.config.from_object('farol.config.Config') | 44 app.config.from_object('farol.config.Config') |
44 app.config.from_pyfile('farol.cfg', silent=True) | 45 app.config.from_pyfile('farol.cfg', silent=True) |
45 | 46 |
46 app.register_blueprint(vulnerability, url_prefix='/vulnerability') | 47 app.register_blueprint(vulnerability, url_prefix='/vulnerability') |
47 app.register_blueprint(producttree, url_prefix='/producttree') | 48 app.register_blueprint(producttree, url_prefix='/producttree') |
49 | |
50 app.wsgi_app = ReverseProxied(app.wsgi_app) | |
48 | 51 |
49 @app.context_processor | 52 @app.context_processor |
50 def cache_content(): | 53 def cache_content(): |
51 """ List the documents in cache """ | 54 """ List the documents in cache """ |
52 dirname = app.config.get('CACHE_DIRECTORY', | 55 dirname = app.config.get('CACHE_DIRECTORY', |
352 if request.method != 'POST': | 355 if request.method != 'POST': |
353 return render_template('save.j2', id_=get_current()._tracking._identification._id) | 356 return render_template('save.j2', id_=get_current()._tracking._identification._id) |
354 # Get some kind of filename, and save the cvrf on cache (disk) | 357 # Get some kind of filename, and save the cvrf on cache (disk) |
355 path = secure_filename(request.form['fname']) | 358 path = secure_filename(request.form['fname']) |
356 path, _ = os.path.splitext(path) | 359 path, _ = os.path.splitext(path) |
357 with open(os.path.join(app.config['CACHE_DIRECTORY'], path + '.xml'), 'wt') as f: | 360 dirname = app.config.get('CACHE_DIRECTORY', |
361 os.path.join(app.instance_path, '_cache')) | |
362 with open(os.path.join(dirname, path + '.xml'), 'wt') as f: | |
358 f.write(render_cvrf(get_current(), 'cvrf.j2').encode('utf-8')) | 363 f.write(render_cvrf(get_current(), 'cvrf.j2').encode('utf-8')) |
359 flash('File saved as %s' % path) | 364 flash('File saved as %s' % path) |
360 del_current() | 365 del_current() |
361 return redirect(url_for('new')) | 366 return redirect(url_for('new')) |
362 | 367 |
365 if request.method != 'POST': | 370 if request.method != 'POST': |
366 if has_current(): | 371 if has_current(): |
367 # Suggest to save first | 372 # Suggest to save first |
368 return render_template('load.j2', element=element) | 373 return render_template('load.j2', element=element) |
369 | 374 |
370 fpath = os.path.join(app.config['CACHE_DIRECTORY'], element+'.xml') | 375 dirname = app.config.get('CACHE_DIRECTORY', |
376 os.path.join(app.instance_path, '_cache')) | |
377 fpath = os.path.join(dirname, element+'.xml') | |
371 with open(fpath, 'rt') as f: | 378 with open(fpath, 'rt') as f: |
372 set_current(parse(f)) | 379 set_current(parse(f)) |
373 os.remove(fpath) | 380 os.remove(fpath) |
374 flash('"%s" has been removed from cache' % element) | 381 flash('"%s" has been removed from cache' % element) |
375 # Get some kind of id, and load the file. | 382 # Get some kind of id, and load the file. |