Beispiel #1
0
    def test_edit_pppoe_connection(self):
        """Check that we can update a PPPoE connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_pppoe_connection(
            connection, 'plinth_test_pppoe_new', 'eth2', 'external',
            'x-user-new', 'x-password-new')

        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)
Beispiel #2
0
    def test_edit_pppoe_connection(self):
        """Check that we can update a PPPoE connection."""
        connection = network.get_connection(self.ethernet_uuid)
        network.edit_pppoe_connection(connection, 'plinth_test_pppoe_new',
                                      'eth2', 'external', 'x-user-new',
                                      'x-password-new')

        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)
Beispiel #3
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})
Beispiel #4
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})