mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
networks: Ability to configure generic interfaces
After batman-adv kernel driver takes over the Wi-Fi network interface and provides a bat0 interface, this interface shows up as device type 'batadv'. This type is not recognized by network manager is dealt with as a generic device. Configuring this device for IPv4/IPv6 in auto/shared mode etc. works fine. So, add the ability to configure generic interfaces.
This commit is contained in:
parent
561c7c1e6b
commit
04babacafa
@ -124,6 +124,21 @@ available over this interfaces. Select Internal only for trusted networks.'),
|
||||
return ipv4
|
||||
|
||||
|
||||
class GenericForm(ConnectionForm):
|
||||
"""Form to create/edit a generic connection."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize the form, populate interface choices."""
|
||||
super(GenericForm, self).__init__(*args, **kwargs)
|
||||
choices = self._get_interface_choices(nm.DeviceType.GENERIC)
|
||||
self.fields['interface'].choices = choices
|
||||
|
||||
def get_settings(self):
|
||||
"""Return settings dict from cleaned data."""
|
||||
settings = super().get_settings()
|
||||
settings['common']['type'] = 'generic'
|
||||
return settings
|
||||
|
||||
|
||||
class EthernetForm(ConnectionForm):
|
||||
"""Form to create/edit a ethernet connection."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@ -23,8 +23,8 @@ from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
from django.views.decorators.http import require_POST
|
||||
from logging import Logger
|
||||
|
||||
from .forms import (ConnectionTypeSelectForm, EthernetForm, PPPoEForm,
|
||||
WifiForm)
|
||||
from .forms import (ConnectionTypeSelectForm, EthernetForm, GenericForm,
|
||||
PPPoEForm, WifiForm)
|
||||
from plinth import network
|
||||
|
||||
|
||||
@ -113,7 +113,9 @@ def edit(request, uuid):
|
||||
form_data = {'name': connection.get_id()}
|
||||
|
||||
if request.method == 'POST':
|
||||
if connection.get_connection_type() == '802-11-wireless':
|
||||
if connection.get_connection_type() == 'generic':
|
||||
form = GenericForm(request.POST)
|
||||
elif connection.get_connection_type() == '802-11-wireless':
|
||||
form = WifiForm(request.POST)
|
||||
elif connection.get_connection_type() == '802-3-ethernet':
|
||||
form = EthernetForm(request.POST)
|
||||
@ -156,7 +158,9 @@ def edit(request, uuid):
|
||||
if second_dns:
|
||||
form_data['ipv4_second_dns'] = second_dns
|
||||
|
||||
if settings_connection.get_connection_type() == '802-11-wireless':
|
||||
if settings_connection.get_connection_type() == 'generic':
|
||||
form = GenericForm(form_data)
|
||||
elif settings_connection.get_connection_type() == '802-11-wireless':
|
||||
settings_wireless = connection.get_setting_wireless()
|
||||
form_data['ssid'] = settings_wireless.get_ssid().get_data()
|
||||
form_data['mode'] = settings_wireless.get_mode()
|
||||
@ -242,7 +246,9 @@ def add(request):
|
||||
form = ConnectionTypeSelectForm(request.POST)
|
||||
if form.is_valid():
|
||||
connection_type = form.cleaned_data['connection_type']
|
||||
if connection_type == '802-3-ethernet':
|
||||
if connection_type == 'generic':
|
||||
return redirect(reverse_lazy('networks:add_generic'))
|
||||
elif connection_type == '802-3-ethernet':
|
||||
return redirect(reverse_lazy('networks:add_ethernet'))
|
||||
elif connection_type == '802-11-wireless':
|
||||
return redirect(reverse_lazy('networks:add_wifi'))
|
||||
@ -256,6 +262,24 @@ def add(request):
|
||||
'form': form})
|
||||
|
||||
|
||||
def add_generic(request):
|
||||
"""Serve generic connection create form."""
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = GenericForm(request.POST)
|
||||
if form.is_valid():
|
||||
network.add_connection(form.get_settings())
|
||||
return redirect(reverse_lazy('networks:index'))
|
||||
else:
|
||||
form = GenericForm()
|
||||
|
||||
return TemplateResponse(request, 'connections_create.html',
|
||||
{'title': _('Adding New Generic Connection'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'form': form})
|
||||
|
||||
|
||||
def add_ethernet(request):
|
||||
"""Serve ethernet connection create form."""
|
||||
form = None
|
||||
|
||||
@ -34,6 +34,7 @@ urlpatterns = [
|
||||
name='deactivate'),
|
||||
url(r'^sys/networks/scan/$', views.scan, name='scan'),
|
||||
url(r'^sys/networks/add/$', views.add, name='add'),
|
||||
url(r'^sys/networks/add/generic/$', views.add_generic, name='add_generic'),
|
||||
url(r'^sys/networks/add/ethernet/$', views.add_ethernet,
|
||||
name='add_ethernet'),
|
||||
url(r'^sys/networks/add/pppoe/$', views.add_pppoe, name='add_pppoe'),
|
||||
|
||||
@ -36,7 +36,8 @@ logger = logging.getLogger(__name__)
|
||||
CONNECTION_TYPE_NAMES = collections.OrderedDict([
|
||||
('802-3-ethernet', _('Ethernet')),
|
||||
('802-11-wireless', _('Wi-Fi')),
|
||||
('pppoe', _('PPPoE'))
|
||||
('pppoe', _('PPPoE')),
|
||||
('generic', _('Generic')),
|
||||
])
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user