feat: certbot well-known redirection
This commit is contained in:
@@ -73,8 +73,9 @@ curl -X DELETE \
|
|||||||
- [x] header to setup .host file instead of in archive
|
- [x] header to setup .host file instead of in archive
|
||||||
- [x] ignore .gitignore/.host etc at root
|
- [x] ignore .gitignore/.host etc at root
|
||||||
- [x] cerbot install in container + path env/arg
|
- [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
|
- [ ] certbot/self-signed create/renew in specific dir
|
||||||
|
- [ ] better logger
|
||||||
- [ ] renew command
|
- [ ] renew command
|
||||||
- [ ] https mode w/ multiple hosts
|
- [ ] https mode w/ multiple hosts
|
||||||
- [ ] restart command (on new/deleted host)
|
- [ ] restart command (on new/deleted host)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
*
|
*
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
!.certbot
|
||||||
@@ -11,6 +11,7 @@ from . import project, params, registry, data_dir
|
|||||||
class StaplerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
class StaplerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
protocol_version = "HTTP/2.0"
|
protocol_version = "HTTP/2.0"
|
||||||
server_version = "StaplerServer/" + project.get_version()
|
server_version = "StaplerServer/" + project.get_version()
|
||||||
|
CERTBOT_CHALLENGE_PATH = "/.well-known/acme-challenge"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, *args, params: params.Parameters, registry: registry.Registry, **kwargs
|
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.data_dir = data_dir.DataDir(params.data_dir)
|
||||||
self.max_size_bytes = params.max_size_bytes
|
self.max_size_bytes = params.max_size_bytes
|
||||||
self.registry = registry
|
self.registry = registry
|
||||||
|
self.certbot_www = os.path.realpath(params.certbot_www)
|
||||||
super().__init__(*args, directory=params.data_dir, **kwargs)
|
super().__init__(*args, directory=params.data_dir, **kwargs)
|
||||||
|
|
||||||
def list_directory(self, *_, **__):
|
def list_directory(self, *_, **__):
|
||||||
@@ -27,6 +29,8 @@ class StaplerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||||||
self.send_error(http.HTTPStatus.NOT_FOUND, "File not found")
|
self.send_error(http.HTTPStatus.NOT_FOUND, "File not found")
|
||||||
|
|
||||||
def translate_path(self, path: str) -> str:
|
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:
|
if (page := self.registry.get_from_host(self.get_host())) is not None:
|
||||||
path = f"/{page.path}" + path
|
path = f"/{page.path}" + path
|
||||||
path = super().translate_path(path)
|
path = super().translate_path(path)
|
||||||
|
|||||||
+16
-5
@@ -1,13 +1,13 @@
|
|||||||
import http.server
|
import http.server
|
||||||
|
import os
|
||||||
|
|
||||||
from . import params, handler, registry
|
from . import params, handler, registry, project
|
||||||
|
|
||||||
|
|
||||||
class StaplerServer:
|
class StaplerServer:
|
||||||
def __init__(self, params: params.Parameters):
|
def __init__(self, params: params.Parameters):
|
||||||
self.default_host = params.host
|
|
||||||
self.registry = registry.Registry(params)
|
|
||||||
self.params = params
|
self.params = params
|
||||||
|
self.registry = registry.Registry(params)
|
||||||
self.server = http.server.ThreadingHTTPServer(
|
self.server = http.server.ThreadingHTTPServer(
|
||||||
(params.bind, params.port),
|
(params.bind, params.port),
|
||||||
self.request_handler,
|
self.request_handler,
|
||||||
@@ -18,10 +18,21 @@ class StaplerServer:
|
|||||||
*args, params=self.params, registry=self.registry
|
*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.registry.load_pages()
|
||||||
|
self.__init_certbot_www()
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.__startup()
|
||||||
print(
|
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:
|
try:
|
||||||
self.server.serve_forever()
|
self.server.serve_forever()
|
||||||
|
|||||||
Reference in New Issue
Block a user