def test_edit_wifi_connection(self): """Check that we can update a wifi connection.""" connection = network.get_connection(self.wifi_uuid) wifi_settings2 = copy.deepcopy(wifi_settings) wifi_settings2["common"]["name"] = "plinth_test_wifi_new" wifi_settings2["common"]["interface"] = "wlan1" wifi_settings2["common"]["zone"] = "external" wifi_settings2["ipv4"]["method"] = "auto" wifi_settings2["wireless"]["ssid"] = "plinthtestwifi2" wifi_settings2["wireless"]["mode"] = "infrastructure" wifi_settings2["wireless"]["auth_mode"] = "wpa" wifi_settings2["wireless"]["passphrase"] = "secretpassword" network.edit_connection(connection, wifi_settings2) connection = network.get_connection(self.wifi_uuid) self.assertEqual(connection.get_id(), "plinth_test_wifi_new") settings_connection = connection.get_setting_connection() self.assertEqual(settings_connection.get_interface_name(), "wlan1") self.assertEqual(settings_connection.get_zone(), "external") settings_wireless = connection.get_setting_wireless() self.assertEqual(settings_wireless.get_ssid().get_data(), b"plinthtestwifi2") self.assertEqual(settings_wireless.get_mode(), "infrastructure") wifi_sec = connection.get_setting_wireless_security() self.assertEqual(wifi_sec.get_key_mgmt(), "wpa-psk") secrets = connection.get_secrets("802-11-wireless-security") self.assertEqual(secrets["802-11-wireless-security"]["psk"], "secretpassword")
def test_wifi_manual_ipv6_address(self): """Check that we can manually set IPv6 address on wifi.""" connection = network.get_connection(self.wifi_uuid) wifi_settings2 = copy.deepcopy(wifi_settings) wifi_settings2['ipv6']['method'] = 'manual' wifi_settings2['ipv6']['address'] = '::ffff:169.254.0.2' wifi_settings2['ipv6']['prefix'] = 63 wifi_settings2['ipv6']['gateway'] = '::ffff:169.254.0.254' wifi_settings2['ipv6']['dns'] = '::ffff:1.2.3.4' wifi_settings2['ipv6']['second_dns'] = '::ffff:1.2.3.5' wifi_settings2['wireless']['ssid'] = 'plinthtestwifi' wifi_settings2['wireless']['mode'] = 'adhoc' wifi_settings2['wireless']['auth_mode'] = 'open' network.edit_connection(connection, wifi_settings2) connection = network.get_connection(self.wifi_uuid) settings_ipv6 = connection.get_setting_ip6_config() self.assertEqual(settings_ipv6.get_method(), 'manual') address = settings_ipv6.get_address(0) self.assertEqual(address.get_address(), '::ffff:169.254.0.2') self.assertEqual(address.get_prefix(), 63) self.assertEqual(settings_ipv6.get_gateway(), '::ffff:169.254.0.254') self.assertEqual(settings_ipv6.get_num_dns(), 2) self.assertEqual(settings_ipv6.get_dns(0), '::ffff:1.2.3.4') self.assertEqual(settings_ipv6.get_dns(1), '::ffff:1.2.3.5')
def test_edit_pppoe_connection(self): """Check that we can update a PPPoE connection.""" connection = network.get_connection(self.ethernet_uuid) pppoe_settings2 = copy.deepcopy(pppoe_settings) pppoe_settings2['common']['name'] = 'plinth_test_pppoe_new' pppoe_settings2['common']['interface'] = 'eth2' pppoe_settings2['common']['zone'] = 'external' pppoe_settings2['pppoe']['username'] = '******' pppoe_settings2['pppoe']['password'] = '******' network.edit_connection(connection, pppoe_settings2) connection = network.get_connection(self.ethernet_uuid) self.assertEqual(connection.get_id(), 'plinth_test_pppoe_new') settings_connection = connection.get_setting_connection() self.assertEqual(settings_connection.get_interface_name(), 'eth2') self.assertEqual(settings_connection.get_zone(), 'external') settings_pppoe = connection.get_setting_pppoe() self.assertEqual(settings_pppoe.get_username(), 'x-user-new') secrets = connection.get_secrets('pppoe') self.assertEqual(secrets['pppoe']['password'], 'x-password-new') settings_ppp = connection.get_setting_ppp() self.assertEqual(settings_ppp.get_lcp_echo_failure(), 5) self.assertEqual(settings_ppp.get_lcp_echo_interval(), 30)
def test_wifi_manual_ipv4_address(self): """Check that we can manually set IPv4 address on wifi.""" connection = network.get_connection(self.wifi_uuid) wifi_settings2 = copy.deepcopy(wifi_settings) wifi_settings2["ipv4"]["method"] = "manual" wifi_settings2["ipv4"]["address"] = "169.254.0.2" wifi_settings2["ipv4"]["netmask"] = "255.255.254.0" wifi_settings2["ipv4"]["gateway"] = "169.254.0.254" wifi_settings2["ipv4"]["dns"] = "1.2.3.4" wifi_settings2["ipv4"]["second_dns"] = "1.2.3.5" wifi_settings2["wireless"]["ssid"] = "plinthtestwifi" wifi_settings2["wireless"]["mode"] = "adhoc" wifi_settings2["wireless"]["auth_mode"] = "open" network.edit_connection(connection, wifi_settings2) connection = network.get_connection(self.wifi_uuid) settings_ipv4 = connection.get_setting_ip4_config() self.assertEqual(settings_ipv4.get_method(), "manual") address = settings_ipv4.get_address(0) self.assertEqual(address.get_address(), "169.254.0.2") self.assertEqual(address.get_prefix(), 23) self.assertEqual(settings_ipv4.get_gateway(), "169.254.0.254") self.assertEqual(settings_ipv4.get_num_dns(), 2) self.assertEqual(settings_ipv4.get_dns(0), "1.2.3.4") self.assertEqual(settings_ipv4.get_dns(1), "1.2.3.5")
def test_edit_pppoe_connection(self): """Check that we can update a PPPoE connection.""" connection = network.get_connection(self.ethernet_uuid) pppoe_settings2 = copy.deepcopy(pppoe_settings) pppoe_settings2["common"]["name"] = "plinth_test_pppoe_new" pppoe_settings2["common"]["interface"] = "eth2" pppoe_settings2["common"]["zone"] = "external" pppoe_settings2["pppoe"]["username"] = "******" pppoe_settings2["pppoe"]["password"] = "******" network.edit_connection(connection, pppoe_settings2) connection = network.get_connection(self.ethernet_uuid) self.assertEqual(connection.get_id(), "plinth_test_pppoe_new") settings_connection = connection.get_setting_connection() self.assertEqual(settings_connection.get_interface_name(), "eth2") self.assertEqual(settings_connection.get_zone(), "external") settings_pppoe = connection.get_setting_pppoe() self.assertEqual(settings_pppoe.get_username(), "x-user-new") secrets = connection.get_secrets("pppoe") self.assertEqual(secrets["pppoe"]["password"], "x-password-new") settings_ppp = connection.get_setting_ppp() self.assertEqual(settings_ppp.get_lcp_echo_failure(), 5) self.assertEqual(settings_ppp.get_lcp_echo_interval(), 30)
def test_edit_wifi_connection(self): """Check that we can update a wifi connection.""" connection = network.get_connection(self.wifi_uuid) wifi_settings2 = copy.deepcopy(wifi_settings) wifi_settings2['common']['name'] = 'plinth_test_wifi_new' wifi_settings2['common']['interface'] = 'wlan1' wifi_settings2['common']['zone'] = 'external' wifi_settings2['ipv4']['method'] = 'auto' wifi_settings2['wireless']['ssid'] = 'plinthtestwifi2' wifi_settings2['wireless']['mode'] = 'infrastructure' wifi_settings2['wireless']['auth_mode'] = 'wpa' wifi_settings2['wireless']['passphrase'] = 'secretpassword' network.edit_connection(connection, wifi_settings2) connection = network.get_connection(self.wifi_uuid) self.assertEqual(connection.get_id(), 'plinth_test_wifi_new') settings_connection = connection.get_setting_connection() self.assertEqual(settings_connection.get_interface_name(), 'wlan1') self.assertEqual(settings_connection.get_zone(), 'external') settings_wireless = connection.get_setting_wireless() self.assertEqual(settings_wireless.get_ssid().get_data(), b'plinthtestwifi2') self.assertEqual(settings_wireless.get_mode(), 'infrastructure') wifi_sec = connection.get_setting_wireless_security() self.assertEqual(wifi_sec.get_key_mgmt(), 'wpa-psk') secrets = connection.get_secrets('802-11-wireless-security') self.assertEqual( secrets['802-11-wireless-security']['psk'], 'secretpassword')
def test_wifi_manual_ipv4_address(self): """Check that we can manually set IPv4 address on wifi.""" connection = network.get_connection(self.wifi_uuid) wifi_settings2 = copy.deepcopy(wifi_settings) wifi_settings2['ipv4']['method'] = 'manual' wifi_settings2['ipv4']['address'] = '169.254.0.2' wifi_settings2['ipv4']['netmask'] = '255.255.254.0' wifi_settings2['ipv4']['gateway'] = '169.254.0.254' wifi_settings2['ipv4']['dns'] = '1.2.3.4' wifi_settings2['ipv4']['second_dns'] = '1.2.3.5' wifi_settings2['wireless']['ssid'] = 'plinthtestwifi' wifi_settings2['wireless']['mode'] = 'adhoc' wifi_settings2['wireless']['auth_mode'] = 'open' network.edit_connection(connection, wifi_settings2) connection = network.get_connection(self.wifi_uuid) settings_ipv4 = connection.get_setting_ip4_config() self.assertEqual(settings_ipv4.get_method(), 'manual') address = settings_ipv4.get_address(0) self.assertEqual(address.get_address(), '169.254.0.2') self.assertEqual(address.get_prefix(), 23) self.assertEqual(settings_ipv4.get_gateway(), '169.254.0.254') self.assertEqual(settings_ipv4.get_num_dns(), 2) self.assertEqual(settings_ipv4.get_dns(0), '1.2.3.4') self.assertEqual(settings_ipv4.get_dns(1), '1.2.3.5')
def edit_server(interface, settings): """Edit information for connecting to a server.""" settings['common']['interface'] = interface settings['common']['name'] = 'WireGuard-Client-' + interface if not settings['wireguard']['private_key']: settings['wireguard']['private_key'] = _generate_private_key() connection = network.get_connection_by_interface_name(interface) network.edit_connection(connection, settings) network.reactivate_connection(connection.get_uuid())
def test_edit_ethernet_connection(self): """Check that we can update an ethernet connection.""" connection = network.get_connection(self.ethernet_uuid) ethernet_settings2 = copy.deepcopy(ethernet_settings) ethernet_settings2["common"]["name"] = "plinth_test_eth_new" ethernet_settings2["common"]["interface"] = "eth1" ethernet_settings2["common"]["zone"] = "external" ethernet_settings2["ipv4"]["method"] = "auto" network.edit_connection(connection, ethernet_settings2) connection = network.get_connection(self.ethernet_uuid) self.assertEqual(connection.get_id(), "plinth_test_eth_new") settings_connection = connection.get_setting_connection() self.assertEqual(settings_connection.get_interface_name(), "eth1") self.assertEqual(settings_connection.get_zone(), "external") settings_ipv4 = connection.get_setting_ip4_config() self.assertEqual(settings_ipv4.get_method(), "auto")
def enable_connections(enable): """Activate all connections and set them to auto-connect.""" setting_name = nm.SETTING_WIREGUARD_SETTING_NAME client = network.get_nm_client() for connection in client.get_connections(): if connection.get_connection_type() != setting_name: continue network.edit_connection(connection, {'common': { 'autoconnect': enable }}) if enable: network.activate_connection(connection.get_uuid()) else: try: network.deactivate_connection(connection.get_uuid()) except network.ConnectionNotFound: pass # Connection is already inactive
def test_edit_ethernet_connection(self): """Check that we can update an ethernet connection.""" connection = network.get_connection(self.ethernet_uuid) ethernet_settings2 = copy.deepcopy(ethernet_settings) ethernet_settings2['common']['name'] = 'plinth_test_eth_new' ethernet_settings2['common']['interface'] = 'eth1' ethernet_settings2['common']['zone'] = 'external' ethernet_settings2['ipv4']['method'] = 'auto' network.edit_connection(connection, ethernet_settings2) connection = network.get_connection(self.ethernet_uuid) self.assertEqual(connection.get_id(), 'plinth_test_eth_new') settings_connection = connection.get_setting_connection() self.assertEqual(settings_connection.get_interface_name(), 'eth1') self.assertEqual(settings_connection.get_zone(), 'external') settings_ipv4 = connection.get_setting_ip4_config() self.assertEqual(settings_ipv4.get_method(), 'auto')
def test_ethernet_manual_ipv4_address(self): """Check that we can manually set IPv4 address on ethernet.""" connection = network.get_connection(self.ethernet_uuid) ethernet_settings2 = copy.deepcopy(ethernet_settings) ethernet_settings2['ipv4']['method'] = 'manual' ethernet_settings2['ipv4']['address'] = '169.254.0.1' ethernet_settings2['ipv4']['netmask'] = '255.255.254.0' ethernet_settings2['ipv4']['gateway'] = '169.254.0.254' ethernet_settings2['ipv4']['dns'] = '1.2.3.4' ethernet_settings2['ipv4']['second_dns'] = '1.2.3.5' network.edit_connection(connection, ethernet_settings2) connection = network.get_connection(self.ethernet_uuid) settings_ipv4 = connection.get_setting_ip4_config() self.assertEqual(settings_ipv4.get_method(), 'manual') address = settings_ipv4.get_address(0) self.assertEqual(address.get_address(), '169.254.0.1') self.assertEqual(address.get_prefix(), 23) self.assertEqual(settings_ipv4.get_gateway(), '169.254.0.254') self.assertEqual(settings_ipv4.get_num_dns(), 2) self.assertEqual(settings_ipv4.get_dns(0), '1.2.3.4') self.assertEqual(settings_ipv4.get_dns(1), '1.2.3.5')
def test_ethernet_manual_ipv4_address(self): """Check that we can manually set IPv4 address on ethernet.""" connection = network.get_connection(self.ethernet_uuid) ethernet_settings2 = copy.deepcopy(ethernet_settings) ethernet_settings2["ipv4"]["method"] = "manual" ethernet_settings2["ipv4"]["address"] = "169.254.0.1" ethernet_settings2["ipv4"]["netmask"] = "255.255.254.0" ethernet_settings2["ipv4"]["gateway"] = "169.254.0.254" ethernet_settings2["ipv4"]["dns"] = "1.2.3.4" ethernet_settings2["ipv4"]["second_dns"] = "1.2.3.5" network.edit_connection(connection, ethernet_settings2) connection = network.get_connection(self.ethernet_uuid) settings_ipv4 = connection.get_setting_ip4_config() self.assertEqual(settings_ipv4.get_method(), "manual") address = settings_ipv4.get_address(0) self.assertEqual(address.get_address(), "169.254.0.1") self.assertEqual(address.get_prefix(), 23) self.assertEqual(settings_ipv4.get_gateway(), "169.254.0.254") self.assertEqual(settings_ipv4.get_num_dns(), 2) self.assertEqual(settings_ipv4.get_dns(0), "1.2.3.4") self.assertEqual(settings_ipv4.get_dns(1), "1.2.3.5")
def test_ethernet_manual_ipv6_address(self): """Check that we can manually set IPv6 address on ethernet.""" connection = network.get_connection(self.ethernet_uuid) ethernet_settings2 = copy.deepcopy(ethernet_settings) ethernet_settings2['ipv6']['method'] = 'manual' ethernet_settings2['ipv6']['address'] = '::ffff:169.254.0.1' ethernet_settings2['ipv6']['prefix'] = '63' ethernet_settings2['ipv6']['gateway'] = '::ffff:169.254.0.254' ethernet_settings2['ipv6']['dns'] = '::ffff:1.2.3.4' ethernet_settings2['ipv6']['second_dns'] = '::ffff:1.2.3.5' network.edit_connection(connection, ethernet_settings2) connection = network.get_connection(self.ethernet_uuid) settings_ipv6 = connection.get_setting_ip6_config() self.assertEqual(settings_ipv6.get_method(), 'manual') address = settings_ipv6.get_address(0) self.assertEqual(address.get_address(), '::ffff:169.254.0.1') self.assertEqual(address.get_prefix(), 63) self.assertEqual(settings_ipv6.get_gateway(), '::ffff:169.254.0.254') self.assertEqual(settings_ipv6.get_num_dns(), 2) self.assertEqual(settings_ipv6.get_dns(0), '::ffff:1.2.3.4') self.assertEqual(settings_ipv6.get_dns(1), '::ffff:1.2.3.5')
def edit(request, uuid): """Serve connection editing form.""" try: connection = network.get_connection(uuid) except network.ConnectionNotFound: messages.error(request, _('Cannot edit connection: ' 'Connection not found.')) return redirect(reverse_lazy('networks:index')) if connection.get_connection_type() not in network.CONNECTION_TYPE_NAMES: messages.error(request, _('This type of connection is not yet understood.')) return redirect(reverse_lazy('networks:index')) form = None form_data = {'name': connection.get_id()} if request.method == 'POST': if connection.get_connection_type() == '802-11-wireless': form = WifiForm(request.POST) elif connection.get_connection_type() == '802-3-ethernet': form = EthernetForm(request.POST) elif connection.get_connection_type() == 'pppoe': form = PPPoEForm(request.POST) if form.is_valid(): network.edit_connection(connection, form.get_settings()) return redirect(reverse_lazy('networks:index')) else: return TemplateResponse( request, 'connections_edit.html', { 'title': _('Edit Connection'), 'subsubmenu': subsubmenu, 'form': form }) else: settings_connection = connection.get_setting_connection() form_data['interface'] = connection.get_interface_name() try: form_data['zone'] = settings_connection.get_zone() except KeyError: form_data['zone'] = 'external' if settings_connection.get_connection_type() != 'pppoe': settings_ipv4 = connection.get_setting_ip4_config() form_data['ipv4_method'] = settings_ipv4.get_method() address, netmask = network.get_first_ip_address_from_connection( connection) gateway = settings_ipv4.get_gateway() dns = settings_ipv4.get_dns(0) second_dns = settings_ipv4.get_dns(1) if address: form_data['ipv4_address'] = address if netmask: form_data['ipv4_netmask'] = netmask if gateway: form_data['ipv4_gateway'] = gateway if dns: form_data['ipv4_dns'] = dns if second_dns: form_data['ipv4_second_dns'] = second_dns if 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() try: wifi_sec = connection.get_setting_wireless_security() if wifi_sec: if wifi_sec.get_key_mgmt() == 'wpa-psk': form_data['auth_mode'] = 'wpa' secrets = connection.get_secrets( '802-11-wireless-security') psk = secrets['802-11-wireless-security']['psk'] form_data['passphrase'] = psk else: form_data['auth_mode'] = 'open' except KeyError: form_data['auth_mode'] = 'open' form = WifiForm(form_data) elif settings_connection.get_connection_type() == '802-3-ethernet': form = EthernetForm(form_data) elif settings_connection.get_connection_type() == 'pppoe': settings_pppoe = connection.get_setting_pppoe() form_data['username'] = settings_pppoe.get_username() secrets = connection.get_secrets('pppoe') form_data['password'] = secrets['pppoe']['password'] form = PPPoEForm(form_data) return TemplateResponse(request, 'connections_edit.html', { 'title': _('Edit Connection'), 'subsubmenu': subsubmenu, 'form': form })
def edit(request, uuid): """Serve connection editing form.""" try: connection = network.get_connection(uuid) except network.ConnectionNotFound: messages.error(request, _('Cannot edit connection: ' 'Connection not found.')) return redirect(reverse_lazy('networks:index')) if connection.get_connection_type() not in network.CONNECTION_TYPE_NAMES: messages.error(request, _('This type of connection is not yet understood.')) return redirect(reverse_lazy('networks:index')) form = None form_data = {'name': connection.get_id()} if request.method == 'POST': 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) elif connection.get_connection_type() == 'pppoe': form = PPPoEForm(request.POST) if form.is_valid(): network.edit_connection(connection, form.get_settings()) return redirect(reverse_lazy('networks:index')) else: return TemplateResponse(request, 'connections_edit.html', { 'title': _('Edit Connection'), 'form': form }) else: settings_connection = connection.get_setting_connection() form_data['interface'] = connection.get_interface_name() try: form_data['zone'] = settings_connection.get_zone() except KeyError: form_data['zone'] = 'external' if settings_connection.get_connection_type() != 'pppoe': settings_ipv4 = connection.get_setting_ip4_config() form_data['ipv4_method'] = settings_ipv4.get_method() if settings_ipv4.get_num_addresses(): address = settings_ipv4.get_address(0) form_data['ipv4_address'] = address.get_address() prefix = address.get_prefix() netmask = network.nm.utils_ip4_prefix_to_netmask(prefix) form_data['ipv4_netmask'] = network.ipv4_int_to_string(netmask) gateway = settings_ipv4.get_gateway() if gateway: form_data['ipv4_gateway'] = gateway number_of_dns = settings_ipv4.get_num_dns() if number_of_dns: form_data['ipv4_dns'] = settings_ipv4.get_dns(0) 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': settings_wireless = connection.get_setting_wireless() form_data['ssid'] = settings_wireless.get_ssid().get_data() form_data['mode'] = settings_wireless.get_mode() form_data['band'] = settings_wireless.get_band() or 'auto' form_data['channel'] = settings_wireless.get_channel() form_data['bssid'] = settings_wireless.get_bssid() try: wifi_sec = connection.get_setting_wireless_security() if wifi_sec: if wifi_sec.get_key_mgmt() == 'wpa-psk': form_data['auth_mode'] = 'wpa' secrets = connection.get_secrets( '802-11-wireless-security') psk = secrets['802-11-wireless-security']['psk'] form_data['passphrase'] = psk else: form_data['auth_mode'] = 'open' except KeyError: form_data['auth_mode'] = 'open' form = WifiForm(form_data) elif settings_connection.get_connection_type() == '802-3-ethernet': form = EthernetForm(form_data) elif settings_connection.get_connection_type() == 'pppoe': settings_pppoe = connection.get_setting_pppoe() form_data['username'] = settings_pppoe.get_username() secrets = connection.get_secrets('pppoe') form_data['password'] = secrets['pppoe']['password'] form = PPPoEForm(form_data) return TemplateResponse(request, 'connections_edit.html', { 'title': _('Edit Connection'), 'form': form })
def edit(request, uuid): """Serve connection editing form.""" try: connection = network.get_connection(uuid) except network.ConnectionNotFound: messages.error(request, _('Cannot edit connection: ' 'Connection not found.')) return redirect(reverse_lazy('networks:index')) if connection.get_connection_type() not in network.CONNECTION_TYPE_NAMES: messages.error(request, _('This type of connection is not yet understood.')) return redirect(reverse_lazy('networks:index')) form = None form_data = {'name': connection.get_id()} if request.method == 'POST': if connection.get_connection_type() == '802-11-wireless': form = WifiForm(request.POST) elif connection.get_connection_type() == '802-3-ethernet': form = EthernetForm(request.POST) elif connection.get_connection_type() == 'pppoe': form = PPPoEForm(request.POST) if form.is_valid(): network.edit_connection(connection, form.get_settings()) return redirect(reverse_lazy('networks:index')) else: return TemplateResponse(request, 'connections_edit.html', {'title': _('Edit Connection'), 'subsubmenu': subsubmenu, 'form': form}) else: settings_connection = connection.get_setting_connection() form_data['interface'] = connection.get_interface_name() try: form_data['zone'] = settings_connection.get_zone() except KeyError: form_data['zone'] = 'external' if settings_connection.get_connection_type() != 'pppoe': settings_ipv4 = connection.get_setting_ip4_config() form_data['ipv4_method'] = settings_ipv4.get_method() address, netmask = network.get_first_ip_address_from_connection( connection) gateway = settings_ipv4.get_gateway() dns = settings_ipv4.get_dns(0) second_dns = settings_ipv4.get_dns(1) if address: form_data['ipv4_address'] = address if netmask: form_data['ipv4_netmask'] = netmask if gateway: form_data['ipv4_gateway'] = gateway if dns: form_data['ipv4_dns'] = dns if second_dns: form_data['ipv4_second_dns'] = second_dns if 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() try: wifi_sec = connection.get_setting_wireless_security() if wifi_sec: if wifi_sec.get_key_mgmt() == 'wpa-psk': form_data['auth_mode'] = 'wpa' secrets = connection.get_secrets( '802-11-wireless-security') psk = secrets['802-11-wireless-security']['psk'] form_data['passphrase'] = psk else: form_data['auth_mode'] = 'open' except KeyError: form_data['auth_mode'] = 'open' form = WifiForm(form_data) elif settings_connection.get_connection_type() == '802-3-ethernet': form = EthernetForm(form_data) elif settings_connection.get_connection_type() == 'pppoe': settings_pppoe = connection.get_setting_pppoe() form_data['username'] = settings_pppoe.get_username() secrets = connection.get_secrets('pppoe') form_data['password'] = secrets['pppoe']['password'] form = PPPoEForm(form_data) return TemplateResponse(request, 'connections_edit.html', {'title': _('Edit Connection'), 'subsubmenu': subsubmenu, 'form': form})