Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide base_directory, ease use CLI tools #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions updog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def home(path):
except PermissionError:
abort(403, 'Read Permission Denied: ' + requested_path)

# remove the base_directory
requested_path = requested_path[len(base_directory):]
return render_template('home.html', files=directory_files, back=back,
directory=requested_path, is_subdirectory=is_subdirectory, version=VERSION)
else:
Expand All @@ -121,22 +123,24 @@ def home(path):
@app.route('/upload', methods=['POST'])
@auth.login_required
def upload():
global base_directory

if request.method == 'POST':

# No file part - needs to check before accessing the files['file']
if 'file' not in request.files:
return redirect(request.referrer)
return redirect(request.headers.get('Referer', '/'))

path = request.form['path']
path = base_directory + request.form.get('path', '/')
# Prevent file upload to paths outside of base directory
if not is_valid_upload_path(path, base_directory):
return redirect(request.referrer)
return redirect(request.headers.get('Referer', '/'))

for file in request.files.getlist('file'):

# No filename attached
if file.filename == '':
return redirect(request.referrer)
return redirect(request.headers.get('Referer', '/'))

# Assuming all is good, process and save out the file
# TODO:
Expand All @@ -149,7 +153,7 @@ def upload():
except PermissionError:
abort(403, 'Write Permission Denied: ' + full_path)

return redirect(request.referrer)
return redirect(request.headers.get('Referer', '/'))

# Password functionality is without username
users = {
Expand Down