mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
networks: Support configuring IPv6 networks
- Very similar to configuration of IPv4 networks. - Supports 'auto', 'dhcp', 'manual' and 'ignored' modes as supported by network manager. 'shared' mode is not yet implemented by network manager.
This commit is contained in:
1 parent
c8cfcd03d9
commit
dce51fd6d7
5 files changed
+214
-18
No files matched your search
@@ -89,6 +89,46 @@ available over this interfaces. Select Internal only for trusted networks.'),
|
||||
'provided by a DHCP server will be ignored.'),
|
||||
validators=[validators.validate_ipv4_address],
|
||||
required=False)
|
||||
ipv6_method = forms.ChoiceField(
|
||||
label=_('IPv6 Addressing Method'),
|
||||
help_text=format_lazy(
|
||||
ugettext_lazy(
|
||||
'"Automatic" methods will make {box_name} acquire '
|
||||
'configuration from this network making it a client.'),
|
||||
box_name=ugettext_lazy(cfg.box_name)),
|
||||
choices=[('auto', _('Automatic')),
|
||||
('dhcp', _('Automatic, DHCP only')),
|
||||
('manual', _('Manual')),
|
||||
('ignore', _('Ignore'))])
|
||||
ipv6_address = forms.CharField(
|
||||
label=_('Address'),
|
||||
validators=[validators.validate_ipv6_address],
|
||||
required=False)
|
||||
ipv6_prefix = forms.IntegerField(
|
||||
label=_('Prefix'),
|
||||
help_text=_('Value between 1 and 128.'),
|
||||
min_value=1,
|
||||
max_value=128,
|
||||
required=False)
|
||||
ipv6_gateway = forms.CharField(
|
||||
label=_('Gateway'),
|
||||
help_text=_('Optional value.'),
|
||||
validators=[validators.validate_ipv6_address],
|
||||
required=False)
|
||||
ipv6_dns = forms.CharField(
|
||||
label=_('DNS Server'),
|
||||
help_text=_('Optional value. If this value is given and IPv6 '
|
||||
'addressing method is "Automatic", the DNS Servers '
|
||||
'provided by a DHCP server will be ignored.'),
|
||||
validators=[validators.validate_ipv6_address],
|
||||
required=False)
|
||||
ipv6_second_dns = forms.CharField(
|
||||
label=_('Second DNS Server'),
|
||||
help_text=_('Optional value. If this value is given and IPv6 '
|
||||
'Addressing Method is "Automatic", the DNS Servers '
|
||||
'provided by a DHCP server will be ignored.'),
|
||||
validators=[validators.validate_ipv6_address],
|
||||
required=False)
|
||||
|
||||
@staticmethod
|
||||
def _get_interface_choices(device_type):
|
||||
@@ -111,6 +151,7 @@ available over this interfaces. Select Internal only for trusted networks.'),
|
||||
'zone': self.cleaned_data['zone'],
|
||||
}
|
||||
settings['ipv4'] = self.get_ipv4_settings()
|
||||
settings['ipv6'] = self.get_ipv6_settings()
|
||||
return settings
|
||||
|
||||
def get_ipv4_settings(self):
|
||||
@@ -125,6 +166,18 @@ available over this interfaces. Select Internal only for trusted networks.'),
|
||||
}
|
||||
return ipv4
|
||||
|
||||
def get_ipv6_settings(self):
|
||||
"""Return IPv6 dict from cleaned data."""
|
||||
ipv6 = {
|
||||
'method': self.cleaned_data['ipv6_method'],
|
||||
'address': self.cleaned_data['ipv6_address'],
|
||||
'prefix': self.cleaned_data['ipv6_prefix'],
|
||||
'gateway': self.cleaned_data['ipv6_gateway'],
|
||||
'dns': self.cleaned_data['ipv6_dns'],
|
||||
'second_dns': self.cleaned_data['ipv6_second_dns'],
|
||||
}
|
||||
return ipv6
|
||||
|
||||
|
||||
class GenericForm(ConnectionForm):
|
||||
"""Form to create/edit a generic connection."""
|
||||
@@ -164,6 +217,12 @@ class PPPoEForm(EthernetForm):
|
||||
ipv4_gateway = None
|
||||
ipv4_dns = None
|
||||
ipv4_second_dns = None
|
||||
ipv6_method = None
|
||||
ipv6_address = None
|
||||
ipv6_prefix = None
|
||||
ipv6_gateway = None
|
||||
ipv6_dns = None
|
||||
ipv6_second_dns = None
|
||||
|
||||
username = forms.CharField(label=_('Username'))
|
||||
password = forms.CharField(label=_('Password'),
|
||||
@@ -185,13 +244,19 @@ class PPPoEForm(EthernetForm):
|
||||
"""Return IPv4 settings from cleaned data."""
|
||||
return None
|
||||
|
||||
def get_ipv6_settings(self):
|
||||
"""Return IPv6 settings from cleaned data."""
|
||||
return None
|
||||
|
||||
|
||||
class WifiForm(ConnectionForm):
|
||||
"""Form to create/edit a Wi-Fi connection."""
|
||||
field_order = ['name', 'interface', 'zone', 'ssid', 'mode', 'band',
|
||||
'channel', 'bssid', 'auth_mode', 'passphrase',
|
||||
'ipv4_method', 'ipv4_address', 'ipv4_netmask',
|
||||
'ipv4_gateway', 'ipv4_dns', 'ipv4_second_dns']
|
||||
'ipv4_gateway', 'ipv4_dns', 'ipv4_second_dns',
|
||||
'ipv6_method', 'ipv6_address', 'ipv6_prefix',
|
||||
'ipv6_gateway', 'ipv6_dns', 'ipv6_second_dns']
|
||||
|
||||
ssid = forms.CharField(
|
||||
label=_('SSID'),
|
||||
|
||||
@@ -160,6 +160,24 @@ def edit(request, uuid):
|
||||
if number_of_dns > 1:
|
||||
form_data['ipv4_second_dns'] = settings_ipv4.get_dns(1)
|
||||
|
||||
settings_ipv6 = connection.get_setting_ip6_config()
|
||||
form_data['ipv6_method'] = settings_ipv6.get_method()
|
||||
if settings_ipv6.get_num_addresses():
|
||||
address = settings_ipv6.get_address(0)
|
||||
form_data['ipv6_address'] = address.get_address()
|
||||
form_data['ipv6_prefix'] = address.get_prefix()
|
||||
|
||||
gateway = settings_ipv6.get_gateway()
|
||||
if gateway:
|
||||
form_data['ipv6_gateway'] = gateway
|
||||
|
||||
number_of_dns = settings_ipv6.get_num_dns()
|
||||
if number_of_dns:
|
||||
form_data['ipv6_dns'] = settings_ipv6.get_dns(0)
|
||||
|
||||
if number_of_dns > 1:
|
||||
form_data['ipv6_second_dns'] = settings_ipv6.get_dns(1)
|
||||
|
||||
if settings_connection.get_connection_type() == 'generic':
|
||||
form = GenericForm(form_data)
|
||||
elif settings_connection.get_connection_type() == '802-11-wireless':
|
||||
|
||||
@@ -39,43 +39,61 @@
|
||||
<script type="text/javascript">
|
||||
(function($) {
|
||||
|
||||
function ipv4_required(required, fields) {
|
||||
function ip_required(required, ip_version, fields) {
|
||||
var prefix = '#id_' + ip_version + '_';
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
$('#id_ipv4_' + fields[i]).prop("required", required);
|
||||
$(prefix + fields[i]).prop("required", required);
|
||||
}
|
||||
}
|
||||
|
||||
function ipv4_readonly(readonly, fields) {
|
||||
function ip_readonly(readonly, ip_version, fields) {
|
||||
var prefix = '#id_' + ip_version + '_';
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
$('#id_ipv4_' + fields[i]).prop("readOnly", readonly);
|
||||
$(prefix + fields[i]).prop("readOnly", readonly);
|
||||
if (readonly) {
|
||||
$('#id_ipv4_' + fields[i]).val("");
|
||||
$('#id_ipv4_' + fields[i]).prop("required", false);
|
||||
$(prefix + fields[i]).val("");
|
||||
$(prefix + fields[i]).prop("required", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function on_ipv4_method_change() {
|
||||
if ($("#id_ipv4_method").prop("value") == "manual") {
|
||||
ipv4_required(true, ['address']);
|
||||
ipv4_readonly(false, ['address', 'netmask', 'gateway', 'dns',
|
||||
'second_dns']);
|
||||
ip_required(true, 'ipv4', ['address']);
|
||||
ip_readonly(false, 'ipv4', ['address', 'netmask', 'gateway',
|
||||
'dns', 'second_dns']);
|
||||
} else if ($("#id_ipv4_method").prop("value") == "shared") {
|
||||
ipv4_required(false, ['address']);
|
||||
ipv4_readonly(false, ['address', 'netmask']);
|
||||
ipv4_readonly(true, ['gateway', 'dns', 'second_dns']);
|
||||
ip_required(false, 'ipv4', ['address']);
|
||||
ip_readonly(false, 'ipv4', ['address', 'netmask']);
|
||||
ip_readonly(true, 'ipv4', ['gateway', 'dns', 'second_dns']);
|
||||
} else if ($("#id_ipv4_method").prop("value") == "auto") {
|
||||
ipv4_readonly(true, ['address', 'netmask', 'gateway']);
|
||||
ipv4_readonly(false, ['dns', 'second_dns']);
|
||||
ip_readonly(true, 'ipv4', ['address', 'netmask', 'gateway']);
|
||||
ip_readonly(false, 'ipv4', ['dns', 'second_dns']);
|
||||
} else {
|
||||
ipv4_readonly(true, ['address', 'netmask', 'gateway', 'dns',
|
||||
'second_dns']);
|
||||
ip_readonly(true, 'ipv4', ['address', 'netmask', 'gateway',
|
||||
'dns', 'second_dns']);
|
||||
}
|
||||
}
|
||||
|
||||
function on_ipv6_method_change() {
|
||||
if ($("#id_ipv6_method").prop("value") == "manual") {
|
||||
ip_required(true, 'ipv6', ['address', 'prefix']);
|
||||
ip_readonly(false, 'ipv6', ['address', 'prefix', 'gateway',
|
||||
'dns', 'second_dns']);
|
||||
} else if ($("#id_ipv6_method").prop("value") == "auto" ||
|
||||
$("#id_ipv6_method").prop("value") == "dhcp") {
|
||||
ip_readonly(true, 'ipv6', ['address', 'prefix', 'gateway']);
|
||||
ip_readonly(false, 'ipv6', ['dns', 'second_dns']);
|
||||
} else {
|
||||
ip_readonly(true, 'ipv6', ['address', 'prefix', 'gateway',
|
||||
'dns', 'second_dns']);
|
||||
}
|
||||
}
|
||||
|
||||
$("#id_name").focus();
|
||||
|
||||
$("#id_ipv4_method").change(on_ipv4_method_change).change();
|
||||
$("#id_ipv6_method").change(on_ipv6_method_change).change();
|
||||
|
||||
$('#id_show_password').change(function() {
|
||||
// Changing type attribute from password to text is prevented by
|
||||
|
||||
Reference in new issue
Block a user