diff --git a/templates/nginx_stream_block.conf.j2 b/templates/nginx_stream_block.conf.j2 index 61bfc21..5a6d2cf 100644 --- a/templates/nginx_stream_block.conf.j2 +++ b/templates/nginx_stream_block.conf.j2 @@ -1,8 +1,26 @@ server { # {{ 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 %}; + {% endif %} {% if not extra_content or not "proxy_timeout" in extra_content %} proxy_timeout {{ proxy_timeout }}; diff --git a/vm.py b/vm.py index 2e6ec07..d7a5149 100644 --- a/vm.py +++ b/vm.py @@ -62,6 +62,8 @@ class VM: name = str(portStruct.get("name")).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") proto = portStruct.get("proto") or "tcp" isUDP = proto == "udp" @@ -75,7 +77,9 @@ class VM: component = template.render(targetip=self.ip, udp=isUDP, portstring=portstring, 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) return components