From 70e83e60564a7beaa5b056d3cabf0d8546cc481e Mon Sep 17 00:00:00 2001 From: Flynn Marquardt Date: Fri, 13 Feb 2026 19:18:46 +0100 Subject: [PATCH] Add generation and output of lighttpd configuration fragment. --- code/robots.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/code/robots.py b/code/robots.py index a2fb7ec..21b6cc7 100755 --- a/code/robots.py +++ b/code/robots.py @@ -188,6 +188,13 @@ def json_to_nginx(robot_json): return config +def json_to_lighttpd(robot_json): + # Creates an Lighttpd config file. This config snippet can be included in + # Lighttpd configuration global or in $HTTP conditionals to block AI bots. + config = f"$HTTP[\"url\"] != \"/robots.txt\" {{ $HTTP[\"user-agent\"] =~ \"{list_to_pcre(robot_json.keys())}\" {{ url.access-deny = ( \"\" ) }} }}" + return config + + def json_to_caddy(robot_json): caddyfile = "@aibots {\n " caddyfile += f' header_regexp User-Agent "{list_to_pcre(robot_json.keys())}"' @@ -230,6 +237,10 @@ def conversions(): file_name="./nginx-block-ai-bots.conf", converter=json_to_nginx, ) + update_file_if_changed( + file_name="./lighttpd-block-ai-bots.conf", + converter=json_to_lighttpd, + ) update_file_if_changed( file_name="./Caddyfile", converter=json_to_caddy,