diff --git a/.gitignore b/.gitignore index cbcce01..bce2a15 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__ notes.txt react_OLD -envs.py \ No newline at end of file +envs.py +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7c34d39..f0ec298 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,14 @@ -FROM ubuntu:lunar +FROM docker.io/python:3.8-buster LABEL maintainer="Andrew Simonson " -ENV DEBIAN_FRONTEND noninteractive +WORKDIR /app +ADD ./src /app -RUN apt-get update -RUN apt-get install -y python3-pip nginx gunicorn supervisor +COPY . . -# Setup flask application -RUN mkdir -p /deploy/app -COPY src /deploy/app -RUN pip install -r /deploy/app/requirements.txt --break-system-packages +WORKDIR /app/src -# Setup nginx -RUN rm /etc/nginx/sites-enabled/default -COPY flask.conf /etc/nginx/sites-available/ -RUN ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf && \ - echo "daemon off;" >> /etc/nginx/nginx.conf +RUN apt-get -yq update && \ + pip install --no-cache-dir -r requirements.txt -# Setup supervisord -RUN mkdir -p /var/log/supervisor -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf -COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf - -# Permissions -# RUN adduser --disabled-password --gecos '' supervisor && \ -RUN chmod -R 777 /var/* && \ - chown -R root /var/* - -# Entrypoint -USER root - -# Start processes -CMD ["/usr/bin/supervisord"] +CMD [ "gunicorn", "--bind", "0.0.0.0:8080", "app:app"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..948555a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.8' +services: + portfolio: + image: 'asimonson1125/portfolio' + build: + context: ./ + dockerfile: Dockerfile + restart: 'no' + volumes: + - ${READ_VOLUME:-/dev/null}:/mnt/readonly:ro # Read-only mount for sharing from host to public \ No newline at end of file diff --git a/flask.conf b/flask.conf deleted file mode 100644 index 873f9d8..0000000 --- a/flask.conf +++ /dev/null @@ -1,24 +0,0 @@ -server { - listen 8080; - server_name www.asimonson.com; - return 301 https://asimonson.com$request_uri; -} -server { - listen 8080; - server_name asimonson.com; - - gzip on; - gzip_types text/plain text/javascript text/css; - gunzip on; - - add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; - add_header X-Content-Type-Options 'nosniff'; - add_header X-Frame-Options 'SAMEORIGIN'; - - location / { - proxy_pass http://localhost:5000/; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - -} \ No newline at end of file diff --git a/gunicorn.conf b/gunicorn.conf deleted file mode 100644 index 6412df9..0000000 --- a/gunicorn.conf +++ /dev/null @@ -1,3 +0,0 @@ -[program:gunicorn] -command=/usr/bin/gunicorn app:app -b localhost:5000 -directory=/deploy/app diff --git a/src/app.py b/src/app.py index bb75008..02acfb8 100644 --- a/src/app.py +++ b/src/app.py @@ -4,6 +4,7 @@ import json import werkzeug.exceptions as HTTPerror import requests from config import * +import os proj = json.load(open("./static/json/projects.json", "r")) books = json.load(open("./static/json/books.json", "r")) @@ -43,34 +44,12 @@ def funcGen(pagename, pages): for i in pages: func = funcGen(i, pages) app.add_url_rule(pages[i]['canonical'], i, func) - - -# for i in pages: -# exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])") - @app.route("/resume") @app.route("/Resume.pdf") def resume(): return flask.send_file("./static/Resume.pdf") -@app.route("/hotspots") -def hotspotsRIT(): - url = HotspotsURL - if flask.request.args.get("legend") == "false": - url += "?legend=false" - pagevars = { - "template": "iframe.html", - "title": f"Hotspots @ RIT", - "description": "Hotspots @ RIT by Andrew Simonson", - "canonical": "/hotspots", - } - return flask.render_template("iframe.html", url=url, var=pagevars) - -@app.route("/hotspots/") -def hotspotsProxy(path): - return requests.get(f"{HotspotsURL}/{path}").content - @app.errorhandler(Exception) def page404(e): eCode = e.code @@ -101,10 +80,33 @@ def page404(e): def static_from_root(): return flask.send_from_directory(app.static_folder, flask.request.path[1:]) -@app.route('/files/') +@app.route('/files') +@app.route('/files/') +def no_hacking(): + return "lol nice try" + +@app.route('/files/') def filesystem_send(fname): - print(app.static_folder + "files/") - return flask.send_from_directory(app.static_folder + '/files/', fname) + fname = fname.strip('/') + safe_path = os.path.abspath(os.path.join("/mnt/readonly/", fname)) + if not safe_path.startswith("/mnt/readonly/"): + return "Invalid path", 400 + if os.path.isfile(safe_path): + return flask.send_from_directory("/mnt/readonly/", fname) + elif os.path.isdir(safe_path): + dirContent = "" + if not os.path.abspath("/mnt/readonly/") == os.path.abspath(os.path.join(safe_path, os.path.pardir)): + pardir = "/files/" + os.path.abspath(os.path.join(safe_path, os.path.pardir))[len("/mnt/readonly/"):] + dirContent += f"Parent Directory" + dirContent += "
    " + for i in os.listdir(safe_path): + if os.path.isdir(os.path.join(safe_path, i)): + dirContent += f"
  • DIR: {i}
  • " + else: + dirContent += f"
  • {i}
  • " + dirContent += "
" + return dirContent + raise HTTPerror.NotFound("File or Directory Not Found") if __name__ == "__main__": diff --git a/src/config.py b/src/config.py index 1c932de..c5f3d7e 100644 --- a/src/config.py +++ b/src/config.py @@ -4,5 +4,3 @@ try: __import__('envs.py') except ImportError: pass - -HotspotsURL = env.get('HotspotsURL', 'https://asimonson.com/hotspots') \ No newline at end of file diff --git a/src/static/files/designThinkingCert.pdf b/src/static/files/designThinkingCert.pdf deleted file mode 100644 index 0185850..0000000 Binary files a/src/static/files/designThinkingCert.pdf and /dev/null differ diff --git a/src/static/files/ideationCert.pdf b/src/static/files/ideationCert.pdf deleted file mode 100644 index 9965d71..0000000 Binary files a/src/static/files/ideationCert.pdf and /dev/null differ diff --git a/src/static/files/toolsForInnovatorsCert.pdf b/src/static/files/toolsForInnovatorsCert.pdf deleted file mode 100644 index e095912..0000000 Binary files a/src/static/files/toolsForInnovatorsCert.pdf and /dev/null differ diff --git a/src/templates/header.html b/src/templates/header.html index 9661bdd..b98fe74 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -14,7 +14,7 @@ @@ -23,7 +23,7 @@ @@ -56,7 +56,7 @@ href="{{ url_for('static', filename='css/head.css') }}" /> - + @@ -65,7 +65,8 @@ {% block header %} - + +
diff --git a/supervisord.conf b/supervisord.conf deleted file mode 100644 index 1ff0908..0000000 --- a/supervisord.conf +++ /dev/null @@ -1,19 +0,0 @@ -[supervisord] -nodaemon=true -redirect_stderr=true -stdout_logfile=/dev/null -username = dummy -password = dummy - -[program:nginx] -command=/usr/sbin/nginx -redirect_stderr=true -stdout_logfile=/dev/null - -[unix_http_server] -username = dummy -password = dummy - -[supervisorctl] -username = dummy -password = dummy \ No newline at end of file