From c0cd01221e95044d86c9932d01675c87f1bc8364 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Tue, 17 Mar 2015 07:09:56 -0400 Subject: [PATCH] Add wifi scan page to networks module. --- plinth/modules/networks/networks.py | 12 ++++++ .../modules/networks/templates/wifi_scan.html | 40 +++++++++++++++++++ plinth/modules/networks/urls.py | 1 + plinth/network.py | 11 +++++ 4 files changed, 64 insertions(+) create mode 100644 plinth/modules/networks/templates/wifi_scan.html diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index 296f1aab9..fe5771570 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -31,6 +31,8 @@ from plinth import network subsubmenu = [{'url': reverse_lazy('networks:index'), 'text': _('Network Connections')}, + {'url': reverse_lazy('networks:scan'), + 'text': _('Nearby Wi-Fi Networks')}, {'url': reverse_lazy('networks:add'), 'text': _('Add Connection')}] @@ -136,6 +138,16 @@ def deactivate(request, conn_id): return redirect(reverse_lazy('networks:index')) +@login_required +def scan(request): + """Show a list of nearby visible wifi APs.""" + aps = network.wifi_scan() + return TemplateResponse(request, 'wifi_scan.html', + {'title': _('Nearby Wi-Fi Networks'), + 'subsubmenu': subsubmenu, + 'aps': aps}) + + @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 new file mode 100644 index 000000000..8ecad2b23 --- /dev/null +++ b/plinth/modules/networks/templates/wifi_scan.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} +{% comment %} +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +{% endcomment %} + +{% load bootstrap %} + +{% block content %} + +
+
+
+ {% for ap in aps %} +
+ {{ ap.ssid }} + + {{ ap.strength }}% + +
+ {% endfor %} +
+
+
+ +{% endblock %} diff --git a/plinth/modules/networks/urls.py b/plinth/modules/networks/urls.py index 410fd8777..9698fcec8 100644 --- a/plinth/modules/networks/urls.py +++ b/plinth/modules/networks/urls.py @@ -31,6 +31,7 @@ urlpatterns = patterns( 'activate', name='activate'), url(r'^sys/networks/(?P[\w.@+-]+)/deactivate/$', 'deactivate', name='deactivate'), + url(r'^sys/networks/scan/$', 'scan', name='scan'), 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 ba895d247..3b1359505 100644 --- a/plinth/network.py +++ b/plinth/network.py @@ -235,3 +235,14 @@ def delete_connection(name): _('Failed to delete connection %s: ' 'Connection not found.') % name) conn.Delete() + + +def wifi_scan(): + aps = [] + for dev in NetworkManager.NetworkManager.GetDevices(): + if dev.DeviceType != NetworkManager.NM_DEVICE_TYPE_WIFI: + continue + for ap in dev.SpecificDevice().GetAccessPoints(): + aps.append({'ssid': ap.Ssid, + 'strength': ord(ap.Strength)}) + return aps