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

Dev #4

Merged
merged 7 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Docker: Python - Flask",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "flask"
}
}
]
}
40 changes: 40 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "qbdlgui:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"dockerRun": {
"env": {
"FLASK_APP": "qbdl_gui.py"
}
},
"python": {
"args": [
"run",
"--no-debugger",
"--no-reload",
"--host",
"0.0.0.0",
"--port",
"5000"
],
"module": "flask"
}
}
]
}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Base
FROM python:3.10-slim

EXPOSE 5000

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app

# During debugging, this entry point will be overridden.
CMD ["python", "qbdl_gui.py"]
14 changes: 14 additions & 0 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.4'

services:
qbdlgui:
image: qbdlgui
build:
context: .
dockerfile: ./Dockerfile
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5000"]
ports:
- 5000:5000
- 5678:5678
environment:
- FLASK_APP=qbdl_gui.py
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.4'

services:
qbdlgui:
image: qbdlgui
build:
context: .
dockerfile: ./Dockerfile
ports:
- 5000:5000
21 changes: 12 additions & 9 deletions qbdl_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
quality = int(request.form['quality'])
remember = request.form.get('rememberMe')

qobuz = QobuzDL(
directory=download_location,
quality=quality
)
qobuz.get_tokens()
qobuz.initialize_client(email, password, qobuz.app_id, qobuz.secrets)
qobuz.handle_url(url)
try:
qobuz = QobuzDL(
directory=download_location,
quality=quality
)
qobuz.get_tokens()
qobuz.initialize_client(email, password, qobuz.app_id, qobuz.secrets)
qobuz.handle_url(url)
except Exception as e:
logging.error("An error occurred: " + str(e))
return jsonify(status='error', message=str(e)), 500

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

if remember == 'on':
session['email'] = email
Expand All @@ -33,12 +37,11 @@

return jsonify(status='completed')

# If the user has a session, pre-fill the form with their settings
email = session.get('email', '')
download_location = session.get('download_location', '')
quality = session.get('quality', 7)

return render_template('index.html', email=email, download_location=download_location, quality=quality)

if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
app.run(host='0.0.0.0', debug=True)

Check failure

Code scanning / CodeQL

Flask app is run in debug mode High

A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger.
51 changes: 27 additions & 24 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,36 @@ <h4>Downloading...</h4>
</div>

<script>
$('#downloadForm').submit(function(e) {
e.preventDefault();
$('#progress-container').show();
$('#downloadForm').submit(function(e) {
e.preventDefault();
$('#progress-container').show();

$.ajax({
type: 'POST',
url: '/',
data: $(this).serialize(),
success: function(data) {
if (data.status === 'completed') {
$('#progress-bar').css('width', '100%');
$('#status-text').text('Download Completed!');
}
},
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$('#progress-bar').css('width', percentComplete + '%');
}
}, false);
return xhr;
$.ajax({
type: 'POST',
url: '/',
data: $(this).serialize(),
success: function(data) {
if (data.status === 'completed') {
$('#progress-bar').css('width', '100%');
$('#status-text').text('Download Completed!');
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
$('#status-text').text('An error occurred: ' + jqXHR.responseJSON.message);
},
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$('#progress-bar').css('width', percentComplete + '%');
}
}, false);
return xhr;
}
});
});
</script>
<div class="footer">
<p>QoBuz DL GUI &copy; Gyarbij 2023</p>
Expand Down
Loading