feat: configurate interfaces for listen directive

This commit is contained in:
2024-12-28 15:32:14 +00:00
parent 54c299c21e
commit 105ce44026
2 changed files with 23 additions and 1 deletions

View File

@@ -1,8 +1,26 @@
server { server {
# {{ comment }} # {{ comment }}
{% if port_interfaces %}
{% if "ipv4-all" in port_interfaces %}
listen {{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %};
{% endif %}
{% if "ipv6-all" in port_interfaces %}
listen [::]:{{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %};
{% endif %}
{% for pi in port_interfaces %}
{% if not pi.startswith("ipv") %}
listen {{ pi }}:{{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %};
{% endif %}
{% endfor %}
{% else %}
listen {{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %}; listen {{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %};
listen [::]:{{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %}; listen [::]:{{ portstring }} {% if udp %} udp {% endif %}{% if ssl %} ssl {% endif %};
{% endif %}
{% if not extra_content or not "proxy_timeout" in extra_content %} {% if not extra_content or not "proxy_timeout" in extra_content %}
proxy_timeout {{ proxy_timeout }}; proxy_timeout {{ proxy_timeout }};

6
vm.py
View File

@@ -62,6 +62,8 @@ class VM:
name = str(portStruct.get("name")).replace(" ", "") name = str(portStruct.get("name")).replace(" ", "")
portstring = str(portStruct.get("port")).replace(" ", "") portstring = str(portStruct.get("port")).replace(" ", "")
port_interfaces = portStruct.get("interfaces")
assert(port_interfaces is None or type(port_interfaces) == list)
transparent = portStruct.get("transparent") transparent = portStruct.get("transparent")
proto = portStruct.get("proto") or "tcp" proto = portStruct.get("proto") or "tcp"
isUDP = proto == "udp" isUDP = proto == "udp"
@@ -75,7 +77,9 @@ class VM:
component = template.render(targetip=self.ip, udp=isUDP, portstring=portstring, component = template.render(targetip=self.ip, udp=isUDP, portstring=portstring,
transparent=transparent, proxy_timeout=proxy_timeout, transparent=transparent, proxy_timeout=proxy_timeout,
comment=compositeName, extra_content=extra_content) comment=compositeName, extra_content=extra_content,
port_interfaces=port_interfaces)
components.append(component) components.append(component)
return components return components