Commit 479d49b1 by Bach Dániel

firewall: blacklist api added

parent 6df60690
...@@ -328,6 +328,12 @@ class Blacklist(models.Model): ...@@ -328,6 +328,12 @@ class Blacklist(models.Model):
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True) modified_at = models.DateTimeField(auto_now=True)
def save(self, *args, **kwargs):
self.full_clean()
super(Blacklist, self).save(*args, **kwargs)
def __unicode__(self):
return self.ipv4
def send_task(sender, instance, created, **kwargs): def send_task(sender, instance, created, **kwargs):
from firewall.tasks import ReloadTask from firewall.tasks import ReloadTask
ReloadTask.apply_async(args=[sender.__name__]) ReloadTask.apply_async(args=[sender.__name__])
......
...@@ -39,6 +39,14 @@ def firewall_api(request): ...@@ -39,6 +39,14 @@ def firewall_api(request):
if data["password"] != "bdmegintelrontottaanetet": if data["password"] != "bdmegintelrontottaanetet":
raise Exception(_("Wrong password.")) raise Exception(_("Wrong password."))
if command == "blacklist":
obj, created = Blacklist.objects.get_or_create(ipv4=data["ip"])
if created:
obj.reason=data["reason"]
obj.snort_message=data["snort_message"]
obj.save()
return HttpResponse(_("OK"));
if not (data["vlan"] == "vm-net" or data["vlan"] == "war"): if not (data["vlan"] == "vm-net" or data["vlan"] == "war"):
raise Exception(_("Only vm-net and war can be used.")) raise Exception(_("Only vm-net and war can be used."))
...@@ -75,7 +83,6 @@ def firewall_api(request): ...@@ -75,7 +83,6 @@ def firewall_api(request):
else: else:
raise Exception(_("Unknown command.")) raise Exception(_("Unknown command."))
reload_firewall_lock()
except (ValidationError, IntegrityError, AttributeError, Exception) as e: except (ValidationError, IntegrityError, AttributeError, Exception) as e:
return HttpResponse(_("Something went wrong!\n%s\n") % e); return HttpResponse(_("Something went wrong!\n%s\n") % e);
except: except:
......
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