This commit is contained in:
pika 2025-03-24 18:44:26 +01:00
parent e2618b2d35
commit ad913c0492
2 changed files with 30 additions and 14 deletions

View file

@ -73,18 +73,27 @@ def parse_caddyfile():
with open(CADDYFILE_PATH, "r") as file:
content = file.read()
pattern = re.compile(r"(?P<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{.*?reverse_proxy\s+(?P<target>https?:\/\/[\d\.]+:\d+|[\d\.]+:\d+).*?}", re.DOTALL)
# Improved regex pattern to better handle different Caddyfile formats
pattern = re.compile(r"(?P<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{[^}]*?(?:reverse_proxy|handle|respond)\s+(?P<target>https?:\/\/[\d\.]+:\d+|[\d\.]+:\d+)[^}]*?}", re.DOTALL)
matches = pattern.findall(content)
for domains, target in matches:
for domain in domains.split(", "):
for domain in re.split(r',\s*', domains):
domain = domain.strip()
if domain: # Only add non-empty domains
if domain and not domain.lower() == "host": # Skip entries actually named "host"
entries[domain] = target.strip()
logger.info(f"Found {len(entries)} domain entries in Caddyfile")
# Debug output to help diagnose parsing issues
for domain, target in entries.items():
logger.debug(f"Parsed domain: {domain} -> {target}")
except Exception as e:
logger.error(f"Error parsing Caddyfile: {e}")
# Log the error details for debugging
import traceback
logger.error(traceback.format_exc())
return entries