Commit e01052c4 by Bence Dányi

firewall_gui: save new vlans

parent bc2a90c8
......@@ -119,7 +119,7 @@ urlpatterns = patterns('',
url(r'^firewall/rules/new/$', 'firewall_gui.views.show_rule'),
url(r'^firewall/hosts/new/$', 'firewall_gui.views.show_host'),
# url(r'^firewall/vlans/save/$', 'firewall_gui.views.save_vlan'),
url(r'^firewall/vlans/new/$', 'firewall_gui.views.show_vlan'),
# url(r'^firewall/vlangroups/save/$', 'firewall_gui.views.save_vlangroup'),
# url(r'^firewall/hostgroups/save/$', 'firewall_gui.views.save_hostgroup'),
# url(r'^firewall/domains/save/$', 'firewall_gui.views.save_domain'),
......
......@@ -320,46 +320,71 @@ def show_host(request, id=None):
return HttpResponse(json.dumps(host), content_type='application/json')
def show_vlan(request, id):
vlan = get_object_or_404(Vlan, id=id)
vlan = {
'id': vlan.id,
'vid': vlan.vid,
'name': vlan.name,
'ipv4': vlan.ipv4+'/'+str(vlan.prefix4),
'ipv6': vlan.ipv6+'/'+str(vlan.prefix6),
'nat': vlan.snat_ip,
'description': vlan.description,
'comment': vlan.comment,
'reverse_domain': vlan.reverse_domain,
'dhcp_pool': vlan.dhcp_pool,
'interface': vlan.interface,
'created_at': vlan.created_at.isoformat(),
'modified_at': vlan.modified_at.isoformat(),
'owner': {
'name': str(vlan.owner),
'id': vlan.owner.id
} if vlan.owner else None,
'domain': {
'id': vlan.domain.id,
'name': vlan.domain.name,
},
'rules': [{
'id': rule.id,
'direction': rule.get_direction_display(),
'proto': rule.proto,
'owner': {
'id': rule.owner.id,
'name': str(rule.owner),
},
'accept': rule.accept,
'nat': rule.nat
} for rule in vlan.rules.all()],
'vlans': [{
def show_vlan(request, id=None):
try:
vlan = Vlan.objects.get(id=id)
vlan = {
'id': vlan.id,
'vid': vlan.vid,
'name': vlan.name,
} for vlan in vlan.snat_to.all()]
}
'ipv4': vlan.ipv4+'/'+str(vlan.prefix4),
'ipv6': vlan.ipv6+'/'+str(vlan.prefix6),
'nat': vlan.snat_ip,
'description': vlan.description,
'comment': vlan.comment,
'reverse_domain': vlan.reverse_domain,
'dhcp_pool': vlan.dhcp_pool,
'interface': vlan.interface,
'created_at': vlan.created_at.isoformat(),
'modified_at': vlan.modified_at.isoformat(),
'owner': {
'name': str(vlan.owner),
'id': vlan.owner.id
} if vlan.owner else None,
'domain': {
'id': vlan.domain.id,
'name': vlan.domain.name,
},
'rules': [{
'id': rule.id,
'direction': rule.get_direction_display(),
'proto': rule.proto,
'owner': {
'id': rule.owner.id,
'name': str(rule.owner),
},
'accept': rule.accept,
'nat': rule.nat
} for rule in vlan.rules.all()],
'vlans': [{
'id': vlan.id,
'name': vlan.name,
} for vlan in vlan.snat_to.all()]
}
except:
vlan = {
'id': None,
'vid': None,
'name': None,
'ipv4': None,
'ipv6': None,
'nat': '',
'description': '',
'comment': '',
'reverse_domain': '',
'dhcp_pool': '',
'interface': '',
'created_at': None,
'modified_at': None,
'owner': {
'name': None,
},
'domain': {
'name': None,
},
'rules': [],
'vlans': []
}
return HttpResponse(json.dumps(vlan), content_type='application/json')
......@@ -589,9 +614,9 @@ def save_vlan(request):
errors = {}
vlan.vid = data['vid']
vlan.name = data['name']
vlan.ipv4 = data['ipv4'].split('/')[0]
vlan.ipv4 = vlan.net4 = data['ipv4'].split('/')[0]
vlan.prefix4 = data['ipv4'].split('/')[1]
vlan.ipv6 = data['ipv6'].split('/')[0]
vlan.ipv6 = vlan.net6 = data['ipv6'].split('/')[0]
vlan.prefix6 = data['ipv6'].split('/')[1]
vlan.snat_ip = data['nat']
vlan.description = data['description']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment