[update] jinja brackets so that resulting output on xml files are better

human readable
This commit is contained in:
David Bezuidenhout 2015-03-11 16:04:00 +02:00
parent b584c44edc
commit 847417f03e
2 changed files with 125 additions and 107 deletions

View File

@ -1,24 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<service> <service>
{% if 'short' in service %}<short>{{ service.short }}</short>{% else %}<short>{{ name }}</short>{% endif %} {%- if 'short' in service %}<short>{{ service.short }}</short>{%- else %}<short>{{ name }}</short>{%- endif %}
{% if 'description' in service %}<description>{{ service.description }}</description>{% endif %} {%- if 'description' in service %}<description>{{ service.description }}</description>{%- endif %}
{% if 'ports' in service %} {%- if 'ports' in service %}
{% if 'tcp' in service.ports %} {%- if 'tcp' in service.ports %}
{% for v in service.ports.tcp %}<port port="{{ v }}" protocol="tcp" />{% endfor %} {%- for v in service.ports.tcp %}
{% endif %} <port port="{{ v }}" protocol="tcp" />
{% if 'udp' in service.ports %} {%- endfor %}
{% for v in service.ports.udp %}<port port="{{ v }}" protocol="udp" />{% endfor %} {%- endif %}
{% endif %} {%- if 'udp' in service.ports %}
{% if 'modules' in service %} {%- for v in service.ports.udp %}
{% for v in service.modules %}<module name="{{ v }}" />{% endfor %} <port port="{{ v }}" protocol="udp" />
{% endif %} {%- endfor %}
{% endif %} {%- endif %}
{% if 'destinations' in service %} {%- if 'modules' in service %}
{% if 'ipv4' in service.destinations %} {%- for v in service.modules %}
{% for v in service.destinations.ipv4 %}<destination ipv4="{{ v }}" />{% endfor %} <module name="{{ v }}" />
{% endif %} {%- endfor %}
{% if 'ipv6' in service.destinations %} {%- endif %}
{% for v in service.destinations.ipv6 %}<destination ipv6="{{ v }}" />{% endfor %} {%- endif %}
{% endif %} {%- if 'destinations' in service %}
{% endif %} {%- if 'ipv4' in service.destinations %}
{%- for v in service.destinations.ipv4 %}
<destination ipv4="{{ v }}" />
{%- endfor %}
{%- endif %}
{%- if 'ipv6' in service.destinations %}
{%- for v in service.destinations.ipv6 %}
<destination ipv6="{{ v }}" />
%- endfor %}
{%- endif %}
{%- endif %}
</service> </service>

View File

