Пример #1
0
    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)
Пример #2
0
    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')
Пример #3
0
    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)
Пример #4
0
    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")
Пример #5
0
    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')
Пример #6
0
    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")
Пример #7
0
    def test_edit_wifi_connection(self):
        """Check that we can update a wifi connection."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(connection, 'plinth_test_wifi_new',
                                     'wlan1', 'external', 'plinthtestwifi2',
                                     'infrastructure', 'wpa', 'secretpassword',
                                     'auto', '')

        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')
Пример #8
0
    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)
Пример #9
0
    def test_edit_wifi_connection(self):
        """Check that we can update a wifi connection."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(
            connection, 'plinth_test_wifi_new', 'wlan1', 'external',
            'plinthtestwifi2', 'infrastructure', 'wpa', 'secretpassword',
            'auto', '', '', '', '', '')

        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')
Пример #10
0
    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')
Пример #11
0
    def test_edit_wifi_connection(self):
        """Check that we can update a wifi connection."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(
            connection,
            "plinth_test_wifi_new",
            "wlan0",
            "external",
            "plinthtestwifi2",
            "infrastructure",
            "wpa",
            "secretpassword",
            "auto",
            "",
        )

        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_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")
Пример #12
0
    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')
Пример #13
0
    def test_get_connection(self):
        """Check that we can get a connection by name."""
        connection = network.get_connection(self.ethernet_uuid)
        self.assertEqual(connection.get_id(), "plinth_test_eth")

        connection = network.get_connection(self.wifi_uuid)
        self.assertEqual(connection.get_id(), "plinth_test_wifi")

        self.assertRaises(network.ConnectionNotFound, network.get_connection, "x-invalid-network-id")
Пример #14
0
    def test_get_connection(self):
        """Check that we can get a connection by name."""
        connection = network.get_connection(self.ethernet_uuid)
        self.assertEqual(connection.get_id(), 'plinth_test_eth')

        connection = network.get_connection(self.wifi_uuid)
        self.assertEqual(connection.get_id(), 'plinth_test_wifi')

        self.assertRaises(network.ConnectionNotFound, network.get_connection,
                          'x-invalid-network-id')
Пример #15
0
    def test_ethernet_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on ethernet."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(connection, "plinth_test_eth_new", "eth0", "external", "manual", "169.254.0.1")

        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")
Пример #16
0
    def test_get_connection(self):
        """Check that we can get a connection by name."""
        connection = network.get_connection(self.ethernet_uuid)
        self.assertEqual(
            connection.GetSettings()['connection']['id'], 'plinth_test_eth')

        connection = network.get_connection(self.wifi_uuid)
        self.assertEqual(
            connection.GetSettings()['connection']['id'], 'plinth_test_wifi')

        self.assertRaises(network.ConnectionNotFound, network.get_connection,
                          'x-invalid-network-id')
Пример #17
0
    def test_edit_ethernet_connection(self):
        """Check that we can update an ethernet connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(connection, 'plinth_test_eth_new',
                                         'external', 'manual', '169.254.0.1')

        connection = network.get_connection(self.ethernet_uuid)
        settings = connection.GetSettings()
        self.assertEqual(settings['connection']['id'], 'plinth_test_eth_new')
        self.assertEqual(settings['connection']['zone'], 'external')
        self.assertEqual(settings['ipv4']['method'], 'manual')
        self.assertEqual(settings['ipv4']['addresses'],
                         [['169.254.0.1', 24, '0.0.0.0']])
Пример #18
0
    def test_ethernet_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on ethernet."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(connection, 'plinth_test_eth_new',
                                         'eth0', 'external', 'manual',
                                         '169.254.0.1')

        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')
