Commit fece1a96 by Bence Dányi

firewall_gui: allow to crete new vlangroup

parent e01052c4
...@@ -388,65 +388,93 @@ def show_vlan(request, id=None): ...@@ -388,65 +388,93 @@ def show_vlan(request, id=None):
return HttpResponse(json.dumps(vlan), content_type='application/json') return HttpResponse(json.dumps(vlan), content_type='application/json')
def show_vlangroup(request, id): def show_vlangroup(request, id=None):
group = get_object_or_404(VlanGroup, id=id) try:
group = { group = VlanGroup.objects.get(id=id)
'id': group.id, group = {
'name': group.name, 'id': group.id,
'vlans': [{ 'name': group.name,
'id': vlan.id, 'vlans': [{
'name': vlan.name 'id': vlan.id,
} for vlan in group.vlans.all()], 'name': vlan.name
'description': group.description, } for vlan in group.vlans.all()],
'owner': { 'description': group.description,
'id': group.owner.id,
'name': str(group.owner)
},
'created_at': group.created_at.isoformat(),
'modified_at': group.modified_at.isoformat(),
'rules': [{
'id': rule.id,
'direction': rule.get_direction_display(),
'proto': rule.proto,
'owner': { 'owner': {
'id': rule.owner.id, 'id': group.owner.id,
'name': str(rule.owner), 'name': str(group.owner)
}, },
'accept': rule.accept, 'created_at': group.created_at.isoformat(),
'nat': rule.nat 'modified_at': group.modified_at.isoformat(),
} for rule in group.rules.all()] '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 group.rules.all()]
}
except:
group = {
'id': None,
'name': None,
'vlans': [],
'description': '',
'owner': {
'name': None
},
'created_at': None,
'modified_at': None,
'rules': []
}
return HttpResponse(json.dumps(group), content_type='application/json') return HttpResponse(json.dumps(group), content_type='application/json')
def show_hostgroup(request, id): def show_hostgroup(request, id=None):
group = get_object_or_404(Group, id=id) try:
group = { group = get_object_or_404(Group, id=id)
'id': group.id, group = {
'name': group.name, 'id': group.id,
'description': group.description, 'name': group.name,
'owner': { 'description': group.description,
'id': group.owner.id,
'name': str(group.owner),
},
'created_at': group.created_at.isoformat(),
'modified_at': group.modified_at.isoformat(),
'hosts': [{
'id': host.id,
'name': host.hostname
} for host in group.host_set.all()],
'rules': [{
'id': rule.id,
'direction': rule.get_direction_display(),
'proto': rule.proto,
'owner': { 'owner': {
'id': rule.owner.id, 'id': group.owner.id,
'name': str(rule.owner), 'name': str(group.owner),
}, },
'accept': rule.accept, 'created_at': group.created_at.isoformat(),
'nat': rule.nat 'modified_at': group.modified_at.isoformat(),
} for rule in group.rules.all()] 'hosts': [{
} 'id': host.id,
'name': host.hostname
} for host in group.host_set.all()],
'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 group.rules.all()]
}
except:
group = {
'id': None,
'name': None,
'description': '',
'owner': {
'name': None,
},
'created_at': None,
'modified_at': None,
'hosts': [],
'rules': []
}
return HttpResponse(json.dumps(group), content_type='application/json') return HttpResponse(json.dumps(group), content_type='application/json')
def show_record(request, id): def show_record(request, id):
......
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