34 lines
No EOL
961 B
Python
34 lines
No EOL
961 B
Python
from flask import request, redirect, session, render_template, send_from_directory, Flask, url_for
|
|
import bleach
|
|
|
|
import generate
|
|
|
|
def sanitize_html(html):
|
|
# Allow only a limited set of tags and attributes
|
|
allowed_tags = ['a', 'b', 'i', 'em', 'strong']
|
|
allowed_attributes = {'a': ['href']}
|
|
return bleach.clean(html, tags=allowed_tags, attributes=allowed_attributes)
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
|
def index():
|
|
if request.method == 'POST':
|
|
subnet = request.form['subnet']
|
|
ip = generate.generate_ip(subnet)
|
|
return redirect(url_for('result', ip=ip))
|
|
return render_template('index.j2')
|
|
|
|
@app.route('/result')
|
|
def result():
|
|
ip = request.args.get('ip')
|
|
ip = sanitize_html(ip)
|
|
return render_template('result.j2', result=ip)
|
|
|
|
@app.route('/assets/style.css')
|
|
def css():
|
|
return send_from_directory('static', 'index.css')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True) |