Proxy, Upload

Proxy paramter if behinf nginx
Upload can be done into a folder directly from the webpage
This commit is contained in:
azlux 2017-01-26 00:30:34 +01:00
parent 4f31a99374
commit 54068a151e
5 changed files with 49 additions and 6 deletions

View File

@ -1,8 +1,9 @@
[bot] [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 volume = 0.1
admin = Azlux;AzMobile admin = Azlux;AzMobile
music_folder = /home/dmichel/botamusique/music/ music_folder = /home/dmichel/botamusique/music/
is_proxified = True
[debug] [debug]
ffmpeg = False ffmpeg = False

View File

@ -1,10 +1,11 @@
#!/usr/bin/python3 #!/usr/bin/python3
from flask import Flask, render_template, request from flask import Flask, render_template, request, redirect
import variables as var import variables as var
import os.path import os.path
from os import listdir from os import listdir
import random import random
from werkzeug.utils import secure_filename
class ReverseProxied(object): class ReverseProxied(object):
@ -46,7 +47,12 @@ class ReverseProxied(object):
web = Flask(__name__) 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']) @web.route("/", methods=['GET', 'POST'])
@ -81,8 +87,29 @@ def index():
current_music=current_music, current_music=current_music,
user=var.user, user=var.user,
playlist=var.playlist, 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__': if __name__ == '__main__':

View File

@ -31,15 +31,19 @@ class MumbleBot:
args = parser.parse_args() args = parser.parse_args()
self.volume = self.config.getfloat('bot', 'volume') self.volume = self.config.getfloat('bot', 'volume')
self.channel = args.channel self.channel = args.channel
var.current_music = None var.current_music = None
var.playlist = [] var.playlist = []
var.user = args.user var.user = args.user
var.music_folder = self.config.get('bot', 'music_folder') var.music_folder = self.config.get('bot', 'music_folder')
var.is_proxified = self.config.getboolean("bot", "is_proxified")
self.exit = False self.exit = False
self.nb_exit = 0 self.nb_exit = 0
self.thread = None self.thread = None
interface.init_proxy()
t = threading.Thread(target=start_web_interface) t = threading.Thread(target=start_web_interface)
t.daemon = True t.daemon = True
t.start() t.start()

View File

@ -9,7 +9,17 @@
<body> <body>
<a href="."><h5>Refresh</h5></a> <a href="."><h5>Refresh</h5></a>
<br> <br>
<div id="download">
<form action="./download" method="post" enctype="multipart/form-data">
<input type="file" name="music_file" value="Browse Music file"/>
<select name="directory">
{% for dir in all_files %}
<option value={{ dir }}>{{ dir }}</option>
{% endfor %}
</select>
<input type="submit" value="Upload"/>
</form>
</div>
<div id="playlist"> <div id="playlist">
Current Playing : Current Playing :
{% if current_music %} {% if current_music %}

View File

@ -2,3 +2,4 @@ current_music = ""
playlist = [] playlist = []
user = "" user = ""
music_folder = "" music_folder = ""
is_proxified = False