@ -1,96 +1,104 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<zone{% if 'target' in zone %} target="{{ zone.target }}"{% endif %}> <zone{%- if 'target' in zone %} target="{{ zone.target }}"{%- endif %}>
{% if 'short' in zone %}<short>{{ zone.short }}</short>{% else %}<short>{{ name }}</short>{% endif %} {% if 'short' in zone %}<short>{{ zone.short }}</short>{% else %}<short>{{ name }}</short>{% endif %}
{% if 'description' in zone %}<description>{{ zone.description }}</description>{% endif %} {% if 'description' in zone %}<description>{{ zone.description }}</description>{% endif %}
{% if 'interfaces' in zone %} {%- if 'interfaces' in zone %}
{% for v in zone.interfaces %}<interface name="{{ v }}" />{% endfor %} {%- for v in zone.interfaces %}
{% endif %} <interface name="{{ v }}" />
{% if 'sources' in zone %} {%- endfor %}
{% for v in zone.sources %}<source address="{{ v }}" />{% endfor %} {%- endif %}
{% endif %} {%- if 'sources' in zone %}
{% if 'services' in zone %} {%- for v in zone.sources %}
{% for v in zone.services %}<service name="{{ v }}" />{% endfor %} <source address="{{ v }}" />
{% endif %} {%- endfor %}
{% if 'ports' in zone %} {%- endif %}
{% for v in zone.ports %} {%- if 'services' in zone %}
{% if 'comment' in v %} {%- for v in zone.services %}
<!-- {{ v.comment }} --> <service name="{{ v }}" />
{% endif %} {%- endfor %}
<port port="{{ v.port }}" protocol="{{ v.protocol }}"/> {%- endif %}
{% endfor %} {%- if 'ports' in zone %}
{% endif %} {%- for v in zone.ports %}
{% if 'icmp_blocks' in zone %} {%- if 'comment' in v %}
{% for v in zone.icmp_blocks %}<icmp-block name="{{ v }}" />{% endfor %} <!-- {{ v.comment }} -->
{% endif %} {%- endif %}
{% if 'masquerade' in zone %}{% if zone.masquerade %}<masquerade/>{% endif %}{% endif %} <port port="{{ v.port }}" protocol="{{ v.protocol }}"/>
{% if 'forward_ports' in zone %} {%- endfor %}
{% for v in zone.forward_ports %} {%- endif %}
{% if 'comment' in v %} {%- if 'icmp_blocks' in zone %}
<!-- {{ v.comment }} --> {%- for v in zone.icmp_blocks %}
{% endif %} <icmp-block name="{{ v }}" />
<forward-port port="{{ v.portid }}" protocol="{{ v.protocol }}"{% if 'to_port' in v %} to-port="{{ v.to_port }}"{% endif %}{% if 'to_addr' in v %} to-addr="{{ v.to_addr }}"{% endif %} /> {%- endfor %}
{% endfor %} {%- endif %}
{% endif %} {%- if 'masquerade' in zone %}
{%- if zone.masquerade %}
<masquerade/>
{%- endif %}
{%- endif %}
{%- if 'forward_ports' in zone %}
{%- for v in zone.forward_ports %}
{%- if 'comment' in v %}
<!-- {{ v.comment }} -->
{%- endif %}
<forward-port port="{{ v.portid }}" protocol="{{ v.protocol }}"{%- if 'to_port' in v %} to-port="{{ v.to_port }}"{%- endif %}{%- if 'to_addr' in v %} to-addr="{{ v.to_addr }}"{%- endif %} />
{%- endfor %}
{%- endif %}
{% if 'rich_rules' in zone %} {%- if 'rich_rules' in zone %}
{% for rule in zone.rich_rules %} {%- for rule in zone.rich_rules %}
{% if 'family' in rule %} {%- if 'family' in rule %}
<rule family="{{ rule.family }}"> <rule family="{{ rule.family }}">
{% else %} {%- else %}
<rule> <rule>
{% endif %} {%- endif %}
{% if 'source' in rule %} {%- if 'source' in rule %}
<source address="{{ rule.source.address }}" {% if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{% endif %}/> <source address="{{ rule.source.address }}" {%- if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{%- endif %}/>
{% endif %} {%- endif %}
{% if 'destination' in rule %} {%- if 'destination' in rule %}
<destination address="{{ rule.destination.address }}" {% if 'invert' in rule.destination %}invert="{{ rule.destination.invert }}"{% endif %}/> <destination address="{{ rule.destination.address }}" {%- if 'invert' in rule.destination %}invert="{{ rule.destination.invert }}"{%- endif %}/>
{% endif %} {%- endif %}
{% if 'service' in rule %} {%- if 'service' in rule %}
<destination name="{{ rule.service }}"/> <destination name="{{ rule.service }}"/>
{% endif %} {%- endif %}
{% if 'port' in rule %} {%- if 'port' in rule %}
<port port="{{ rule.port.portid }}" protocol="{{ rule.port.protocol }}"/> <port port="{{ rule.port.portid }}" protocol="{{ rule.port.protocol }}"/>
{% endif %} {%- endif %}
{% if 'protocol' in rule %} {%- if 'protocol' in rule %}
<protocol value="{{ rule.protocol }}"/> <protocol value="{{ rule.protocol }}"/>
{% endif %} {%- endif %}
{% if 'icmp_block' in rule %} {%- if 'icmp_block' in rule %}
<icmp_block name="{{ rule.icmp_block }}"/> <icmp_block name="{{ rule.icmp_block }}"/>
{% endif %} {%- endif %}
{% if 'masquerade' in rule %} {%- if 'masquerade' in rule %}
{% if rule.masquerade %}<masquerade/>{% endif %} {%- if rule.masquerade %}<masquerade/>{%- endif %}
{% endif %} {%- endif %}
{% if 'forward_port' in rule %} {%- if 'forward_port' in rule %}
{% if 'comment' in rule.forward_port %} {%- if 'comment' in rule.forward_port %}
<!-- {{ rule.forward_port.comment }} --> <!-- {{ rule.forward_port.comment }} -->
{% endif %} {%- endif %}
<forward-port port="{{ rule.forward_port.portid }}" protocol="{{ rule.forward_port.protocol }}"{% if 'to_port' in rule.forward_port %} to-port="{{ rule.forward_port.to_port }}"{% endif %}{% if 'to_addr' in rule.forward_port %} to-addr="{{ rule.forward_port.to_addr }}"{% endif %} /> <forward-port port="{{ rule.forward_port.portid }}" protocol="{{ rule.forward_port.protocol }}"{%- if 'to_port' in rule.forward_port %} to-port="{{ rule.forward_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.forward_port %} to-addr="{{ rule.forward_port.to_addr }}"{%- endif %} />
{% endif %} {%- endif %}
{% if 'log' in rule %} {%- if 'log' in rule %}
<log{% if 'prefix' in rule.log %} prefix="{{ rule.log.prefix }}"{% endif %}{% if 'level' in rule.log %} level="{{ rule.log.level }}"{% endif %}> <log{%- if 'prefix' in rule.log %} prefix="{{ rule.log.prefix }}"{%- endif %}{%- if 'level' in rule.log %} level="{{ rule.log.level }}"{%- endif %}>
{% if 'limit' in rule.log %} {%- if 'limit' in rule.log %}
<limit value="{{ rule.log.limit }}"/> <limit value="{{ rule.log.limit }}"/>
{% endif %} {%- endif %}
</log> </log>
{% endif %} {%- endif %}
{% if 'audit' in rule %} {%- if 'audit' in rule %}
<audit>{% if 'limit' in rule.audit %} <limit value="{{ rule.audit.limit }}"/>{% endif %}</audit> <audit>{%- if 'limit' in rule.audit %} <limit value="{{ rule.audit.limit }}"/>{%- endif %}</audit>
{% endif %} {%- endif %}
{% if 'accept' in rule %} {%- if 'accept' in rule %}
<accept/> <accept/>
{% endif %} {%- endif %}
{% if 'reject' in rule %} {%- if 'reject' in rule %}
<reject{% if 'type' in rule.reject %} type="{{ rule.reject.type }}"{% endif %}/> <reject{%- if 'type' in rule.reject %} type="{{ rule.reject.type }}"{%- endif %}/>
{% endif %} {%- endif %}
{% if 'drop' in rule %} {%- if 'drop' in rule %}
<drop/> <drop/>
{% endif %} {%- endif %}
</rule> </rule>
{% endfor %} {%- endfor %}
{% endif %} {%- endif %}
</zone> </zone>