devel...
This commit is contained in:
parent
20707946d3
commit
a9d0a707f6
56
app.py
56
app.py
|
@ -1,28 +1,52 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from flask import Flask, render_template, redirect, url_for, abort, request
|
from flask import Flask, render_template, redirect, url_for, request, session
|
||||||
import openvpnstatus
|
import openvpnstatus
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route('/status', methods=['GET', 'POST'])
|
@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":
|
||||||
|
session["username"] = request.form["username"]
|
||||||
|
if 'login' in request.referrer:
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
else:
|
||||||
|
return redirect(request.referrer)
|
||||||
|
return render_template("login.html")
|
||||||
|
|
||||||
|
@app.route("/logout")
|
||||||
|
def logout():
|
||||||
|
session.pop("username", None)
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
@app.route("/status")
|
||||||
def status():
|
def status():
|
||||||
o = openvpnstatus.openvpnstatus()
|
if "username" in session:
|
||||||
return render_template('status.html', connections = o.connections, routes = o.routes)
|
o = openvpnstatus.openvpnstatus()
|
||||||
|
return render_template("status.html", connections = o.connections, routes = o.routes, username = session["username"])
|
||||||
|
return render_template("login.html")
|
||||||
|
|
||||||
@app.route('/socialnerds')
|
@app.route("/form", methods=["GET", "POST"])
|
||||||
def redir():
|
|
||||||
return redirect('https://www.socialnerds.org')
|
|
||||||
|
|
||||||
@app.route('/form', methods=['GET', 'POST'])
|
|
||||||
def formular():
|
def formular():
|
||||||
something = "iatren"
|
if "username" in session:
|
||||||
if request.method == 'POST':
|
something = "iatren"
|
||||||
value = request.form['textfield']
|
if request.method == "POST":
|
||||||
return render_template("footer.html", test=value, test2=value)
|
value = request.form["textfield"]
|
||||||
else:
|
return render_template("footer.html", test=value, test2=value)
|
||||||
return render_template("form.html")
|
else:
|
||||||
|
return render_template("form.html")
|
||||||
|
return render_template("login.html")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
Hello, my dear {{ test2 }}!
|
Hello, my dear {{ test2 }}!
|
||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
<a href="form">form</a> | <a href="status">status</a> | <a href="socialnerds">socialnerds</a>
|
<a href="form">form</a> | <a href="status">status</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block title %}home{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Home</h1>
|
||||||
|
Hello, my dear {{ username }}!
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
{% block head %}
|
||||||
|
<title>{% block title %}socialnerds.org{% endblock %}</title>
|
||||||
|
{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="content">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
<div id="footer">
|
||||||
|
{% block footer %}
|
||||||
|
<br>
|
||||||
|
{% if username %} <a href="/">home</a> | <a href="status">status</a> | <a href="logout">logout</a>{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block title %}login{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Login</h1>
|
||||||
|
<b>Please login:</b><br><br>
|
||||||
|
<form method="post" action="login">
|
||||||
|
username: <input type="text" name="username"><br>
|
||||||
|
password: <input type="password" name="password"><br>
|
||||||
|
<input type="submit" value="login">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -1,7 +1,8 @@
|
||||||
<!doctype html>
|
{% extends "layout.html" %}
|
||||||
<title>OpenVPN Status</title>
|
{% block title %}status{% endblock %}
|
||||||
|
{% block content %}
|
||||||
<h1>OpenVPN Status</h1>
|
<h1>OpenVPN Status</h1>
|
||||||
<form method="post" action="status">
|
<form method="get" action="status">
|
||||||
<input type="submit" value="refresh status">
|
<input type="submit" value="refresh status">
|
||||||
</form>
|
</form>
|
||||||
<h3>Connections:</h3>
|
<h3>Connections:</h3>
|
||||||
|
@ -24,3 +25,4 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
|
Reference in New Issue