Exemplo n.º 1
0
def add_wifi(request, ssid=None, interface_name=None):
    """Serve wifi connection create form."""
    form = None
    form_data = None

    if ssid:
        device = network.get_device_by_interface_name(interface_name)
        form_data = {'name': ssid,
                     'interface': interface_name if device else None,
                     'zone': 'external',
                     'ssid': ssid,
                     'mode': 'infrastructure',
                     'auth_mode': 'wpa',
                     'ipv4_method': 'auto'}

    if request.method == 'POST':
        form = WifiForm(request.POST)
        if form.is_valid():
            network.add_connection(form.get_settings())
            return redirect(reverse_lazy('networks:index'))
    else:
        if form_data:
            form = WifiForm(form_data)
        else:
            form = WifiForm()

    return TemplateResponse(request, 'connections_create.html',
                            {'title': _('Adding New Wi-Fi Connection'),
                             'subsubmenu': subsubmenu,
                             'form': form})
Exemplo n.º 2
0
 def setUp(cls):
     cls.ethernet_uuid = network.add_connection(ethernet_settings)
     cls.wifi_uuid = network.add_connection(wifi_settings)
     cls.pppoe_uuid = network.add_connection(pppoe_settings)
     # XXX: Handle this properly by waiting for asynchronous add_connection
     # to complete.
     time.sleep(0.1)
Exemplo n.º 3
0
def add_wifi(request, ssid=None, interface_name=None):
    """Serve wifi connection create form."""
    form = None
    form_data = None

    if ssid:
        device = network.get_device_by_interface_name(interface_name)
        form_data = {
            'name': ssid,
            'interface': interface_name if device else None,
            'zone': 'external',
            'ssid': ssid,
            'mode': 'infrastructure',
            'band': 'auto',
            'auth_mode': 'wpa',
            'ipv4_method': 'auto'
        }

    if request.method == 'POST':
        form = WifiForm(request.POST)
        if form.is_valid():
            network.add_connection(form.get_settings())
            return redirect(reverse_lazy('networks:index'))
    else:
        if form_data:
            form = WifiForm(form_data)
        else:
            form = WifiForm()

    return TemplateResponse(request, 'connections_create.html', {
        'title': _('Adding New Wi-Fi Connection'),
        'form': form
    })
Exemplo n.º 4
0
def setup_server():
    """Setup a server connection that clients can connect to."""
    from plinth.modules.wireguard import app

    setting_name = nm.SETTING_WIREGUARD_SETTING_NAME
    private_key = _generate_private_key()
    settings = {
        'common': {
            'name': 'WireGuard-Server-wg0',
            'type': setting_name,
            'zone': 'internal',
            'interface': 'wg0',
            'autoconnect': app.is_enabled(),
        },
        'ipv4': {
            'method': 'manual',
            'address': IP_TEMPLATE.format(1),
            'netmask': '255.255.255.0',
            'gateway': '',
            'dns': '',
            'second_dns': '',
        },
        'wireguard': {
            'private_key': private_key,
            'listen_port': 51820,
        }
    }
    network.add_connection(settings)
    logger.info('Created new WireGuard server connection')
Exemplo n.º 5
0
 def setUp(cls):
     cls.ethernet_uuid = network.add_connection(ethernet_settings)
     cls.wifi_uuid = network.add_connection(wifi_settings)
     cls.pppoe_uuid = network.add_connection(pppoe_settings)
     # XXX: Handle this properly by waiting for asynchronous add_connection
     # to complete.
     time.sleep(0.1)
Exemplo n.º 6
0
def add_server(settings):
    """Add information for connecting to a server."""
    from plinth.modules.wireguard import app

    interface_name = _find_next_interface()
    settings['common']['name'] = 'WireGuard-Client-' + interface_name
    settings['common']['interface'] = interface_name
    settings['common']['autoconnect'] = app.is_enabled()
    if not settings['wireguard']['private_key']:
        settings['wireguard']['private_key'] = _generate_private_key()

    network.add_connection(settings)
Exemplo n.º 7
0
def add_pppoe(request):
    """Serve pppoe connection create form."""
    form = None

    if request.method == 'POST':
        form = PPPoEForm(request.POST)
        if form.is_valid():
            network.add_connection(form.get_settings())
            return redirect(reverse_lazy('networks:index'))
    else:
        form = PPPoEForm()

    return TemplateResponse(request, 'connections_create.html',
                            {'title': _('Adding New PPPoE Connection'),
                             'subsubmenu': subsubmenu,
                             'form': form})
Exemplo n.º 8
0
def add_pppoe(request):
    """Serve pppoe connection create form."""
    form = None

    if request.method == 'POST':
        form = PPPoEForm(request.POST)
        if form.is_valid():
            network.add_connection(form.get_settings())
            return redirect(reverse_lazy('networks:index'))
    else:
        form = PPPoEForm()

    return TemplateResponse(request, 'connections_create.html', {
        'title': _('Adding New PPPoE Connection'),
        'form': form
    })
Exemplo n.º 9
0
def add_generic(request):
    """Serve generic connection create form."""
    form = None

    if request.method == 'POST':
        form = GenericForm(request.POST)
        if form.is_valid():
            network.add_connection(form.get_settings())
            return redirect(reverse_lazy('networks:index'))
    else:
        form = GenericForm()

    return TemplateResponse(request, 'connections_create.html',
                            {'title': _('Adding New Generic Connection'),
                             'subsubmenu': subsubmenu,
                             'form': form})
Exemplo n.º 10
0
 def setUp(cls):
     cls.ethernet_uuid = network.add_connection(ethernet_settings)
     cls.wifi_uuid = network.add_connection(wifi_settings)
     cls.pppoe_uuid = network.add_connection(pppoe_settings)
Exemplo n.º 11
0
 def setUp(cls):
     cls.ethernet_uuid = network.add_connection(ethernet_settings)
     cls.wifi_uuid = network.add_connection(wifi_settings)
     cls.pppoe_uuid = network.add_connection(pppoe_settings)