Пример #19
0
    def test_edit_ethernet_connection(self):
        """Check that we can update an ethernet connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(connection, "plinth_test_eth_new", "eth0", "external", "auto", "")

        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_zone(), "external")

        settings_ipv4 = connection.get_setting_ip4_config()
        self.assertEqual(settings_ipv4.get_method(), "auto")
Пример #20
0
    def test_wifi_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on wifi."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(connection, 'plinth_test_wifi_new',
                                     'wlan0', 'external', 'plinthtestwifi',
                                     'adhoc', 'open', '', 'manual',
                                     '169.254.0.2')

        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')
Пример #21
0
    def test_wifi_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on wifi."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(
            connection, 'plinth_test_wifi_new', 'wlan0', 'external',
            'plinthtestwifi', 'adhoc', 'open', '',
            'manual', '169.254.0.2')

        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')
Пример #22
0
    def test_edit_ethernet_connection(self):
        """Check that we can update an ethernet connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(
            connection, 'plinth_test_eth_new', 'external', 'manual',
            '169.254.0.1')

        connection = network.get_connection(self.ethernet_uuid)
        settings = connection.GetSettings()
        self.assertEqual(settings['connection']['id'], 'plinth_test_eth_new')
        self.assertEqual(settings['connection']['zone'], 'external')
        self.assertEqual(settings['ipv4']['method'], 'manual')
        self.assertEqual(settings['ipv4']['addresses'],
                         [['169.254.0.1', 24, '0.0.0.0']])
Пример #23
0
    def test_edit_ethernet_connection(self):
        """Check that we can update an ethernet connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(
            connection, 'plinth_test_eth_new', 'eth1', 'external', 'auto', '')

        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')
Пример #24
0
    def test_edit_ethernet_connection(self):
        """Check that we can update an ethernet connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(connection, 'plinth_test_eth_new',
                                         'eth1', 'external', 'auto', '')

        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')
Пример #25
0
def delete(request, uuid):
    """Handle deleting connections, showing a confirmation dialog first.

    On GET, display a confirmation page.
    On POST, delete the connection.
    """
    if request.method == 'POST':
        try:
            name = network.delete_connection(uuid)
            messages.success(request, _('Connection %s deleted.') % name)
        except network.ConnectionNotFound:
            messages.error(request, _('Failed to delete connection: '
                                      'Connection not found.'))

        return redirect(reverse_lazy('networks:index'))

    try:
        connection = network.get_connection(uuid)
        name = connection.get_id()
    except network.ConnectionNotFound:
        messages.error(request, _('Failed to delete connection: '
                                  'Connection not found.'))
        return redirect(reverse_lazy('networks:index'))

    return TemplateResponse(request, 'connections_delete.html',
                            {'title': _('Delete Connection'),
                             'subsubmenu': subsubmenu,
                             'name': name})
Пример #26
0
def delete(request, uuid):
    """Handle deleting connections, showing a confirmation dialog first.

    On GET, display a confirmation page.
    On POST, delete the connection.
    """
    if request.method == "POST":
        try:
            name = network.delete_connection(uuid)
            messages.success(request, _("Connection %s deleted.") % name)
        except network.ConnectionNotFound:
            messages.error(request, _("Failed to delete connection: " "Connection not found."))

        return redirect(reverse_lazy("networks:index"))

    try:
        connection = network.get_connection(uuid)
        name = connection.get_id()
    except network.ConnectionNotFound:
        messages.error(request, _("Failed to delete connection: " "Connection not found."))
        return redirect(reverse_lazy("networks:index"))

    return TemplateResponse(
        request, "connections_delete.html", {"title": _("Delete Connection"), "subsubmenu": subsubmenu, "name": name}
    )
Пример #27
0
def delete(request, uuid):
    """Handle deleting connections, showing a confirmation dialog first.

    On GET, display a confirmation page.
    On POST, delete the connection.
    """
    if request.method == 'POST':
        try:
            name = network.delete_connection(uuid)
            messages.success(request, _('Connection {name} deleted.')
                             .format(name=name))
        except network.ConnectionNotFound:
            messages.error(request, _('Failed to delete connection: '
                                      'Connection not found.'))

        return redirect(reverse_lazy('networks:index'))

    try:
        connection = network.get_connection(uuid)
        name = connection.get_id()
    except network.ConnectionNotFound:
        messages.error(request, _('Failed to delete connection: '
                                  'Connection not found.'))
        return redirect(reverse_lazy('networks:index'))

    return TemplateResponse(request, 'connections_delete.html',
                            {'title': _('Delete Connection'),
                             'subsubmenu': subsubmenu,
                             'name': name})
