mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
Add Ethernet or Wifi connection
This commit is contained in:
parent
17040d4762
commit
0f99de9347
@ -16,6 +16,7 @@
|
||||
#
|
||||
|
||||
from dbus.exceptions import DBusException
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
@ -23,22 +24,20 @@ from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from gettext import gettext as _
|
||||
import NetworkManager
|
||||
import uuid
|
||||
import urllib
|
||||
|
||||
from plinth import cfg
|
||||
|
||||
|
||||
subsubmenu = [{'url': reverse_lazy('network:index'),
|
||||
'text': _('Network Connections')},
|
||||
{'url': reverse_lazy('network:add'),
|
||||
'text': _('Add Connection')}]
|
||||
|
||||
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',
|
||||
}
|
||||
|
||||
|
||||
@ -78,6 +77,7 @@ def index(request):
|
||||
|
||||
return TemplateResponse(request, 'connections_list.html',
|
||||
{'title': _('Network Connections'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'connections': connections})
|
||||
|
||||
|
||||
@ -140,6 +140,101 @@ def deactivate(request, conn_id):
|
||||
return redirect(reverse_lazy('network:index'))
|
||||
|
||||
|
||||
class ConnectionAddForm(forms.Form):
|
||||
"""Form to select type for new connection."""
|
||||
conn_type = forms.ChoiceField(
|
||||
label=_('Connection Type'),
|
||||
choices=[(k, v) for k, v in CONNECTION_TYPE_NAMES.items()])
|
||||
|
||||
|
||||
@login_required
|
||||
def add(request):
|
||||
"""Serve the connection type selection form."""
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ConnectionAddForm(request.POST)
|
||||
if form.is_valid():
|
||||
conn_type = form.cleaned_data['conn_type']
|
||||
if conn_type == '802-3-ethernet':
|
||||
return redirect(reverse_lazy('network:add_ethernet'))
|
||||
elif conn_type == '802-11-wireless':
|
||||
return redirect(reverse_lazy('network:add_wifi'))
|
||||
else:
|
||||
form = ConnectionAddForm()
|
||||
return TemplateResponse(request, 'connections_add.html',
|
||||
{'title': _('Add Connection'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'form': form})
|
||||
|
||||
|
||||
class AddEthernetForm(forms.Form):
|
||||
"""Form to create a new ethernet connection."""
|
||||
name = forms.CharField(label=_('Connection Name'))
|
||||
|
||||
|
||||
@login_required
|
||||
def add_ethernet(request):
|
||||
"""Serve ethernet connection create form."""
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = AddEthernetForm(request.POST)
|
||||
if form.is_valid():
|
||||
conn = {
|
||||
'connection': {
|
||||
'id': form.cleaned_data['name'],
|
||||
'type': '802-3-ethernet',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
},
|
||||
'802-3-ethernet': {},
|
||||
}
|
||||
NetworkManager.Settings.AddConnection(conn)
|
||||
return redirect(reverse_lazy('network:index'))
|
||||
else:
|
||||
form = AddEthernetForm()
|
||||
|
||||
return TemplateResponse(request, 'connections_create.html',
|
||||
{'title': _('Editing New Ethernet Connection'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'form': form})
|
||||
|
||||
|
||||
class AddWifiForm(forms.Form):
|
||||
"""Form to create a new wifi connection."""
|
||||
name = forms.CharField(label=_('Connection Name'))
|
||||
ssid = forms.CharField(label=_('SSID'))
|
||||
|
||||
|
||||
@login_required
|
||||
def add_wifi(request):
|
||||
"""Serve wifi connection create form."""
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = AddWifiForm(request.POST)
|
||||
if form.is_valid():
|
||||
conn = {
|
||||
'connection': {
|
||||
'id': form.cleaned_data['name'],
|
||||
'type': '802-11-wireless',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
},
|
||||
'802-11-wireless': {
|
||||
'ssid': form.cleaned_data['ssid'],
|
||||
},
|
||||
}
|
||||
NetworkManager.Settings.AddConnection(conn)
|
||||
return redirect(reverse_lazy('network:index'))
|
||||
else:
|
||||
form = AddWifiForm()
|
||||
|
||||
return TemplateResponse(request, 'connections_create.html',
|
||||
{'title': _('Editing New Wi-Fi Connection'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def delete(request, conn_id):
|
||||
"""Handle deleting connections, showing a confirmation dialog first.
|
||||
@ -162,4 +257,5 @@ def delete(request, conn_id):
|
||||
|
||||
return TemplateResponse(request, 'connections_delete.html',
|
||||
{'title': _('Delete Connection'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'name': name})
|
||||
|
||||
44
plinth/modules/network/templates/connections_add.html
Normal file
44
plinth/modules/network/templates/connections_add.html
Normal file
@ -0,0 +1,44 @@
|
||||
{% 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 %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form|bootstrap }}
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="Create..."/>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block page_js %}
|
||||
<script>
|
||||
$('#id_type').focus();
|
||||
</script>
|
||||
{% endblock %}
|
||||
44
plinth/modules/network/templates/connections_create.html
Normal file
44
plinth/modules/network/templates/connections_create.html
Normal file
@ -0,0 +1,44 @@
|
||||
{% 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 %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form|bootstrap }}
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="Create Connection"/>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block page_js %}
|
||||
<script>
|
||||
$('#id_name').focus();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@ -29,6 +29,9 @@ urlpatterns = patterns(
|
||||
'activate', name='activate'),
|
||||
url(r'^sys/network/(?P<conn_id>[\w.@+-]+)/deactivate/$',
|
||||
'deactivate', name='deactivate'),
|
||||
url(r'^sys/network/add/$', 'add', name='add'),
|
||||
url(r'^sys/network/add/ethernet/$', 'add_ethernet', name='add_ethernet'),
|
||||
url(r'^sys/network/add/wifi/$', 'add_wifi', name='add_wifi'),
|
||||
url(r'^sys/network/(?P<conn_id>[\w.@+-]+)/delete/$',
|
||||
'delete', name='delete'),
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user