Commit 4a295ff8 by Bence Dányi

firewall_gui: save rule

parent c0a19e60
...@@ -117,4 +117,6 @@ urlpatterns = patterns('', ...@@ -117,4 +117,6 @@ urlpatterns = patterns('',
url(r'^firewall/autocomplete/firewall/$', 'firewall_gui.views.autocomplete_firewall'), url(r'^firewall/autocomplete/firewall/$', 'firewall_gui.views.autocomplete_firewall'),
url(r'^firewall/autocomplete/domain/$', 'firewall_gui.views.autocomplete_domain'), url(r'^firewall/autocomplete/domain/$', 'firewall_gui.views.autocomplete_domain'),
url(r'^firewall/autocomplete/record/$', 'firewall_gui.views.autocomplete_record'), url(r'^firewall/autocomplete/record/$', 'firewall_gui.views.autocomplete_record'),
url(r'^firewall/rules/save/$', 'firewall_gui.views.save_rule'),
) )
...@@ -236,6 +236,18 @@ function EntityController(url, init) { ...@@ -236,6 +236,18 @@ function EntityController(url, init) {
$scope.destroyed = function(item) { $scope.destroyed = function(item) {
return !item.__destroyed; return !item.__destroyed;
} }
$scope.save = function() {
console.log($scope.entity);
console.log(JSON.stringify($scope.entity));
$.ajax({
url: url + 'save/',
type: 'post',
data: JSON.stringify($scope.entity),
success: function(data) {
console.log(data);
}
})
}
$http.get(url + id + '/').success(function success(data) { $http.get(url + id + '/').success(function success(data) {
$scope.entity = data; $scope.entity = data;
['vlan', 'vlangroup', 'host', 'hostgroup', 'firewall'].forEach(function(t) { ['vlan', 'vlangroup', 'host', 'hostgroup', 'firewall'].forEach(function(t) {
......
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
</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 (nem működik!)</button>
</div> </div>
</div> </div>
</div> </div>
......
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.contrib.auth.models import User
from firewall.fw import * from firewall.fw import *
from firewall.models import * from firewall.models import *
...@@ -425,3 +426,28 @@ def autocomplete_record(request): ...@@ -425,3 +426,28 @@ def autocomplete_record(request):
'id': record.id, 'id': record.id,
'name': record.name 'name': record.name
} for record in Record.objects.filter(name__icontains=request.POST['name'])[:5]]), content_type='application/json') } for record in Record.objects.filter(name__icontains=request.POST['name'])[:5]]), content_type='application/json')
def save_rule(request):
data = json.loads(request.body)
if data['id']:
rule = get_object_or_404(Rule, id=data['id'])
else:
rule = Rule.objects.create()
rule.direction = data['direction']['value']
rule.description = data['description']
rule.dport = data['dport']
rule.sport = data['sport']
rule.proto = data['proto']['value']
rule.extra = data['extra']
rule.accept = data['accept']
rule.owner = get_object_or_404(User, username=data['owner']['name'])
rule.nat = data['nat']
rule.nat_dport = data['nat_dport']
rule.host = get_object_or_404(Host, hostname=data['target']['name']) if data['target']['type'] == 'host' else None
rule.hostgroup = get_object_or_404(Group, name=data['target']['name']) if data['target']['type'] == 'hostgroup' else None
rule.vlan = get_object_or_404(Vlan, name=data['target']['name']) if data['target']['type'] == 'vlan' else None
rule.vlangroup = get_object_or_404(VlanGroup, name=data['target']['name']) if data['target']['type'] == 'vlangroup' else None
rule.firewall = get_object_or_404(Firewall, name=data['target']['name']) if data['target']['type'] == 'firewall' else None
rule.foreign_network = get_object_or_404(VlanGroup, name=data['foreignNetwork']['name'])
rule.save()
return HttpResponse(str(json.loads(request.body)))
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