networks: Always bind connections to a device

This commit is contained in:
Daniel Steglich authored and Sunil Mohan Adapa committed 2015-07-27 22:03:02 +05:30
1 parent c171d89554
commit 378d6b8d84
3 files changed
+71 -18

No files matched your search

+35
View File
@@ -20,6 +20,9 @@ from django.core import validators
from gettext import gettext as _
from plinth import network
from gi.repository import NM as nm
DEFAULT_SELECT_MSG = 'please select'
class ConnectionTypeSelectForm(forms.Form):
@@ -32,7 +35,17 @@ class ConnectionTypeSelectForm(forms.Form):
class AddEthernetForm(forms.Form):
"""Form to create a new ethernet connection."""
interfaces = network.get_interface_list(nm.DeviceType.ETHERNET)
interfaces_list = (('', DEFAULT_SELECT_MSG), )
for interface, mac in interfaces.items():
displaystring = str(interface + ' (' + mac + ')')
newentry = interfaces_list + ((interface, displaystring), )
interfaces_list = newentry
name = forms.CharField(label=_('Connection Name'))
interface = forms.ChoiceField(
label=_('Physical Interface'),
choices=interfaces_list)
zone = forms.ChoiceField(
label=_('Firewall Zone'),
help_text=_('The firewall zone will control which services are \
@@ -48,10 +61,26 @@ available over this interfaces. Select Internal only for trusted networks.'),
validators=[validators.validate_ipv4_address],
required=False)
def clean(self):
""" validate the form fields """
cleaned_data = super(forms.Form, self).clean()
if DEFAULT_SELECT_MSG == cleaned_data.get('interface'):
raise forms.ValidationError('Please select a interface to be used')
class AddWifiForm(forms.Form):
"""Form to create a new wifi connection."""
interfaces = network.get_interface_list(nm.DeviceType.WIFI)
interfaces_list = (('', DEFAULT_SELECT_MSG), )
for interface, mac in interfaces.items():
displaystring = str(interface + ' (' + mac + ')')
newentry = interfaces_list + ((interface, displaystring), )
interfaces_list = newentry
name = forms.CharField(label=_('Connection Name'))
interface = forms.ChoiceField(
label=_('Physical interface'),
choices=interfaces_list)
zone = forms.ChoiceField(
label=_('Firewall Zone'),
help_text=_('The firewall zone will control which services are \
@@ -86,3 +115,9 @@ Point.'))
label=_('Address'),
validators=[validators.validate_ipv4_address],
required=False)
def clean(self):
""" validate the form fields """
cleaned_data = super(forms.Form, self).clean()
if DEFAULT_SELECT_MSG == cleaned_data.get('interface'):
raise forms.ValidationError('Please select a interface to be used')
+9 -4
View File
@@ -78,12 +78,13 @@ def edit(request, uuid):
zone = form.cleaned_data['zone']
ipv4_method = form.cleaned_data['ipv4_method']
ipv4_address = form.cleaned_data['ipv4_address']
interface = form.cleaned_data['interface']
if connection.get_connection_type() == '802-3-ethernet':
network.edit_ethernet_connection(
connection,
name, zone,
ipv4_method, ipv4_address)
ipv4_method, ipv4_address, interface)
elif connection.get_connection_type() == '802-11-wireless':
ssid = form.cleaned_data['ssid']
mode = form.cleaned_data['mode']
@@ -93,7 +94,7 @@ def edit(request, uuid):
network.edit_wifi_connection(
connection, name, zone,
ssid, mode, auth_mode, passphrase,
ipv4_method, ipv4_address)
ipv4_method, ipv4_address, interface)
return redirect(reverse_lazy('networks:index'))
else:
@@ -109,6 +110,8 @@ def edit(request, uuid):
except KeyError:
form_data['zone'] = 'external'
form_data['interface'] = connection.get_interface_name()
form_data['ipv4_method'] = settings_ipv4.get_method()
if settings_ipv4.get_num_addresses():
@@ -215,10 +218,11 @@ def add_ethernet(request):
zone = form.cleaned_data['zone']
ipv4_method = form.cleaned_data['ipv4_method']
ipv4_address = form.cleaned_data['ipv4_address']
interface = form.cleaned_data['interface']
network.add_ethernet_connection(
name, zone,
ipv4_method, ipv4_address)
ipv4_method, ipv4_address, interface)
return redirect(reverse_lazy('networks:index'))
else:
form = AddEthernetForm()
@@ -253,11 +257,12 @@ def add_wifi(request, ssid=None):
passphrase = form.cleaned_data['passphrase']
ipv4_method = form.cleaned_data['ipv4_method']
ipv4_address = form.cleaned_data['ipv4_address']
interface = form.cleaned_data['interface']
network.add_wifi_connection(
name, zone,
ssid, mode, auth_mode, passphrase,
ipv4_method, ipv4_address)
ipv4_method, ipv4_address, interface)
return redirect(reverse_lazy('networks:index'))
else:
if form_data: