From 90b7820678da5d6bdde45d6599c756663de526a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Martin?= Date: Sun, 26 Feb 2023 20:24:11 +0100 Subject: [PATCH] Initial version --- .gitignore | 1 + README.md | 3 +++ sorry.py | 19 +++++++++++++++++++ templates/index.html | 8 ++++++++ 4 files changed, 31 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 sorry.py create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/README.md b/README.md new file mode 100644 index 0000000..0e54359 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Sorry. + +Minimalist sorry server using flask. diff --git a/sorry.py b/sorry.py new file mode 100755 index 0000000..a6dbcc6 --- /dev/null +++ b/sorry.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# Copyright (c) 2022 Clément Martin twisla@twis.la. All rights reserved. +# Unauthorized copying of this file, via any medium is strictly prohibited + +import re +from flask import Flask, render_template, request +from markupsafe import Markup + +app = Flask(__name__) + +@app.route('/', defaults={'path': ''}) +@app.route('/') +def index(path): + wildcard = re.compile('.+\.home\.twis\.la') + raw_host = request.headers.get('Host') + vhost = Markup.escape(raw_host) + if not wildcard.match(vhost): + vhost = None + return render_template('index.html', vhost=vhost) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..323901f --- /dev/null +++ b/templates/index.html @@ -0,0 +1,8 @@ + +Sorry. :-( +

Hello Stranger

+{% if vhost %} +

Unfortunately, the host {{ vhost }} is not available at the moment, most likely it is because it was powered off.

+{% else %} +

It looks like you are doing something wrong, we have nothing interresting to see here.

+{% endif %}