devel...
This commit is contained in:
parent
20707946d3
commit
a9d0a707f6
56
app.py
56
app.py
@ -1,28 +1,52 @@
|
||||
#!/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
|
||||
|
||||
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():
|
||||
o = openvpnstatus.openvpnstatus()
|
||||
return render_template('status.html', connections = o.connections, routes = o.routes)
|
||||
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('/socialnerds')
|
||||
def redir():
|
||||
return redirect('https://www.socialnerds.org')
|
||||
|
||||
@app.route('/form', methods=['GET', 'POST'])
|
||||
@app.route("/form", methods=["GET", "POST"])
|
||||
def formular():
|
||||
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")
|
||||
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")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
|
@ -5,6 +5,6 @@
|
||||
Hello, my dear {{ test2 }}!
|
||||
</p>
|
||||
<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 %}
|
||||
{% endblock %}
|
||||
|
6
templates/home.html
Normal file
6
templates/home.html
Normal file
@ -0,0 +1,6 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block title %}home{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Home</h1>
|
||||
Hello, my dear {{ username }}!
|
||||
{% endblock %}
|
19
templates/layout.html
Normal file
19
templates/layout.html
Normal file
@ -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>
|
11
templates/login.html
Normal file
11
templates/login.html
Normal file
@ -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>
|
||||
<title>OpenVPN Status</title>
|
||||
{% extends "layout.html" %}
|
||||
{% block title %}status{% endblock %}
|
||||
{% block content %}
|
||||
<h1>OpenVPN Status</h1>
|
||||
<form method="post" action="status">
|
||||
<form method="get" action="status">
|
||||
<input type="submit" value="refresh status">
|
||||
</form>
|
||||
<h3>Connections:</h3>
|
||||
@ -24,3 +25,4 @@
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user