addet a way to edit current entries

This commit is contained in:
pika 2025-03-10 14:22:52 +01:00
parent 3dc25d2ace
commit d0adc68719

View file

@ -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<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{.*?reverse_proxy\s+(?P<target>https?:\/\/[\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":