{% import 'languages/'+lang|default('en')+'.html' as lang %}
{% set services_name = {
	'roxy-wi-checker': { 'name': 'Checker', 'desc': lang.admin_page.desc.checker_desc },
	'roxy-wi-keep_alive': { 'name': 'Auto start', 'desc': lang.admin_page.desc.auto_start_desc },
	'roxy-wi-metrics': { 'name': 'Metrics', 'desc': lang.admin_page.desc.metrics_desc },
	'roxy-wi-portscanner': { 'name': 'Port scanner', 'desc': lang.admin_page.desc.p_s_desc },
	'roxy-wi-smon': { 'name': 'SMON', 'desc': lang.admin_page.desc.smon_desc },
	'roxy-wi-socket': { 'name': 'Socket', 'desc': lang.admin_page.desc.socket_desc },
	'roxy-wi-prometheus-exporter': { 'name': 'Prometheus exporter', 'desc': 'Prometheus exporter exports Roxy-WI metrics' },
	'prometheus': { 'name': 'Prometheus', 'desc': 'Prometheus server' },
	'grafana-server': { 'name': 'Grafana', 'desc': 'Grafana server' },
	'fail2ban': { 'name': 'Fail2ban', 'desc': 'Fail2ban scans log files (e.g. /var/log/apache/error_log) and bans IPs that show the malicious signs' },
    'rabbitmq-server': { 'name': 'RabbitMQ', 'desc': 'RabbitMQ server' },
    }
%}
{% for s in services %}
{% set is_service_started_class = '' %}
{% set is_service_stopped_class = '' %}
{% set onclick_start_action = "confirmAjaxServiceAction('start', '"+s.0+"')" %}
{% set onclick_stop_action = "confirmAjaxServiceAction('stop', '"+s.0+"')" %}
{% set is_service_started_title = lang.words.start|title()+" "+lang.words.and+" "+lang.words.enable+" "+services_name[s.0]['name']+" "+lang.words.service %}
{% set is_service_stopped_title = lang.words.stop|title()+" "+lang.words.and+" "+lang.words.disable+" "+services_name[s.0]['name']+" "+lang.words.service %}
<tr class="{{ loop.cycle('odd', 'even') }}" id="{{s.0}}">
    <td class="padding10 first-collumn">
        {% if s.1 == 'active' or s.1 == 'RUNNING' %}
            <span title="{{lang.words.service|title()}} {{services_name[s.0]['name']}} {{lang.words.started}}"><span class="serverUp server-status"></span></span>
            {% set is_service_started_class = 'disabled-button' %}
            {% set onclick_start_action = "" %}
            {% set is_service_started_title = lang.words.service|title()+" "+services_name[s.0]['name']+" "+lang.words.already+" "+lang.words.started %}
        {% else %}
            {% if (s.1 == 'inactive' or s.1 == 'failed' or s.1 == 'activating' or s.1 == 'STOPPED') and 'is not installed' not in s.2['current_version'] %}
                <span title="{{lang.words.service|title()}} {{services_name[s.0]['name']}} {{lang.words.stopped}}"><span class="serverDown server-status"></span></span>
                {% set is_service_stopped_class = 'disabled-button' %}
                {% set onclick_stop_action = "" %}
                {% set is_service_stopped_title = lang.words.service|title()+" "+services_name[s.0]['name']+" "+lang.words.already+" "+lang.words.stopped %}
            {% else %}
                <span title="{{lang.words.service|title()}} {{services_name[s.0]['name']}} {{lang.words.not}} {{lang.words.installed}}"><span class="serverNone server-status"></span></span>
            {% endif %}
        {% endif %}
        {{services_name[s.0]['name']}}
    </td>
    <td class="padding10 first-collumn">
        {% if 'is not installed' in s.2['current_version'] or not s.2['current_version'] or s.2['current_version'] == '0' %}
            {% if s.0 in ('prometheus', 'grafana-server') %}
                <a href="/app/install#monitoring" class="ui-button ui-widget ui-corner-all" title="{{lang.words.install|title()}} {{service_name}}">{{lang.words.install|title()}}</a>
            {% elif s.0 in ('rabbitmq-server', 'fail2ban') %}
                <a class="ui-button ui-widget ui-corner-all" href="https://roxy-wi.org/tools/{{s.0.split('-')[0]}}" title="{{lang.words.install|title()}} {{services_name[s.0]['name']}}" target="_blank">{{lang.words.install|title()}}</a>
            {% else %}
                <a class="ui-button ui-widget ui-corner-all" onclick="updateService('{{s.0}}', 'install')" title="{{lang.words.install|title()}} {{service_name}}">{{lang.words.install|title()}}</a>
            {% endif %}
        {% else %}
        <a id="start-{{ s.0 }}" class="start" title="{{is_service_started_title}}">
            <span class="service-start {{is_service_started_class}}" onclick="{{onclick_start_action}}"></span>
        </a>
        <a id="restart-{{ s.2 }}" class="restart" title="{{lang.words.restart|title()}} {{services_name[s.0]['name']}} {{lang.words.service}}">
            <span class="service-reload service-restart" onclick="confirmAjaxServiceAction('restart', '{{s.0}}')"></span>
        </a>
        <a id="stop-{{ s.0 }}" class="stop" title="{{is_service_stopped_title}}">
            <span class="service-stop {{is_service_stopped_class}}" onclick="{{onclick_stop_action}}"></span>
        </a>
        {% endif %}
    </td>
    <td>
        {% if 'is not installed' not in s.2['current_version'] %}
        {{s.2['current_version']}}
        {% endif %}
    </td>
    <td colspan="2">
        {{ services_name[s.0]['desc'] | safe }}
    </td>
</tr>
{% endfor %}
