Allow several subdomains at once
This commit is contained in:
		
							
								
								
									
										15
									
								
								scripts/add
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								scripts/add
									
									
									
									
									
								
							@ -11,18 +11,33 @@ def render_template(template_path, **kwargs):
 | 
				
			|||||||
    return output
 | 
					    return output
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def format_subdomain(subdomains, domain):
 | 
				
			||||||
 | 
					    if isinstance(subdomains, list):
 | 
				
			||||||
 | 
					        return ", ".join([f"{sub}.{domain}" for sub in subdomains])
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        return f"{subdomains}.{domain}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def process_sites_config(config_path, template_path, check_mode):
 | 
					def process_sites_config(config_path, template_path, check_mode):
 | 
				
			||||||
    with open(config_path, "r") as file:
 | 
					    with open(config_path, "r") as file:
 | 
				
			||||||
        sites_config = yaml.safe_load(file)
 | 
					        sites_config = yaml.safe_load(file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    default_domain = sites_config.get("default_domain", None)
 | 
				
			||||||
 | 
					    if default_domain is None:
 | 
				
			||||||
 | 
					        raise ValueError("YAML configuration is missing default_domain key")
 | 
				
			||||||
    total_sites = len(sites_config["sites"])
 | 
					    total_sites = len(sites_config["sites"])
 | 
				
			||||||
    enabled_sites = 0
 | 
					    enabled_sites = 0
 | 
				
			||||||
    disabled_sites = 0
 | 
					    disabled_sites = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for site in sites_config["sites"]:
 | 
					    for site in sites_config["sites"]:
 | 
				
			||||||
 | 
					        domain = site.get("domain", default_domain)
 | 
				
			||||||
        # Check if site is enabled
 | 
					        # Check if site is enabled
 | 
				
			||||||
        if site.get("enabled", True):  # Default to True if 'enabled' key is not present
 | 
					        if site.get("enabled", True):  # Default to True if 'enabled' key is not present
 | 
				
			||||||
            enabled_sites += 1
 | 
					            enabled_sites += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if "subdomain" in site:
 | 
				
			||||||
 | 
					                site["subdomain"] = format_subdomain(site["subdomain"], domain)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if not check_mode:
 | 
					            if not check_mode:
 | 
				
			||||||
                rendered_content = render_template(template_path, **site)
 | 
					                rendered_content = render_template(template_path, **site)
 | 
				
			||||||
                print(f"{rendered_content}\n")
 | 
					                print(f"{rendered_content}\n")
 | 
				
			||||||
 | 
				
			|||||||
@ -1,17 +1,17 @@
 | 
				
			|||||||
{{ subdomain }}.kucharczyk.xyz {
 | 
					{{ subdomain }} {
 | 
				
			||||||
	handle {
 | 
						handle {
 | 
				
			||||||
		{% if reverse_proxy_config %}
 | 
							{% if reverse_proxy_config %}
 | 
				
			||||||
			reverse_proxy {{ hostname }}:{{ port }} {
 | 
								reverse_proxy {{ hostname }}:{{ port }} {
 | 
				
			||||||
			{{ reverse_proxy_config }}
 | 
								{{ reverse_proxy_config }}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		{% else %}
 | 
							{% else %}
 | 
				
			||||||
			{% if hostname and port %}
 | 
								{% if hostname and port %}
 | 
				
			||||||
				reverse_proxy {{ hostname }}:{{ port }}
 | 
									reverse_proxy {{ hostname }}:{{ port }}
 | 
				
			||||||
			{% endif %}
 | 
								{% endif %}
 | 
				
			||||||
		{% endif %}
 | 
							{% endif %}
 | 
				
			||||||
		{% if additional_config %}
 | 
							{% if additional_config %}
 | 
				
			||||||
			{{ additional_config }}
 | 
								{{ additional_config }}
 | 
				
			||||||
		{% endif %}
 | 
							{% endif %}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	{{ server_config }}
 | 
						{{ server_config }}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user