{% extends "base.html" %}
{% comment %}
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ToDo: if connection is disabled, no information are visible anymore (Bug)
{% endcomment %}

{% load bootstrap %}
{% load i18n %}

{% block page_head %}
  <style type="text/css">
    .list-group-item .btn {
      margin: -5px 0;
    }
    .form-inline {
      display: inline;
    }
  </style>
{% endblock %}

{% block content %}

  <div class="row">
    <div class="col-sm-8 col-sm-offset-2">
      <div>
        <a href="{% url 'networks:edit' connection.uuid %}"
           class="btn btn-primary" role="button"
           title="{% trans "Edit connection" %}">{% trans "Edit" %}</a>

        {% if active_connection %}
          <form class="form form-inline" method="post"
                action="{% url 'networks:deactivate' connection.uuid %}">
            {% csrf_token %}
            <button class="btn btn-default" type="submit">
              {% trans "Deactivate" %}</button>
          </form>
        {% else %}
          <form class="form form-inline" method="post"
                action="{% url 'networks:activate' connection.uuid %}">
            {% csrf_token %}
            <button class="btn btn-default" type="submit">
              {% trans "Activate" %}</button>
          </form>
        {% endif %}

        <a href="{% url 'networks:delete' connection.uuid %}"
           class="btn btn-default" role="button"
           title="{% trans "Delete connection" %}">{% trans "Delete" %}</a>
      </div>

      <h3>{% trans "Connection" %}</h3>

      <div class="list-group">
        {% if connection.primary %}
          <div class="list-group-item">
            {% trans "Primary connection" %}
            <div class="pull-right">
              <span class="label label-success">{% trans "yes" %}</span>
            </div>
          </div>
        {% endif %}
        <div class="list-group-item">
          {% trans "Name" %}
          <div class="pull-right">{{ connection.id }}</div>
        </div>
      </div>

      {% if device %}
        <h3>{% trans "Device" %}</h3>

        <div class="list-group">
          <div class="list-group-item">
            {% trans "State" %}
            <span class="pull-right">{{ device.state }}</span>
          </div>
          {% if device.state_reason != 'none' %}
            <div class="list-group-item">
              {% trans "State reason" %}
              <span class="pull-right">{{ device.state_reason }}</span>
            </div>
          {% endif %}
          <div class="list-group-item">
            {% trans "Type" %}
            <span class="pull-right">{{ device.type }}</span>
          </div>
          <div class="list-group-item">
            {% trans "MAC address" %}
            <span class="pull-right">{{ device.hw_address }}</span>
          </div>
          <div class="list-group-item">
            {% trans "Interface" %}
            <span class="pull-right">{{ device.interface_name }}</span>
          </div>
          <div class="list-group-item">
            {% trans "Description" %}
            <span class="pull-right">{{ device.description }}</span>
          </div>
        </div>
      {% endif %}

      <h3>{% trans "Physical Link" %}</h3>

      <div class="list-group">
        {% if device.ethernet %}
          <div class="list-group-item">
            {% trans "Link state" %}
            <div class="pull-right">
              {% if device.ethernet.carrier %}
                <span class='label label-success'>
                  {% trans "cable is connected" %}</span>
              {% else %}
                <span class='label label-warning'>
                  {% trans "please check cable" %}</span>
              {% endif %}
            </div>
          </div>
          <div class="list-group-item">
            {% trans "Speed" %}
            <span class="pull-right">
              {% blocktrans trimmed with ethernet_speed=device.ethernet.speed %}
                {{ ethernet_speed }} Mbit/s
              {% endblocktrans %}
            </span>
          </div>
        {% endif %}

        {% if connection.type == "802-11-wireless" %}
          <div class="list-group-item">
            {% trans "SSID" %}
            <span class="pull-right">{{ connection.wireless.ssid }}</span>
          </div>
          {% if device %}
            <div class="list-group-item">
              {% trans "Speed" %}
              <span class="pull-right">
                {% blocktrans trimmed with wireless_bitrate=device.wireless.bitrate %}
                  {{ wireless_bitrate }} Mbit/s
                {% endblocktrans %}
              </span>
            </div>
            <div class="list-group-item">
              {% trans "Mode" %}
              <span class="pull-right">{{ device.wireless.mode }}</span>
            </div>
          {% endif %}
          {% if access_point.channel %}
            <div class="list-group-item">
              {% trans "Signal strength" %}
              <div class="pull-right">
                <span class="btn btn-primary btn-xs">
                  {{ access_point.strength }}%
                </span>
              </div>
            </div>
          {% endif %}
          {% if access_point.channel %}
            <div class="list-group-item">
              {% trans "Channel" %}
              <span class="pull-right">{{ access_point.channel }}</span>
            </div>
          {% endif %}
        {% endif %}
      </div>

      {% if active_connection %}
        <h3>{% trans "IPv4" %}</h3>

        <div class="list-group">
          {% if connection.ipv4.method %}
            <div class="list-group-item">
              {% trans "Method" %}
              <span class="pull-right">{{ connection.ipv4.method }}</span>
            </div>
          {% endif %}

          {% for address in device.ip4.addresses %}
            <div class="list-group-item">
              {% trans "IP address" %}
              <span class="pull-right">
                {{ address.address }}/{{ address.prefix }}
              </span>
            </div>
          {% endfor %}

          {% if device.ip4.gateway %}
            <div class="list-group-item">
              {% trans "Gateway" %}
              <span class="pull-right">{{ device.ip4.gateway }}</span>
            </div>
          {% endif %}

          {% for server in device.ip4.nameservers %}
            <div class="list-group-item">
              {% trans "DNS server" %}
              <span class="pull-right">{{ server }}</span>
            </div>
          {% endfor %}

          {% if active_connection.ip4.default %}
            <div class="list-group-item">
              {% trans "Default" %}
              <span class="pull-right">{% trans "yes" %}</span>
            </div>
          {% endif %}
        </div>

        <h3>{% trans "IPv6" %}</h3>

        <div class="list-group">
          {% if connection.ipv6.method %}
            <div class="list-group-item">
              {% trans "Method" %}
              <span class="pull-right">{{ connection.ipv6.method }}</span>
            </div>
          {% endif %}

          {% for address in device.ip6.addresses %}
            <div class="list-group-item">
              {% trans "IP address" %}
              <span class="pull-right">{{ address.address }}/{{ address.prefix }}</span>
            </div>
          {% endfor %}

          {% if device.ip6.gateway %}
            <div class="list-group-item">
              {% trans "Gateway" %}
              <span class="pull-right">{{ device.ip6.gateway }}</span>
            </div>
          {% endif %}

          {% for server in device.ip6.nameservers %}
            <div class="list-group-item">
              {% trans "DNS server" %}
              <span class="pull-right">{{ server }}</span>
            </div>
          {% endfor %}

          {% if active_connection.ip6.default %}
            <div class="list-group-item">
              {% trans "Default" %}
              <span class="pull-right">{% trans "yes" %}</span>
            </div>
          {% endif %}
        </div>
      {% else %}
        <h3>{% trans "Status" %}</h3>

        <p>{% trans "This connection is not active." %}</p>
      {% endif %}

      <h3>{% trans "Security" %}</h3>

      {% if connection.zone == "internal" %}
        <div class="list-group">
          <div class="list-group-item">
            {% trans "Firewall zone" %}
            <div class="pull-right">
              <span class="label label-success">{{ connection.zone }}</span>
            </div>
          </div>
        </div>

        <div class="alert alert-info">
          <span class="fa fa-info-circle" aria-hidden="true"></span>
          {% blocktrans trimmed %}
            This interface should be connected to a local
            network/machine.  If you connect this interface to a
            public network, services meant to be available only
            internally will become available externally.  This is a
            security risk.
          {% endblocktrans %}
        </div>
      {% elif connection.zone == "external" %}
        <div class="list-group">
          <div class="list-group-item">
            {% trans "Firewall zone" %}
            <div class="pull-right">
              <span class="label label-warning">{{ connection.zone }}</span>
            </div>
          </div>
        </div>

        <div class="alert alert-info">
          <span class="fa fa-info-circle" aria-hidden="true"></span>
          {% blocktrans trimmed %}
            This interface should receive your Internet connection.
            If you connect it to a local network/machine, many
            services meant to available only internally will not be
            available.
          {% endblocktrans %}
        </div>
      {% else %}
        <div class="list-group">
          <div class="list-group-item">
            {% trans "Firewall zone" %}
            <div class="pull-right">
              <span class="label label-danger">{{ connection.zone }}</span>
            </div>
          </div>
        </div>

        <div class="alert alert-danger">
          <span class="fa fa-exclamation-circle" aria-hidden="true"></span>
          {% blocktrans trimmed %}
            This interface is not maintained by {{ box_name }}.  Its
            security status is unknown to {{ box_name }}.  Many {{ box_name }}
            services may not be available on this interface.  It is
            recommended that you deactivate or delete this connection and
            re-configure it.
          {% endblocktrans %}
        </div>
      {% endif %}
    </div>
  </div>
{% endblock %}
