From c3e5753b52615d031428f3bd3bd6ac629b1bf3e4 Mon Sep 17 00:00:00 2001 From: Daniel Steglich Date: Tue, 15 Sep 2015 21:24:44 +0000 Subject: [PATCH] Network Status pages: added status pages - implemented network status page which supports: * show IP address and netmask * show MAC address * show device name * show firewall zone name * show DNS server information * show default gateway * show wifi information * shows if connection is shared or not and if connection is the default connection - when clicking on a cennection on the overview page go to the status page, not to the editing page - ToDo: if connection is disabled and re-enabled again, no information are visible anymore (Bug) --- plinth/modules/networks/networks.py | 76 ++++++ .../networks/templates/connection_show.html | 186 ++++++++++++++ .../networks/templates/connections_list.html | 8 +- plinth/modules/networks/urls.py | 2 + plinth/network.py | 239 ++++++++++++++++++ 5 files changed, 507 insertions(+), 4 deletions(-) create mode 100644 plinth/modules/networks/templates/connection_show.html diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index e01854814..e6a522528 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -57,6 +57,82 @@ def index(request): 'connections': connections}) +def show(request, uuid): + """Serve connection information.""" + try: + connection = network.get_connection(uuid) + except network.ConnectionNotFound: + messages.error(request, _('Cannot show connection: ' + 'Connection not found.')) + return redirect(reverse_lazy('networks:index')) + + name = connection.get_interface_name() + connectiontype = connection.get_connection_type() + settings_ipv4 = connection.get_setting_ip4_config() + + mac = network.get_mac_from_device(name) + interface = connection.get_interface_name() + if connectiontype == '802-11-wireless': + settings_wireless = connection.get_setting_wireless() + ssid = settings_wireless.get_ssid().get_data() + rate = network.get_wifi_rate(interface, ssid) + channel = network.get_wifi_channel(interface, ssid) + strength = network.get_wifi_signal(interface, ssid) + linkstate = True + else: + ssid = "None" + rate = 0 + channel = 0 + linkstate = network.get_linkstate_from_device(name) + strength = 0 + + ip = network.get_all_ip_from_device(name) + ip6 = network.get_all_ip6_from_device(name) + dns = network.get_namesever_from_device(name) + dns6 = network.get_namesever6_from_device(name) + gateway = network.get_gateway_from_device(name) + gateway6 = network.get_gateway6_from_device(name) + method = settings_ipv4.get_method() + + zone = connection.get_setting_connection().get_zone() + active = network.connection_is_active(uuid) + + if network.get_primary_connection().get_id() == connection.get_id(): + primary = True + else: + primary = False + + if not ip: + ip.append("0.0.0.0/0") + + if not ip6: + ip6.append("::0/0") + + return TemplateResponse(request, 'connection_show.html', + {'title': _('Show Connection information'), + 'ip': ip, + 'ip6': ip6, + 'gateway': gateway, + 'gateway6': gateway6, + 'dns': dns, + 'dns6': dns6, + 'interface': interface, + 'mac': mac, + 'linkstate': linkstate, + 'zone': zone, + 'primary': primary, + 'subsubmenu': subsubmenu, + 'method': method, + 'connectiontype': connectiontype, + 'ssid': ssid, + 'strength': strength, + 'rate': rate, + 'channel': channel, + 'active': active, + 'uuid': uuid, + 'name': name}) + + def edit(request, uuid): """Serve connection editing form.""" try: diff --git a/plinth/modules/networks/templates/connection_show.html b/plinth/modules/networks/templates/connection_show.html new file mode 100644 index 000000000..f657a30da --- /dev/null +++ b/plinth/modules/networks/templates/connection_show.html @@ -0,0 +1,186 @@ +{% extends "base.html" %} +{% comment %} +# +# This file is part of Plinth. +# +# 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 . +# +# ToDo: if connection is disabled, no information are visible anymore (Bug) +{% endcomment %} +{% block page_head %} + +{% endblock %} +{% load bootstrap %} + +{% block content %} + {% if active %} +

Physical Link Information

+ + {% if linkstate and connectiontype == "802-3-ethernet" %} + cable is connected +

+ {% elif connectiontype == "802-3-ethernet" %} + please check cable +

+ {% endif %} +
+
+
+ {% if connectiontype == "802-11-wireless" %} +
+ SSID + {{ ssid }} +
+
+ Speed + {{ rate }} +
+
+ Signal + + + {{ strength }}% + + +
+
+ Channel + {{ channel }} +
+ {% endif %} +
+ MAC adress + {{ mac }} +
+
+ Interface + {{ interface }} +
+
+
+
+ +

IP Address Information

+ +
+
+
+ {% for addr in ip %} +
+ IPv4 Address + {{ addr }} + +
+ {% endfor %} + {% for addr in ip6 %} +
+ IPv6 Address + {{ addr }} + +
+ {% endfor %} + {% for server in dns %} +
+ DNS Server + {{ server }} +
+ {% endfor %} + {% for server in dns6 %} +
+ DNS Server + {{ server }} +
+ {% endfor %} + {% if gateway %} +
+ IPv4 Default Gateway + {{ gateway }} +
+ {% endif %} + {% if gateway6 %} +
+ IPv6 Default Gateway + {{ gateway6 }} +
+ {% endif %} + {% if method == "shared" %} +
+ DHCP Server + enabled +
+ {% elif method == "auto" %} +
+ IP Method + {{ method }} + +
+ {% endif %} + {% if primary %} +
+ Default Connection + + yes + +
+ {% endif %} +
+
+
+

Security Information

+ {% if zone == "internal" %} + Firewall: {{ zone }}

+ INFO: This interface should be connected to local network.
+ If you connect this interface to a public + network, others may have access to your data. + {% elif zone == "external" %} + Firewall: {{ zone }}

+ INFO: This interface should be connected to your internet upstream + connection + {% else %} + Firewall: {{ zone }}

+ WARNING: This interface is not assigned to a zone which is maintained by + freedombox + {% endif %} + {% else %} + This connections is not active. Please activate connection. + {% endif %} +

+ + Edit + + {% if active %} + + Deactivate + + {% else %} + + Activate + + {% endif %} + + Delete + +{% endblock %} diff --git a/plinth/modules/networks/templates/connections_list.html b/plinth/modules/networks/templates/connections_list.html index 34ee28b4a..8b481484f 100644 --- a/plinth/modules/networks/templates/connections_list.html +++ b/plinth/modules/networks/templates/connections_list.html @@ -22,7 +22,7 @@ {% block page_head %}