diff --git a/data/etc/plinth/modules-enabled/network b/data/etc/plinth/modules-enabled/network new file mode 100644 index 000000000..923bdfd58 --- /dev/null +++ b/data/etc/plinth/modules-enabled/network @@ -0,0 +1 @@ +plinth.modules.network diff --git a/plinth/modules/network/__init__.py b/plinth/modules/network/__init__.py new file mode 100644 index 000000000..7b8cd9e90 --- /dev/null +++ b/plinth/modules/network/__init__.py @@ -0,0 +1,27 @@ +# +# 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 . +# + +""" +Plinth module to interface with network-manager +""" + +from . import network +from .network import init + +__all__ = ['network', 'init'] + +depends = ['plinth.modules.system'] diff --git a/plinth/modules/network/network.py b/plinth/modules/network/network.py new file mode 100644 index 000000000..2dd02c020 --- /dev/null +++ b/plinth/modules/network/network.py @@ -0,0 +1,91 @@ +# +# 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 . +# + +from django.contrib import messages +from django.contrib.auth.decorators import login_required +from django.core.urlresolvers import reverse_lazy +from django.shortcuts import redirect +from django.template.response import TemplateResponse +from gettext import gettext as _ +import NetworkManager +import urllib + +from plinth import cfg + + +CONNECTION_TYPE_NAMES = { + '802-3-ethernet': 'Ethernet', + '802-11-wireless': 'Wi-Fi', + 'bridge': 'Bridge', + 'bond': 'Bond', + 'gsm': 'Mobile Broadband', + 'infiniband': 'InfiniBand', + 'pppoe': 'DSL', + 'vlan': 'VLAN', + 'vpn': 'VPN', + 'wimax': 'WiMAX', +} + + +def init(): + """Initialize the Network module.""" + menu = cfg.main_menu.get('system:index') + menu.add_urlname(_('Network'), 'glyphicon-signal', 'network:index', 18) + + +@login_required +def index(request): + """Show connection list.""" + connections = [] + for conn in NetworkManager.Settings.ListConnections(): + settings = conn.GetSettings()['connection'] + # Display a friendly type name if known. + conn_type = CONNECTION_TYPE_NAMES.get(settings['type'], + settings['type']) + connections.append({ + 'name': settings['id'], + 'id': urllib.parse.quote_plus(settings['id']), + 'type': conn_type + }) + return TemplateResponse(request, 'connections_list.html', + {'title': _('Network Connections'), + 'connections': connections}) + + +@login_required +def delete(request, conn_id): + """Handle deleting connections, showing a confirmation dialog first. + + On GET, display a confirmation page. + On POST, delete the connection. + """ + name = urllib.parse.unquote_plus(conn_id) + if request.method == 'POST': + for conn in NetworkManager.Settings.ListConnections(): + settings = conn.GetSettings()['connection'] + if settings['id'] == name: + conn.Delete() + messages.success(request, _('Connection %s deleted.') % name) + return redirect(reverse_lazy('network:index')) + messages.failure( + request, + _('Failed to delete connection %s: not found.') % name) + return redirect(reverse_lazy('network:index')) + + return TemplateResponse(request, 'connections_delete.html', + {'title': _('Delete Connection'), + 'name': name}) diff --git a/plinth/modules/network/templates/connections_delete.html b/plinth/modules/network/templates/connections_delete.html new file mode 100644 index 000000000..66e3a1488 --- /dev/null +++ b/plinth/modules/network/templates/connections_delete.html @@ -0,0 +1,39 @@ +{% 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 . +# +{% endcomment %} + +{% load bootstrap %} + +{% block content %} + +

Delete Connection {{ name }}

+ +

Delete connection permanently?

+ +
+ {% csrf_token %} + + + + Cancel +
+ +{% endblock %} diff --git a/plinth/modules/network/templates/connections_list.html b/plinth/modules/network/templates/connections_list.html new file mode 100644 index 000000000..5804b274c --- /dev/null +++ b/plinth/modules/network/templates/connections_list.html @@ -0,0 +1,60 @@ +{% 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 . +# +{% endcomment %} + +{% load bootstrap %} + +{% block page_head %} + +{% endblock %} + +{% block content %} + +
+
+
+ {% for conn in connections %} +
+ + + + + + {{ conn.name }} + + {{ conn.type }} +
+ {% endfor %} +
+
+
+ +{% endblock %} diff --git a/plinth/modules/network/urls.py b/plinth/modules/network/urls.py new file mode 100644 index 000000000..9d18c9ccf --- /dev/null +++ b/plinth/modules/network/urls.py @@ -0,0 +1,30 @@ +# +# 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 . +# + +""" +URLs for the Network module +""" + +from django.conf.urls import patterns, url + + +urlpatterns = patterns( + 'plinth.modules.network.network', + url(r'^sys/network/$', 'index', name='index'), + url(r'^sys/network/(?P[\w.@+-]+)/delete/$', + 'delete', name='delete') +)