From b1611621dcab81e310e0dae63b7e8db5a8ecf5e5 Mon Sep 17 00:00:00 2001 From: azlux Date: Wed, 6 Jun 2018 01:12:39 +0200 Subject: [PATCH] fix when no read right on file --- interface.py | 26 ++++++++++++++------------ util.py | 7 +++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/interface.py b/interface.py index f575a50..e94f19a 100644 --- a/interface.py +++ b/interface.py @@ -11,6 +11,7 @@ from werkzeug.utils import secure_filename import errno import media + class ReverseProxied(object): '''Wrap the application in this middleware and configure the front-end server to add these headers, to let you quietly bind @@ -72,7 +73,7 @@ def index(): item = ('file', request.form['add_file'], datetime.now().timestamp()) var.playlist.append(item) - elif ('add_folder' in request.form and ".." not in request.form['add_folder']) or ('add_folder_recursively' in request.form and ".." not in request.form['add_folder_recursively']) : + elif ('add_folder' in request.form and ".." not in request.form['add_folder']) or ('add_folder_recursively' in request.form and ".." not in request.form['add_folder_recursively']): try: folder = request.form['add_folder'] except: @@ -90,7 +91,7 @@ def index(): print('Adding to playlist: ', files) var.playlist.extend(files) - elif 'add_url' in request.form : + elif 'add_url' in request.form: var.playlist.append(['url', request.form['add_url']]) elif 'add_radio' in request.form: @@ -138,12 +139,12 @@ def index(): current_music = None return render_template('index.html', - all_files=files, - current_music=current_music, - music_library=music_library, - os=os, - playlist=var.playlist, - user=var.user) + all_files=files, + current_music=current_music, + music_library=music_library, + os=os, + playlist=var.playlist, + user=var.user) @web.route('/upload', methods=["POST"]) @@ -162,10 +163,10 @@ def upload(): elif '../' in targetdir: return redirect("./", code=406) - #print('Uploading file:') - #print('filename:', filename) - #print('targetdir:', targetdir) - #print('mimetype:', file.mimetype) + # print('Uploading file:') + # print('filename:', filename) + # print('targetdir:', targetdir) + # print('mimetype:', file.mimetype) if "audio" in file.mimetype: storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir)) @@ -187,6 +188,7 @@ def upload(): else: return redirect("./", code=409) + @web.route('/download', methods=["GET"]) def download(): if 'file' in request.args: diff --git a/util.py b/util.py index b979f41..70ab20b 100644 --- a/util.py +++ b/util.py @@ -21,7 +21,6 @@ def get_recursive_filelist_sorted(path): fullpath = os.path.join(path, relroot, file) if not os.access(fullpath, os.R_OK): - print("coucou") continue mime = magic.from_file(fullpath, mime=True) @@ -54,8 +53,12 @@ def zipdir(zippath, zipname_prefix=None): zipf = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED) for file in files: - filepath = os.path.dirname(file) file_to_add = os.path.join(zippath, file) + if not os.access(file_to_add, os.R_OK): + continue + if file in var.config.get('bot', 'ignored_files'): + continue + add_file_as = os.path.relpath(os.path.join(zippath, file), os.path.join(zippath, '..')) zipf.write(file_to_add, add_file_as)