Пример #28
0
    def test_edit_ethernet_connection(self):
        """Check that we can update an ethernet connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(
            connection, 'plinth_test_eth_new', 'external', 'manual',
            '169.254.0.1')

        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_zone(), 'external')

        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')
Пример #29
0
    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')
Пример #30
0
    def test_ethernet_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on ethernet."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(connection, 'plinth_test_eth_new',
                                         'eth0', 'external', 'manual',
                                         '169.254.0.1', '255.255.254.0',
                                         '169.254.0.254', '1.2.3.4', '1.2.3.5')

        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')
Пример #31
0
    def test_ethernet_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on ethernet."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_ethernet_connection(
            connection, 'plinth_test_eth_new', 'eth0', 'external', 'manual',
            '169.254.0.1', '255.255.254.0', '169.254.0.254', '1.2.3.4',
            '1.2.3.5')

        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')
Пример #32
0
    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')
Пример #33
0
    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")
Пример #34
0
    def test_edit_wifi_connection(self):
        """Check that we can update a wifi connection."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(
            connection, 'plinth_test_wifi_new', 'external',
            'plinthtestwifi2', 'infrastructure', 'wpa', 'secretpassword',
            'auto', '')

        connection = network.get_connection(self.wifi_uuid)
        settings = connection.GetSettings()
        self.assertEqual(settings['connection']['id'], 'plinth_test_wifi_new')
        self.assertEqual(settings['connection']['zone'], 'external')
        self.assertEqual(settings['802-11-wireless']['ssid'],
                         'plinthtestwifi2')
        self.assertEqual(settings['802-11-wireless']['mode'], 'infrastructure')
        self.assertEqual(settings['802-11-wireless-security']['key-mgmt'],
                         'wpa-psk')
        self.assertEqual(
            connection.GetSecrets()['802-11-wireless-security']['psk'],
            'secretpassword')
