From ed74953fd7c5889b107fd5432352a2a6034dbaed Mon Sep 17 00:00:00 2001 From: klemek Date: Sun, 12 Apr 2026 23:51:43 +0200 Subject: [PATCH] feat: favicon --- README.md | 4 +++- data/.gitignore | 3 ++- data/favicon.ico | Bin 0 -> 15086 bytes logo.svg | 19 +++++++++++++++++++ src/handler.py | 5 ++++- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 data/favicon.ico create mode 100644 logo.svg diff --git a/README.md b/README.md index 80df3ce..11976eb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Stapler +![logo.svg](logo.svg) + ```txt usage: stapler [-h] [--debug | --no-debug] [-d DATA_DIR] [--certificates | --no-certificates] [--certbot | --no-certbot] [--self-signed-path SELF_SIGNED_PATH] [--certbot-conf CERTBOT_CONF] [--certbot-www CERTBOT_WWW] [--host HOST] [-p PORT] [--https | --no-https] [-t TOKEN] [--max-size-bytes MAX_SIZE] [-b BIND] @@ -96,7 +98,7 @@ curl -X DELETE \ - [x] create certificate on request - [x] certbot copy certificates for unique path - [x] better error page -- [ ] add favicon.ico + special path +- [x] add favicon.ico + special path - [ ] [http.server security](https://docs.python.org/3/library/http.server.html#http-server-security) - [ ] proper doc diff --git a/data/.gitignore b/data/.gitignore index c96a04f..e948666 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,2 +1,3 @@ * -!.gitignore \ No newline at end of file +!.gitignore +!favicon.ico \ No newline at end of file diff --git a/data/favicon.ico b/data/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..1b356603ed9f5e9e07a5d2a748d7cd66c61997ee GIT binary patch literal 15086 zcmeI3$xl;J6vm&?r320bie;!w+E$=ITPPqPl%ZkJjk++BC~ieJ2!<8Nf+=Fqn7C6! z+z>+|LevE=bfwV^Q%wW~|BB;x9(~e*mZ2(bI8AJr%4B5K^%w&2|y1Le@sylNCqh&6`Ta8 zfMITmOyD#~o13I`kO9mfb9R!lfCX5A4dl#DP%f~4pP)RD52XCz-TtxT!=xV@q!Xiq zl;|c2$7GNKQi1Np?OClbf`W=alXy14rYhan*hdt}m2@w8f2eWPofS z$4&050m^;%GGzNHy;wl!v!jEO_;E}vzooY&=yUvc?DtyK@~3?mUGZ7xg?uT$w7-{~ zgp2*u=EYG-UAc-L{g%i7VD?{rsgTO*%E;2+=eGYbuX=g*u_|XeRbDA0N7J=`X8#p6 zS$^|Zu<{$xUp?oqVEwnK^Y&kxzXFXvQvSf>r?mf)|0edcICo3`U7!Cf_9ONa%KA&} zN9;%JXVC^ceO&S1Mg#i);=hUi=Gj;HT>Llj-#l$X#!nePSF`^w{-^k#;(v<&8E*bV zr0<`5&c*Wm%fEkd`^fjZ845K2MvDDJ`uA(mZ;1XRnEw+<7bMsJPYbY4O9%47N;)k~ zqs96x)@JQxZEs}*}Hb{Ouq}Jcs-Ap#5b3krqBiR{TvGTlsDYJ>iTE4-&}SN)BLbieSfVj#_v8~ZeXBfj7)u-$E-jHma>fpd-_us-Rf!nPY!f%8gWN1Tsu{shDYY5lSIdNo;l z?)*vT^)!>CzG^9rHNS8Ec<_S4n0to?*)zoGV@_4eOT2dUpD%=p^? literal 0 HcmV?d00001 diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..7484a30 --- /dev/null +++ b/logo.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/handler.py b/src/handler.py index a0bf881..9b97c81 100644 --- a/src/handler.py +++ b/src/handler.py @@ -20,6 +20,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): CERTBOT_CHALLENGE_PATH = "/.well-known/acme-challenge" PATH_REGEX = re.compile(r"^\/([\w-]+)\/") HOST_PART_REGEX = re.compile(r"^([a-zA-Z0-9]|[a-zA-Z0-9]*[a-zA-Z0-9][a-zA-Z0-9])$") + AUTHORIZED_PATHS: typing.ClassVar[list[str]] = ["/favicon.ico"] @typing.override def __init__( @@ -116,7 +117,9 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): 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 - if self.__get_subpath(path) is None: # not a valid path + if ( + path not in self.AUTHORIZED_PATHS and self.__get_subpath(path) is None + ): # not a valid path return "" if pathlib.Path(path).name.startswith("."): # hidden files return ""