diff --git a/Caddy/addEntry.py b/Caddy/addEntry.py index 6f010eb..a9b0a18 100644 --- a/Caddy/addEntry.py +++ b/Caddy/addEntry.py @@ -26,7 +26,7 @@ def parse_existing_entries(caddyfile_path): with open(caddyfile_path, "r") as file: content = file.read() - # Regex to find domain blocks + # Regex to find domain blocks and associated reverse proxy targets pattern = re.compile(r"(?P[^\s{]+(?:,\s*[^\s{]+)*)\s*{.*?reverse_proxy\s+(?Phttps?:\/\/[\d\.]+:\d+|[\d\.]+:\d+).*?}", re.DOTALL) matches = pattern.findall(content) @@ -127,20 +127,33 @@ def add_caddy_entry(caddyfile_path): print("❌ No domain provided. Skipping entry.") continue + # If domain exists, extract its current values if domain in existing_entries: print(f"⚠ The domain {domain} already exists.") edit_existing = get_user_input("Do you want to edit this entry? (y/n)", "y").lower() == "y" if not edit_existing: continue - target_ip = get_user_input("Enter the target IP", "192.168.1.100") - target_port = get_user_input("Enter the target port", "8080") + existing_target = existing_entries[domain] + existing_ip, existing_port = existing_target.replace("https://", "").replace("http://", "").split(":") + + else: + existing_ip, existing_port = "192.168.1.100", "8080" + + target_ip = get_user_input("Enter the target IP", existing_ip) + target_port = get_user_input("Enter the target port", existing_port) print("\nChoose the proxy mode:") print("1️⃣ Standard (No HTTPS changes)") print("2️⃣ Internal HTTPS (skip verify)") print("3️⃣ OPNsense Mode (skip verify + enforce HTTP/1.1)") - mode_choice = get_user_input("Enter option (1/2/3)", "1") + + # Pre-fill proxy type if editing + mode_choice_default = "1" + if "https://" in existing_entries.get(domain, "") and "tls_insecure_skip_verify" in existing_entries.get(domain, ""): + mode_choice_default = "3" if "versions h1.1" in existing_entries.get(domain, "") else "2" + + mode_choice = get_user_input("Enter option (1/2/3)", mode_choice_default) proxy_type = "standard" if mode_choice == "2":