Add firewall zone selection for networks.

This commit is contained in:
James Valleroy 2015-03-17 19:25:50 -04:00 committed by Sunil Mohan Adapa
parent f0c5cd080c
commit 45086ff003
3 changed files with 34 additions and 9 deletions

View File

@ -31,6 +31,9 @@ class ConnectionTypeSelectForm(forms.Form):
class AddEthernetForm(forms.Form): class AddEthernetForm(forms.Form):
"""Form to create a new ethernet connection.""" """Form to create a new ethernet connection."""
name = forms.CharField(label=_('Connection Name')) name = forms.CharField(label=_('Connection Name'))
zone = forms.ChoiceField(
label=_('Firewall Zone'),
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)'), ('manual', 'Manual')])
@ -40,6 +43,9 @@ class AddEthernetForm(forms.Form):
class AddWifiForm(forms.Form): class AddWifiForm(forms.Form):
"""Form to create a new wifi connection.""" """Form to create a new wifi connection."""
name = forms.CharField(label=_('Connection Name')) name = forms.CharField(label=_('Connection Name'))
zone = forms.ChoiceField(
label=_('Firewall Zone'),
choices=[('external', 'External'), ('internal', 'Internal')])
ssid = forms.CharField(label=_('SSID')) ssid = forms.CharField(label=_('SSID'))
auth_mode = forms.ChoiceField( auth_mode = forms.ChoiceField(
label=_('Authentication Mode'), label=_('Authentication Mode'),

View File

@ -76,18 +76,22 @@ def edit(request, conn_id):
form = AddEthernetForm(request.POST) form = AddEthernetForm(request.POST)
if form.is_valid(): if form.is_valid():
name = form.cleaned_data['name'] name = form.cleaned_data['name']
zone = form.cleaned_data['zone']
ipv4_method = form.cleaned_data['ipv4_method'] ipv4_method = form.cleaned_data['ipv4_method']
ipv4_address = form.cleaned_data['ipv4_address'] ipv4_address = form.cleaned_data['ipv4_address']
if settings['connection']['type'] == '802-3-ethernet': if settings['connection']['type'] == '802-3-ethernet':
network.edit_ethernet_connection(conn, name, ipv4_method, ipv4_address) network.edit_ethernet_connection(
conn,
name, zone,
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']
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, conn, name, zone,
ssid, auth_mode, passphrase, ssid, auth_mode, passphrase,
ipv4_method, ipv4_address) ipv4_method, ipv4_address)
else: else:
@ -97,6 +101,11 @@ def edit(request, conn_id):
'Connection type not supported.') % name) 'Connection type not supported.') % name)
return redirect(reverse_lazy('networks:index')) return redirect(reverse_lazy('networks:index'))
else: else:
try:
form_data['zone'] = settings['connection']['zone']
except KeyError:
form_data['zone'] = 'external'
form_data['ipv4_method'] = settings['ipv4']['method'] form_data['ipv4_method'] = settings['ipv4']['method']
if settings['ipv4']['addresses']: if settings['ipv4']['addresses']:
@ -171,6 +180,7 @@ def connect(request, connect_path):
form = None form = None
ssid = urllib.parse.unquote_plus(connect_path) ssid = urllib.parse.unquote_plus(connect_path)
form_data = {'name': ssid, form_data = {'name': ssid,
'zone': 'external',
'ssid': ssid, 'ssid': ssid,
'auth_mode': 'wpa', 'auth_mode': 'wpa',
'ipv4_method': 'auto'} 'ipv4_method': 'auto'}
@ -179,6 +189,7 @@ def connect(request, connect_path):
form = AddWifiForm(request.POST) form = AddWifiForm(request.POST)
if form.is_valid(): if form.is_valid():
name = form.cleaned_data['name'] name = form.cleaned_data['name']
zone = form.cleaned_data['zone']
ssid = form.cleaned_data['ssid'] ssid = form.cleaned_data['ssid']
auth_mode = form.cleaned_data['auth_mode'] auth_mode = form.cleaned_data['auth_mode']
passphrase = form.cleaned_data['passphrase'] passphrase = form.cleaned_data['passphrase']
@ -186,7 +197,7 @@ def connect(request, connect_path):
ipv4_address = form.cleaned_data['ipv4_address'] ipv4_address = form.cleaned_data['ipv4_address']
network.add_wifi_connection( network.add_wifi_connection(
name, name, zone,
ssid, auth_mode, passphrase, ssid, auth_mode, passphrase,
ipv4_method, ipv4_address) ipv4_method, ipv4_address)
return redirect(reverse_lazy('networks:index')) return redirect(reverse_lazy('networks:index'))
@ -229,10 +240,13 @@ def add_ethernet(request):
form = AddEthernetForm(request.POST) form = AddEthernetForm(request.POST)
if form.is_valid(): if form.is_valid():
name = form.cleaned_data['name'] name = form.cleaned_data['name']
zone = form.cleaned_data['zone']
ipv4_method = form.cleaned_data['ipv4_method'] ipv4_method = form.cleaned_data['ipv4_method']
ipv4_address = form.cleaned_data['ipv4_address'] ipv4_address = form.cleaned_data['ipv4_address']
network.add_ethernet_connection(name, ipv4_method, ipv4_address) network.add_ethernet_connection(
name, zone,
ipv4_method, ipv4_address)
return redirect(reverse_lazy('networks:index')) return redirect(reverse_lazy('networks:index'))
else: else:
form = AddEthernetForm() form = AddEthernetForm()
@ -252,6 +266,7 @@ def add_wifi(request):
form = AddWifiForm(request.POST) form = AddWifiForm(request.POST)
if form.is_valid(): if form.is_valid():
name = form.cleaned_data['name'] name = form.cleaned_data['name']
zone = form.cleaned_data['zone']
ssid = form.cleaned_data['ssid'] ssid = form.cleaned_data['ssid']
auth_mode = form.cleaned_data['auth_mode'] auth_mode = form.cleaned_data['auth_mode']
passphrase = form.cleaned_data['passphrase'] passphrase = form.cleaned_data['passphrase']
@ -259,7 +274,7 @@ def add_wifi(request):
ipv4_address = form.cleaned_data['ipv4_address'] ipv4_address = form.cleaned_data['ipv4_address']
network.add_wifi_connection( network.add_wifi_connection(
name, name, zone,
ssid, auth_mode, passphrase, ssid, auth_mode, passphrase,
ipv4_method, ipv4_address) ipv4_method, ipv4_address)
return redirect(reverse_lazy('networks:index')) return redirect(reverse_lazy('networks:index'))

