Commit f99474fe by Bence Dányi

firewall_gui: save vlan/hostgroup details

parent 6ec6913c
...@@ -108,4 +108,6 @@ urlpatterns = patterns('', ...@@ -108,4 +108,6 @@ urlpatterns = patterns('',
url(r'^firewall/rules/save/$', 'firewall_gui.views.save_rule'), url(r'^firewall/rules/save/$', 'firewall_gui.views.save_rule'),
url(r'^firewall/hosts/save/$', 'firewall_gui.views.save_host'), url(r'^firewall/hosts/save/$', 'firewall_gui.views.save_host'),
url(r'^firewall/vlans/save/$', 'firewall_gui.views.save_vlan'), url(r'^firewall/vlans/save/$', 'firewall_gui.views.save_vlan'),
url(r'^firewall/vlangroups/save/$', 'firewall_gui.views.save_vlangroup'),
url(r'^firewall/hostgroups/save/$', 'firewall_gui.views.save_hostgroup'),
) )
...@@ -18,30 +18,33 @@ ...@@ -18,30 +18,33 @@
<input class="input" type="text" id="modified_at" ng-model="entity.modified_at" disabled="disabled"> <input class="input" type="text" id="modified_at" ng-model="entity.modified_at" disabled="disabled">
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group" ng-class="hasError('name')">
<label class="control-label" for="name">Name</label> <label class="control-label" for="name">Name</label>
<div class="controls"> <div class="controls">
<input type="text" id="name" ng-model="entity.name" /> <input type="text" id="name" ng-model="entity.name" />
<span class="help-inline" ng-bind="getError('name')"></span>
</div> </div>
</div> </div>
</div> </div>
<div class="span5"> <div class="span5">
<div class="control-group"> <div class="control-group" ng-class="hasError('owner')">
<label class="control-label" for="owner">Owner</label> <label class="control-label" for="owner">Owner</label>
<div class="controls"> <div class="controls">
<input type="text" autocomplete="off" id="owner" ng-model="entity.owner.name" /> <input type="text" autocomplete="off" id="owner" ng-model="entity.owner.name" />
<span class="help-inline" ng-bind="getError('owner')"></span>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group" ng-class="hasError('description')">
<label class="control-label" for="description">Description</label> <label class="control-label" for="description">Description</label>
<div class="controls"> <div class="controls">
<textarea rows="4" id="description" ng-model="entity.description"> <textarea rows="4" id="description" ng-model="entity.description">
<span class="help-inline" ng-bind="getError('description')"></span>
</textarea> </textarea>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<div class="controls"> <div class="controls">
<button type="submit" class="btn">Save (nem működik!)</button> <button type="submit" class="btn" ng-click="save()">Save</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -18,28 +18,31 @@ ...@@ -18,28 +18,31 @@
<input class="input" type="text" id="modified_at" ng-model="entity.modified_at" disabled="disabled"> <input class="input" type="text" id="modified_at" ng-model="entity.modified_at" disabled="disabled">
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group" ng-class="hasError('name')">
<label class="control-label" for="name">Name</label> <label class="control-label" for="name">Name</label>
<div class="controls"> <div class="controls">
<input type="text" id="name" ng-model="entity.name" /> <input type="text" id="name" ng-model="entity.name" />
<span class="help-inline" ng-bind="getError('name')"></span>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group" ng-class="hasError('owner')">
<label class="control-label" for="owner">Owner</label> <label class="control-label" for="owner">Owner</label>
<div class="controls"> <div class="controls">
<input type="text" autocomplete="off" id="owner" ng-model="entity.owner.name" /> <input type="text" autocomplete="off" id="owner" ng-model="entity.owner.name" />
<span class="help-inline" ng-bind="getError('owner')"></span>
</div> </div>
</div> </div>
</div> </div>
<div class="span5"> <div class="span5">
<div class="control-group"> <div class="control-group" ng-class="hasError('description')">
<label class="control-label" for="description">Description</label> <label class="control-label" for="description">Description</label>
<div class="controls"> <div class="controls">
<textarea rows="2" id="description" ng-model="entity.description"> <textarea rows="2" id="description" ng-model="entity.description">
</textarea> </textarea>
<span class="help-inline" ng-bind="getError('description')"></span>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group" ng-class="hasError('vlangroups')">
<label class="control-label" for="vlangroups">Vlans</label> <label class="control-label" for="vlangroups">Vlans</label>
<div class="controls"> <div class="controls">
<div class="well well-small"> <div class="well well-small">
...@@ -51,12 +54,13 @@ ...@@ -51,12 +54,13 @@
<div class="input-append"> <div class="input-append">
<input class="span2 vlan" id="vlan" type="text" data-provide="typeahead"> <input class="span2 vlan" id="vlan" type="text" data-provide="typeahead">
<button class="btn" type="button">Add</button> <button class="btn" type="button">Add</button>
<span class="help-inline" ng-bind="getError('vlangroups')"></span>
</div> </div>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<div class="controls"> <div class="controls">
<button type="submit" class="btn">Save (nem működik!)</button> <button type="submit" class="btn" ng-click="save()">Save</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -459,6 +459,7 @@ def save_host(request): ...@@ -459,6 +459,7 @@ def save_host(request):
host.save() host.save()
return HttpResponse('KTHXBYE') return HttpResponse('KTHXBYE')
@user_passes_test(req_staff)
def save_vlan(request): def save_vlan(request):
data = json.loads(request.body) data = json.loads(request.body)
if data['id']: if data['id']:
...@@ -488,3 +489,45 @@ def save_vlan(request): ...@@ -488,3 +489,45 @@ def save_vlan(request):
return HttpResponse(json.dumps(errors), content_type='application/json', status=400) return HttpResponse(json.dumps(errors), content_type='application/json', status=400)
vlan.save() vlan.save()
return HttpResponse('KTHXBYE') return HttpResponse('KTHXBYE')
@user_passes_test(req_staff)
def save_vlangroup(request):
data = json.loads(request.body)
if data['id']:
vlangroup = get_object_or_404(VlanGroup, id=data['id'])
else:
vlangroup = VlanGroup.objects.create()
errors = {}
vlangroup.name = data['name']
vlangroup.description = data['description']
# TODO: save vlans
set_field(vlangroup, 'owner', errors, username=data['owner']['name'])
try:
vlangroup.full_clean()
except Exception as e:
errors = dict(errors.items() + e.message_dict.items())
if len(errors) > 0:
return HttpResponse(json.dumps(errors), content_type='application/json', status=400)
vlangroup.save()
return HttpResponse('KTHXBYE')
@user_passes_test(req_staff)
def save_hostgroup(request):
data = json.loads(request.body)
if data['id']:
hostgroup = get_object_or_404(Group, id=data['id'])
else:
hostgroup = Group.objects.create()
errors = {}
hostgroup.name = data['name']
hostgroup.description = data['description']
# TODO: save hosts
set_field(hostgroup, 'owner', errors, username=data['owner']['name'])
try:
hostgroup.full_clean()
except Exception as e:
errors = dict(errors.items() + e.message_dict.items())
if len(errors) > 0:
return HttpResponse(json.dumps(errors), content_type='application/json', status=400)
hostgroup.save()
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