Add AP and adhoc wifi modes, and shared IPv4 addressing mode.

This commit is contained in:
James Valleroy 2015-03-22 19:49:54 -04:00 committed by Sunil Mohan Adapa
parent 8d9b388375
commit 2441caf647
4 changed files with 31 additions and 9 deletions

View File

@ -39,7 +39,9 @@ available over this interfaces. Select Internal only for trusted networks.'),
choices=[('external', 'External'), ('internal', 'Internal')]) choices=[('external', 'External'), ('internal', 'Internal')])
ipv4_method = forms.ChoiceField( ipv4_method = forms.ChoiceField(
label=_('IPv4 Addressing Method'), label=_('IPv4 Addressing Method'),
choices=[('auto', 'Automatic (DHCP)'), ('manual', 'Manual')]) choices=[('auto', 'Automatic (DHCP)'),
('shared', 'Shared'),
('manual', 'Manual')])
ipv4_address = forms.CharField( ipv4_address = forms.CharField(
label=_('Address'), label=_('Address'),
validators=[validators.validate_ipv4_address], validators=[validators.validate_ipv4_address],
@ -57,15 +59,28 @@ available over this interfaces. Select Internal only for trusted networks.'),
ssid = forms.CharField( ssid = forms.CharField(
label=_('SSID'), label=_('SSID'),
help_text=_('The visible name of the network.')) help_text=_('The visible name of the network.'))
mode = forms.ChoiceField(
label=_('Mode'),
choices=[('infrastructure', 'Infrastructure'),
('ap', 'Access Point'),
('adhoc', 'Ad-hoc')])
auth_mode = forms.ChoiceField( auth_mode = forms.ChoiceField(
label=_('Authentication Mode'), label=_('Authentication Mode'),
help_text=_('Select WPA if the wireless network is secured and \ help_text=_('Select WPA if the wireless network is secured and \
requires clients to have the password to connect.'), requires clients to have the password to connect.'),
choices=[('wpa', 'WPA'), ('open', 'Open')]) choices=[('wpa', 'WPA'), ('open', 'Open')])
passphrase = forms.CharField(label=_('Passphrase'), required=False) passphrase = forms.CharField(
label=_('Passphrase'),
validators=[validators.MinLengthValidator(8)],
required=False)
ipv4_method = forms.ChoiceField( ipv4_method = forms.ChoiceField(
label=_('IPv4 Addressing Method'), label=_('IPv4 Addressing Method'),
choices=[('auto', 'Automatic (DHCP)'), ('manual', 'Manual')]) choices=[('auto', 'Automatic (DHCP)'),
('shared', 'Shared'),
('manual', 'Manual')],
help_text=_('Select Automatic (DHCP) if you are connecting to an \
existing wireless network. Shared mode is useful when running an Access \
Point.'))
ipv4_address = forms.CharField( ipv4_address = forms.CharField(
label=_('Address'), label=_('Address'),
validators=[validators.validate_ipv4_address], validators=[validators.validate_ipv4_address],

View File

@ -86,12 +86,13 @@ def edit(request, conn_id):
ipv4_method, ipv4_address) ipv4_method, ipv4_address)
elif settings['connection']['type'] == '802-11-wireless': elif settings['connection']['type'] == '802-11-wireless':
ssid = form.cleaned_data['ssid'] ssid = form.cleaned_data['ssid']
mode = form.cleaned_data['mode']
auth_mode = form.cleaned_data['auth_mode'] auth_mode = form.cleaned_data['auth_mode']
passphrase = form.cleaned_data['passphrase'] passphrase = form.cleaned_data['passphrase']
network.edit_wifi_connection( network.edit_wifi_connection(
conn, name, zone, conn, name, zone,
ssid, auth_mode, passphrase, ssid, mode, auth_mode, passphrase,
ipv4_method, ipv4_address) ipv4_method, ipv4_address)
else: else:
messages.error( messages.error(
@ -117,6 +118,7 @@ def edit(request, conn_id):
if settings['connection']['type'] == '802-11-wireless': if settings['connection']['type'] == '802-11-wireless':
form_data['ssid'] = settings['802-11-wireless']['ssid'] form_data['ssid'] = settings['802-11-wireless']['ssid']
form_data['mode'] = settings['802-11-wireless']['mode']
try: try:
if (settings['802-11-wireless']['security'] == '802-11-wireless-security' if (settings['802-11-wireless']['security'] == '802-11-wireless-security'
and settings['802-11-wireless-security']['key-mgmt'] == 'wpa-psk'): and settings['802-11-wireless-security']['key-mgmt'] == 'wpa-psk'):
@ -272,6 +274,7 @@ def add_wifi(request):
name = form.cleaned_data['name'] name = form.cleaned_data['name']
zone = form.cleaned_data['zone'] zone = form.cleaned_data['zone']
ssid = form.cleaned_data['ssid'] ssid = form.cleaned_data['ssid']
mode = form.cleaned_data['mode']
auth_mode = form.cleaned_data['auth_mode'] auth_mode = form.cleaned_data['auth_mode']
passphrase = form.cleaned_data['passphrase'] passphrase = form.cleaned_data['passphrase']
ipv4_method = form.cleaned_data['ipv4_method'] ipv4_method = form.cleaned_data['ipv4_method']
@ -279,7 +282,7 @@ def add_wifi(request):
network.add_wifi_connection( network.add_wifi_connection(
name, zone, name, zone,
ssid, auth_mode, passphrase, ssid, mode, auth_mode, passphrase,
ipv4_method, ipv4_address) ipv4_method, ipv4_address)
return redirect(reverse_lazy('networks:index')) return redirect(reverse_lazy('networks:index'))
else: else:

View File

@ -118,7 +118,7 @@ def edit_ethernet_connection(conn, name, zone, ipv4_method, ipv4_address):
def edit_wifi_connection(conn, name, zone, def edit_wifi_connection(conn, name, zone,
ssid, auth_mode, passphrase, ssid, mode, auth_mode, passphrase,
ipv4_method, ipv4_address): ipv4_method, ipv4_address):
settings = conn.GetSettings() settings = conn.GetSettings()
@ -131,6 +131,7 @@ def edit_wifi_connection(conn, name, zone,
}, },
'802-11-wireless': { '802-11-wireless': {
'ssid': ssid, 'ssid': ssid,
'mode': mode,
}, },
'ipv4': {'method': ipv4_method}, 'ipv4': {'method': ipv4_method},
} }
@ -221,7 +222,7 @@ def add_ethernet_connection(name, zone, ipv4_method, ipv4_address):
def add_wifi_connection(name, zone, def add_wifi_connection(name, zone,
ssid, auth_mode, passphrase, ssid, mode, auth_mode, passphrase,
ipv4_method, ipv4_address): ipv4_method, ipv4_address):
conn = { conn = {
'connection': { 'connection': {
@ -232,6 +233,7 @@ def add_wifi_connection(name, zone,
}, },
'802-11-wireless': { '802-11-wireless': {
'ssid': ssid, 'ssid': ssid,
'mode': mode,
}, },
'ipv4': {'method': ipv4_method}, 'ipv4': {'method': ipv4_method},
} }

View File

@ -31,7 +31,7 @@ class TestNetwork(unittest.TestCase):
'auto', '') 'auto', '')
network.add_wifi_connection( network.add_wifi_connection(
'plinth_test_wifi', 'external', 'plinth_test_wifi', 'external',
'plinthtestwifi', 'open', '', 'plinthtestwifi', 'adhoc', 'open', '',
'auto', '') 'auto', '')
@classmethod @classmethod
@ -72,13 +72,15 @@ class TestNetwork(unittest.TestCase):
conn = network.get_connection('plinth_test_wifi') conn = network.get_connection('plinth_test_wifi')
network.edit_wifi_connection( network.edit_wifi_connection(
conn, 'plinth_test_wifi', 'external', conn, 'plinth_test_wifi', 'external',
'plinthtestwifi2', 'wpa', 'secretpassword', 'plinthtestwifi2', 'infrastructure', 'wpa', 'secretpassword',
'auto', '') 'auto', '')
conn = network.get_connection('plinth_test_wifi') conn = network.get_connection('plinth_test_wifi')
self.assertEqual(conn.GetSettings()['connection']['zone'], 'external') self.assertEqual(conn.GetSettings()['connection']['zone'], 'external')
self.assertEqual( self.assertEqual(
conn.GetSettings()['802-11-wireless']['ssid'], 'plinthtestwifi2') conn.GetSettings()['802-11-wireless']['ssid'], 'plinthtestwifi2')
self.assertEqual(
conn.GetSettings()['802-11-wireless']['mode'], 'infrastructure')
self.assertEqual( self.assertEqual(
conn.GetSettings()['802-11-wireless-security']['key-mgmt'], conn.GetSettings()['802-11-wireless-security']['key-mgmt'],
'wpa-psk') 'wpa-psk')