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