From 7bf48daab55663f09463f56b5bf7407a1700ff4a Mon Sep 17 00:00:00 2001 From: JMARyA Date: Tue, 23 Aug 2022 02:26:24 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 136 +++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 11 ++++ Makefile | 11 ++++ README.md | 3 + docker-compose.yml | 11 ++++ requirements.txt | 2 + src/assets.py | 17 ++++++ src/config.py | 3 + src/index.py | 88 +++++++++++++++++++++++++++++ src/main.py | 15 +++++ 10 files changed, 297 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 requirements.txt create mode 100644 src/assets.py create mode 100644 src/config.py create mode 100644 src/index.py create mode 100644 src/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b63f137 --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pdm +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzerw +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +.idea/ + +# Specific +.DS_Store +/config/ +/db/ +.vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fb75c8d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3 + +COPY requirements.txt / + +RUN pip3 install -r /requirements.txt + +VOLUME /config + +COPY src /app + +CMD [ "python3", "/app/main.py" ] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..92bae95 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ + +fmt: + black . + +clean: + fd pycache -I -x rm -rv {} + +restart: + docker-compose down + docker-compose build + docker-compose up -d diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a04b3b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Me Site + +Simple website for personal information \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0d25bfb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3' + +services: + app: + build: "." + environment: + TZ: Europe/Berlin + ports: + - 1030:1030 + volumes: + - ./config:/config \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4a6b337 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask +git+https://github.com/jmarya/htmlpy#egg=htmlpy \ No newline at end of file diff --git a/src/assets.py b/src/assets.py new file mode 100644 index 0000000..6ad8172 --- /dev/null +++ b/src/assets.py @@ -0,0 +1,17 @@ +from flask import request, session, Blueprint, Response, send_from_directory +from htmlpy import * +from config import CONFIG +import os + +asset_pages = Blueprint("assets", __name__) + + +def filesend(path): + filename = os.path.basename(path) + dirpath = os.path.dirname(path) + return send_from_directory(dirpath, filename) + + +@asset_pages.route("/me", methods=["GET"]) +def me_picture(): + return filesend("/config/me.avif") diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..1488ae5 --- /dev/null +++ b/src/config.py @@ -0,0 +1,3 @@ +import json + +CONFIG = json.loads(open("/config/config.json").read()) diff --git a/src/index.py b/src/index.py new file mode 100644 index 0000000..089f619 --- /dev/null +++ b/src/index.py @@ -0,0 +1,88 @@ +from flask import request, session, Blueprint, Response +from htmlpy import * +from config import CONFIG +from os.path import exists + +main_pages = Blueprint("main", __name__) + +BOOTSTRAP = [ + Reference( + "https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css", + "stylesheet", + ), + Reference( + "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css", + "stylesheet", + ), + Script( + src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" + ), +] + + +def buildSite(content): + return Document( + head=Head( + [Meta(name="viewport", content="width=350, user-scalable=0;"), BOOTSTRAP] + ), + body=Body( + content, + global_attr=GlobalAttributes( + css_class="bg-dark text-white justify-content-center text-center" + ), + ), + ) + + +@main_pages.route("/public_key", methods=["GET"]) +def public_key(): + try: + ret = open("/config/pub.key").read() + + ua = request.user_agent.string.lower() + if "chrome" in ua or "safari" in ua or "firefox" in ua: + return buildSite(Paragraph(ret.replace("\n", "
"))).to_code() + + resp = Response(response=ret, status=200, mimetype="application/pgp-keys") + return resp + except: + return Response(response="", status=502) + + +# Main +@main_pages.route("/", methods=["GET"]) +def index(): + return buildSite( + [ + Div( + [ + Image( + "/assets/me", + 200, + 200, + "Me", + global_attr=GlobalAttributes(css_class="rounded"), + ), + LineBreak(), + LineBreak(), + Heading(1, CONFIG["name"]), + ThematicBreak(), + ], + global_attr=GlobalAttributes( + css_class="container border-dark", style="margin-top: 20px" + ), + ), + Div( + [ + Heading(1, "Contact"), + ThematicBreak(), + [Link("/public_key", "My PGP Key"), LineBreak()] + if exists("/config/pub.key") + else None, + Link(f"mailto:{CONFIG['email']}", CONFIG["email"]), + LineBreak(), + ], + global_attr=GlobalAttributes(css_class="container border-dark"), + ), + ] + ).to_code() diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..e929542 --- /dev/null +++ b/src/main.py @@ -0,0 +1,15 @@ +from flask import Flask, session, request +from config import CONFIG + +app = Flask(__name__) +app.secret_key = CONFIG["secret_key"] + +from index import main_pages +from assets import asset_pages + +app.register_blueprint(main_pages) +app.register_blueprint(asset_pages, url_prefix="/assets") + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=1030, debug=True, threaded=True)