View File

@ -95,13 +95,14 @@ def get_active_connection(name):
return connections.get(name) return connections.get(name)
def edit_ethernet_connection(conn, name, ipv4_method, ipv4_address): def edit_ethernet_connection(conn, name, zone, ipv4_method, ipv4_address):
settings = conn.GetSettings() settings = conn.GetSettings()
new_settings = { new_settings = {
'connection': { 'connection': {
'id': name, 'id': name,
'type': settings['connection']['type'], 'type': settings['connection']['type'],
'zone': zone,
'uuid': settings['connection']['uuid'], 'uuid': settings['connection']['uuid'],
}, },
'802-3-ethernet': {}, '802-3-ethernet': {},
@ -116,7 +117,7 @@ def edit_ethernet_connection(conn, name, ipv4_method, ipv4_address):
conn.Update(new_settings) conn.Update(new_settings)
def edit_wifi_connection(conn, name, def edit_wifi_connection(conn, name, zone,
ssid, auth_mode, passphrase, ssid, auth_mode, passphrase,
ipv4_method, ipv4_address): ipv4_method, ipv4_address):
settings = conn.GetSettings() settings = conn.GetSettings()
@ -125,6 +126,7 @@ def edit_wifi_connection(conn, name,
'connection': { 'connection': {
'id': name, 'id': name,
'type': settings['connection']['type'], 'type': settings['connection']['type'],
'zone': zone,
'uuid': settings['connection']['uuid'], 'uuid': settings['connection']['uuid'],
}, },
'802-11-wireless': { '802-11-wireless': {
@ -197,11 +199,12 @@ def deactivate_connection(name):
'Connection not found.') % name) 'Connection not found.') % name)
def add_ethernet_connection(name, ipv4_method, ipv4_address): def add_ethernet_connection(name, zone, ipv4_method, ipv4_address):
conn = { conn = {
'connection': { 'connection': {
'id': name, 'id': name,
'type': '802-3-ethernet', 'type': '802-3-ethernet',
'zone': zone,
'uuid': str(uuid.uuid4()), 'uuid': str(uuid.uuid4()),
}, },
'802-3-ethernet': {}, '802-3-ethernet': {},
@ -217,13 +220,14 @@ def add_ethernet_connection(name, ipv4_method, ipv4_address):
NetworkManager.Settings.AddConnection(conn) NetworkManager.Settings.AddConnection(conn)
def add_wifi_connection(name, def add_wifi_connection(name, zone,
ssid, auth_mode, passphrase, ssid, auth_mode, passphrase,
ipv4_method, ipv4_address): ipv4_method, ipv4_address):
conn = { conn = {
'connection': { 'connection': {
'id': name, 'id': name,
'type': '802-11-wireless', 'type': '802-11-wireless',
'zone': zone,
'uuid': str(uuid.uuid4()), 'uuid': str(uuid.uuid4()),
}, },
'802-11-wireless': { '802-11-wireless': {