feat: certbot well-known redirection

This commit is contained in:
2026-04-12 12:02:52 +02:00
parent 084e8e5ae4
commit de2f150e96
5 changed files with 26 additions and 7 deletions
+2 -1
View File
@@ -73,8 +73,9 @@ curl -X DELETE \
- [x] header to setup .host file instead of in archive
- [x] ignore .gitignore/.host etc at root
- [x] cerbot install in container + path env/arg
- [ ] redirect /.well-known/acme-challenge to specific path
- [x] redirect /.well-known/acme-challenge to specific path
- [ ] certbot/self-signed create/renew in specific dir
- [ ] better logger
- [ ] renew command
- [ ] https mode w/ multiple hosts
- [ ] restart command (on new/deleted host)
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+1
View File
@@ -1,2 +1,3 @@
*
!.gitignore
!.certbot
+4
View File
@@ -11,6 +11,7 @@ from . import project, params, registry, data_dir
class StaplerRequestHandler(http.server.SimpleHTTPRequestHandler):
protocol_version = "HTTP/2.0"
server_version = "StaplerServer/" + project.get_version()
CERTBOT_CHALLENGE_PATH = "/.well-known/acme-challenge"
def __init__(
self, *args, params: params.Parameters, registry: registry.Registry, **kwargs
@@ -20,6 +21,7 @@ class StaplerRequestHandler(http.server.SimpleHTTPRequestHandler):
self.data_dir = data_dir.DataDir(params.data_dir)
self.max_size_bytes = params.max_size_bytes
self.registry = registry
self.certbot_www = os.path.realpath(params.certbot_www)
super().__init__(*args, directory=params.data_dir, **kwargs)
def list_directory(self, *_, **__):
@@ -27,6 +29,8 @@ class StaplerRequestHandler(http.server.SimpleHTTPRequestHandler):
self.send_error(http.HTTPStatus.NOT_FOUND, "File not found")
def translate_path(self, path: str) -> str:
if path.startswith(self.CERTBOT_CHALLENGE_PATH):
return self.certbot_www + path.removeprefix(self.CERTBOT_CHALLENGE_PATH)
if (page := self.registry.get_from_host(self.get_host())) is not None:
path = f"/{page.path}" + path
path = super().translate_path(path)
+16 -5
View File
@@ -1,13 +1,13 @@
import http.server
import os
from . import params, handler, registry
from . import params, handler, registry, project
class StaplerServer:
def __init__(self, params: params.Parameters):
self.default_host = params.host
self.registry = registry.Registry(params)
self.params = params
self.registry = registry.Registry(params)
self.server = http.server.ThreadingHTTPServer(
(params.bind, params.port),
self.request_handler,
@@ -18,10 +18,21 @@ class StaplerServer:
*args, params=self.params, registry=self.registry
)
def start(self):
def __repr__(self):
return f"StaplerServer ({project.get_version()})"
def __init_certbot_www(self):
os.makedirs(self.params.certbot_www, exist_ok=True)
def __startup(self):
print(f"{self}: starting up...")
self.registry.load_pages()
self.__init_certbot_www()
def start(self):
self.__startup()
print(
f"{handler.StaplerRequestHandler.server_version} serving on http://{self.default_host}:{self.server.server_port}..."
f"{self}: serving on http://{self.params.host}:{self.server.server_port}..."
)
try:
self.server.serve_forever()