Commit e9a40a29 by Bence Dányi

firewall_gui: validate Rule fields

parent a7d77040
...@@ -452,17 +452,21 @@ def save_rule(request): ...@@ -452,17 +452,21 @@ def save_rule(request):
rule.proto = data['proto']['value'] rule.proto = data['proto']['value']
rule.extra = data['extra'] rule.extra = data['extra']
rule.accept = data['accept'] rule.accept = data['accept']
rule.owner = get_object_or_error(User, errors, username=data['owner']['name'])
rule.nat = data['nat'] rule.nat = data['nat']
rule.nat_dport = data['nat_dport'] rule.nat_dport = data['nat_dport']
rule.host = get_object_or_error(Host, errors, hostname=data['target']['name']) if data['target']['type'] == 'host' else None set_field(rule, 'owner', errors, username=data['owner']['name'])
rule.hostgroup = get_object_or_error(Group, errors, name=data['target']['name']) if data['target']['type'] == 'hostgroup' else None for attr in ['host', 'hostgroup', 'vlan', 'vlangroup', 'firewall']:
rule.vlan = get_object_or_error(Vlan, errors, name=data['target']['name']) if data['target']['type'] == 'vlan' else None searchBy = 'name' if attr != 'host' else 'hostname'
rule.vlangroup = get_object_or_error(VlanGroup, errors, name=data['target'][ if data['target']['type'] == attr:
'name']) if data['target']['type'] == 'vlangroup' else None set_field(rule, attr, errors, **{searchBy: data['target']['name']})
rule.firewall = get_object_or_error(Firewall, errors, name=data['target']['name']) if data['target']['type'] == 'firewall' else None else:
rule.foreign_network = get_object_or_error(VlanGroup, errors, name=data['foreignNetwork']['name']) setattr(rule, attr, None)
set_field(rule, 'foreign_network', errors, name=data['foreignNetwork']['name'])
if len(errors) > 0: if len(errors) > 0:
return HttpResponse(json.dumps(errors), content_type='application/json', status=404) return HttpResponse(json.dumps(errors), content_type='application/json', status=404)
try:
rule.full_clean()
except Exception as e:
return HttpResponse(json.dumps(e.message_dict), content_type='application/json', status=409)
rule.save() rule.save()
return HttpResponse('KTHXBYE') return HttpResponse('KTHXBYE')
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