wip
This commit is contained in:
parent
ad913c0492
commit
429d259d06
2 changed files with 19 additions and 17 deletions
19
app.py
19
app.py
|
@ -57,7 +57,7 @@ def verify_token(token):
|
|||
return None
|
||||
|
||||
def parse_local_caddyfile():
|
||||
"""Parse a local Caddyfile with improved logic matching the agent"""
|
||||
"""Parse a local Caddyfile to extract domains and their proxy targets"""
|
||||
entries = {}
|
||||
try:
|
||||
if not os.path.exists(CADDYFILE_PATH):
|
||||
|
@ -67,25 +67,26 @@ def parse_local_caddyfile():
|
|||
with open(CADDYFILE_PATH, "r") as file:
|
||||
content = file.read()
|
||||
|
||||
# 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)
|
||||
# Revert to simpler pattern that was working previously
|
||||
pattern = re.compile(r"(?P<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{.*?reverse_proxy\s+(?P<target>https?:\/\/[\d\.]+:\d+|[\d\.]+:\d+).*?}", re.DOTALL)
|
||||
matches = pattern.findall(content)
|
||||
|
||||
logger.info(f"Found {len(matches)} matches in local Caddyfile")
|
||||
|
||||
for domains, target in matches:
|
||||
for domain in re.split(r',\s*', domains):
|
||||
domain = domain.strip()
|
||||
if domain and not domain.lower() == "host": # Skip entries actually named "host"
|
||||
if domain and domain.lower() != "host": # Skip entries named "host"
|
||||
entries[domain] = target.strip()
|
||||
|
||||
logger.info(f"Found {len(entries)} domain entries in local Caddyfile")
|
||||
|
||||
# Debug output to help diagnose parsing issues
|
||||
logger.info(f"Extracted {len(entries)} domain entries from local Caddyfile")
|
||||
|
||||
# Debug output of parsed entries
|
||||
for domain, target in entries.items():
|
||||
logger.debug(f"Parsed domain: {domain} -> {target}")
|
||||
logger.debug(f"Domain: {domain} -> {target}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error parsing local Caddyfile: {e}")
|
||||
# Log the error details for debugging
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue