Add wifi scan page to networks module.

This commit is contained in:
James Valleroy 2015-03-17 07:09:56 -04:00 committed by Sunil Mohan Adapa
parent 9b201a2daf
commit c0cd01221e
4 changed files with 64 additions and 0 deletions

View File

@ -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."""

View File

@ -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 <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block content %}
<div class="row">
<div class="col-sm-6">
<div class="list-group">
{% for ap in aps %}
<div class="list-group-item clearfix">
<a display="inline-block" width="40%">{{ ap.ssid }}</a>
<span class="btn btn-primary btn-xs pull-right">
{{ ap.strength }}%
</span>
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock %}

View File

@ -31,6 +31,7 @@ urlpatterns = patterns(
'activate', name='activate'),
url(r'^sys/networks/(?P<conn_id>[\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'),

View File

@ -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