Hotfix/http request before use backend (#999)

* Ensured http-request options are written before use_backend. Removed excessive newlines
This commit is contained in:
Mathias Aerts
2018-11-25 23:44:44 +01:00
committed by Frank Wall
parent 1cb21ac507
commit 1f9250e15b
@@ -1,23 +1,24 @@
#
# Automatically generated configuration.
# Do not edit this file manually.
{% if helpers.exists('OPNsense.HAProxy') %}
#
{%- if helpers.exists('OPNsense.HAProxy') -%}
{# ############################### #}
{# GLOBAL VARIABLES #}
{# ############################### #}
{#- ############################### -#}
{#- GLOBAL VARIABLES -#}
{#- ############################### -#}
{%- if helpers.exists('OPNsense.HAProxy.general.peers') and OPNsense.HAProxy.general.peers.enabled|default("") == "1" -%}
{% set peers_enabled = True %}
{% set peers_name = 'opnsense-haproxy-peers' %}
{%- set peers_enabled = True -%}
{%- set peers_name = 'opnsense-haproxy-peers' -%}
{%- endif -%}
{# ############################### #}
{# MACROS #}
{# ############################### #}
{#- ############################### -#}
{#- MACROS -#}
{#- ############################### -#}
{# Macro expects a CSV list of Error Files and validates them. #}
{% macro ErrorFiles(linkedData) -%}
{#- Macro expects a CSV list of Error Files and validates them. #}
{%- macro ErrorFiles(linkedData) -%}
{% if linkedData is defined %}
{# # remember all Errorfiles to avoid duplicate HTTP codes #}
{% set http_codes_seen = [] %}
@@ -35,13 +36,15 @@
{% else %}
# ERROR: ErrorFiles called with empty data
{% endif %}
{%- endmacro %}
{%- endmacro -%}
{# Macro expects a CSV list of Actions and validates them. #}
{% macro AclsAndActions(linkedData) -%}
{%- macro AclsAndActions(linkedData) -%}
{% if linkedData is defined %}
{# # remember all ACLs to avoid duplicate declarations #}
{% set acls_seen = [] %}
{% set global_action_options = [] %}
{% set global_use_options = [] %}
{% for action in linkedData.split(",") %}
{% set action_data = helpers.getUUID(action) %}
{# # collect ACLs for this action #}
@@ -297,10 +300,11 @@
{% if acl_errors|int == 0 %}
{% set action_enabled = '1' %}
{% set action_options = [] %}
{% set use_options = [] %}
{% if action_data.type == 'use_backend' %}
{% if action_data.use_backend|default("") != "" %}
{% set acl_backend_data = helpers.getUUID(action_data.use_backend) %}
{% do action_options.append('use_backend ' ~ acl_backend_data.name) %}
{% do use_options.append('use_backend ' ~ acl_backend_data.name) %}
{% else %}
{% set action_enabled = '0' %}
# ERROR: missing parameters
@@ -308,7 +312,7 @@
{% elif action_data.type == 'use_server' %}
{% if action_data.use_server|default("") != "" %}
{% set server_data = helpers.getUUID(action_data.use_server) %}
{% do action_options.append('use-server ' ~ server_data.name) %}
{% do use_options.append('use-server ' ~ server_data.name) %}
{% else %}
{% set action_enabled = '0' %}
# ERROR: missing parameters
@@ -326,7 +330,7 @@
{% set defaultbackend_option = '' %}
{% endif %}
{# # Finally add map file to config #}
{% do action_options.append('use_backend %[req.hdr(host),lower,map_dom(' ~ mapfile_path ~ defaultbackend_option ~ ')]') %}
{% do use_options.append('use_backend %[req.hdr(host),lower,map_dom(' ~ mapfile_path ~ defaultbackend_option ~ ')]') %}
{% else %}
{% set action_enabled = '0' %}
# ERROR: missing parameters
@@ -473,7 +477,7 @@
{% elif action_data.type == 'tcp-request_content_reject' %}
{% do action_options.append('tcp-request content reject') %}
{% elif action_data.type == 'tcp-request_content_lua' %}
{% if action_data.tcp-request_content_lua|default("") != "" %}
{% if action_data.tcp_request_content_lua|default("") != "" %}
{% do action_options.append('tcp-request content lua.' ~ action_data.tcp_request_content_lua) %}
{% else %}
{% set action_enabled = '0' %}
@@ -518,13 +522,20 @@
{% set join_operator = ' ' %}
{% endif %}
{# # check if action depends on ACLs #}
{% set comment_lines = ['# ACTION: ' + action_data.name] %}
{% if action_acls|length > 0 %}
# ACTION: {{action_data.name}}
{{action_options|join(' ')}} {{action_data.testType}} {{action_acls|join(join_operator)}}
{% set acl_line = [action_data.testType, action_acls|join(join_operator)]|join(' ') %}
{% else %}
# NOTE: actions with no ACLs/conditions will always match
# ACTION: {{action_data.name}}
{{action_options|join(' ')}}
{% set acl_line = '' %}
{% set comment_lines = ['# NOTE: actions with no ACLs/conditions will always match'] + comment_lines %}
{% endif %}
{% if action_options|length > 0 %}
{% do global_action_options.append(comment_lines|join('\n')) %}
{% do global_action_options.append(([action_options|join(' '), acl_line]|join(' '))) %}
{% endif %}
{% if use_options|length > 0 %}
{% do global_use_options.append(comment_lines|join('\n')) %}
{% do global_use_options.append(([use_options|join(' '), acl_line]|join(' '))) %}
{% endif %}
{% else %}
# ACTION INVALID: {{action_data.name}}
@@ -534,6 +545,14 @@
# ACL ERROR COUNT: {{acl_errors}}
{% endif %}
{% endfor %}
{% if global_action_options|length > 0 %}
{{global_action_options|join('\n' + ' ')}}
{% endif %}
{% if global_use_options|length > 0 %}
{{global_use_options|join('\n' + ' ')}}
{% endif %}
{% else %}
# ERROR: AclsAndActions called with empty data
{% endif %}
@@ -738,11 +757,11 @@ userlist list_{{proxy.id}}
#
# NOTE: HAProxy is currently DISABLED
#
{% endif %}
{%- endif -%}
{# ############################### #}
{# GLOBAL #}
{# ############################### #}
{#- ############################### -#}
{#- GLOBAL -#}
{#- ############################### -#}
global
{% if OPNsense.HAProxy.general.tuning.root != "1" %}
@@ -830,7 +849,7 @@ global
{% for customOpt in OPNsense.HAProxy.general.tuning.customOptions.split("\n") %}
{{customOpt}}
{% endfor %}
{% endif %}
{%- endif -%}
{# ############################### #}
{# DEFAULTS #}
@@ -866,7 +885,7 @@ defaults
{{customOpt}}
{% endfor %}
{% endif %}
{% endif %}
{%- endif -%}
{# ############################### #}
{# USERLISTS #}
@@ -1086,13 +1105,13 @@ frontend {{frontend.name}}
{% endif %}
{% endfor %}
{% endif %}
{%- endif -%}
{# ############################### #}
{# BACKENDS #}
{# ############################### #}
{% if helpers.exists('OPNsense.HAProxy.backends') %}
{%- if helpers.exists('OPNsense.HAProxy.backends') %}
{% for backend in helpers.toList('OPNsense.HAProxy.backends.backend') %}
{# # ignore disabled backends and those without a server #}
{% if backend.enabled == '1' and backend.linkedServers|default("") != "" %}
@@ -1359,13 +1378,13 @@ backend {{backend.name}}
{% endif %}
{% endfor %}
{% endif %}
{%- endif -%}
{# ############################### #}
{# PEERS #}
{# ############################### #}
{% if helpers.exists('OPNsense.HAProxy.general.peers') and OPNsense.HAProxy.general.peers.enabled|default("") == "1" %}
{%- if helpers.exists('OPNsense.HAProxy.general.peers') and OPNsense.HAProxy.general.peers.enabled|default("") == "1" %}
{# # ensure that no value is missing #}
{% if OPNsense.HAProxy.general.peers.name1|default("") != '' and
OPNsense.HAProxy.general.peers.listen1|default("") != '' and
@@ -1376,14 +1395,14 @@ backend {{backend.name}}
peers {{peers_name}}
peer {{OPNsense.HAProxy.general.peers.name1}} {{OPNsense.HAProxy.general.peers.listen1}}:{{OPNsense.HAProxy.general.peers.port1}}
peer {{OPNsense.HAProxy.general.peers.name2}} {{OPNsense.HAProxy.general.peers.listen2}}:{{OPNsense.HAProxy.general.peers.port2}}
{% endif %}
{% endif %}
{%- endif -%}
{%- endif -%}
{# ############################### #}
{# STATISTICS #}
{# ############################### #}
{% if helpers.exists('OPNsense.HAProxy.general.stats') and OPNsense.HAProxy.general.stats.enabled|default("") == "1" %}
{%- if helpers.exists('OPNsense.HAProxy.general.stats') and OPNsense.HAProxy.general.stats.enabled|default("") == "1" %}
{# # enable local stats #}
listen local_statistics
bind 127.0.0.1:{{OPNsense.HAProxy.general.stats.port}}
@@ -1428,5 +1447,4 @@ listen remote_statistics
{% endif %}
{% endif %}
{% endif %}
{%- endif -%}