mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
Add wifi security settings.
This commit is contained in:
parent
f63d8d29de
commit
f0c5cd080c
@ -41,6 +41,10 @@ class AddWifiForm(forms.Form):
|
||||
"""Form to create a new wifi connection."""
|
||||
name = forms.CharField(label=_('Connection Name'))
|
||||
ssid = forms.CharField(label=_('SSID'))
|
||||
auth_mode = forms.ChoiceField(
|
||||
label=_('Authentication Mode'),
|
||||
choices=[('wpa', 'WPA'), ('open', 'Open')])
|
||||
passphrase = forms.CharField(label=_('Passphrase'), required=False)
|
||||
ipv4_method = forms.ChoiceField(
|
||||
label=_('IPv4 Addressing Method'),
|
||||
choices=[('auto', 'Automatic (DHCP)'), ('manual', 'Manual')])
|
||||
|
||||
@ -83,7 +83,13 @@ def edit(request, conn_id):
|
||||
network.edit_ethernet_connection(conn, name, ipv4_method, ipv4_address)
|
||||
elif settings['connection']['type'] == '802-11-wireless':
|
||||
ssid = form.cleaned_data['ssid']
|
||||
network.edit_wifi_connection(conn, name, ssid, ipv4_method, ipv4_address)
|
||||
auth_mode = form.cleaned_data['auth_mode']
|
||||
passphrase = form.cleaned_data['passphrase']
|
||||
|
||||
network.edit_wifi_connection(
|
||||
conn, name,
|
||||
ssid, auth_mode, passphrase,
|
||||
ipv4_method, ipv4_address)
|
||||
else:
|
||||
messages.error(
|
||||
request,
|
||||
@ -98,6 +104,17 @@ def edit(request, conn_id):
|
||||
|
||||
if settings['connection']['type'] == '802-11-wireless':
|
||||
form_data['ssid'] = settings['802-11-wireless']['ssid']
|
||||
try:
|
||||
if (settings['802-11-wireless']['security'] == '802-11-wireless-security'
|
||||
and settings['802-11-wireless-security']['key-mgmt'] == 'wpa-psk'):
|
||||
form_data['auth_mode'] = 'wpa'
|
||||
secrets = conn.GetSecrets()
|
||||
form_data['passphrase'] = secrets['802-11-wireless-security']['psk']
|
||||
else:
|
||||
form_data['auth_mode'] = 'open'
|
||||
except KeyError:
|
||||
form_data['auth_mode'] = 'open'
|
||||
|
||||
form = AddWifiForm(form_data)
|
||||
else:
|
||||
form = AddEthernetForm(form_data)
|
||||
@ -153,17 +170,25 @@ 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'}
|
||||
form_data = {'name': ssid,
|
||||
'ssid': ssid,
|
||||
'auth_mode': 'wpa',
|
||||
'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']
|
||||
auth_mode = form.cleaned_data['auth_mode']
|
||||
passphrase = form.cleaned_data['passphrase']
|
||||
ipv4_method = form.cleaned_data['ipv4_method']
|
||||
ipv4_address = form.cleaned_data['ipv4_address']
|
||||
|
||||
network.add_wifi_connection(name, ssid, ipv4_method, ipv4_address)
|
||||
network.add_wifi_connection(
|
||||
name,
|
||||
ssid, auth_mode, passphrase,
|
||||
ipv4_method, ipv4_address)
|
||||
return redirect(reverse_lazy('networks:index'))
|
||||
else:
|
||||
form = AddWifiForm(form_data)
|
||||
@ -228,10 +253,15 @@ def add_wifi(request):
|
||||
if form.is_valid():
|
||||
name = form.cleaned_data['name']
|
||||
ssid = form.cleaned_data['ssid']
|
||||
auth_mode = form.cleaned_data['auth_mode']
|
||||
passphrase = form.cleaned_data['passphrase']
|
||||
ipv4_method = form.cleaned_data['ipv4_method']
|
||||
ipv4_address = form.cleaned_data['ipv4_address']
|
||||
|
||||
network.add_wifi_connection(name, ssid, ipv4_method, ipv4_address)
|
||||
network.add_wifi_connection(
|
||||
name,
|
||||
ssid, auth_mode, passphrase,
|
||||
ipv4_method, ipv4_address)
|
||||
return redirect(reverse_lazy('networks:index'))
|
||||
else:
|
||||
form = AddWifiForm()
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
Helper functions for working with network manager.
|
||||
"""
|
||||
|
||||
from dbus.exceptions import DBusException
|
||||
from gettext import gettext as _
|
||||
import NetworkManager
|
||||
import uuid
|
||||
@ -115,7 +116,9 @@ def edit_ethernet_connection(conn, name, ipv4_method, ipv4_address):
|
||||
conn.Update(new_settings)
|
||||
|
||||
|
||||
def edit_wifi_connection(conn, name, ssid, ipv4_method, ipv4_address):
|
||||
def edit_wifi_connection(conn, name,
|
||||
ssid, auth_mode, passphrase,
|
||||
ipv4_method, ipv4_address):
|
||||
settings = conn.GetSettings()
|
||||
|
||||
new_settings = {
|
||||
@ -129,6 +132,14 @@ def edit_wifi_connection(conn, name, ssid, ipv4_method, ipv4_address):
|
||||
},
|
||||
'ipv4': {'method': ipv4_method},
|
||||
}
|
||||
|
||||
if auth_mode == 'wpa' and passphrase:
|
||||
new_settings['connection']['security'] = '802-11-wireless-security'
|
||||
new_settings['802-11-wireless-security'] = {
|
||||
'key-mgmt': 'wpa-psk',
|
||||
'psk': passphrase,
|
||||
}
|
||||
|
||||
if ipv4_method == 'manual' and ipv4_address:
|
||||
new_settings['ipv4']['addresses'] = [
|
||||
(ipv4_address,
|
||||
@ -206,7 +217,9 @@ def add_ethernet_connection(name, ipv4_method, ipv4_address):
|
||||
NetworkManager.Settings.AddConnection(conn)
|
||||
|
||||
|
||||
def add_wifi_connection(name, ssid, ipv4_method, ipv4_address):
|
||||
def add_wifi_connection(name,
|
||||
ssid, auth_mode, passphrase,
|
||||
ipv4_method, ipv4_address):
|
||||
conn = {
|
||||
'connection': {
|
||||
'id': name,
|
||||
@ -219,6 +232,13 @@ def add_wifi_connection(name, ssid, ipv4_method, ipv4_address):
|
||||
'ipv4': {'method': ipv4_method},
|
||||
}
|
||||
|
||||
if auth_mode == 'wpa' and passphrase:
|
||||
conn['connection']['security'] = '802-11-wireless-security'
|
||||
conn['802-11-wireless-security'] = {
|
||||
'key-mgmt': 'wpa-psk',
|
||||
'psk': passphrase,
|
||||
}
|
||||
|
||||
if ipv4_method == 'manual' and ipv4_address:
|
||||
conn['ipv4']['addresses'] = [
|
||||
(ipv4_address,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user