Пример #35
0
    def test_edit_wifi_connection(self):
        """Check that we can update a wifi connection."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(connection, 'plinth_test_wifi_new',
                                     'external', 'plinthtestwifi2',
                                     'infrastructure', 'wpa', 'secretpassword',
                                     'auto', '')

        connection = network.get_connection(self.wifi_uuid)
        settings = connection.GetSettings()
        self.assertEqual(settings['connection']['id'], 'plinth_test_wifi_new')
        self.assertEqual(settings['connection']['zone'], 'external')
        self.assertEqual(settings['802-11-wireless']['ssid'],
                         'plinthtestwifi2')
        self.assertEqual(settings['802-11-wireless']['mode'], 'infrastructure')
        self.assertEqual(settings['802-11-wireless-security']['key-mgmt'],
                         'wpa-psk')
        self.assertEqual(
            connection.GetSecrets()['802-11-wireless-security']['psk'],
            'secretpassword')
Пример #36
0
    def test_wifi_manual_ipv4_address(self):
        """Check that we can manually set IPv4 address on wifi."""
        connection = network.get_connection(self.wifi_uuid)
        network.edit_wifi_connection(
            connection,
            "plinth_test_wifi_new",
            "wlan0",
            "external",
            "plinthtestwifi",
            "adhoc",
            "open",
            "",
            "manual",
            "169.254.0.2",
        )

        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")
Пример #37
0
    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")
Пример #38
0
    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')
Пример #39
0
    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')
Пример #40
0
def show(request, uuid):
    """Serve connection information."""
    try:
        connection = network.get_connection(uuid)
    except network.ConnectionNotFound:
        messages.error(request,
                       _('Cannot show connection: '
                         'Connection not found.'))
        return redirect(reverse_lazy('networks:index'))

    # Connection status
    connection_status = network.get_status_from_connection(connection)

    # Active connection status
    try:
        active_connection = network.get_active_connection(uuid)
        active_connection_status = \
            network.get_status_from_active_connection(active_connection)
    except network.ConnectionNotFound:
        active_connection_status = {}
        active_connection = None

    # Device status
    device = None
    if active_connection and active_connection.get_devices():
        device = active_connection.get_devices()[0]
    else:
        interface_name = connection_status['interface_name']
        if interface_name:
            device = network.get_device_by_interface_name(interface_name)

    device_status = network.get_status_from_device(device)

    # Access point status
    access_point_status = None
    if connection_status['type'] == '802-11-wireless':
        access_point_status = network.get_status_from_wifi_access_point(
            device, connection_status['wireless']['ssid'])

    return TemplateResponse(
        request, 'connection_show.html', {
            'title': _('Connection Information'),
            'subsubmenu': subsubmenu,
            'connection': connection_status,
            'active_connection': active_connection_status,
            'device': device_status,
            'access_point': access_point_status
        })
Пример #41
0
def show(request, uuid):
    """Serve connection information."""
    try:
        connection = network.get_connection(uuid)
    except network.ConnectionNotFound:
        messages.error(request, _('Cannot show connection: '
                                  'Connection not found.'))
        return redirect(reverse_lazy('networks:index'))

    # Connection status
    connection_status = network.get_status_from_connection(connection)

    # Active connection status
    try:
        active_connection = network.get_active_connection(uuid)
        active_connection_status = \
            network.get_status_from_active_connection(active_connection)
    except network.ConnectionNotFound:
        active_connection_status = {}
        active_connection = None

    # Device status
    device = None
    if active_connection and active_connection.get_devices():
        device = active_connection.get_devices()[0]
    else:
        interface_name = connection_status['interface_name']
        if interface_name:
            device = network.get_device_by_interface_name(interface_name)

    device_status = network.get_status_from_device(device)

    # Access point status
    access_point_status = None
    if connection_status['type'] == '802-11-wireless':
        access_point_status = network.get_status_from_wifi_access_point(
            device, connection_status['wireless']['ssid'])

    return TemplateResponse(request, 'connection_show.html',
                            {'title': _('Show Connection information'),
                             'subsubmenu': subsubmenu,
                             'connection': connection_status,
                             'active_connection': active_connection_status,
                             'device': device_status,
                             'access_point': access_point_status})
Пример #42
0
def _get_shared_interfaces():
    """Get active network interfaces in shared mode."""
    shared_interfaces = []
    for connection in network.get_connection_list():
        if not connection['is_active']:
            continue

        connection_uuid = connection['uuid']
        connection = network.get_connection(connection_uuid)

        settings_ipv4 = connection.get_setting_ip4_config()
        if settings_ipv4.get_method() == 'shared':
            settings_connection = connection.get_setting_connection()
            interface = settings_connection.get_interface_name()
            if interface:
                shared_interfaces.append(interface)

    return shared_interfaces
Пример #43
0
def _get_shared_interfaces():
    """Get active network interfaces in shared mode."""
    shared_interfaces = []
    for connection in network.get_connection_list():
        if not connection['is_active']:
            continue

        connection_uuid = connection['uuid']
        connection = network.get_connection(connection_uuid)

        settings_ipv4 = connection.get_setting_ip4_config()
        if settings_ipv4.get_method() == 'shared':
            settings_connection = connection.get_setting_connection()
            interface = settings_connection.get_interface_name()
            if interface:
                shared_interfaces.append(interface)

    return shared_interfaces
Пример #44
0
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 = AddWifiForm(request.POST)
        elif connection.get_connection_type() == '802-3-ethernet':
            form = AddEthernetForm(request.POST)
        elif connection.get_connection_type() == 'pppoe':
            form = AddPPPoEForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            interface = form.cleaned_data['interface']
            zone = form.cleaned_data['zone']
            if connection.get_connection_type() == 'pppoe':
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']
            else:
                ipv4_method = form.cleaned_data['ipv4_method']
                ipv4_address = form.cleaned_data['ipv4_address']
                ipv4_netmask = form.cleaned_data['ipv4_netmask']
                ipv4_gateway = form.cleaned_data['ipv4_gateway']
                ipv4_dns = form.cleaned_data['ipv4_dns']
                ipv4_second_dns = form.cleaned_data['ipv4_second_dns']

            if connection.get_connection_type() == '802-3-ethernet':
                network.edit_ethernet_connection(
                    connection, name, interface, zone, ipv4_method,
                    ipv4_address, ipv4_netmask, ipv4_gateway, ipv4_dns,
                    ipv4_second_dns)
            elif connection.get_connection_type() == '802-11-wireless':
                ssid = form.cleaned_data['ssid']
                mode = form.cleaned_data['mode']
                auth_mode = form.cleaned_data['auth_mode']
                passphrase = form.cleaned_data['passphrase']

                network.edit_wifi_connection(
                    connection, name, interface, zone, ssid, mode, auth_mode,
                    passphrase, ipv4_method, ipv4_address, ipv4_netmask,
                    ipv4_gateway, ipv4_dns, ipv4_second_dns)
            elif connection.get_connection_type() == 'pppoe':
                network.edit_pppoe_connection(
                    connection, name, interface, zone, username, password)

            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 = AddWifiForm(form_data)
        elif settings_connection.get_connection_type() == '802-3-ethernet':
            form = AddEthernetForm(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 = AddPPPoEForm(form_data)

        return TemplateResponse(request, 'connections_edit.html',
                                {'title': _('Edit Connection'),
                                 'subsubmenu': subsubmenu,
                                 'form': form})
Пример #45
0
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'))

    form = None
    settings = connection.GetSettings()
    form_data = {'name': settings['connection']['id']}

    if request.method == 'POST':
        if settings['connection']['type'] == '802-11-wireless':
            form = AddWifiForm(request.POST)
        else:
            form = AddEthernetForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            zone = form.cleaned_data['zone']
            ipv4_method = form.cleaned_data['ipv4_method']
            ipv4_address = form.cleaned_data['ipv4_address']

            if settings['connection']['type'] == '802-3-ethernet':
                network.edit_ethernet_connection(connection, name, zone,
                                                 ipv4_method, ipv4_address)
            elif settings['connection']['type'] == '802-11-wireless':
                ssid = form.cleaned_data['ssid']
                mode = form.cleaned_data['mode']
                auth_mode = form.cleaned_data['auth_mode']
                passphrase = form.cleaned_data['passphrase']

                network.edit_wifi_connection(connection, name, zone, ssid,
                                             mode, auth_mode, passphrase,
                                             ipv4_method, ipv4_address)

            return redirect(reverse_lazy('networks:index'))
        else:
            return TemplateResponse(
                request, 'connections_edit.html', {
                    'title': _('Edit Connection'),
                    'subsubmenu': subsubmenu,
                    'form': form
                })
    else:
        try:
            form_data['zone'] = settings['connection']['zone']
        except KeyError:
            form_data['zone'] = 'external'

        form_data['ipv4_method'] = settings['ipv4']['method']

        if settings['ipv4']['addresses']:
            form_data['ipv4_address'] = settings['ipv4']['addresses'][0][0]

        if settings['connection']['type'] == '802-11-wireless':
            settings_wifi = settings['802-11-wireless']
            form_data['ssid'] = settings_wifi['ssid']
            form_data['mode'] = settings_wifi['mode']
            try:
                if settings_wifi['security'] == '802-11-wireless-security':
                    wifi_sec = settings['802-11-wireless-security']
                    if wifi_sec['key-mgmt'] == 'wpa-psk':
                        form_data['auth_mode'] = 'wpa'
                        secret = connection.GetSecrets()
                        psk = secret['802-11-wireless-security']['psk']
                        form_data['passphrase'] = psk
                else:
                    form_data['auth_mode'] = 'open'
            except KeyError:
                form_data['auth_mode'] = 'open'

            form = AddWifiForm(form_data)
        else:
            form = AddEthernetForm(form_data)

        return TemplateResponse(request, 'connections_edit.html', {
            'title': _('Edit Connection'),
            'subsubmenu': subsubmenu,
            'form': form
        })
Пример #46
0
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
        })
Пример #47
0
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'),
                                     '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()
            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'),
                                 'subsubmenu': subsubmenu,
                                 'form': form})
Пример #48
0
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 = AddWifiForm(request.POST)
        elif connection.get_connection_type() == '802-3-ethernet':
            form = AddEthernetForm(request.POST)
        elif connection.get_connection_type() == 'pppoe':
            form = AddPPPoEForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            interface = form.cleaned_data['interface']
            zone = form.cleaned_data['zone']
            if connection.get_connection_type() == 'pppoe':
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']
            else:
                ipv4_method = form.cleaned_data['ipv4_method']
                ipv4_address = form.cleaned_data['ipv4_address']

            if connection.get_connection_type() == '802-3-ethernet':
                network.edit_ethernet_connection(
                    connection, name, interface, zone, ipv4_method,
                    ipv4_address)
            elif connection.get_connection_type() == '802-11-wireless':
                ssid = form.cleaned_data['ssid']
                mode = form.cleaned_data['mode']
                auth_mode = form.cleaned_data['auth_mode']
                passphrase = form.cleaned_data['passphrase']

                network.edit_wifi_connection(
                    connection, name, interface, zone, ssid, mode, auth_mode,
                    passphrase, ipv4_method, ipv4_address)
            elif connection.get_connection_type() == 'pppoe':
                network.edit_pppoe_connection(
                    connection, name, interface, zone, username, password)

            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 = network.get_first_ip_address_from_connection(connection)
            if address:
                form_data['ipv4_address'] = address

        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 = AddWifiForm(form_data)
        elif settings_connection.get_connection_type() == '802-3-ethernet':
            form = AddEthernetForm(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 = AddPPPoEForm(form_data)

        return TemplateResponse(request, 'connections_edit.html',
                                {'title': _('Edit Connection'),
                                 'subsubmenu': subsubmenu,
                                 'form': form})
Пример #49
0
def show(request, uuid):
    """Serve connection information."""
    try:
        connection = network.get_connection(uuid)
    except network.ConnectionNotFound:
        messages.error(request,
                       _('Cannot show connection: '
                         'Connection not found.'))
        return redirect(reverse_lazy('networks:index'))

    # Connection status
    connection_status = network.get_status_from_connection(connection)
    connection_status['zone_string'] = dict(network.ZONES).get(
        connection_status['zone'], connection_status['zone'])
    connection_status['ipv4']['method_string'] = CONNECTION_METHOD_STRINGS.get(
        connection_status['ipv4']['method'],
        connection_status['ipv4']['method'])
    connection_status['ipv6']['method_string'] = CONNECTION_METHOD_STRINGS.get(
        connection_status['ipv6']['method'],
        connection_status['ipv6']['method'])

    # Active connection status
    try:
        active_connection = network.get_active_connection(uuid)
        active_connection_status = \
            network.get_status_from_active_connection(active_connection)
    except network.ConnectionNotFound:
        active_connection_status = {}
        active_connection = None

    # Device status
    device = None
    if active_connection and active_connection.get_devices():
        device = active_connection.get_devices()[0]
    else:
        interface_name = connection_status['interface_name']
        if interface_name:
            device = network.get_device_by_interface_name(interface_name)

    device_status = network.get_status_from_device(device)
    device_status['state_string'] = DEVICE_STATE_STRINGS.get(
        device_status['state'], device_status['state'])
    device_status['state_reason_string'] = DEVICE_STATE_REASON_STRINGS.get(
        device_status['state_reason'], device_status['state_reason'])
    device_status['type_string'] = DEVICE_TYPE_STRINGS.get(
        device_status['type'], device_status['type'])

    # Access point status
    access_point_status = None
    if connection_status['type'] == '802-11-wireless':
        access_point_status = network.get_status_from_wifi_access_point(
            device, connection_status['wireless']['ssid'])
        connection_status['wireless'][
            'mode_string'] = WIRELESS_MODE_STRINGS.get(
                connection['wireless']['mode'], connection['wireless']['mode'])

    return TemplateResponse(
        request, 'connection_show.html', {
            'title': _('Connection Information'),
            'connection': connection_status,
            'active_connection': active_connection_status,
            'device': device_status,
            'access_point': access_point_status
        })
Пример #50
0
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'))

    form = None
    form_data = {'name': connection.get_id()}

    if request.method == 'POST':
        if connection.get_connection_type() == '802-11-wireless':
            form = AddWifiForm(request.POST)
        else:
            form = AddEthernetForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            interface = form.cleaned_data['interface']
            zone = form.cleaned_data['zone']
            ipv4_method = form.cleaned_data['ipv4_method']
            ipv4_address = form.cleaned_data['ipv4_address']

            if connection.get_connection_type() == '802-3-ethernet':
                network.edit_ethernet_connection(
                    connection, name, interface, zone, ipv4_method,
                    ipv4_address)
            elif connection.get_connection_type() == '802-11-wireless':
                ssid = form.cleaned_data['ssid']
                mode = form.cleaned_data['mode']
                auth_mode = form.cleaned_data['auth_mode']
                passphrase = form.cleaned_data['passphrase']

                network.edit_wifi_connection(
                    connection, name, interface, zone, ssid, mode, auth_mode,
                    passphrase, ipv4_method, ipv4_address)

            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()
        settings_ipv4 = connection.get_setting_ip4_config()
        form_data['interface'] = connection.get_interface_name()
        try:
            form_data['zone'] = settings_connection.get_zone()
        except KeyError:
            form_data['zone'] = 'external'

        form_data['ipv4_method'] = settings_ipv4.get_method()

        if settings_ipv4.get_num_addresses():
            # XXX: Plinth crashes here. Possibly because a double free bug
            # address = settings_ipv4.get_address(0)
            # form_data['ipv4_address'] = address.get_address()
            pass

        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 = AddWifiForm(form_data)
        else:
            form = AddEthernetForm(form_data)

        return TemplateResponse(request, 'connections_edit.html',
                                {'title': _('Edit Connection'),
                                 'subsubmenu': subsubmenu,
                                 'form': form})