%PDF- %PDF-
| Direktori : /backups/router/usr/local/opnsense/service/templates/OPNsense/Sample/ |
| Current File : //backups/router/usr/local/opnsense/service/templates/OPNsense/Sample/example_simple_page.txt |
This is a very simple example of how to generate configuration files based on templates.
In +TARGETS you can find the mapping between this template and the output it should generate.
Now lets retrieve some configuration data from the OPNsense configuration file:
last change date : {{ lastchange|default('unknown') }}
version according to config.xml : {{ version|default('?') }}
list of configured network interfaces :
{% for key,item in interfaces.items() %}
interface {{ key }}
--- interface {{ item.if }}
--- address {{ item.ipaddr }}
--- subnet {{ item.subnet }}
{% endfor %}
Physical interface connected to "lan" : {{ helpers.physical_interface('lan') }} or both lan and wan {{ helpers.physical_interfaces(['lan', 'wan']) }}
and a short list of firewall rules created (multiple rule items in filter section):
{% for item in filter.rule %}
descr : {{ item.descr }}
type : {{ item.type }}
interface : {{ item.interface }}
{% endfor %}
The full documentation for the template engine can be found at : http://jinja.pocoo.org/docs/dev/templates/
A sample with multiple output files ( for example based on interface ) can be found in the example_config.txt template
{% if helpers.exists('filter.rule') %}
filter.rule exists
{% endif %}