Added a Caddyfile converter

This commit is contained in:
Julian Beittel 2025-04-22 20:17:37 +02:00
parent bbec639c14
commit e519f9f94c
3 changed files with 68 additions and 1 deletions

View file

@ -178,6 +178,12 @@ def json_to_nginx(robot_json):
config = f"if ($http_user_agent ~* \"{list_to_pcre(robot_json.keys())}\") {{\n return 403;\n}}"
return config
def json_to_caddy(robot_json):
caddyfile = "@aibots {\n "
caddyfile += "\n ".join(f'header User-Agent "*{k}*"' for k in robot_json.keys())
caddyfile += "\n}"
return caddyfile
def update_file_if_changed(file_name, converter):
"""Update files if newer content is available and log the (in)actions."""
@ -208,6 +214,10 @@ def conversions():
file_name="./nginx-block-ai-bots.conf",
converter=json_to_nginx,
)
update_file_if_changed(
file_name="./Caddyfile",
converter=json_to_caddy
)
if __name__ == "__main__":