From 54068a151ecba07190febb099fc30cb4d6de9399 Mon Sep 17 00:00:00 2001 From: azlux Date: Thu, 26 Jan 2017 00:30:34 +0100 Subject: [PATCH] Proxy, Upload Proxy paramter if behinf nginx Upload can be done into a folder directly from the webpage --- configuration.ini | 3 ++- interface.py | 35 +++++++++++++++++++++++++++++++---- mumbleBot.py | 4 ++++ templates/index.html | 12 +++++++++++- variables.py | 1 + 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/configuration.ini b/configuration.ini index 4f85d79..4917f06 100644 --- a/configuration.ini +++ b/configuration.ini @@ -1,8 +1,9 @@ [bot] -comment = Coucou, Je suis née du savoir du Azlux +comment = Coucou, Je suis née du savoir du Azlux, accès au https://azlux.fr/bot volume = 0.1 admin = Azlux;AzMobile music_folder = /home/dmichel/botamusique/music/ +is_proxified = True [debug] ffmpeg = False diff --git a/interface.py b/interface.py index 3ca848b..1fcd62f 100644 --- a/interface.py +++ b/interface.py @@ -1,10 +1,11 @@ #!/usr/bin/python3 -from flask import Flask, render_template, request +from flask import Flask, render_template, request, redirect import variables as var import os.path from os import listdir import random +from werkzeug.utils import secure_filename class ReverseProxied(object): @@ -46,7 +47,12 @@ class ReverseProxied(object): web = Flask(__name__) -web.wsgi_app = ReverseProxied(web.wsgi_app) + + +def init_proxy(): + global web + if var.is_proxified: + web.wsgi_app = ReverseProxied(web.wsgi_app) @web.route("/", methods=['GET', 'POST']) @@ -81,8 +87,29 @@ def index(): current_music=current_music, user=var.user, playlist=var.playlist, - all_files=files - ) + all_files=files) + + +@web.route('/download', methods=["POST"]) +def download(): + print(request.form) + + file = request.files['music_file'] + if not file: + return redirect("./", code=406) + elif file.filename == '': + return redirect("./", code=406) + elif '..' in request.form['directory']: + return redirect("./", code=406) + + if file.name == "music_file" and "audio" in file.headers.to_list()[1][1]: + web.config['UPLOAD_FOLDER'] = var.music_folder + request.form['directory'] + filename = secure_filename(file.filename) + print(filename) + file.save(os.path.join(web.config['UPLOAD_FOLDER'], filename)) + return redirect("./", code=302) + else: + return redirect("./", code=409) if __name__ == '__main__': diff --git a/mumbleBot.py b/mumbleBot.py index e0f756c..a9b60d7 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -31,15 +31,19 @@ class MumbleBot: args = parser.parse_args() self.volume = self.config.getfloat('bot', 'volume') + self.channel = args.channel var.current_music = None var.playlist = [] var.user = args.user var.music_folder = self.config.get('bot', 'music_folder') + var.is_proxified = self.config.getboolean("bot", "is_proxified") self.exit = False self.nb_exit = 0 self.thread = None + interface.init_proxy() + t = threading.Thread(target=start_web_interface) t.daemon = True t.start() diff --git a/templates/index.html b/templates/index.html index 886cfc6..2550d46 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,7 +9,17 @@
Refresh

- +
+
+ + + +
+
Current Playing : {% if current_music %} diff --git a/variables.py b/variables.py index 94d7d3a..f0396d3 100644 --- a/variables.py +++ b/variables.py @@ -2,3 +2,4 @@ current_music = "" playlist = [] user = "" music_folder = "" +is_proxified = False \ No newline at end of file