-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
import os | ||
import json | ||
import secrets | ||
|
||
from flask import Blueprint, session, render_template, request, redirect, url_for | ||
|
||
from helper import sanitize_string | ||
from role_based_access import check_access | ||
from filehandler import sanitize_filename | ||
|
||
|
||
blueprint = Blueprint('pibooth', __name__, template_folder='extensions/pibooth/templates') | ||
|
||
def load_config(): | ||
# In case the config file do not exist, create it | ||
if not os.path.exists("extensions/pibooth/config.json"): | ||
with open("extensions/pibooth/config.json", "+w") as f: | ||
f.write('{"token": "' + secrets.token_urlsafe(64) + '"}') | ||
|
||
with open('extensions/pibooth/config.json', 'r') as config_file: | ||
return json.load(config_file) | ||
|
||
def save_config(config:json): | ||
with open('extensions/pibooth/config.json', 'w') as config_file: | ||
json.dump(config, config_file) | ||
|
||
def get_token(): | ||
config = load_config() | ||
return config.get("token") | ||
|
||
def renew_token(): | ||
config = load_config() | ||
config['token'] = secrets.token_urlsafe(64) | ||
save_config(config) | ||
|
||
@blueprint.route('/', methods=['GET','POST']) | ||
#@login_required | ||
def index(): | ||
user_name = session.get("user_name") | ||
if not check_access(user_name, 9): | ||
return error_page("You are not allowed to access this page") | ||
|
||
if request.method == "POST": | ||
renew_token() | ||
return redirect(url_for("pibooth.index")) | ||
else: | ||
token = get_token() | ||
url = request.host_url + url_for("pibooth.upload_extension_pibooth")[1:] | ||
return render_template('pibooth.html', url=url, token=token) | ||
|
||
|
||
@blueprint.route('/upload', methods=['POST']) | ||
#@login_required | ||
def upload_extension_pibooth(): | ||
req_pibooth_token = request.headers.get('token') | ||
req_pibooth_file = request.files.get('file') | ||
if not req_pibooth_token == get_token(): | ||
return "Token not valid" | ||
elif not req_pibooth_file: | ||
return "No file received" | ||
|
||
file_name = sanitize_filename(req_pibooth_file.filename) | ||
file_path = os.path.join("static/uploads/", file_name) | ||
req_pibooth_file.save(file_path) | ||
return "success" | ||
|
||
def error_page(error_message: str): | ||
error_message = sanitize_string(error_message, extend_allowed_chars=True) | ||
return render_template('errors/error.html', error_message=error_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Management Users</title> | ||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}"> | ||
</head> | ||
<body> | ||
<header> | ||
<div class="menu-container"> | ||
<nav class="menu"> | ||
<a href="{{ url_for('index') }}" {% if request.path == url_for('index') %}class="selected"{% endif %}>Home</a> | ||
<a href="{{ url_for('dashboard') }}" {% if request.path == url_for('dashboard') %}class="selected"{% endif %}>Dashboard</a> | ||
{% if session['user_role'] >= 6 %} | ||
<a href="{{ url_for('management_approve') }}" {% if request.path == url_for('management_approve') %}class="selected"{% endif %}>Approve</a> | ||
<a href="{{ url_for('management_delete') }}" {% if request.path == url_for('management_delete') %}class="selected"{% endif %}>Delete files</a> | ||
{% endif %} | ||
{% if session['user_role'] >= 9 %} | ||
<a href="{{ url_for('management_users') }}" {% if request.path == url_for('management_users') %}class="selected"{% endif %}>Users</a> | ||
<a href="{{ url_for('management_extensions') }}" {% if request.path == url_for('management_extensions') %}class="selected"{% endif %}>Extensions</a> | ||
{% endif %} | ||
<a class="logout-button" href="{{ url_for('logout') }}">Logout</a> | ||
</nav> | ||
</div> | ||
</header> | ||
<div class="head-container"> | ||
</div> | ||
|
||
<h1>Pibooth configuration</h1> | ||
<div class="extension-container"> | ||
<div class="extension-management"> | ||
<p>Endpoint URL: <p><pre>{{ url }}</pre> | ||
<p>Token: </p><pre>{{ token }}</pre> | ||
<form action="/management/extensions/pibooth" method="post"> | ||
<button type="submit" class="green-button">Renew Token</button> | ||
</form> | ||
</div> | ||
</div> | ||
</body> | ||
<footer> | ||
<a href="{{ url_for('index') }}">Home</a> | <a href="{{ url_for('faq') }}">FAQ</a> | ||
<p>Nextride2-infobeamer by Inflac | Hackerspace-Bielefeld e.V.</p> | ||
</footer> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters