2013-08-24 17:47:25 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-08-25 18:38:39 +02:00
|
|
|
from flask import Flask, render_template, redirect, url_for, request, session
|
2013-08-24 17:47:25 +02:00
|
|
|
import openvpnstatus
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2013-08-25 18:38:39 +02:00
|
|
|
@app.route("/")
|
|
|
|
def index():
|
|
|
|
if "username" in session:
|
|
|
|
return render_template("home.html", username = session["username"])
|
|
|
|
return render_template("login.html")
|
|
|
|
|
|
|
|
@app.route("/login", methods = ["GET", "POST"])
|
|
|
|
def login():
|
|
|
|
if request.method == "POST":
|
2013-08-25 19:59:06 +02:00
|
|
|
if request.form["password"] == "tool":
|
|
|
|
session["username"] = request.form["username"]
|
|
|
|
if 'login' in request.referrer:
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
else:
|
|
|
|
return redirect(request.referrer)
|
2013-08-25 18:38:39 +02:00
|
|
|
else:
|
2013-08-25 19:59:06 +02:00
|
|
|
return 'Error: Wrong username or password! <a href="login">login</a>'
|
2013-08-25 18:38:39 +02:00
|
|
|
return render_template("login.html")
|
|
|
|
|
|
|
|
@app.route("/logout")
|
|
|
|
def logout():
|
|
|
|
session.pop("username", None)
|
|
|
|
return redirect(url_for("index"))
|
2013-08-24 17:47:25 +02:00
|
|
|
|
2013-08-25 18:38:39 +02:00
|
|
|
@app.route("/status")
|
|
|
|
def status():
|
|
|
|
if "username" in session:
|
|
|
|
o = openvpnstatus.openvpnstatus()
|
|
|
|
return render_template("status.html", connections = o.connections, routes = o.routes, username = session["username"])
|
|
|
|
return render_template("login.html")
|
2013-08-24 21:06:19 +02:00
|
|
|
|
2013-08-25 18:38:39 +02:00
|
|
|
@app.route("/form", methods=["GET", "POST"])
|
2013-08-24 21:06:19 +02:00
|
|
|
def formular():
|
2013-08-25 18:38:39 +02:00
|
|
|
if "username" in session:
|
|
|
|
something = "iatren"
|
|
|
|
if request.method == "POST":
|
|
|
|
value = request.form["textfield"]
|
|
|
|
return render_template("footer.html", test=value, test2=value)
|
|
|
|
else:
|
|
|
|
return render_template("form.html")
|
|
|
|
return render_template("login.html")
|
|
|
|
|
|
|
|
|
|
|
|
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
|
2013-08-24 21:06:19 +02:00
|
|
|
|
|
|
|
|
2013-08-25 18:38:39 +02:00
|
|
|
if __name__ == "__main__":
|
2013-08-24 21:06:19 +02:00
|
|
|
app.run(debug=True)
|