flask experiment
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

55 lines
1.7 KiB

#!/usr/bin/env python
from flask import Flask, render_template, redirect, url_for, request, session
import openvpnstatus
app = Flask(__name__)
@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":
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)
else:
return 'Error: Wrong username or password! <a href="login">login</a>'
return render_template("login.html")
@app.route("/logout")
def logout():
session.pop("username", None)
return redirect(url_for("index"))
@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")
@app.route("/form", methods=["GET", "POST"])
def formular():
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'
if __name__ == "__main__":
app.run(debug=True)