diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index fe5771570..a2cb706a6 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -123,7 +123,7 @@ def activate(request, conn_id): return redirect(reverse_lazy('networks:index')) messages.success(request, _('Activated connection %s.') % name) - return redirect(reverse_lazy('network:index')) + return redirect(reverse_lazy('networks:index')) @login_required @@ -148,6 +148,32 @@ def scan(request): 'aps': aps}) +@login_required +def connect(request, connect_path): + """Create a new wifi connection to an existing AP.""" + form = None + ssid = urllib.parse.unquote_plus(connect_path) + form_data = {'name': ssid, 'ssid': ssid, 'ipv4_method': 'auto'} + + if request.method == 'POST': + form = AddWifiForm(request.POST) + if form.is_valid(): + name = form.cleaned_data['name'] + ssid = form.cleaned_data['ssid'] + ipv4_method = form.cleaned_data['ipv4_method'] + ipv4_address = form.cleaned_data['ipv4_address'] + + network.add_wifi_connection(name, ssid, ipv4_method, ipv4_address) + return redirect(reverse_lazy('networks:index')) + else: + form = AddWifiForm(form_data) + + return TemplateResponse(request, 'connections_create.html', + {'title': _('Connect to Wi-Fi Network'), + 'subsubmenu': subsubmenu, + 'form': form}) + + @login_required def add(request): """Serve the connection type selection form.""" diff --git a/plinth/modules/networks/templates/wifi_scan.html b/plinth/modules/networks/templates/wifi_scan.html index 8ecad2b23..0e767b9fe 100644 --- a/plinth/modules/networks/templates/wifi_scan.html +++ b/plinth/modules/networks/templates/wifi_scan.html @@ -27,7 +27,10 @@
{% for ap in aps %}
- {{ ap.ssid }} + + {{ ap.ssid }} + {{ ap.strength }}% diff --git a/plinth/modules/networks/urls.py b/plinth/modules/networks/urls.py index 9698fcec8..7799da764 100644 --- a/plinth/modules/networks/urls.py +++ b/plinth/modules/networks/urls.py @@ -32,6 +32,7 @@ urlpatterns = patterns( url(r'^sys/networks/(?P[\w.@+-]+)/deactivate/$', 'deactivate', name='deactivate'), url(r'^sys/networks/scan/$', 'scan', name='scan'), + url(r'^sys/networks/connect/(?P[\w.@+-]+)/$', 'connect', name='connect'), url(r'^sys/networks/add/$', 'add', name='add'), url(r'^sys/networks/add/ethernet/$', 'add_ethernet', name='add_ethernet'), url(r'^sys/networks/add/wifi/$', 'add_wifi', name='add_wifi'), diff --git a/plinth/network.py b/plinth/network.py index 3b1359505..136886edf 100644 --- a/plinth/network.py +++ b/plinth/network.py @@ -244,5 +244,6 @@ def wifi_scan(): continue for ap in dev.SpecificDevice().GetAccessPoints(): aps.append({'ssid': ap.Ssid, + 'connect_path': urllib.parse.quote_plus(ap.Ssid), 'strength': ord(ap.Strength)}) return aps