Network connection list and delete

This commit is contained in:
James Valleroy 2015-02-28 14:25:25 -05:00 committed by Sunil Mohan Adapa
parent d4ac0c3b46
commit 6ad1fb9ce7
6 changed files with 248 additions and 0 deletions

View File

@ -0,0 +1 @@
plinth.modules.network

View File

@ -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 <http://www.gnu.org/licenses/>.
#
"""
Plinth module to interface with network-manager
"""
from . import network
from .network import init
__all__ = ['network', 'init']
depends = ['plinth.modules.system']

View File

@ -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 <http://www.gnu.org/licenses/>.
#
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})

View File

@ -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 <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block content %}
<h3>Delete Connection <em>{{ name }}</em></h3>
<p>Delete connection permanently?</p>
<form class="form" method="post">
{% csrf_token %}
<input type="submit" class="btn btn-md btn-primary"
value="Delete {{ name }}"/>
<a href="{% url 'network:index' %}" role="button"
class="btn btn-md btn-primary">Cancel</a>
</form>
{% endblock %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block page_head %}
<style type="text/css">
.connection-edit-label {
display: inline-block;
width: 75%;
}
.list-group-item .btn {
margin: -5px 0;
}
</style>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-4">
<div class="list-group">
{% for conn in connections %}
<div class="list-group-item clearfix">
<a href="{% url 'network:delete' conn.id %}"
class="btn btn-default btn-sm pull-right"
role="button" title="Delete connection {{ conn.name }}">
<span class="glyphicon glyphicon-trash"
aria-hidden="true"></span>
</a>
<a class='connection-edit-label'
title="Edit connection {{ conn.name }}">
{{ conn.name }}
</a>
{{ conn.type }}
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock %}

View File

@ -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 <http://www.gnu.org/licenses/>.
#
"""
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<conn_id>[\w.@+-]+)/delete/$',
'delete', name='delete')
)