{% import 'languages/'+lang|default('en')+'.html' as lang %}
	<div class="left-space">
		<h4>{{lang.words.config|title()}} {% if config_file_name != 'undefined' %}{{config_file_name.replace('92', '/')}}{%endif%} {{lang.words.from}} {{serv}} ({{hostname}})</h4>
		<p class="accordion-expand-holder">
			{% if role <= 3 %}
				{% if not is_serv_protected or role <= 2 %}
				{% if not configver %}
				<a class="ui-button ui-widget ui-corner-all" title="Edit this run config" id="edit_link" href="/app/config/{{service}}/{{serv}}/edit/{{config_file_name}}">{{lang.words.edit|title()}}</a>
				{% endif %}
				{% if service == 'haproxy' %}
				<a class="ui-button ui-widget ui-corner-all" title="{{lang.words.add|title()}} {{lang.words.proxy}}" href="/app/add/haproxy#proxy">{{lang.words.add|title()}}</a>
				{% elif service == 'keepalived' %}
				<a class="ui-button ui-widget ui-corner-all" title="{{lang.words.add|title()}} VRRP" href="/app/ha">{{lang.words.add|title()}}</a>
				{% endif %}
				{% endif %}
			{% endif %}
			<a class="accordion-expand-all ui-button ui-widget ui-corner-all" id="expand_link" href="#">{{lang.words.expand_all|title()}}</a>
			<button id="raw">{{lang.words.raw|title()}}</button>
			<button id="according" style="display: none;">According</button>
		</p>
	</div>

	<div class="configShow left-space">
	{% set i = 0 -%}
	{% set section_name = {} %}
	{% for line in conf -%}
		{% set i = i + loop.index0 %}
		{% if not role %}
			{% if line.startswith('#HideBlockStart') %}
				<!--{{line}}
				{% continue %}
			{% endif %}
			{% if line.startswith('#HideBlockEnd') %}
				{{line}}-->
				{% continue %}
			{% endif %}
		{% endif %}
		{% if service == 'nginx' %}
			{% if i == 0 and "server {" not in line %}
				<span class="param">
				</span><div>
				<span class="configLine">
					<span class="numRow">{{ i }}</span>
					&emsp;&emsp;{{ line }}
				</span><br />
				{% continue %}
			{% endif %}
			{%- if "server {" in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{%- if "stream {" in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{%- if "http {" in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{%- if "events {" in line -%}
				</div>
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}

			{% if "listen " in line or "location" in line or "server_name" in line or "}" in line  %}
				{% if "#" not in line %}
					<span class="numRow">
						{{ i }}
					</span>
					<span class="paramInSec">
						&emsp;{{ line }}
					</span><br />
					{% continue %}
				{% endif %}
			{% endif %}
			{% if "#" in line %}
				<span class="numRow">
					{{ i }}
				</span>
				<span class="comment">
					&emsp;{{ line }}
				</span><br />
				{% continue %}
			{% endif %}
			{% if line|length > 1 %}
				<span class="configLine">
					<span class="numRow">{{ i }}</span>
					&emsp;&emsp;{{ line }}
				</span><br />
			{% endif %}
		{% elif service == 'apache' %}
			{% if i == 0 and "<VirtualHost" not in line %}
				<span class="param">
				</span><div>
				<span class="configLine">
					<span class="numRow">{{ i }}</span>
					&emsp;&emsp;{{ line }}
				</span><br />
				{% continue %}
			{% endif %}
			{%- if "<VirtualHost" in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{% if "<" in line or "</" in line  %}
				{% if "#" not in line %}
					<span class="numRow">
						{{ i }}
					</span>
					<span class="paramInSec">
						&emsp;{{ line }}
					</span><br />
					{% continue %}
				{% endif %}
			{% endif %}
			{% if "#" in line %}
				<span class="numRow">
					{{ i }}
				</span>
				<span class="comment">
					&emsp;{{ line }}
				</span><br />
				{% continue %}
			{% endif %}
			{% if line|length > 1 %}
				<span class="configLine">
					<span class="numRow">{{ i }}</span>
					&emsp;&emsp;{{ line }}
				</span><br />
			{% endif %}
		{% elif service == 'keepalived' %}
			{%- if "global_defs {" in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{%- if "vrrp_instance " in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{%- if "virtual_server " in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{%- if "vrrp_script " in line -%}
				{% if i > 1 %}
					</div>
				{% endif %}
				<span class="param">{{ line }}
				</span><div>
				{% continue %}
			{% endif %}
			{% if "state " in line or "interface" in line or "priority" in line or "}" in line  %}
				{% if "#" not in line %}
					<span class="numRow">
						{{ i }}
					</span>
					<span class="paramInSec">
						&emsp;&emsp;{{ line }}
					</span><br />
					{% continue %}
				{% endif %}
			{% endif %}
			{% if "#" in line %}
				<span class="numRow">
					{{ i }}
				</span>
				<span class="comment">
					&emsp;&emsp;{{ line }}
				</span><br />
				{% continue %}
			{% endif %}
			{% if line|length > 1 %}
				<span class="configLine">
					<span class="numRow">{{ i }}</span>
					&emsp;&emsp;{{ line }}
				</span><br />
			{% endif %}
		{% else %}
			{% if line.startswith('global') %}
				<span class="param">{{ line }}
					{% if role %}
						{% if service != 'keepalived' %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}</a>
						</span>
						{% endif %}
					{% endif %}
				</span><div>
				{% continue %}
			{% endif %}
			{% if line.startswith('defaults') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
						<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}</a>
						</span>
					{% endif %}
					</span><div>
				{% continue %}
			{% endif %}
			{%- if line.startswith('listen') -%}
				</div><span class="param">{{- line -}}
					{% if role %}
					<span class="accordion-link">
						<a href="/app/config/section/haproxy/{{serv}}/{{ line }}" target="_blank">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
					</span>
					{% endif %}
					{%- set backend = line.split(' ') -%}
					<span class="accordion-link">
						<a href="/app/stats/haproxy/{{-serv-}}#{{- backend[1]-}}" target="_blank">{{lang.words.stats|title()}}</a>
					</span>
					{%- set backend = backend|join('_') -%}
					{%- do section_name.update({i: backend}) -%}
					<span id="{{-section_name[i]|replace('\n', '')-}}" class="accordion-link" target="_blank"></span>
					</span><div>
					{% continue %}
			{%- endif -%}
			{%- if line.startswith('frontend') -%}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
					{% set backend = line.split(' ') %}
					<span class="accordion-link">
						<a href="/app/stats/haproxy/{{-serv-}}#{{- backend[1]-}}" target="_blank">{{lang.words.stats|title()}}</a>
					</span>
					{% set backend = backend|join('_') %}
					{% do section_name.update({i: backend}) %}
					<span id="{{section_name[i]|replace('\n', '')}}" class="accordion-link"></span>
					</span><div>
					{% continue %}
			{%- endif -%}
			{% if line.startswith('backend') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
					{% set backend = line.split(' ') %}
					<span class="accordion-link">
						<a href="/app/stats/haproxy/{{-serv-}}#{{- backend[1]-}}" target="_blank">{{lang.words.stats|title()}}</a>
					</span>
					</span><div>
				{% continue %}
			{% endif %}
			{% if line.startswith('cache') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
				</span><div>
				{% continue %}
			{% endif %}
			{% if line.startswith('peers') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
				</span><div>
				{% continue %}
			{% endif %}
			{% if line.startswith('resolvers') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
				</span><div>
				{% continue %}
			{% endif %}
			{% if line.startswith('userlist') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
				</span><div>
				{% continue %}
			{% endif %}
			{% if line.startswith('http-errors') %}
				</div><span class="param">{{ line }}
					{% if role %}
						<span class="accordion-link">
							<a href="/app/config/section/haproxy/{{serv}}/{{ line }}">{{lang.words.edit|title()}}/{{lang.words.delete|title()}}</a>
						</span>
					{% endif %}
				</span><div>
			{% continue %}
			{% endif %}
			{% if "acl" in line or "option" in line or "server" in line %}
				{% if "timeout" not in line and "default-server" not in line and "#use_backend" not in line and "#" not in line%}
					<span class="numRow">
						{{ i }}
					</span>
					<span class="paramInSec">
						{{ line }}
					</span><br />
					{% continue %}
				{% endif %}
			{% endif %}
			{% if line.startswith("#") %}
				<span class="numRow">
					{{ i }}
				</span>
				<span class="comment">
					{{ line }}
				</span><br />
				{% continue %}
			{% endif %}
			{% if line|length > 1 %}
				<span class="configLine">
					<span class="numRow">{{ i }}</span>
					{{ line }}
				</span><br />
			{% endif %}
			{%- if "bind" in line and "@" not in line and "-" not in line -%}
				{%- set bind = line.split(':')[1] -%}
				{%- set bind = bind.split(' ') -%}
				<script>
					{% set k = i - 1 %}
					$('#{{-section_name[k]|replace("\n", "")-}}').html('<a href="http://{{-serv-}}:{{-bind[0]|replace("\n", "")-}}" title="Open {{serv-}}:{{-bind[0]|replace("\n", "")-}}" target="_blank">{{lang.words.open|title()}}</a>')
				</script>
			{%- endif -%}
		{%- endif -%}
	{%- endfor -%}
	</div>
	</div>
	{% if configver %}
	<br>
		{% if role <= 3 %}
		{% if not is_serv_protected or role <= 2 %}
		<form action="/app/config/versions/{{service}}/{{serv}}/{{configver}}/save" method="post" class="left-space">
			<input type="hidden" value="{{serv}}" name="serv">
			<input type="hidden" value="{{service}}" name="service">
			<input type="hidden" value="{{configver}}" name="configver">
			<input type="hidden" value="1" name="config">
			<button type='submit' value='save' name='save' class='btn btn-default' title="{{lang.phrases.save_title}}">{{lang.words.save|title()}}</button>
			{% if is_restart|int == 0 %}
			<button type='submit' value='' name='' class='btn btn-default'>{{lang.phrases.upload_and_restart}}</button>
			{% endif %}
			{% if service != 'keepalived' %}
			<button type='submit' value='reload' name='save' class='btn btn-default'>{{lang.phrases.upload_and_reload}}</button>
			{% endif %}
		</form>
		{% endif %}
		{% endif %}
		<div class="alert alert-info"><b>{{lang.words.note|title()}}:</b> {{lang.phrases.master_slave|title()}}</div>
	{% endif %}
	<script>
		{% if role <= 3 %}
			{% if not is_serv_protected or role <= 2 %}
			$(document).bind('keydown', 'e', function (){
				window.location = document.getElementById('edit_link').href;
			});
			{% endif %}
		{% endif %}
		$(document).on('keydown', null, 'r', raw_button);
		function raw_button(event) {
			$("#raw").trigger("click");
		}
		$(document).on('keydown', null, 'a', according_button);
		function according_button(event) {
			$("#according").click();
		}
		$(document).on('keydown', null, 'x', expand_button);
		function expand_button(event) {
			$("#expand_link").click();
		}

	</script>
